Flutter error: The argument type 'Future<Object?> Function()' can't be assigned to the parameter type 'FutureOr<dynamic> Function(dynamic)'

Viewed 785

I'm getting this error when I put a Navigator in .then method of an async function called when the submit button is pressed.

    await profileNotifier(false)
        .createProfile(
            context: context,
            profileDTO: ProfileDTO(
              useremail: userEmail,
              profile_name: profileName,
            ))
        .then(
            () => Navigator.of(context).popAndPushNamed(HomeRoute));

The future function is in another file.

  Future createProfile({
    required BuildContext context,
    required ProfileDTO profileDTO,
  }) async {
    try {
      await _profileAPI.createProfile(profileDTO);
    } catch (e) {
      print(e.toString());
    }
  }

Can someone help me understand the error and how to rectify it. What changes do I need to make to get it to work?

1 Answers
Related