如何在Flutter中绘制可扩展和可折叠的侧边栏菜单?

时间:2019-11-07 10:16:12

标签: flutter navigation-drawer expansion

尽管我是Flutter的新手,但现在我正在克隆在互联网上看到的网站的可扩展和可折叠侧边栏菜单。

我的尝试

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  final appTitle = 'Drawer Demo';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: appTitle,
      home: MyHomePage(title: appTitle),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;

  MyHomePage({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(title)),
      body: Center(child: Text('Dashboard')),
      drawer: Drawer(
  child: ListView(
    children: <Widget>[
      Text('Dashboard'),
      ExpansionTile(
        title: Text("User management"),
        children: <Widget>[Text("Users"), 
        Text("Add user"),
        Text("Migrate users")
        ],
      ),
      ExpansionTile(
        title: Text("Remittance management"),
        children: <Widget>[Text("Add remittance"), 
        Text("Trace remittance"),
        Text("Remittance history"),
        Text("Search remittances"),
        Text("Online remittance requests")
        ],
      )
    ],
  ),
),
    );
  }
}

代码输出

enter image description here

必需的输出

enter image description here

尊敬的成员,有什么帮助吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

使用ExpansionPanelList()包装您的ExpansionPanels