flutterback4app

Unable to get current user


I am unable to get current user from session in Back4App using flutter. My variable currentUser is returning a null value. As per documentation I think I am doing it as they say, but I cannot figure out where could be the error.

Future<void> saveTodo(String title, String DogsAge, String breedselection,
    ParseFileBase parseFile) async {

  ParseUser? currentUser = await ParseUser.currentUser() as ParseUser?;


  await Future.delayed(Duration(seconds: 1), () {});
  final todo = ParseObject('Todo')
    ..set('UserId', currentUser!.objectId)
    ..set('UserMail', currentUser.emailAddress)

Solution

  • currentUser() returns null if your device is not logged in. Check if there is any login or register option and use and await it first, before calling currentUser().