Flutter

Flutter(二十一)Scaffold

2019-07-17  本文已影响5人  天色将变

Scaffold是Flutter提供的一个组合widget内部封装了常用的控件

属性
image.png
class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 1;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        //导航栏
        title: Text("Scaffold"),
        actions: <Widget>[
          //导航栏右侧菜单
          IconButton(icon: Icon(Icons.add_alarm), onPressed: () {}),
        ],
      ),
      drawer: new MyDrawer(), //左边抽屉
      endDrawer: new MyDrawer(),// 右边抽屉
      bottomNavigationBar: BottomNavigationBar(
        // 底部导航
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
              icon: Icon(Icons.access_alarms), title: Text('alarm')),
          BottomNavigationBarItem(
              icon: Icon(Icons.search), title: Text('search')),
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('home')),
          BottomNavigationBarItem(icon: Icon(Icons.edit), title: Text('edit')),
        ],
        type: BottomNavigationBarType.fixed,
        currentIndex: _selectedIndex,
        fixedColor: Colors.blue,
        onTap: onTap,
      ),
      floatingActionButton: FloatingActionButton(
          //悬浮按钮
          child: Icon(Icons.add),
          onPressed: _onAdd),
      //floatingActionButton 的位置
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,// 按钮居中,
//      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
//      floatingActionButtonLocation: FloatingActionButtonLocation.startTop,
//      floatingActionButtonLocation: FloatingActionButtonLocation.miniStartTop,
//      floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
//      floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
//      floatingActionButtonLocation: FloatingActionButtonLocation.endTop,

//      floatingActionButtonAnimator: FloatingActionButtonAnimator.scaling,//???
    // 底部导航栏上方的工具栏
        persistentFooterButtons:<Widget>[
          Icon(Icons.edit),
          Icon(Icons.save_alt),
          Icon(Icons.verified_user),
        ],
      // persistentFooterButtons上方的widget
      bottomSheet: Icon(Icons.alarm),

      //顶部导航栏与底部导航栏之间的背景色
      backgroundColor: Colors.red[200],

      resizeToAvoidBottomInset: false,//???
      resizeToAvoidBottomPadding: false,//????

      primary: true,//???
      drawerDragStartBehavior: DragStartBehavior.down,//???
      drawerScrimColor: Colors.green[100],//drawer拉出来后,drawer外的部分的颜色
    );
  }

  void onTap(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  void _onAdd() {}
}

class MyDrawer extends StatelessWidget {
  const MyDrawer({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(top: 38.0),
            child: Row(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 17.0),
                  child: ClipOval(
                    child: Image.asset(
                      "images/avatar3.jpg",
                      width: 80,
                    ),
                  ),
                ),
                Text(
                  "zzc",
                  style: TextStyle(fontWeight: FontWeight.bold),
                )
              ],
            ),
          ),
          Expanded(
            child: ListView(
              children: <Widget>[
                ListTile(
                  leading: const Icon(Icons.access_alarms),
                  title: const Text('access_alarms'),
                ),
                ListTile(
                  leading: const Icon(Icons.delete),
                  title: const Text('delete'),
                ),
                ListTile(
                  leading: const Icon(Icons.save),
                  title: const Text('save'),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
上一篇 下一篇

猜你喜欢

热点阅读