Skip to content

Commit

Permalink
Apply new dialog use context global of GoRouter for all screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Nov 6, 2023
1 parent ebace03 commit 556aaa1
Show file tree
Hide file tree
Showing 44 changed files with 254 additions and 301 deletions.
11 changes: 4 additions & 7 deletions lib/pages/add_story/add_story.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'dart:math';

import 'package:collection/collection.dart';
import 'package:file_picker/file_picker.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:flutter/material.dart';

import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:go_router/go_router.dart';
import 'package:image_picker/image_picker.dart';
import 'package:matrix/matrix.dart';
Expand Down Expand Up @@ -89,8 +89,7 @@ class AddStoryController extends State<AddStoryPage> {
source: ImageSource.camera,
);
if (picked == null) return;
final matrixFile = await showFutureLoadingDialog(
context: context,
final matrixFile = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
final bytes = await picked.readAsBytes();
return MatrixImageFile(
Expand Down Expand Up @@ -139,8 +138,7 @@ class AddStoryController extends State<AddStoryPage> {
var storiesRoom = await client.getStoriesRoom(context);

// Invite contacts if necessary
final undecided = await showFutureLoadingDialog(
context: context,
final undecided = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => client.getUndecidedContactsForStories(storiesRoom),
);
final result = undecided.result;
Expand All @@ -156,8 +154,7 @@ class AddStoryController extends State<AddStoryPage> {
}

// Post story
final postResult = await showFutureLoadingDialog(
context: context,
final postResult = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
if (storiesRoom == null) throw ('Stories room is null');
var video = this.video?.detectFileType;
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/add_story/invite_story_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:flutter/material.dart';

import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';

import 'package:matrix/matrix.dart';

import 'package:fluffychat/utils/localized_exception_extension.dart';
Expand Down Expand Up @@ -33,8 +34,7 @@ class InviteStoryPageState extends State<InviteStoryPage> {
cancelLabel: L10n.of(context)!.cancel,
);
if (confirmed != OkCancelResult.ok) return;
final result = await showFutureLoadingDialog(
context: context,
final result = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
final client = Matrix.of(context).client;
var room = await client.getStoriesRoom(context);
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/archive/archive.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:flutter/material.dart';

import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';

import 'package:matrix/matrix.dart';

import 'package:fluffychat/pages/archive/archive_view.dart';
Expand Down Expand Up @@ -38,8 +39,7 @@ class ArchiveController extends State<Archive> {
OkCancelResult.ok) {
return;
}
await showFutureLoadingDialog(
context: context,
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
while (archive.isNotEmpty) {
Logs().v('Forget room ${archive.last.getLocalizedDisplayname()}');
Expand Down
26 changes: 11 additions & 15 deletions lib/pages/bootstrap/bootstrap_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/bootstrap/tom_bootstrap_dialog.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/adaptive_flat_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';

import 'package:google_fonts/google_fonts.dart';
import 'package:matrix/encryption.dart';
import 'package:matrix/encryption/utils/bootstrap.dart';
Expand All @@ -19,24 +20,19 @@ import '../key_verification/key_verification_dialog.dart';
class BootstrapDialog extends StatefulWidget {
final bool wipe;
final Client client;

const BootstrapDialog({
Key? key,
this.wipe = false,
required this.client,
}) : super(key: key);

Future<bool?> show(BuildContext context) => PlatformInfos.isCupertinoStyle
? showCupertinoDialog(
context: context,
builder: (context) => this,
barrierDismissible: true,
useRootNavigator: false,
Future<bool?> show() => PlatformInfos.isCupertinoStyle
? TwakeDialog.showCupertinoDialogFullScreen(
builder: () => this,
)
: showDialog(
context: context,
builder: (context) => this,
barrierDismissible: true,
useRootNavigator: false,
: TwakeDialog.showDialogFullScreen(
builder: () => this,
);

@override
Expand Down Expand Up @@ -344,8 +340,8 @@ class BootstrapDialogState extends State<BootstrapDialog> {
onPressed: _recoveryKeyInputLoading
? null
: () async {
final req = await showFutureLoadingDialog(
context: context,
final req = await TwakeDialog
.showFutureLoadingDialogFullScreen(
future: () => widget.client
.userDeviceKeys[widget.client.userID!]!
.startVerification(),
Expand Down Expand Up @@ -380,7 +376,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
wipe: true,
wipeRecovery: true,
client: widget.client,
).show(context).then(
).show().then(
(value) => Navigator.of(
context,
rootNavigator: false,
Expand Down
10 changes: 4 additions & 6 deletions lib/pages/bootstrap/tom_bootstrap_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/model/recovery_words/recovery_words.dart';
import 'package:fluffychat/domain/usecase/recovery/delete_recovery_words_interactor.dart';
import 'package:fluffychat/domain/usecase/recovery/save_recovery_words_interactor.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:fluffychat/widgets/adaptive_flat_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
Expand All @@ -25,11 +26,8 @@ class TomBootstrapDialog extends StatefulWidget {
required this.client,
}) : super(key: key);

Future<bool?> show(BuildContext context) => showDialog(
context: context,
builder: (context) => this,
barrierDismissible: true,
useRootNavigator: false,
Future<bool?> show() => TwakeDialog.showDialogFullScreen(
builder: () => this,
);

@override
Expand Down Expand Up @@ -157,7 +155,7 @@ class TomBootstrapDialogState extends State<TomBootstrapDialog> {
AdaptiveFlatButton(
label: L10n.of(context)!.next,
onPressed: () async {
await BootstrapDialog(client: widget.client).show(context).then(
await BootstrapDialog(client: widget.client).show().then(
(value) => Navigator.of(context, rootNavigator: false)
.pop<bool>(false),
);
Expand Down
49 changes: 18 additions & 31 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import 'package:fluffychat/presentation/mixins/send_files_mixin.dart';
import 'package:fluffychat/presentation/model/forward/forward_argument.dart';
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
import 'package:fluffychat/utils/clipboard.dart';
import 'package:fluffychat/utils/dialog/twake_loading_dialog.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:fluffychat/utils/extension/build_context_extension.dart';
import 'package:fluffychat/utils/extension/value_notifier_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/event_extension.dart';
Expand All @@ -52,7 +52,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';

import 'package:go_router/go_router.dart';
import 'package:image_picker/image_picker.dart';
import 'package:linagora_design_flutter/images_picker/asset_counter.dart';
Expand Down Expand Up @@ -160,8 +160,7 @@ class ChatController extends State<Chat>
final sendFileOnWebInteractor = getIt.get<SendFileOnWebInteractor>();

draggingNotifier.value = false;
final bytesList = await showFutureLoadingDialog(
context: context,
final bytesList = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => Future.wait(
details.files.map(
(xfile) => xfile.readAsBytes(),
Expand Down Expand Up @@ -221,8 +220,7 @@ class ChatController extends State<Chat>
'Try to recreate a room with is not a DM room. This should not be possible from the UI!',
);
}
final success = await showFutureLoadingDialog(
context: context,
final success = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
final client = room.client;
final waitForSync = client.onSync.stream
Expand All @@ -244,8 +242,7 @@ class ChatController extends State<Chat>
'Leave room button clicked while room is null. This should not be possible from the UI!',
);
}
final success = await showFutureLoadingDialog(
context: context,
final success = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: room.leave,
);
if (success.error != null) return;
Expand Down Expand Up @@ -361,8 +358,7 @@ class ChatController extends State<Chat>
) async {
switch (dialogAcceptInviteResult) {
case DialogAcceptInviteResult.accept:
await showFutureLoadingDialog(
context: context,
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
final waitForRoom = room?.client.waitForRoomInSync(
room!.id,
Expand Down Expand Up @@ -603,16 +599,16 @@ class ChatController extends State<Chat>
if (failure is DownloadFileForPreviewFailure) {
TwakeSnackBar.show(context, 'Error: ${failure.exception}');
}
TwakeLoadingDialog.hideLoadingDialog(context);
TwakeDialog.hideLoadingDialog(context);
}, (success) {
if (success is DownloadFileForPreviewSuccess) {
_openDownloadedFileForPreview(
downloadFileForPreviewResponse:
success.downloadFileForPreviewResponse,
);
TwakeLoadingDialog.hideLoadingDialog(context);
TwakeDialog.hideLoadingDialog(context);
} else if (success is DownloadFileForPreviewLoading) {
TwakeLoadingDialog.showLoadingDialog(context);
TwakeDialog.showLoadingDialog(context);
}
});
});
Expand Down Expand Up @@ -857,8 +853,7 @@ class ChatController extends State<Chat>
textFields: [DialogTextField(hintText: L10n.of(context)!.reason)],
);
if (reason == null || reason.single.isEmpty) return;
final result = await showFutureLoadingDialog(
context: context,
final result = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => Matrix.of(context).client.reportContent(
event.roomId!,
event.eventId,
Expand All @@ -885,8 +880,7 @@ class ChatController extends State<Chat>
OkCancelResult.ok;
if (!confirmed) return;
for (final event in selectedEvents) {
await showFutureLoadingDialog(
context: context,
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
if (event.status.isSent) {
if (event.canRedact) {
Expand Down Expand Up @@ -991,8 +985,7 @@ class ChatController extends State<Chat>
if (eventIndex == -1) {
// event id not found...maybe we can fetch it?
// the try...finally is here to start and close the loading dialog reliably
await showFutureLoadingDialog(
context: context,
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
// okay, we first have to fetch if the event is in the room
try {
Expand Down Expand Up @@ -1073,8 +1066,7 @@ class ChatController extends State<Chat>
}

void forgetRoom() async {
final result = await showFutureLoadingDialog(
context: context,
final result = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: room!.forget,
);
if (result.error != null) return;
Expand Down Expand Up @@ -1183,17 +1175,15 @@ class ChatController extends State<Chat>
)) {
return;
}
final result = await showFutureLoadingDialog(
context: context,
final result = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => room!.client.joinRoom(
room!
.getState(EventTypes.RoomTombstone)!
.parsedTombstoneContent
.replacementRoom,
),
);
await showFutureLoadingDialog(
context: context,
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: room!.leave,
);
if (result.error == null) {
Expand Down Expand Up @@ -1253,8 +1243,7 @@ class ChatController extends State<Chat>
if (response == OkCancelResult.ok) {
final events = room!.pinnedEventIds
..removeWhere((oldEvent) => oldEvent == eventId);
showFutureLoadingDialog(
context: context,
TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => room!.setPinnedEvents(events),
);
}
Expand All @@ -1272,8 +1261,7 @@ class ChatController extends State<Chat>
} else {
pinnedEventIds.addAll(selectedEventIds);
}
showFutureLoadingDialog(
context: context,
TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => room.setPinnedEvents(pinnedEventIds),
);
}
Expand Down Expand Up @@ -1359,8 +1347,7 @@ class ChatController extends State<Chat>
);
if (callType == null) return;

final success = await showFutureLoadingDialog(
context: context,
final success = await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () =>
Matrix.of(context).voipPlugin!.voip.requestTurnServerCredentials(),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat/events/encrypted_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mixin EncryptedMixin {
if (client.isUnknownSession && client.encryption!.crossSigning.enabled) {
final success = await BootstrapDialog(
client: Matrix.of(context).client,
).show(context);
).show();
if (success != true) return;
}
event.requestKey();
Expand Down
5 changes: 2 additions & 3 deletions lib/pages/chat/events/message_reactions.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:fluffychat/pages/chat/events/message_reactions_style.dart';
import 'package:fluffychat/utils/dialog/twake_dialog.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:collection/collection.dart' show IterableExtension;
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart';

import 'package:fluffychat/config/app_config.dart';
Expand Down Expand Up @@ -109,8 +109,7 @@ class ReactionsList extends StatelessWidget {
relatedTo['key'] == r.key;
});
if (evt != null) {
showFutureLoadingDialog(
context: context,
TwakeDialog.showFutureLoadingDialogFullScreen(
future: () => evt.redactEvent(),
);
}
Expand Down
Loading

0 comments on commit 556aaa1

Please sign in to comment.