小部件之间的 Flutter 减少 space
Flutter reduce space between widgets
我尝试显示一个 ExpansionTile,其中包含一些文本,后跟一个图像。参考屏幕截图,您可以看到两个小部件之间有一些 space。有人知道我怎样才能减少这个 space 吗?
class Test extends StatelessWidget {
const Test({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: backGround,
appBar: AppBar(
title: const Text('Aromatics'),
backgroundColor: appbarColor,
),
body: Column(
children: [
ExpansionTile(
iconColor: titleColor,
title: const Text('Tst', style: TextStyle(color: titleColor)),
subtitle: const Text('Test subtitle',
style: TextStyle(color: Colors.white)),
children: [
Container(
margin: const EdgeInsets.only(left: 20),
child: Column(
children: const [
Text('Test text',
style:
TextStyle(color: Colors.white, fontSize: 13)),
],
),
),
]),
const SizedBox(
height: 1,
),
Expanded(
child: Image.asset('assets/images/test.webp'),
),
],
));
}
}
根据 ExpansionTile Doc,您可以使用 childrenPadding
来管理子部件的填充
Specifies padding for children.
If this property is null then ExpansionTileThemeData.childrenPadding is used. If that is also null then the value of childrenPadding is EdgeInsets.zero.
只需删除图像周围的 Expanded
小部件,因为它占用了图像 Column
中的所有剩余 space。
当前代码:
Column(
children: [
...
Expanded(
child: Image.asset('assets/images/test.webp'),
),
...
],
),
新代码:
Column(
children: [
...
Image.asset('assets/images/test.webp'),
...
],
),```
移除 Expanded
不符合您的目标吗?
...
const SizedBox(
height: 1,
),
Image.asset('assets/images/test.webp'),
...
我尝试显示一个 ExpansionTile,其中包含一些文本,后跟一个图像。参考屏幕截图,您可以看到两个小部件之间有一些 space。有人知道我怎样才能减少这个 space 吗?
class Test extends StatelessWidget {
const Test({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: backGround,
appBar: AppBar(
title: const Text('Aromatics'),
backgroundColor: appbarColor,
),
body: Column(
children: [
ExpansionTile(
iconColor: titleColor,
title: const Text('Tst', style: TextStyle(color: titleColor)),
subtitle: const Text('Test subtitle',
style: TextStyle(color: Colors.white)),
children: [
Container(
margin: const EdgeInsets.only(left: 20),
child: Column(
children: const [
Text('Test text',
style:
TextStyle(color: Colors.white, fontSize: 13)),
],
),
),
]),
const SizedBox(
height: 1,
),
Expanded(
child: Image.asset('assets/images/test.webp'),
),
],
));
}
}
根据 ExpansionTile Doc,您可以使用 childrenPadding
来管理子部件的填充
Specifies padding for children. If this property is null then ExpansionTileThemeData.childrenPadding is used. If that is also null then the value of childrenPadding is EdgeInsets.zero.
只需删除图像周围的 Expanded
小部件,因为它占用了图像 Column
中的所有剩余 space。
当前代码:
Column(
children: [
...
Expanded(
child: Image.asset('assets/images/test.webp'),
),
...
],
),
新代码:
Column(
children: [
...
Image.asset('assets/images/test.webp'),
...
],
),```
移除 Expanded
不符合您的目标吗?
...
const SizedBox(
height: 1,
),
Image.asset('assets/images/test.webp'),
...