how to use Future in check for Beamer Guard in flutter

Viewed 18

If secure storage have user_id, I want auth state to change true

Error: A non-null value must be returned since the return type 'bool' doesn't allow null. check: (context, location) {

final _routerDelegate = BeamerDelegate(
  updateListenable: authNotifier,
  guards: [
    BeamGuard(
      beamToNamed: (origin, target) => '/$locationAuth',
      pathPatterns: [
        ...HomeLocation().pathPatterns,
      ],
      check: (context, location) {
        final loginNotifier =
            Provider.of<AuthenticationNotifier>(context, listen: false);
        Future<bool> _getUserId() async {
          const storage = FlutterSecureStorage();
          final userId = await storage.read(key: "userId");
          if (userId != null) {
            loginNotifier.setUserAuth(true);
          }
          return loginNotifier.isAuthenticated;
        }
        _getUserId().then((val) => val);
      },
    ),
  ],
  locationBuilder: BeamerLocationBuilder(beamLocations: [
    HomeLocation(),
    AuthLocation(),
  ]),
);
1 Answers

Write all that in asynchronous mode.

remove all async & await

Related