![](/img/trans.png)
[英]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.