Skip to content

Commit

Permalink
fix: reset settings when navigating back
Browse files Browse the repository at this point in the history
  • Loading branch information
sashatalalasha committed Nov 29, 2023
1 parent 76c49d3 commit a779d50
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
10 changes: 5 additions & 5 deletions flutter-ory-network/lib/blocs/settings/settings_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
on<CreateSettingsFlow>(_onCreateSettingsFlow);
on<GetSettingsFlow>(_onGetSettingsFlow);
on<ChangeSettingsNodeValue>(_onChangeNodeValue, transformer: sequential());
on<ResetButtonValues>(_onResetButtonValues);
on<ResetSettings>(_onResetSettings);
on<UpdateSettingsFlow>(_onUpdateSettingsFlow, transformer: sequential());
}

Expand All @@ -51,13 +51,13 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
}
}

_onResetButtonValues(ResetButtonValues event, Emitter<SettingsState> emit) {
_onResetSettings(ResetSettings event, Emitter<SettingsState> emit) async {
if (state.settingsFlow != null) {
emit(state.copyWith(isLoading: true));
final updatedSettings =
repository.resetButtonValues(settingsFlow: state.settingsFlow!);
final settings =
await repository.getSettingsFlow(flowId: state.settingsFlow!.id);
emit(state.copyWith(
settingsFlow: updatedSettings,
settingsFlow: settings,
isSessionRefreshRequired: false,
isLoading: false));
}
Expand Down
2 changes: 1 addition & 1 deletion flutter-ory-network/lib/blocs/settings/settings_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ChangeSettingsNodeValue extends SettingsEvent {
List<Object> get props => [value, name];
}

class ResetButtonValues extends SettingsEvent {}
class ResetSettings extends SettingsEvent {}

class UpdateSettingsFlow extends SettingsEvent {
final UiNodeGroupEnum group;
Expand Down
15 changes: 8 additions & 7 deletions flutter-ory-network/lib/pages/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ class SettingsForm extends StatelessWidget {
}
} else {
// if user goes back without finishing login,
// reset button values to prevent submitting values that
// were selected prior to session refresh navigation
settingsBloc.add(ResetButtonValues());
// reset settings
settingsBloc.add(ResetSettings());
}
});
}
Expand All @@ -97,11 +96,13 @@ class SettingsForm extends StatelessWidget {
BlocListener(
bloc: settingsBloc,
listenWhen: (SettingsState previous, SettingsState current) =>
// listen to changes only when previous
// state was loading (e.g. updating settings),
// current state is not loading and session refresh is not required
previous.isLoading != current.isLoading &&
// listen to changes only when current
// state is not loading (e.g. updating settings),
// previous and current messages differ
// and session refresh is not required
!current.isLoading &&
current.settingsFlow?.ui.messages !=
previous.settingsFlow?.ui.messages &&
!current.isSessionRefreshRequired,
listener: (BuildContext context, SettingsState state) {
if (state.settingsFlow!.ui.messages != null) {
Expand Down
4 changes: 4 additions & 0 deletions flutter-ory-network/lib/services/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ class AuthService {
if (e.response?.statusCode == 401) {
await _storage.deleteToken();
throw const CustomException.unauthorized();
} else if (e.response?.statusCode == 410) {
// settings flow expired, use new flow id
throw CustomException.flowExpired(
flowId: e.response?.data['use_flow_id']);
} else {
throw _handleUnknownException(e.response?.data);
}
Expand Down
2 changes: 2 additions & 0 deletions flutter-ory-network/lib/widgets/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ List<UiNode> getNodesOfGroup(UiNodeGroupEnum group, BuiltList<UiNode> nodes) {
} else {
return true;
}
} else {
return true;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions flutter-ory-network/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,10 @@ packages:
dependency: "direct main"
description:
name: ory_client
sha256: c8d672ee192c77aa4231afbbf7fa6d23387e2a09ac9cf14a596dfcf5b0ecc29b
sha256: "6d6ec2304afd9c20489f2a8118b4cddfbdae4fc22915bd9a168a777620af5c44"
url: "https://pub.dev"
source: hosted
version: "1.2.16"
version: "1.4.3"
package_config:
dependency: transitive
description:
Expand Down

0 comments on commit a779d50

Please sign in to comment.