[英]Can you change the height of an ExpansionTile in Flutter?
ExpansionTile<\/a>继承自具有固定高度的ListTile<\/a> 。 瓷砖高度没有输入参数。
我尝试将 ExpansionTile 包装在具有硬编码高度的 Container 小部件中,但这会导致子小部件仅占用硬编码高度内的空间。 目前,由于
title<\/code>小部件中的内容很大,我有一个“列溢出 23 像素”消息。
有什么方法可以改变扩展瓦片的高度吗? 或者是否有另一个我可以使用的具有扩展\/手风琴功能的小部件?
我可能会复制ExpansionTile
并制作自己的版本。 使用Container
或SizedBox
调整ListTile
大小很容易,但ExpansionTile
是一个材质小部件,它看起来不像是在考虑您的用例的情况下构建的。
你可能想试试这个包: configuration_expansion_tile
示例应用程序:
import 'package:flutter/material.dart';
import 'package:configurable_expansion_tile/configurable_expansion_tile.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Configurable Expansion Tile Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Configurable Expansion Tile Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ConfigurableExpansionTile(
borderColorStart: Colors.blue,
borderColorEnd: Colors.orange,
animatedWidgetFollowingHeader: const Icon(
Icons.expand_more,
color: const Color(0xFF707070),
),
headerExpanded:
Flexible(child: Center(child: Text("A Header Changed"))),
header: Container(
color: Colors.transparent,
child: Center(child: Text("A Header"))),
headerBackgroundColorStart: Colors.grey,
expandedBackgroundColor: Colors.amber,
headerBackgroundColorEnd: Colors.teal,
children: [
Row(
children: <Widget>[Text("CHILD 1")],
),
Row(
children: <Widget>[Text("CHILD 2")],
)
],
)
],
),
),
);
}
}
它应该让你得到你想要的结果。
希望有帮助,
谢谢
这是一种解决方法:您可以使用 ExpansionTile 小部件的标题来呈现整个内容,而不是使用前导或尾随。 您可以向标题小部件添加填充以增加 ExpansionTile 的高度。
将“ExpansionTile”包裹在“Container”中并设置边距
Container(
margin: EdgeInsets.only(right: .5.sw),
decoration: BoxDecoration(
color: AppColor.profileBoarderColor,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: AppColor.profileBoarderColor)
),
child: ExpansionTile(
title: AppTextView(text: 'Seeson 01',),
children: List.generate(10, (index) {
return SizedBox(
width: 200,
child: ListTile(title: AppTextView(text: 'Seeson 01',),));
}
),
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.