1. FittedBox
FittedBox
是一个用于调整子元素大小和形状以适应其父容器的Box Widget
,它可以将子容器的大小和形状根据需要进行缩放或裁剪,以适应其父容器的大小和形状
const FittedBox({
super.key,
this.fit = BoxFit.contain, // 适配方式
this.alignment = Alignment.center, // 对齐方式
this.clipBehavior = Clip.none, // 是否剪裁
super.child,
});
@override
Widget build(BuildContext context) {
return Center(
child: Column(
children: [
wRow(' 90000000000000001 '),
FittedBox(child: wRow(' 90000000000000000001 ')),
wRow(' 801 '),
FittedBox(child: wRow(' 801 '),)
],
),
);
}
Widget wRow(String text) {
Widget child = Text(text);
child = Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
child,
child,
child
],
);
return child;
}