颤振中的不同导航栏

时间:2021-07-03 03:16:13

标签: android flutter dart user-interface

1

当我点击图片中我用红色绘制的地方时,我是否可以打开带有图标的页面,例如 Instagram 上的底部导航栏,但我希望我的页面像图片中那样

1 个答案:

答案 0 :(得分:1)

你需要做的是:

  • 为您的脚手架添加一个抽屉
  • 向您的小部件添加一个 GlobalKey,您将使用它来打开抽屉
  • 如果您不想要它,请删除 AppBar 菜单按钮
  • 添加按钮并将其放置在您的身体中
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;
  //Add GlobalKey which you will use to open the drawer
  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //Set GlobalKey
      key: _scaffoldKey,
   

      appBar: AppBar(title: Text(title), 
      //This will remove the AppBar menu button
      automaticallyImplyLeading: false,),
      body:
      Center(child: 
      Container(
        width: double.infinity,
        alignment: Alignment.centerLeft,
        child: InkWell(
          //This function will open the Side Menu
          onTap: ()=> _scaffoldKey.currentState?.openDrawer()
          ,
                  child: Icon(
            Icons.menu,
            size: 20,
          ),
        ),
      ),
            ),
      //Add Drawer to your Scaffold
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            DrawerHeader(
              decoration: BoxDecoration(
                color: Colors.blue,
              ),
              child: Text('Drawer Header'),
            ),
            ListTile(
              title: Text('Item 1'),
              onTap: () {
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: Text('Item 2'),
              onTap: () {
                Navigator.pop(context);
              },
            ),
          ],
        ),
      ),
    );
  }
}