假如用了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(),
)
);
}