4

I try to implement Firebase Auth for Flutter according to this tutorial: https://youtu.be/vrPk6LB9bjo?t=393

The Widget should check whether the user is login using riverpod hook method and provider and load either HomeScreen or LoginScreen Widget.

main.dart

class AuthWrapper extends HookWidget {
      const AuthWrapper({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        final authControllerState = useProvider(authControllerProvider.state);
        print(authControllerState);
    
        if (authControllerState != null) {
          return const HomeScreen();
        }
        return LoginScreen();
      }
    }

Provider Controller:

final authControllerProvider = StateNotifierProvider<AuthController>(
  (ref) => AuthController(ref.read),
);

class AuthController extends StateNotifier<User?> {
  final Reader _read;

  StreamSubscription<User?>? _authStateChangeSubscription;

  AuthController(this._read) : super(null) {
    _authStateChangeSubscription?.cancel();
    _authStateChangeSubscription =
        _read(authProvider).authStateChanges.listen((user) {
      state = user;
    });
  }
}

But I got this error.

'package:riverpod/src/framework/base provider.dart': failed assertion: line 944 pos 7: 'exposedvalue is listened': a provider tried to assign null to a non-nullable exposedvalue

I think the error might be in the implementation of the Provider Controller but I don't know how I should do it differently.

Does anyone have an idea how I could fix this error?

asian_gang
  • 51
  • 4

0 Answers0