chore: Follow up router fixes
This commit is contained in:
parent
0c69ce0552
commit
b7dac8365a
8 changed files with 54 additions and 67 deletions
|
|
@ -412,19 +412,17 @@ abstract class AppRoutes {
|
|||
),
|
||||
];
|
||||
|
||||
static Page defaultPageBuilder(BuildContext context, Widget child) {
|
||||
Matrix.of(context).navigatorContext = context;
|
||||
return CustomTransitionPage(
|
||||
child: child,
|
||||
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
|
||||
FluffyThemes.isColumnMode(context)
|
||||
? FadeTransition(opacity: animation, child: child)
|
||||
: CupertinoPageTransition(
|
||||
primaryRouteAnimation: animation,
|
||||
secondaryRouteAnimation: secondaryAnimation,
|
||||
linearTransition: false,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
static Page defaultPageBuilder(BuildContext context, Widget child) =>
|
||||
CustomTransitionPage(
|
||||
child: child,
|
||||
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
|
||||
FluffyThemes.isColumnMode(context)
|
||||
? FadeTransition(opacity: animation, child: child)
|
||||
: CupertinoPageTransition(
|
||||
primaryRouteAnimation: animation,
|
||||
secondaryRouteAnimation: secondaryAnimation,
|
||||
linearTransition: false,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import 'package:flutter_blurhash/flutter_blurhash.dart';
|
|||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:fluffychat/widgets/mxc_image.dart';
|
||||
|
||||
class ImageBubble extends StatelessWidget {
|
||||
|
|
@ -72,7 +71,7 @@ class ImageBubble extends StatelessWidget {
|
|||
}
|
||||
if (!tapToView) return;
|
||||
showDialog(
|
||||
context: Matrix.of(context).navigatorContext,
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
builder: (_) => ImageViewer(event),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_app_badger/flutter_app_badger.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:unifiedpush/unifiedpush.dart';
|
||||
|
||||
import 'package:fluffychat/utils/matrix_sdk_extensions/client_stories_extension.dart';
|
||||
import 'package:fluffychat/utils/push_helper.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||
import '../config/app_config.dart';
|
||||
import '../config/setting_keys.dart';
|
||||
import '../widgets/matrix.dart';
|
||||
|
|
@ -53,15 +53,15 @@ class BackgroundPush {
|
|||
FlutterLocalNotificationsPlugin();
|
||||
Client client;
|
||||
MatrixState? matrix;
|
||||
BuildContext? get context => matrix?.navigatorContext;
|
||||
String? _fcmToken;
|
||||
void Function(String errorMsg, {Uri? link})? onFcmError;
|
||||
L10n? l10n;
|
||||
Store? _store;
|
||||
Store get store => _store ??= Store();
|
||||
Future<void> loadLocale() async {
|
||||
final context = matrix?.context;
|
||||
// inspired by _lookupL10n in .dart_tool/flutter_gen/gen_l10n/l10n.dart
|
||||
l10n ??= (context != null ? L10n.of(context!) : null) ??
|
||||
l10n ??= (context != null ? L10n.of(context) : null) ??
|
||||
(await L10n.delegate.load(PlatformDispatcher.instance.locale));
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +77,6 @@ class BackgroundPush {
|
|||
onRoomSync ??= client.onSync.stream
|
||||
.where((s) => s.hasRoomUpdate)
|
||||
.listen((s) => _onClearingPush(getFromServer: false));
|
||||
final context = this.context;
|
||||
firebase?.setListeners(
|
||||
onMessage: (message) => pushHelper(
|
||||
PushNotification.fromJson(
|
||||
|
|
@ -85,9 +84,7 @@ class BackgroundPush {
|
|||
),
|
||||
client: client,
|
||||
l10n: l10n,
|
||||
activeRoomId: context == null
|
||||
? null
|
||||
: GoRouterState.of(context).pathParameters['roomid'],
|
||||
activeRoomId: matrix?.activeRoomId,
|
||||
onSelectNotification: goToRoom,
|
||||
),
|
||||
);
|
||||
|
|
@ -231,7 +228,7 @@ class BackgroundPush {
|
|||
Logs().d("SetupPush");
|
||||
if (client.onLoginStateChanged.value != LoginState.loggedIn ||
|
||||
!PlatformInfos.isMobile ||
|
||||
context == null) {
|
||||
matrix == null) {
|
||||
return;
|
||||
}
|
||||
// Do not setup unifiedpush if this has been initialized by
|
||||
|
|
@ -261,7 +258,7 @@ class BackgroundPush {
|
|||
}
|
||||
|
||||
Future<void> _noFcmWarning() async {
|
||||
if (context == null) {
|
||||
if (matrix == null) {
|
||||
return;
|
||||
}
|
||||
if (await store.getItemBool(SettingKeys.showNoGoogle, true) == true) {
|
||||
|
|
@ -315,14 +312,15 @@ class BackgroundPush {
|
|||
?.content
|
||||
.tryGet<String>('type') ==
|
||||
ClientStoriesExtension.storiesRoomType;
|
||||
context?.go(['', isStory ? 'stories' : 'rooms', roomId].join('/'));
|
||||
FluffyChatApp.router
|
||||
.go(['', isStory ? 'stories' : 'rooms', roomId].join('/'));
|
||||
} catch (e, s) {
|
||||
Logs().e('[Push] Failed to open room', e, s);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setupUp() async {
|
||||
await UnifiedPush.registerAppWithDialog(context!);
|
||||
await UnifiedPush.registerAppWithDialog(matrix!.context);
|
||||
}
|
||||
|
||||
Future<void> _newUpEndpoint(String newEndpoint, String i) async {
|
||||
|
|
@ -391,14 +389,11 @@ class BackgroundPush {
|
|||
);
|
||||
// UP may strip the devices list
|
||||
data['devices'] ??= [];
|
||||
final context = this.context;
|
||||
await pushHelper(
|
||||
PushNotification.fromJson(data),
|
||||
client: client,
|
||||
l10n: l10n,
|
||||
activeRoomId: context == null
|
||||
? null
|
||||
: GoRouterState.of(context).pathParameters['roomid'],
|
||||
activeRoomId: matrix?.activeRoomId,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import 'package:fluffychat/widgets/matrix.dart';
|
|||
|
||||
extension UiaRequestManager on MatrixState {
|
||||
Future uiaRequestHandler(UiaRequest uiaRequest) async {
|
||||
final l10n = L10n.of(navigatorContext)!;
|
||||
final l10n = L10n.of(context)!;
|
||||
try {
|
||||
if (uiaRequest.state != UiaRequestState.waitForUser ||
|
||||
uiaRequest.nextStages.isEmpty) {
|
||||
|
|
@ -22,7 +22,7 @@ extension UiaRequestManager on MatrixState {
|
|||
case AuthenticationTypes.password:
|
||||
final input = cachedPassword ??
|
||||
(await showTextInputDialog(
|
||||
context: navigatorContext,
|
||||
context: context,
|
||||
title: l10n.pleaseEnterYourPassword,
|
||||
okLabel: l10n.ok,
|
||||
cancelLabel: l10n.cancel,
|
||||
|
|
@ -49,7 +49,7 @@ extension UiaRequestManager on MatrixState {
|
|||
case AuthenticationTypes.emailIdentity:
|
||||
if (currentThreepidCreds == null) {
|
||||
return uiaRequest.cancel(
|
||||
UiaException(L10n.of(navigatorContext)!.serverRequiresEmail),
|
||||
UiaException(L10n.of(context)!.serverRequiresEmail),
|
||||
);
|
||||
}
|
||||
final auth = AuthenticationThreePidCreds(
|
||||
|
|
@ -63,7 +63,7 @@ extension UiaRequestManager on MatrixState {
|
|||
if (OkCancelResult.ok ==
|
||||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: navigatorContext,
|
||||
context: context,
|
||||
title: l10n.weSentYouAnEmail,
|
||||
message: l10n.pleaseClickOnLink,
|
||||
okLabel: l10n.iHaveClickedOnLink,
|
||||
|
|
@ -88,7 +88,7 @@ extension UiaRequestManager on MatrixState {
|
|||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
message: l10n.pleaseFollowInstructionsOnWeb,
|
||||
context: navigatorContext,
|
||||
context: context,
|
||||
okLabel: l10n.next,
|
||||
cancelLabel: l10n.cancel,
|
||||
)) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class VoipPlugin with WidgetsBindingObserver implements WebRTCDelegate {
|
|||
late VoIP voip;
|
||||
ConnectivityResult? _currentConnectivity;
|
||||
OverlayEntry? overlayEntry;
|
||||
BuildContext get context => matrix.navigatorContext;
|
||||
BuildContext get context => matrix.context;
|
||||
|
||||
void _handleNetworkChanged(ConnectivityResult result) async {
|
||||
/// Got a new connectivity status!
|
||||
|
|
|
|||
|
|
@ -43,10 +43,13 @@ class FluffyChatApp extends StatelessWidget {
|
|||
localizationsDelegates: L10n.localizationsDelegates,
|
||||
supportedLocales: L10n.supportedLocales,
|
||||
routerConfig: router,
|
||||
builder: (context, child) => Matrix(
|
||||
context: context,
|
||||
clients: clients,
|
||||
child: testWidget ?? child,
|
||||
builder: (context, child) => Navigator(
|
||||
onGenerateRoute: (_) => MaterialPageRoute(
|
||||
builder: (_) => Matrix(
|
||||
clients: clients,
|
||||
child: testWidget ?? child,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -33,10 +33,9 @@ extension LocalNotificationsExtension on MatrixState {
|
|||
if (room.notificationCount == 0) return;
|
||||
|
||||
final event = Event.fromJson(eventUpdate.content, room);
|
||||
final title =
|
||||
room.getLocalizedDisplayname(MatrixLocals(L10n.of(navigatorContext)!));
|
||||
final title = room.getLocalizedDisplayname(MatrixLocals(L10n.of(context)!));
|
||||
final body = await event.calcLocalizedBody(
|
||||
MatrixLocals(L10n.of(navigatorContext)!),
|
||||
MatrixLocals(L10n.of(context)!),
|
||||
withSenderNamePrefix:
|
||||
!room.isDirectChat || room.lastEvent?.senderId == client.userID,
|
||||
plaintextBody: true,
|
||||
|
|
@ -95,11 +94,11 @@ extension LocalNotificationsExtension on MatrixState {
|
|||
actions: [
|
||||
NotificationAction(
|
||||
DesktopNotificationActions.openChat.name,
|
||||
L10n.of(navigatorContext)!.openChat,
|
||||
L10n.of(context)!.openChat,
|
||||
),
|
||||
NotificationAction(
|
||||
DesktopNotificationActions.seen.name,
|
||||
L10n.of(navigatorContext)!.markAsRead,
|
||||
L10n.of(context)!.markAsRead,
|
||||
),
|
||||
],
|
||||
hints: [
|
||||
|
|
@ -114,7 +113,7 @@ extension LocalNotificationsExtension on MatrixState {
|
|||
room.setReadMarker(event.eventId, mRead: event.eventId);
|
||||
break;
|
||||
case DesktopNotificationActions.openChat:
|
||||
navigatorContext.go(['', 'rooms', room.id].join('/'));
|
||||
context.go(['', 'rooms', room.id].join('/'));
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import 'package:collection/collection.dart';
|
|||
import 'package:desktop_notifications/desktop_notifications.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:matrix/encryption.dart';
|
||||
|
|
@ -24,6 +23,7 @@ import 'package:fluffychat/utils/localized_exception_extension.dart';
|
|||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/utils/uia_request_manager.dart';
|
||||
import 'package:fluffychat/utils/voip_plugin.dart';
|
||||
import 'package:fluffychat/widgets/fluffy_chat_app.dart';
|
||||
import '../config/app_config.dart';
|
||||
import '../config/setting_keys.dart';
|
||||
import '../pages/key_verification/key_verification_dialog.dart';
|
||||
|
|
@ -37,16 +37,12 @@ import 'local_notifications_extension.dart';
|
|||
class Matrix extends StatefulWidget {
|
||||
final Widget? child;
|
||||
|
||||
@Deprecated('')
|
||||
final BuildContext context;
|
||||
|
||||
final List<Client> clients;
|
||||
|
||||
final Map<String, String>? queryParameters;
|
||||
|
||||
const Matrix({
|
||||
this.child,
|
||||
required this.context,
|
||||
required this.clients,
|
||||
this.queryParameters,
|
||||
Key? key,
|
||||
|
|
@ -64,7 +60,6 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
int _activeClient = -1;
|
||||
String? activeBundle;
|
||||
Store store = Store();
|
||||
late BuildContext navigatorContext;
|
||||
|
||||
HomeserverSummary? loginHomeserverSummary;
|
||||
XFile? loginAvatar;
|
||||
|
|
@ -172,7 +167,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
ClientManager.addClientNameToStore(_loginClientCandidate!.clientName);
|
||||
_registerSubs(_loginClientCandidate!.clientName);
|
||||
_loginClientCandidate = null;
|
||||
navigatorContext.go('/rooms');
|
||||
FluffyChatApp.router.go('/rooms');
|
||||
});
|
||||
return candidate;
|
||||
}
|
||||
|
|
@ -239,8 +234,11 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
|
||||
bool webHasFocus = true;
|
||||
|
||||
String? get activeRoomId =>
|
||||
GoRouterState.of(navigatorContext).pathParameters['roomid'];
|
||||
String? get activeRoomId {
|
||||
final route = FluffyChatApp.router.routeInformationProvider.value.location;
|
||||
if (route == null || !route.startsWith('/rooms/')) return null;
|
||||
return route.split('/')[2];
|
||||
}
|
||||
|
||||
final linuxNotifications =
|
||||
PlatformInfos.isLinux ? NotificationsClient() : null;
|
||||
|
|
@ -309,13 +307,13 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
if (!hidPopup &&
|
||||
{KeyVerificationState.done, KeyVerificationState.error}
|
||||
.contains(request.state)) {
|
||||
Navigator.of(navigatorContext).pop('dialog');
|
||||
Navigator.of(context).pop('dialog');
|
||||
}
|
||||
hidPopup = true;
|
||||
};
|
||||
request.onUpdate = null;
|
||||
hidPopup = true;
|
||||
await KeyVerificationDialog(request: request).show(navigatorContext);
|
||||
await KeyVerificationDialog(request: request).show(context);
|
||||
});
|
||||
onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) {
|
||||
final loggedInWithMultipleClients = widget.clients.length > 1;
|
||||
|
|
@ -330,16 +328,11 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
);
|
||||
|
||||
if (state != LoginState.loggedIn) {
|
||||
navigatorContext.go(
|
||||
Uri(
|
||||
path: '/rooms',
|
||||
queryParameters:
|
||||
GoRouterState.of(navigatorContext).uri.queryParameters,
|
||||
).toString(),
|
||||
);
|
||||
FluffyChatApp.router.go('/rooms');
|
||||
}
|
||||
} else {
|
||||
navigatorContext.go(state == LoginState.loggedIn ? '/rooms' : '/home');
|
||||
FluffyChatApp.router
|
||||
.go(state == LoginState.loggedIn ? '/rooms' : '/home');
|
||||
}
|
||||
});
|
||||
onUiaRequest[name] ??= c.onUiaRequest.stream.listen(uiaRequestHandler);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue