mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-10 11:05:10 +00:00
refactor: Dialog BuildContext
This commit is contained in:
parent
40003628b9
commit
315a43c1a4
24 changed files with 30 additions and 68 deletions
|
@ -383,14 +383,16 @@ abstract class AppRoutes {
|
|||
static Page defaultPageBuilder(BuildContext context, Widget child) =>
|
||||
CustomTransitionPage(
|
||||
child: child,
|
||||
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
|
||||
FluffyThemes.isColumnMode(context)
|
||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
||||
Matrix.of(context).navigatorContext = context;
|
||||
return FluffyThemes.isColumnMode(context)
|
||||
? FadeTransition(opacity: animation, child: child)
|
||||
: CupertinoPageTransition(
|
||||
primaryRouteAnimation: animation,
|
||||
secondaryRouteAnimation: secondaryAnimation,
|
||||
linearTransition: false,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ class ArchiveController extends State<Archive> {
|
|||
final client = Matrix.of(context).client;
|
||||
if (archive.isEmpty) return;
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
|
|
|
@ -378,7 +378,6 @@ class BootstrapDialogState extends State<BootstrapDialog> {
|
|||
: () async {
|
||||
if (OkCancelResult.ok ==
|
||||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.recoveryKeyLost,
|
||||
message: L10n.of(context)!.wipeChatBackup,
|
||||
|
|
|
@ -77,7 +77,6 @@ class ImageBubble extends StatelessWidget {
|
|||
if (!tapToView) return;
|
||||
showDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
builder: (_) => ImageViewer(event),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -193,7 +193,6 @@ class _AdaptableReactorsDialog extends StatelessWidget {
|
|||
context: context,
|
||||
builder: (context) => this,
|
||||
barrierDismissible: true,
|
||||
useRootNavigator: false,
|
||||
);
|
||||
|
||||
@override
|
||||
|
|
|
@ -59,7 +59,6 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
|||
);
|
||||
} else if (!kIsWeb && tmpFile != null && _chewieManager == null) {
|
||||
_chewieManager ??= ChewieController(
|
||||
useRootNavigator: false,
|
||||
videoPlayerController: VideoPlayerController.file(tmpFile),
|
||||
autoPlay: true,
|
||||
autoInitialize: true,
|
||||
|
|
|
@ -176,7 +176,6 @@ class ChatListController extends State<ChatList>
|
|||
|
||||
void setServer() async {
|
||||
final newServer = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
title: L10n.of(context)!.changeTheHomeserver,
|
||||
context: context,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
@ -473,12 +472,12 @@ class ChatListController extends State<ChatList>
|
|||
|
||||
Future<void> archiveAction() async {
|
||||
final confirmed = await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
cancelLabel: L10n.of(context)!.cancel,
|
||||
message: L10n.of(context)!.archiveRoomDescription,
|
||||
isDestructiveAction: true,
|
||||
) ==
|
||||
OkCancelResult.ok;
|
||||
if (!confirmed) return;
|
||||
|
@ -493,7 +492,6 @@ class ChatListController extends State<ChatList>
|
|||
final client = Matrix.of(context).client;
|
||||
final currentPresence = await client.fetchCurrentPresence(client.userID!);
|
||||
final input = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.setStatus,
|
||||
message: L10n.of(context)!.leaveEmptyToClearStatus,
|
||||
|
|
|
@ -118,7 +118,6 @@ class ChatListItem extends StatelessWidget {
|
|||
shareFile != null) {
|
||||
await showDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
builder: (c) => SendFileDialog(
|
||||
files: [shareFile],
|
||||
room: room,
|
||||
|
@ -160,12 +159,12 @@ class ChatListItem extends StatelessWidget {
|
|||
return;
|
||||
}
|
||||
final confirmed = await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
cancelLabel: L10n.of(context)!.no,
|
||||
message: L10n.of(context)!.archiveRoomDescription,
|
||||
isDestructiveAction: true,
|
||||
);
|
||||
if (confirmed == OkCancelResult.cancel) return;
|
||||
await showFutureLoadingDialog(
|
||||
|
|
|
@ -94,7 +94,6 @@ class ChatPermissionsSettingsController extends State<ChatPermissionsSettings> {
|
|||
if (newVersion == null ||
|
||||
OkCancelResult.cancel ==
|
||||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
cancelLabel: L10n.of(context)!.cancel,
|
||||
|
|
|
@ -85,7 +85,6 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||
);
|
||||
if (valid.error != null) {
|
||||
await showOkAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
message: L10n.of(context)!.incorrectPassphraseOrKey,
|
||||
);
|
||||
|
|
|
@ -127,7 +127,6 @@ class LoginController extends State<Login> {
|
|||
);
|
||||
final dialogResult = await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
message:
|
||||
L10n.of(context)!.noMatrixServer(newDomain, oldHomeserver!),
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
@ -157,7 +156,6 @@ class LoginController extends State<Login> {
|
|||
|
||||
void passwordForgotten() async {
|
||||
final input = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.passwordForgotten,
|
||||
message: L10n.of(context)!.enterAnEmailAddress,
|
||||
|
@ -186,7 +184,6 @@ class LoginController extends State<Login> {
|
|||
);
|
||||
if (response.error != null) return;
|
||||
final password = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.passwordForgotten,
|
||||
message: L10n.of(context)!.chooseAStrongPassword,
|
||||
|
@ -204,7 +201,6 @@ class LoginController extends State<Login> {
|
|||
);
|
||||
if (password == null) return;
|
||||
final ok = await showOkAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.weSentYouAnEmail,
|
||||
message: L10n.of(context)!.pleaseClickOnLink,
|
||||
|
|
|
@ -35,7 +35,6 @@ class SettingsController extends State<Settings> {
|
|||
void setDisplaynameAction() async {
|
||||
final profile = await profileFuture;
|
||||
final input = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.editDisplayname,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
@ -62,7 +61,6 @@ class SettingsController extends State<Settings> {
|
|||
void logoutAction() async {
|
||||
final noBackup = showChatBackupBanner == true;
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSureYouWantToLogout,
|
||||
message: L10n.of(context)!.noBackupWarning,
|
||||
|
|
|
@ -20,7 +20,6 @@ class Settings3Pid extends StatefulWidget {
|
|||
class Settings3PidController extends State<Settings3Pid> {
|
||||
void add3PidAction() async {
|
||||
final input = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.enterAnEmailAddress,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
@ -44,7 +43,6 @@ class Settings3PidController extends State<Settings3Pid> {
|
|||
);
|
||||
if (response.error != null) return;
|
||||
final ok = await showOkAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.weSentYouAnEmail,
|
||||
message: L10n.of(context)!.pleaseClickOnLink,
|
||||
|
@ -69,7 +67,6 @@ class Settings3PidController extends State<Settings3Pid> {
|
|||
|
||||
void delete3Pid(ThirdPartyIdentifier identifier) async {
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
|
|
|
@ -119,7 +119,6 @@ class _ImportEmoteArchiveDialogState extends State<ImportEmoteArchiveDialog> {
|
|||
final completer = Completer<OkCancelResult>();
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||
final result = await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.emoteExists,
|
||||
message: imageCode,
|
||||
|
|
|
@ -138,7 +138,6 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||
if (pack!.images.keys.any((k) => k == imageCode && k != oldImageCode)) {
|
||||
controller.text = oldImageCode;
|
||||
showOkAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
message: L10n.of(context)!.emoteExists,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
@ -148,7 +147,6 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||
if (!RegExp(r'^[-\w]+$').hasMatch(imageCode)) {
|
||||
controller.text = oldImageCode;
|
||||
showOkAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
message: L10n.of(context)!.emoteInvalid,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
@ -184,7 +182,6 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||
if (newImageCodeController.text.isEmpty ||
|
||||
newImageController.value == null) {
|
||||
await showOkAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
message: L10n.of(context)!.emoteWarnNeedToPick,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
@ -194,7 +191,6 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||
final imageCode = newImageCodeController.text;
|
||||
if (pack!.images.containsKey(imageCode)) {
|
||||
await showOkAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
message: L10n.of(context)!.emoteExists,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
@ -203,7 +199,6 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||
}
|
||||
if (!RegExp(r'^[-\w]+$').hasMatch(imageCode)) {
|
||||
await showOkAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
message: L10n.of(context)!.emoteInvalid,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
@ -310,7 +305,7 @@ class EmotesSettingsController extends State<EmotesSettings> {
|
|||
await showDialog(
|
||||
context: context,
|
||||
// breaks [Matrix.of] calls otherwise
|
||||
useRootNavigator: false,
|
||||
|
||||
builder: (context) => ImportEmoteArchiveDialog(
|
||||
controller: this,
|
||||
archive: archive,
|
||||
|
|
|
@ -28,7 +28,6 @@ class SettingsSecurityController extends State<SettingsSecurity> {
|
|||
AppLock.of(context).showLockScreen();
|
||||
}
|
||||
final newLock = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.pleaseChooseAPasscode,
|
||||
message: L10n.of(context)!.pleaseEnter4Digits,
|
||||
|
@ -57,7 +56,6 @@ class SettingsSecurityController extends State<SettingsSecurity> {
|
|||
|
||||
void deleteAccountAction() async {
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.warning,
|
||||
message: L10n.of(context)!.deactivateAccountWarning,
|
||||
|
@ -69,7 +67,6 @@ class SettingsSecurityController extends State<SettingsSecurity> {
|
|||
}
|
||||
final supposedMxid = Matrix.of(context).client.userID!;
|
||||
final mxids = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.confirmMatrixId,
|
||||
textFields: [
|
||||
|
@ -86,7 +83,6 @@ class SettingsSecurityController extends State<SettingsSecurity> {
|
|||
return;
|
||||
}
|
||||
final input = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.pleaseEnterYourPassword,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
|
|
@ -120,7 +120,6 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
);
|
||||
if (score == null) return;
|
||||
final reason = await showTextInputDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.whyDoYouWantToReportThis,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
|
@ -150,12 +149,12 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
case UserBottomSheetAction.ban:
|
||||
if (user == null) throw ('User must not be null for this action!');
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
cancelLabel: L10n.of(context)!.no,
|
||||
message: L10n.of(context)!.banUserDescription,
|
||||
isDestructiveAction: true,
|
||||
) ==
|
||||
OkCancelResult.ok) {
|
||||
await showFutureLoadingDialog(
|
||||
|
@ -168,7 +167,6 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
case UserBottomSheetAction.unban:
|
||||
if (user == null) throw ('User must not be null for this action!');
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
|
@ -186,7 +184,6 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
case UserBottomSheetAction.kick:
|
||||
if (user == null) throw ('User must not be null for this action!');
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
|
@ -210,7 +207,6 @@ class UserBottomSheetController extends State<UserBottomSheet> {
|
|||
if (newPermission != null) {
|
||||
if (newPermission == 100 &&
|
||||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
|
|
|
@ -324,7 +324,7 @@ class BackgroundPush {
|
|||
}
|
||||
|
||||
Future<void> setupUp() async {
|
||||
await UnifiedPush.registerAppWithDialog(matrix!.context);
|
||||
await UnifiedPush.registerAppWithDialog(matrix!.navigatorContext);
|
||||
}
|
||||
|
||||
Future<void> _newUpEndpoint(String newEndpoint, String i) async {
|
||||
|
|
|
@ -22,7 +22,7 @@ extension UiaRequestManager on MatrixState {
|
|||
case AuthenticationTypes.password:
|
||||
final input = cachedPassword ??
|
||||
(await showTextInputDialog(
|
||||
context: context,
|
||||
context: navigatorContext,
|
||||
title: l10n.pleaseEnterYourPassword,
|
||||
okLabel: l10n.ok,
|
||||
cancelLabel: l10n.cancel,
|
||||
|
@ -62,8 +62,7 @@ extension UiaRequestManager on MatrixState {
|
|||
);
|
||||
if (OkCancelResult.ok ==
|
||||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
context: navigatorContext,
|
||||
title: l10n.weSentYouAnEmail,
|
||||
message: l10n.pleaseClickOnLink,
|
||||
okLabel: l10n.iHaveClickedOnLink,
|
||||
|
@ -86,9 +85,8 @@ extension UiaRequestManager on MatrixState {
|
|||
launchUrlString(url.toString());
|
||||
if (OkCancelResult.ok ==
|
||||
await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
message: l10n.pleaseFollowInstructionsOnWeb,
|
||||
context: context,
|
||||
context: navigatorContext,
|
||||
okLabel: l10n.next,
|
||||
cancelLabel: l10n.cancel,
|
||||
)) {
|
||||
|
|
|
@ -189,7 +189,6 @@ class UrlLauncher {
|
|||
}
|
||||
if (roomIdOrAlias.sigil == '!') {
|
||||
if (await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: 'Join room $roomIdOrAlias',
|
||||
) ==
|
||||
|
|
|
@ -247,7 +247,6 @@ class CallKeepManager {
|
|||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
useRootNavigator: false,
|
||||
builder: (_) => AlertDialog(
|
||||
title: Text(L10n.of(context)!.callingPermissions),
|
||||
content: Column(
|
||||
|
|
|
@ -106,12 +106,12 @@ class ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
switch (choice) {
|
||||
case 'leave':
|
||||
final confirmed = await showOkCancelAlertDialog(
|
||||
useRootNavigator: false,
|
||||
context: context,
|
||||
title: L10n.of(context)!.areYouSure,
|
||||
okLabel: L10n.of(context)!.ok,
|
||||
cancelLabel: L10n.of(context)!.cancel,
|
||||
message: L10n.of(context)!.archiveRoomDescription,
|
||||
isDestructiveAction: true,
|
||||
);
|
||||
if (confirmed == OkCancelResult.ok) {
|
||||
final success = await showFutureLoadingDialog(
|
||||
|
|
|
@ -52,19 +52,13 @@ class FluffyChatApp extends StatelessWidget {
|
|||
builder: (context, child) => AppLockWidget(
|
||||
pincode: pincode,
|
||||
clients: clients,
|
||||
// Need a navigator above the Matrix widget for
|
||||
// displaying dialogs
|
||||
child: Navigator(
|
||||
onGenerateRoute: (_) => MaterialPageRoute(
|
||||
builder: (_) => Matrix(
|
||||
child: Matrix(
|
||||
clients: clients,
|
||||
store: store,
|
||||
child: testWidget ?? child,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,8 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
|
||||
BackgroundPush? backgroundPush;
|
||||
|
||||
late BuildContext navigatorContext;
|
||||
|
||||
Client get client {
|
||||
if (widget.clients.isEmpty) {
|
||||
widget.clients.add(getLoginClient());
|
||||
|
@ -311,7 +313,8 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
};
|
||||
request.onUpdate = null;
|
||||
hidPopup = true;
|
||||
await KeyVerificationDialog(request: request).show(context);
|
||||
|
||||
await KeyVerificationDialog(request: request).show(navigatorContext);
|
||||
});
|
||||
onLoginStateChanged[name] ??= c.onLoginStateChanged.stream.listen((state) {
|
||||
final loggedInWithMultipleClients = widget.clients.length > 1;
|
||||
|
@ -322,7 +325,7 @@ 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(navigatorContext).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(L10n.of(context)!.oneClientLoggedOut),
|
||||
),
|
||||
|
@ -382,7 +385,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
onFcmError: (errorMsg, {Uri? link}) async {
|
||||
final result = await showOkCancelAlertDialog(
|
||||
barrierDismissible: true,
|
||||
context: context,
|
||||
context: navigatorContext,
|
||||
title: L10n.of(context)!.pushNotificationsNotAvailable,
|
||||
message: errorMsg,
|
||||
fullyCapitalizedForMaterial: false,
|
||||
|
|
Loading…
Reference in a new issue