【发布时间】:2019-08-01 04:15:09
【问题描述】:
我正在尝试使用 ClipRect 并在其中使用 Column,但它似乎效果不佳。
我想要实现的是剪辑列的内容并在溢出时显示一条文本消息(如果列的内容无法在可用空间内显示)。
你有什么建议可以让我实现它吗?
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."),
),
),
],
),
),
);
}
}
【问题讨论】:
-
您可以使用“SingleChildScrollView”而不是“列”
-
恐怕我不需要滚动。此外,如果示例中的“Column”考虑到它支持子而不是子列,那么我不太明白如何使用“SingleChildScrollView”代替。