【问题标题】:Creating flutter expandable with toggle button使用切换按钮创建可扩展的颤振
【发布时间】:2020-04-24 16:38:43
【问题描述】:

我在 Flutter 中实现 UI 设计时遇到了一些困难。我想做一个这样的扩展小部件,我能提供线索吗?

折叠

扩展

我曾尝试使用Expandable,但我无法让它看起来像我的设计。谢谢

【问题讨论】:

    标签: android flutter flutter-layout


    【解决方案1】:

    您可以使用AnimatedContainer

    例如:

    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      bool expanded = false;
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: Text('Example')),
          body: Column(
            children: [
              Container(color: Colors.green, height: 100),
              AnimatedContainer(
                duration: const Duration(milliseconds: 200),
                height: expanded ? 120 : 0,
                child: Container(height: 120, color: Colors.red),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  FloatingActionButton(
                    child:
                        Icon(expanded ? Icons.arrow_upward : Icons.arrow_downward),
                    onPressed: () => setState(() {
                      expanded = !expanded;
                    }),
                  ),
                ],
              ),
            ],
          ),
        );
      }
    }
    
    
    

    【讨论】:

      猜你喜欢
      • 2021-01-31
      • 2014-09-21
      • 2022-08-19
      • 1970-01-01
      • 2017-10-13
      • 2021-06-02
      • 2023-01-03
      • 2021-10-05
      相关资源
      最近更新 更多