Created
May 1, 2021 08:47
-
-
Save Lootwig/95967e6fe54a5ceee387f4da44e84a13 to your computer and use it in GitHub Desktop.
Column inside ClipRect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return SizedBox( | |
width: 200, | |
child: ClipRect( | |
clipper: RectClipper(), | |
child: Container( | |
width: 10000, | |
child: Column(children: [ | |
Text( | |
'This line is longer than 200 units and should simply be clipped, not wrapped, using the 10000 units allocated by its parent cointainer. Note that instead of a text widget, where this could be achieved with maxLines and overflow, the behavior should work on an arbitrary widget that does not have these properties.'), | |
]), | |
), | |
), | |
); | |
} | |
} | |
class RectClipper extends CustomClipper<Rect> { | |
@override | |
Rect getClip(Size size) { | |
return Rect.fromLTRB(0, 0, size.width, size.height); | |
} | |
@override | |
bool shouldReclip(covariant CustomClipper<Rect> oldClipper) { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment