I am trying to save a string to shared preferences and then retrieve it.
However, my Android Studio tells me that there is an error.
Specifically, it says:
The argument type 'String?' can't be assigned to the parameter type 'String'. However, I don't know what it is referring to as I don't think I ever specify that the variable is a String?.
Here is the code:
void _setFirstAppLaunchDate(DateTime value) async{
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('firstLaunchDate', value.toString());
}
Future<DateTime> getFirstAppLaunchDate() async{
SharedPreferences prefs = await SharedPreferences.getInstance();
if (prefs.getString('firstLaunchDate') != null)
return DateTime.parse(prefs.getString('firstLaunchDate'));
else {
var now = DateTime.now();
_setFirstAppLaunchDate(now);
return now;
}