【问题标题】:Can you change the height of an ExpansionTile in Flutter?你可以在 Flutter 中更改 ExpansionTile 的高度吗?
【发布时间】:2018-03-08 01:04:36
【问题描述】:

ExpansionTile 继承自具有固定高度的ListTile。瓦片高度没有输入参数。

我尝试将 ExpansionTile 包装在具有硬编码高度的 Container 小部件中,但这会导致子小部件仅占用硬编码高度内的空间。目前,由于title 小部件中的内容很大,我有一个“列溢出23 像素”的消息。

有什么方法可以改变扩展图块的高度吗?或者是否有另一个我可以使用的具有扩展/手风琴功能的小部件?

【问题讨论】:

    标签: widget accordion flutter


    【解决方案1】:

    我可能会复制ExpansionTile 并制作您自己的版本。使用ContainerSizedBox 调整ListTile 的大小很容易,但ExpansionTile 是一个材质小部件,它看起来不像是根据您的用例构建的。

    【讨论】:

    • 如何调整 ListTile 的大小?
    【解决方案2】:

    你可能想试试这个包:configurable_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")],
                    )
                  ],
                )
              ],
            ),
          ),
        );
      }
    }
    

    它应该可以得到你想要的结果。

    希望对你有帮助,

    谢谢

    【讨论】:

    【解决方案3】:

    这是一种解决方法:您可以使用 ExpansionTile 小部件的 title 来呈现整个内容,而不是使用前导或尾随。您可以向标题小部件添加填充以增加 ExpansionTile 的高度。

    【讨论】:

      猜你喜欢
      • 2019-12-17
      • 2023-03-15
      • 2021-11-07
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多