出于性能考慮,ListView.separated每次進(jìn)入都會(huì)加載,因此api要求必須要設(shè)置大小,解決方法是(注意情況:不要在build內(nèi)部運(yùn)算或刷新,因?yàn)閘istview 每次進(jìn)入都會(huì)刷新,這樣會(huì)大幅度占用內(nèi)存)
Expanded(
child:{})
provider狀態(tài)無(wú)改變的時(shí)候
Consumer(builder: (
BuildContext context,
RemindModel value,
Widget? child,
) {})
Row的平分布局
用 Expanded 包裹 row 里的每個(gè)組件:
Row(
children: [
Expanded(child: Text()),
Expanded(child: Text()),
Expanded(child: Text()),
],
)
pub get 后本地的代碼沒有更新,重新get也不會(huì)改變
pub get 后沒有更新
1. 本地的 pubspec.lock 鎖定了版本,刪除掉, 重新 pub get
2. 指定 ref 版本
進(jìn)入app,就設(shè)置整個(gè)app為豎屏顯示
void main() {
WidgetsFlutterBinding.ensureInitialized(); //不加這個(gè)強(qiáng)制橫/豎屏?xí)?bào)錯(cuò)
SystemChrome.setPreferredOrientations([
// 強(qiáng)制豎屏
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
runApp(const DemoApp());
}
WidgetsFlutterBinding.ensureInitialized();這行代碼一定要寫,要不然就報(bào)錯(cuò),而且設(shè)置也無(wú)效
當(dāng)進(jìn)入某個(gè)頁(yè)面時(shí)控制橫豎屏顯示
強(qiáng)制豎屏,代碼如下:
// 強(qiáng)制豎屏
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
強(qiáng)制橫屏,代碼如下:
// 強(qiáng)制橫屏
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight
]);
退出這個(gè)頁(yè)面時(shí),恢復(fù)豎屏顯示,代碼如下:
@override
void dispose() {
// 強(qiáng)制豎屏
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
super.dispose();
}
list轉(zhuǎn)string
String? result;
<String>["a","b","c"].forEach((e) {
if (result == null) {
result = e.name;
} else {
result = "${e.name},${result}";
};
});
自適應(yīng)高度控件
IntrinsicHeight();