diff --git a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart index f9a339d..7cbc7bf 100644 --- a/flutter-ory-network/lib/blocs/settings/settings_bloc.dart +++ b/flutter-ory-network/lib/blocs/settings/settings_bloc.dart @@ -52,17 +52,29 @@ class SettingsBloc extends Bloc { } _onResetSettings(ResetSettings event, Emitter emit) async { - if (state.settingsFlow != null) { - emit(state.copyWith(isLoading: true)); - final settings = - await repository.getSettingsFlow(flowId: state.settingsFlow!.id); - List updatedConditions = List.from(state.conditions); - updatedConditions - .removeWhere((element) => element is SessionRefreshRequested); - emit(state.copyWith( - settingsFlow: settings, - conditions: updatedConditions, - isLoading: false)); + try { + if (state.settingsFlow != null) { + emit(state.copyWith(isLoading: true)); + final settings = + await repository.getSettingsFlow(flowId: state.settingsFlow!.id); + List updatedConditions = List.from(state.conditions); + updatedConditions + .removeWhere((element) => element is SessionRefreshRequested); + emit(state.copyWith( + settingsFlow: settings, + conditions: updatedConditions, + isLoading: false)); + } + } on UnauthorizedException catch (_) { + // change auth status as the user is not authenticated + authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated)); + } on FlowExpiredException catch (e) { + // get new settings flow + add(GetSettingsFlow(flowId: e.flowId)); + } on UnknownException catch (e) { + emit(state.copyWith(isLoading: false, message: e.message)); + } catch (_) { + emit(state.copyWith(isLoading: false)); } } diff --git a/flutter-ory-network/lib/pages/settings.dart b/flutter-ory-network/lib/pages/settings.dart index bc57772..3ed174f 100644 --- a/flutter-ory-network/lib/pages/settings.dart +++ b/flutter-ory-network/lib/pages/settings.dart @@ -123,11 +123,12 @@ class SettingsForm extends StatelessWidget { listenWhen: (SettingsState previous, SettingsState current) => // listen to changes only when current // state is not loading (e.g. updating settings), - // previous and current messages differ + // previous state was loading, + // there is a new message, // and session refresh is not required !current.isLoading && - current.settingsFlow?.ui.messages != - previous.settingsFlow?.ui.messages && + previous.isLoading && + current.settingsFlow?.ui.messages != null && !isSessionRefreshRequired(current.conditions), listener: (BuildContext context, SettingsState state) { if (state.settingsFlow!.ui.messages != null) { @@ -153,6 +154,14 @@ class SettingsForm extends StatelessWidget { content: Text(state.message!), )); } + }), + // remove snackbars when loading + BlocListener( + bloc: settingsBloc, + listener: (BuildContext context, SettingsState state) { + if (state.isLoading) { + ScaffoldMessenger.of(context).clearSnackBars(); + } }) ], child: BlocBuilder(