lucavenir / go_router_riverpod

An example on how to use Riverpod + GoRouter
460 stars 68 forks source link

Complete example throws error #16

Closed Kublick closed 1 year ago

Kublick commented 1 year ago

Got the complete example in order to check how it works but as soon you tap the login button it will throw an error on this function

 Future<void> login(String email, String password) async {
    state = await AsyncValue.guard<User>(() async {
      return Future.delayed(
        networkRoundTripTime,
        () =>
      );
    });
  }

in the console I can see

type 'AsyncData<User?>' is not a subtype of type 'AsyncValue<User>' of 'previous'

Removing after guard resolves the issue.

leedeblade commented 1 year ago

Hi @Kublick Because AuthNotifier extends AutoDisposeAsyncNotifier<User?>, therefore, i think login functions should be:

 Future<void> login(String email, String password) async {
    state = await AsyncValue.guard<User?>(() async{
  return Future.delayed(
        networkRoundTripTime,
        () =>
      );
    });
  }
lucavenir commented 1 year ago

Oddly enough, while this makes sense, this should be a compile-time error, which I don't have. Moreover, the example runs fine to me.

@Kublick please try out @leedeblade 's fix and let us know if it works.

Kublick commented 1 year ago

Indeed adding ? does the trick.