項目搭建01 做底部 4個item 分頁. package導(dǎo)入
1.flutter保證文字大小不受手機(jī)系統(tǒng)設(shè)置影響
只需要要在 MaterialApp 的builder MediaQuery 如下:
MaterialApp(
......
builder: (context, child) {
/// 保證文字大小不受手機(jī)系統(tǒng)設(shè)置影響 https://www.kikt.top/posts/flutter/layout/dynamic-text/
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor:
1.0), // 或者 MediaQueryData.fromWindow(WidgetsBinding.instance.window).copyWith(textScaleFactor: 1.0),
child: child,
);
});
2.flutter去除BottomNavigationBar水紋
1.在外層包裹一層 Theme 用 ThemeData去除(如下)
2.用 ios 風(fēng)格的 CupertinoTabBar
Scaffold(
bottomNavigationBar: Theme(
data: ThemeData(
brightness: Brightness.light,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
child: BottomNavigationBar(
items: _buildBottomNavigationBarItem(),
type: BottomNavigationBarType.fixed,
currentIndex:value,
.........
));
3.flutter BottomNavigationBar 保持狀態(tài)
AutomaticKeepAliveClientMixin蚀之,通過在子頁面的 State 類重寫wantKeepAlive為true
- BottomNavigationBar+indexStack //缺點(diǎn) 一開頭就會加重 下面所有的 頁面
- BottomNavigationBar+Stack+ Offstage //其實和上面是一樣的.缺點(diǎn) 一開頭就會加重 下面所有的 頁面
- PageView+BottomNavigationBar //推薦
詳情請看 https://zhuanlan.zhihu.com/p/58582876
4.flutter ValueNotifier 數(shù)據(jù)通信
ValueNotifier是一個包含單個值的變更通知器鹊杖,當(dāng)它的值改變的時候校哎,會通知它的監(jiān)聽。
class HomeProvider extends ValueNotifier<int> {
HomeProvider() : super(0);
}
初始化
HomeProvider provider=HomeProvider();
每當(dāng) 改變provider.value 的值 會通知刷新 ,可以結(jié)合provider consumer 刷新局部