[英]How to save and get a list of lists using Shared preferences in dart/flutter
[英]show an alert box when the app is installed for the first time using shared preferences + flutter + dart
我正在开发一个 android 应用程序,
我希望仅当用户使用共享首选项首次安装应用程序时才弹出警告框。
默认情况下,在启动时共享首选项应为 false,当用户安装应用程序并出现警告框时,共享首选项应更改为 true。
下次用户打开应用程序时,根据共享首选项(true),它不应显示警告框。
只有当用户卸载并安装应用程序时,才会出现警告框。
关于如何实现这一目标的任何想法?
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final prefs = await SharedPreferences.getInstance();
bool? firstTime = prefs.getBool('first_time');
if (firstTime == null) {
// show alert box
prefs.setBool('first_time', true);
}
runApp(MyApp());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.