Prior to migrating to null safety this worked. This is a user login verification method.
Future<bool> loginValidate() async {
final String dir = await getDocDir(); //getting documents directory
try {
await File('$dir/$_userLoginString.json')
.readAsString()
.then((String contents) {
final json = jsonDecode(contents) as Map<String, dynamic>;
final user = PersonLoginJson.fromJson(json);
if (_userPasswordString != user.password) {
//invalid password
return Future<bool>.value(false);
}
});
} on FileSystemException {
//invalid username
return Future<bool>.value(false);
} catch (e) {
return Future<bool>.value(false);
}
//success
return Future<bool>.value(true);
}
This error occurs when the app is being built.
I believe it has to do with the anonymous function argument within the .then() method.