Skip to content

Instantly share code, notes, and snippets.

@Lootwig
Created May 1, 2021 08:47
Show Gist options
  • Save Lootwig/95967e6fe54a5ceee387f4da44e84a13 to your computer and use it in GitHub Desktop.
Save Lootwig/95967e6fe54a5ceee387f4da44e84a13 to your computer and use it in GitHub Desktop.
Column inside ClipRect
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