【问题标题】:I can't find widget to fold or expand children widget我找不到要折叠或展开子小部件的小部件
【发布时间】:2022-11-16 15:15:28
【问题描述】:

很抱歉因为先注册无法上传图像。所以我得到了链接

https://getbootstrap.com/docs/3.3/javascript/#collapse

喜欢这个功能,

我想在平时制作一个小部件,只有父小部件显示它的形状, 但是如果我按下父窗口小部件,它的子窗口小部件会在其形状下显示它们的形状。 但我找不到一个小部件来获得这个功能。 你能告诉我这个小部件吗? 或者我可以用动画解决这个问题吗?

我找 StackOverflow,flutter 文档。但我找不到

【问题讨论】:

    标签: flutter dart widget collapse folding


    【解决方案1】:

    您可以为此使用 ExpansionTile Widget。参考下面的代码希望它能帮助你。

    ExpansionTile(
              title: Text('Collapsible Group Item #1'),
              children: <Widget>[
                ListTile(
                  title: Text(
                    'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus'
                    'terry richardson ad squid. 3 wolf moon officia aute,'
                    'non cupidatat skateboard dolor brunch. Food truck quinoa'
                    'nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put'
                    'a bird on it squid single-origin coffee nulla assumenda shoreditch et.'
                    'Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred'
                    'nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo.'
                    'Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt'
                    'you probably havent heard of them accusamus labore sustainable VHS.',
                  ),
                ),
              ],
            ),
    

    完整代码:

    import 'package:flutter/material.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      static const String _title = 'Flutter Code Sample';
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          title: _title,
          home: Scaffold(
            appBar: AppBar(title: const Text(_title)),
            body: const MyStatefulWidget(),
          ),
        );
      }
    }
    
    class MyStatefulWidget extends StatefulWidget {
      const MyStatefulWidget({Key? key}) : super(key: key);
    
      @override
      State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
    }
    
    class _MyStatefulWidgetState extends State<MyStatefulWidget> {
      bool _customTileExpanded = false;
    
      @override
      Widget build(BuildContext context) {
        return const ExpansionTile(
          title: Text('Collapsible Group Item #1'),
          children: <Widget>[
            ListTile(
              title: Text(
                'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus'
                'terry richardson ad squid. 3 wolf moon officia aute,'
                'non cupidatat skateboard dolor brunch. Food truck quinoa'
                'nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put'
                'a bird on it squid single-origin coffee nulla assumenda shoreditch et.'
                'Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred'
                'nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo.'
                'Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt'
                'you probably havent heard of them accusamus labore sustainable VHS.',
              ),
            ),
          ],
        );
      }
    }
    

    你可以在Dartpad上测试你的代码

    你的结果屏幕->

    【讨论】:

    • 谢谢。我想点击有用的按钮,但我没有得到 15point?所以..我很抱歉,但谢谢你,这是我想要找到的
    • @idkanything 欢迎,不用担心,尽情享受你的旅程吧
    猜你喜欢
    • 1970-01-01
    • 2013-06-12
    • 1970-01-01
    • 2021-05-18
    • 2020-01-02
    • 1970-01-01
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多