Want to detect content overflow and clip it in flutter? You shouldn’t use ClipRect for your goals. Please try to add overflow parameter Overflow.clip to Stack widget.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import 'package:flutter/material.dart'; void main() => runApp(ContentOverflowDetectionApp()); class ContentOverflowDetectionApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text("Overflow detection"), ), body: Stack( fit: StackFit.expand, overflow: Overflow.clip, children: [ Positioned( top: 0, child: Column( children: [ Container( width: 300, height: 400, color: Colors.green[200], child: Text('first widget'), ), Container( width: 350, height: 350, color: Colors.yellow[200], child: Text('overflowed widget'), ), ], ), ), Positioned( child: Align( alignment: FractionalOffset.bottomCenter, child: Text("SHOW THIS TEXT ONLY IF CONTENT HAS OVERFLOWED."), ), ), ], ), ), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.