Mar*_*ary 5 widget accordion flutter
所述ExpansionTile从继承ListTile,它有一个固定的高度。瓷砖高度没有输入参数。
我尝试将 ExpansionTile 包装在具有硬编码高度的 Container 小部件中,但这会导致子小部件仅占用硬编码高度内的空间。目前,由于title小部件中的内容很大,我有一条“列溢出 23 像素”消息。
有没有办法改变扩展瓷砖的高度?或者我可以使用另一个具有扩展/手风琴功能的小部件吗?
我可能会复制ExpansionTile并制作您自己的版本。使用或ListTile可以轻松调整大小,但它是一个材质小部件,它看起来不像是根据您的用例构建的。ContainerSizedBoxExpansionTile
小智 6
在 2023 年遇到了这个,事实证明ListTile可以通过主题来“控制”。
/// Whether this list tile is part of a vertically dense list.
///
/// If this property is null then its value is based on [ListTileTheme.dense].
///
/// Dense list tiles default to a smaller height.
///
/// It is not recommended to set [dense] to true when [ThemeData.useMaterial3] is true.
final bool? dense;
Run Code Online (Sandbox Code Playgroud)
在库的深处你可以找到这段代码:
double get _defaultTileHeight {
final bool hasSubtitle = subtitle != null;
final bool isTwoLine = !isThreeLine && hasSubtitle;
final bool isOneLine = !isThreeLine && !hasSubtitle;
final Offset baseDensity = visualDensity.baseSizeAdjustment;
if (isOneLine) {
return (isDense ? 48.0 : 56.0) + baseDensity.dy;
}
if (isTwoLine) {
return (isDense ? 64.0 : 72.0) + baseDensity.dy;
}
return (isDense ? 76.0 : 88.0) + baseDensity.dy;
}
Run Code Online (Sandbox Code Playgroud)
所以只需将其包裹ExpansionTile在 a 中Theme并设置dense: true
Theme(
data: Theme.of(context).copyWith(
listTileTheme: ListTileTheme.of(context).copyWith(
dense: true,
),
),
child: ExpansionTile(...),
),
Run Code Online (Sandbox Code Playgroud)
虽然不是完全控制,但 的高度48正是我正在寻找的值。
| 归档时间: |
|
| 查看次数: |
8423 次 |
| 最近记录: |