我试着用里面有Column的ClipRect,但是好像不太好用.
我想要实现的是裁剪该列的内容,并在存在溢出时显示一条文本消息(如果该列的内容无法在可用空间内显示).
你有什么建议吗?我怎样才能做到这一点?
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,
children: [
ClipRect(
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."),
),
),
],
),
),
);
}
}