Skip to content

Commit

Permalink
Merge pull request #1381 from krille-chan/krille/remove-duplicated-na…
Browse files Browse the repository at this point in the history
…vigator-workaround

refactor: Remove duplicated navigator workaround
  • Loading branch information
krille-chan authored Oct 3, 2024
2 parents 5ee30c3 + ae52fcf commit cdece9b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/pages/chat_list/chat_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ class ChatListController extends State<ChatList>
isTorBrowser = isTor;
}

Future<void> dehydrate() => Matrix.of(context).dehydrateAction();
Future<void> dehydrate() => Matrix.of(context).dehydrateAction(context);
}

enum EditBundleAction { addToBundle, removeFromBundle }
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/settings_security/settings_security.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class SettingsSecurityController extends State<SettingsSecurity> {
).show(context);
}

Future<void> dehydrateAction() => Matrix.of(context).dehydrateAction();
Future<void> dehydrateAction() => Matrix.of(context).dehydrateAction(context);

@override
Widget build(BuildContext context) => SettingsSecurityView(this);
Expand Down
12 changes: 4 additions & 8 deletions lib/widgets/fluffy_chat_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,10 @@ class FluffyChatApp extends StatelessWidget {
clients: clients,
// Need a navigator above the Matrix widget for
// displaying dialogs
child: Navigator(
onGenerateRoute: (_) => MaterialPageRoute(
builder: (_) => Matrix(
clients: clients,
store: store,
child: testWidget ?? child,
),
),
child: Matrix(
clients: clients,
store: store,
child: testWidget ?? child,
),
),
),
Expand Down
18 changes: 13 additions & 5 deletions lib/widgets/matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,16 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
if (!hidPopup &&
{KeyVerificationState.done, KeyVerificationState.error}
.contains(request.state)) {
Navigator.of(context).pop('dialog');
FluffyChatApp.router.pop('dialog');
}
hidPopup = true;
};
request.onUpdate = null;
hidPopup = true;
await KeyVerificationDialog(request: request).show(context);
await KeyVerificationDialog(request: request).show(
FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ??
context,
);
});
onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) {
final loggedInWithMultipleClients = widget.clients.length > 1;
Expand All @@ -304,7 +307,10 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
_cancelSubs(c.clientName);
widget.clients.remove(c);
ClientManager.removeClientNameFromStore(c.clientName, store);
ScaffoldMessenger.of(context).showSnackBar(
ScaffoldMessenger.of(
FluffyChatApp.router.routerDelegate.navigatorKey.currentContext ??
context,
).showSnackBar(
SnackBar(
content: Text(L10n.of(context)!.oneClientLoggedOut),
),
Expand Down Expand Up @@ -362,7 +368,9 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
onFcmError: (errorMsg, {Uri? link}) async {
final result = await showOkCancelAlertDialog(
barrierDismissible: true,
context: context,
context: FluffyChatApp
.router.routerDelegate.navigatorKey.currentContext ??
context,
title: L10n.of(context)!.pushNotificationsNotAvailable,
message: errorMsg,
fullyCapitalizedForMaterial: false,
Expand Down Expand Up @@ -483,7 +491,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
);
}

Future<void> dehydrateAction() async {
Future<void> dehydrateAction(BuildContext context) async {
final response = await showOkCancelAlertDialog(
context: context,
isDestructiveAction: true,
Expand Down

0 comments on commit cdece9b

Please sign in to comment.