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

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

使用到的方法

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

首屏創建只包含底部導航欄widget  然後widget是頭部和body即可。

 

  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(),
        )
    );
  }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章