# 屏幕相关
设置屏幕横屏
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);
设置屏幕竖屏
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
弹窗
showModalBottomSheet(context: context,
isScrollControlled: true,
enableDrag: false,
isDismissible: false,
builder:(_)=> const Onbording(),);
}
在初始化时使用弹窗用delayed
Future.delayed(
Duration.zero,(){
showModalBottomSheet(context: context,
isScrollControlled: true,
enableDrag: false,
isDismissible: false,
builder:(_)=> const Onbording(),);
}
);
完整代码:
void initState() {
super.initState();
//界面build完成后执行回调函数
Future.delayed(
Duration.zero,(){
showModalBottomSheet(context: context,
isScrollControlled: true,
enableDrag: false,
isDismissible: false,
builder:(_)=> const Onbording(),);
}
);
}
对于SharedPreferences的使用
void newversion() async{
SharedPreferences? newversion = await SharedPreferences.getInstance();
newversion.setString("version", version);
}
可以这样异步调用
void newversionpop() async{
bool ispop = await isversion() ;
setState(() {
if(ispop == false){
Future.delayed(
Duration.zero,(){
showModalBottomSheet(context: context,
isScrollControlled: true,
enableDrag: false,
isDismissible: false,
builder:(_)=> const Onbording(),);
}
);
}
});
}
本文作者:CC米饭
版权声明:除特殊声明之外,博客内容均由米饭个人创作。转载请联系米饭~