Reputation: 13
I want to call a function when app runs for the first time, which will ask the user to enter firstName , lastName and add a profile picture. Once the above process is done the function will never again be called during the lifetime of the app.
Upvotes: 1
Views: 1086
Reputation: 324
Use SharePreference
see below code snippet with little advancement in code you can achieve your result.
Future<bool> isFirstTime() async {
var firstTime = SharedPref.pref.getBool('first_time');
if (firstTime != null && !firstTime) {
SharedPref.pref.setBool('first_time', false);
return false;
} else {
SharedPref.pref.setBool('first_time', false);
return true;
}
}
Upvotes: 0
Reputation: 531
For something like this you need to check if the user has already entered that data or not. If not then show him the page where he can enter information otherwise take him to HomePage. For this When the user enters the information you need to save it to some persistent storage and check it whenever the app runs. In this way, your function will be called only once until the user deletes the app or clear its memory. You could use the following libraries to store the data.
These libraries save the data in key-value
pair and read data faster especially hive.
Upvotes: 1