Skip to content

Commit

Permalink
Fix Android autofill navigation screen bug
Browse files Browse the repository at this point in the history
New entry to save was sometimes not the top screen on the navigation stack.

Could also lead to crashes if user interacted with the top-level screen,
depending upon what that screen was.
  • Loading branch information
luckyrat committed Aug 31, 2023
1 parent f0baec8 commit 31672ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/widgets/entry_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:keevault/cubit/autofill_cubit.dart';
import 'package:keevault/cubit/entry_cubit.dart';
import 'package:keevault/cubit/filter_cubit.dart';
import 'package:keevault/cubit/sort_cubit.dart';
import 'package:keevault/logging/logger.dart';
import 'package:keevault/model/entry.dart';
import 'package:keevault/widgets/entry.dart';
import 'package:keevault/widgets/in_app_messenger.dart';
Expand Down Expand Up @@ -277,6 +278,10 @@ class EntryListItemWidget extends StatelessWidget {
);
},
onClosed: (bool? keepChanges) async {
if (!context.mounted) {
l.e("context not mounted so we can't tidy up or save the entry. Presumably something happened to make the underlying Vault go away, such as autofill save entry screen replacing the main vault.");
return;
}
final entryCubit = BlocProvider.of<EntryCubit>(context);
final iam = InAppMessengerWidget.of(context);
if ((keepChanges == null || keepChanges) && (entryCubit.state as EntryLoaded).entry.isDirty) {
Expand Down
10 changes: 9 additions & 1 deletion lib/widgets/vault.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class _VaultWidgetState extends State<VaultWidget> with WidgetsBindingObserver {
@override
Widget build(BuildContext context) {
final str = S.of(context);
return BlocBuilder<AutofillCubit, AutofillState>(
return BlocConsumer<AutofillCubit, AutofillState>(
builder: (context, autofillState) {
return BlocConsumer<VaultCubit, VaultState>(
buildWhen: (previous, current) => current is VaultLoaded,
Expand Down Expand Up @@ -180,6 +180,14 @@ class _VaultWidgetState extends State<VaultWidget> with WidgetsBindingObserver {
}
});
},
listener: (BuildContext context, AutofillState state) {
if (state is AutofillSaving) {
l.d('Popping until top level reached');
AppConfig.navigatorKey.currentState?.popUntil((r) {
return r.isFirst;
});
}
},
);
}
}
Expand Down

0 comments on commit 31672ad

Please sign in to comment.