我正在使用reevaluateListable来收听我的设置Cubit Streem(自动路由Flutter包),它只做了一次,并且不会再次工作,直到我再次刷新应用程序。
这是我的应用dart
class MizanitiApp extends StatelessWidget {
MizanitiApp({super.key});
final AppRouter router = AppRouter();
@override
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider(
lazy: false,
create: (context) => locator<SettingsCubit>()..initiated()),
BlocProvider(
create: (context) => locator<WalletsWatcherCubit>()..initiated()),
],
child: BlocConsumer<SettingsCubit, SettingsState>(
listenWhen: (previous, current) =>
previous.failureOrSuccessOption != current.failureOrSuccessOption,
listener: (context, state) {
state.failureOrSuccessOption.fold(
() => null,
(either) => either.fold(
// failure
(Failure failure) =>
_onSettingsFailure(context: context, failure: failure),
// success
(_) => _onSettingsSuccess(context: context),
),
);
},
buildWhen: (previous, current) =>
previous.domain.theme != current.domain.theme,
builder: (context, state) {
return MaterialApp.router(
title: 'Mizaniti App',
themeMode: state.domain.theme.getOrNull(),
darkTheme:
ThemeData(useMaterial3: true, brightness: Brightness.dark),
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
routerConfig: router.config(
reevaluateListenable: ReevaluateListenable.stream(
context.read<WalletsWatcherCubit>().stream)),
);
},
),
);
}
}
字符串
这是我的守卫
class BiometricGuard extends AutoRouteGuard {
@override
void onNavigation(NavigationResolver resolver, StackRouter router) async {
final BuildContext? context = router.navigatorKey.currentContext;
optionOf(context).fold(
() => resolver.next(),
(context) {
print('fingerprint');
final bool isAppGuarded =
context.read<SettingsCubit>().state.isAppGuarded;
if (isAppGuarded) {
router.replaceAll([const BiometricGuardRoute()]);
return;
}
resolver.next();
},
);
}
}
型
1条答案
按热度按时间e5nqia271#
我遇到了同样的问题。不确定我的解决方案是否正确,但在我的情况下,我通过在强制重定向之前添加
resolver.redirect(const LoginRoute())
来解决它。这是我的代码,如果你感兴趣。
字符串