Flutter ExpansionTile 标题垂直填充
Flutter ExpansionTile title vertical padding
如何删除 ExpansionTile 中前导 Widget 的垂直填充,使其看起来像下面的 ListTile?
这是我的代码:
Container(
decoration: BoxDecoration(
border: Border.all(color: Color.fromRGBO(200, 200, 200, 1), width: 2),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: ListTileTheme(
contentPadding: EdgeInsets.zero,
dense: true,
child: ExpansionTile(
childrenPadding: EdgeInsets.zero,
tilePadding: EdgeInsets.zero,
title: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text(Constants.texts.chooseFromList,
style: Constants.textStyles.lightGreyMediumSize),
),
children: [
Text('One'),
Text('Two'),
Text('Three'),
],
trailing: Image.asset(
'assets/icons/snn_app_ubytovanie_filter_open_button_merged_idle_crop.png',
)),
),
)
其下的ListTile代码如下:
Container(
decoration: BoxDecoration(
border: Border.all(
color: Color.fromRGBO(200, 200, 200, 1), width: 2),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: ListTileTheme(
contentPadding: EdgeInsets.zero,
dense: true,
child: ListTile(
title: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text("Here it works!",
style: Constants.textStyles.lightGreyMediumSize),
),
trailing: Image.asset(
'assets/icons/snn_app_ubytovanie_filter_open_button_merged_idle_crop.png',
),
),
),
)
我已经从 flutter repo 复制并重构了 ExpansionTile 的源代码,但我似乎无法弄清楚是什么导致了填充。非常感谢任何建议。
好的,所以我发现原始 ExpansionTile 源代码中的间隙实际上是透明边框:
Container(
decoration: BoxDecoration(
color: _backgroundColor.value ?? Colors.transparent,
border: Border(
top: BorderSide(color: borderSideColor),
bottom: BorderSide(color: borderSideColor),
),
),
虽然它从 backgroundColor 参数派生它的颜色,但我发现解决我的问题的唯一解决方法是编辑原始 ExpansionTile 的源代码并删除 BoxDecoration。希望这对遇到同样问题的人有所帮助。
如何删除 ExpansionTile 中前导 Widget 的垂直填充,使其看起来像下面的 ListTile?
这是我的代码:
Container(
decoration: BoxDecoration(
border: Border.all(color: Color.fromRGBO(200, 200, 200, 1), width: 2),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: ListTileTheme(
contentPadding: EdgeInsets.zero,
dense: true,
child: ExpansionTile(
childrenPadding: EdgeInsets.zero,
tilePadding: EdgeInsets.zero,
title: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text(Constants.texts.chooseFromList,
style: Constants.textStyles.lightGreyMediumSize),
),
children: [
Text('One'),
Text('Two'),
Text('Three'),
],
trailing: Image.asset(
'assets/icons/snn_app_ubytovanie_filter_open_button_merged_idle_crop.png',
)),
),
)
其下的ListTile代码如下:
Container(
decoration: BoxDecoration(
border: Border.all(
color: Color.fromRGBO(200, 200, 200, 1), width: 2),
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: ListTileTheme(
contentPadding: EdgeInsets.zero,
dense: true,
child: ListTile(
title: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text("Here it works!",
style: Constants.textStyles.lightGreyMediumSize),
),
trailing: Image.asset(
'assets/icons/snn_app_ubytovanie_filter_open_button_merged_idle_crop.png',
),
),
),
)
我已经从 flutter repo 复制并重构了 ExpansionTile 的源代码,但我似乎无法弄清楚是什么导致了填充。非常感谢任何建议。
好的,所以我发现原始 ExpansionTile 源代码中的间隙实际上是透明边框:
Container(
decoration: BoxDecoration(
color: _backgroundColor.value ?? Colors.transparent,
border: Border(
top: BorderSide(color: borderSideColor),
bottom: BorderSide(color: borderSideColor),
),
),
虽然它从 backgroundColor 参数派生它的颜色,但我发现解决我的问题的唯一解决方法是编辑原始 ExpansionTile 的源代码并删除 BoxDecoration。希望这对遇到同样问题的人有所帮助。