Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove duplicated navigator workaround #1381

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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