flutter 首頁導航切換 不重載 不刷新 不銷燬widget

假如用了Navigator 跳出當前頁面,就會發生dispose事件,因此要想保留住頁面,就必須wiget加載在當前頁面ui

使用到的方法code

Scaffold 疊加Widget 第二個使用Offstage隱藏 其餘窗口  導航欄切換的時候 只顯示一個事件

首屏建立只包含底部導航欄widget  而後widget是頭部和body便可。get

 

Widget build(BuildContext context) {

    return new MaterialApp(
        title: '123',
        theme: new ThemeData(
            primaryColor: Colors.white
        ),
        home: Scaffold(
          body: Stack(
            children: <Widget>[
              new Offstage(
                offstage: _selectedIndex!=0, //這裏控制
                child: WeiboWidget(),
              ),
              new Offstage(
                offstage: _selectedIndex!=1, //這裏控制
                child: OrderWidget(),
              ),
              new Offstage(
                offstage: _selectedIndex!=2, //這裏控制
                child: ServerWidget(),
              ),
              new Offstage(
                offstage: _selectedIndex!=3, //這裏控制
                child: MpWidget(),
              ),
              new Offstage(
                offstage: _selectedIndex!=4, //這裏控制
                child: MpWidget(),
              ),
            ],
          ),
          bottomNavigationBar: MyBottom(),
        )
    );
  }
相關文章
相關標籤/搜索