-
讓安卓和iOS一樣push時從右往左
下載圖片使用占位圖
FadeInImage.assetNetwork(
placeholder: "images/ic_device_image_default.png",
image: imagePath,
fit: BoxFit.cover,
),
- 坐標(biāo)轉(zhuǎn)換 只想獲取手勢在當(dāng)前組件中的位置
//1.坐標(biāo)轉(zhuǎn)換設(shè)置key
GlobalKey indexBarKey = GlobalKey();
//2.在那個需要獲取位置的組件設(shè)置key刻获,這個組件肯定被手勢包著
key:indexBarKey ,
//3.在手勢方法中處理獲取坐標(biāo)
onVerticalDragDown: (DragDownDetails details){
RenderBox getBox = indexBarKey.currentContext.findRenderObject();
Offset local = getBox.globalToLocal(details.globalPosition);
print(local);
},
- 設(shè)置電池欄顏色
appBar: AppBar(
title: Text('123'),
brightness: Brightness.dark,
),
- BottomNavigationBar對應(yīng)頁面保持狀態(tài)的方法
1.with AutomaticKeepAliveClientMixin<>
2.
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
3.builder方法中調(diào)用下父類的builder方法
super.build(context);
4.main函數(shù)里的Scaffold的body要使用PageView
body:PageView(
controller: _controller,
physics: NeverScrollableScrollPhysics(),//禁止首頁4個頁面的左右滑動
children: _pages,
),
5. PageView中的controller要初始化
final PageController _controller = PageController();
6.BottomNavigationBar的ontap方法中要切換_controller對應(yīng)的page
_controller.jumpToPage(index);
- 創(chuàng)建模型并且在模型中創(chuàng)建字典轉(zhuǎn)模型方法
class HomeModel {
final String imageUrl;
final String name;
final String message;
HomeModel({this.imageUrl, this.name, this.message});
//字典Map轉(zhuǎn)模型的構(gòu)造方法
factory HomeModel.fromJson(Map jsonMap){
return HomeModel(imageUrl: jsonMap['imageUrl'],name: jsonMap['name'],message: jsonMap['message']);
}
}