以開發一款APP來說解使用到的相關知識。html
通常開屏頁,就是展現一張圖片。android
圖片加載方式 book.flutterchina.club/chapter3/im…git
本地圖片github
Image(
image: AssetImage("assets/images/splash_bg.png"),
width:double.infinity // 強制在寬度上撐滿
height:
color:
fit://縮放模式
alignment:Alignment.center //對齊方式
);
複製代碼
或segmentfault
Image.asset("assets/images/splash_bg.png",
width: 100.0
)
複製代碼
return Container(
color: Colors.blue,
child: Image.asset(
"assets/images/splash_bg.png",
width: double.infinity,
height: double.infinity,
fit: BoxFit.contain,
alignment: Alignment.center,
),
);
複製代碼
在android中,存在啓動空白頁的狀況。解決辦法,參考 juejin.im/post/5b4439…bash
Flutter中State生命週期less
segmentfault.com/a/119000001…ide
Flutter自帶函數函數
Future.delayed(Duration(milliseconds: 500), () {
});
複製代碼
或者使用Rxdart佈局
Observable.just(1).delay(new Duration(milliseconds: 500)).listen((_) {
});
複製代碼
可使用Flutter提供的輪播組件Swiper。
能夠將開屏widget和新手引導widget統一在一個頁面展現,只是分別切換widget。
能夠本身實現控制widget的顯示和隱藏,也可使用Flutter提供的Offstage組件。
源碼:
A widget that lays the child out as if it was in the tree, but without
painting anything, without making the child available for hit testing, and
without taking any room in the parent.
Animations continue to run in offstage children, and therefore use battery
and CPU time, regardless of whether the animations end up being visible.
[Offstage] can be used to measure the dimensions of a widget without
bringing it on screen (yet). To hide a widget from view while it is not
needed, prefer removing the widget from the tree entirely rather than
keeping it alive in an [Offstage] subtree.
複製代碼
查看其RenderOffstage可知,Offstage並非經過插入或者刪除本身在widget tree中的節點,來達到顯示以及隱藏的效果,而是經過設置自身尺寸、不響應hitTest以及不繪製,來達到展現與隱藏的效果。 上面官方也建議,若是widget肯定不須要展現,最好remove掉。
使用Flutter Plugin中的shared_preferences。 github.com/flutter/plu…