Skip to content

Commit

Permalink
refactor: Implement own adaptive dialogs and remove package
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Dec 10, 2024
1 parent dea2916 commit 8819c40
Show file tree
Hide file tree
Showing 42 changed files with 597 additions and 439 deletions.
5 changes: 0 additions & 5 deletions lib/config/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ abstract class FluffyThemes {
),
),
),
dialogTheme: DialogTheme(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
),
snackBarTheme: const SnackBarThemeData(
behavior: SnackBarBehavior.floating,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/archive/archive.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';

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

import 'package:fluffychat/pages/archive/archive_view.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';

Expand Down
5 changes: 2 additions & 3 deletions lib/pages/bootstrap/bootstrap_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';

import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:matrix/encryption.dart';
Expand All @@ -11,6 +10,7 @@ import 'package:fluffychat/utils/error_reporter.dart';
import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import '../../utils/adaptive_bottom_sheet.dart';
import '../key_verification/key_verification_dialog.dart';
Expand Down Expand Up @@ -366,7 +366,6 @@ class BootstrapDialogState extends State<BootstrapDialog> {
.verifyOtherDeviceDescription,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
fullyCapitalizedForMaterial: false,
);
if (consent != OkCancelResult.ok) return;
final req = await showFutureLoadingDialog(
Expand Down Expand Up @@ -404,7 +403,7 @@ class BootstrapDialogState extends State<BootstrapDialog> {
message: L10n.of(context).wipeChatBackup,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
isDestructiveAction: true,
isDestructive: true,
)) {
setState(() => _createBootstrap(true));
}
Expand Down
51 changes: 24 additions & 27 deletions lib/pages/chat/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:collection/collection.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:device_info_plus/device_info_plus.dart';
Expand Down Expand Up @@ -33,6 +32,9 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/filtered_timeline_extensi
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/show_scaffold_dialog.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/share_scaffold_dialog.dart';
Expand Down Expand Up @@ -691,23 +693,22 @@ class ChatController extends State<ChatPageWithRoom>

void reportEventAction() async {
final event = selectedEvents.single;
final score = await showConfirmationDialog<int>(
final score = await showModalActionPopup<int>(
context: context,
title: L10n.of(context).reportMessage,
message: L10n.of(context).howOffensiveIsThisContent,
cancelLabel: L10n.of(context).cancel,
okLabel: L10n.of(context).ok,
actions: [
AlertDialogAction(
key: -100,
AdaptiveModalAction(
value: -100,
label: L10n.of(context).extremeOffensive,
),
AlertDialogAction(
key: -50,
AdaptiveModalAction(
value: -50,
label: L10n.of(context).offensive,
),
AlertDialogAction(
key: 0,
AdaptiveModalAction(
value: 0,
label: L10n.of(context).inoffensive,
),
],
Expand All @@ -718,15 +719,15 @@ class ChatController extends State<ChatPageWithRoom>
title: L10n.of(context).whyDoYouWantToReportThis,
okLabel: L10n.of(context).ok,
cancelLabel: L10n.of(context).cancel,
textFields: [DialogTextField(hintText: L10n.of(context).reason)],
hintText: L10n.of(context).reason,
);
if (reason == null || reason.single.isEmpty) return;
if (reason == null || reason.isEmpty) return;
final result = await showFutureLoadingDialog(
context: context,
future: () => Matrix.of(context).client.reportContent(
event.roomId!,
event.eventId,
reason: reason.single,
reason: reason,
score: score,
),
);
Expand Down Expand Up @@ -765,18 +766,14 @@ class ChatController extends State<ChatPageWithRoom>
context: context,
title: L10n.of(context).redactMessage,
message: L10n.of(context).redactMessageDescription,
isDestructiveAction: true,
textFields: [
DialogTextField(
hintText: L10n.of(context).optionalRedactReason,
),
],
isDestructive: true,
hintText: L10n.of(context).optionalRedactReason,
okLabel: L10n.of(context).remove,
cancelLabel: L10n.of(context).cancel,
)
: <String>[];
: null;
if (reasonInput == null) return;
final reason = reasonInput.single.isEmpty ? null : reasonInput.single;
final reason = reasonInput.isEmpty ? null : reasonInput;
for (final event in selectedEvents) {
await showFutureLoadingDialog(
context: context,
Expand Down Expand Up @@ -1243,21 +1240,21 @@ class ChatController extends State<ChatPageWithRoom>
}
});
}
final callType = await showModalActionSheet<CallType>(
final callType = await showModalActionPopup<CallType>(
context: context,
title: L10n.of(context).warning,
message: L10n.of(context).videoCallsBetaWarning,
cancelLabel: L10n.of(context).cancel,
actions: [
SheetAction(
AdaptiveModalAction(
label: L10n.of(context).voiceCall,
icon: Icons.phone_outlined,
key: CallType.kVoice,
icon: const Icon(Icons.phone_outlined),
value: CallType.kVoice,
),
SheetAction(
AdaptiveModalAction(
label: L10n.of(context).videoCall,
icon: Icons.video_call_outlined,
key: CallType.kVideo,
icon: const Icon(Icons.video_call_outlined),
value: CallType.kVideo,
),
],
);
Expand Down
12 changes: 7 additions & 5 deletions lib/pages/chat/pinned_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'dart:async';

import 'package:flutter/material.dart';

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

import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/pages/chat/chat_app_bar_list_tile.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';

class PinnedEvents extends StatelessWidget {
Expand All @@ -30,13 +30,15 @@ class PinnedEvents extends StatelessWidget {

final eventId = events.length == 1
? events.single?.eventId
: await showConfirmationDialog<String>(
: await showModalActionPopup<String>(
context: context,
title: L10n.of(context).pinMessage,
title: L10n.of(context).pin,
cancelLabel: L10n.of(context).cancel,
actions: events
.map(
(event) => AlertDialogAction(
key: event?.eventId ?? '',
(event) => AdaptiveModalAction(
value: event?.eventId ?? '',
icon: const Icon(Icons.push_pin_outlined),
label: event?.calcLocalizedBodyFallback(
MatrixLocals(L10n.of(context)),
withSenderNamePrefix: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat/send_file_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/utils/size_string.dart';
import 'package:fluffychat/widgets/adaptive_dialog_action.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/adaptive_dialog_action.dart';
import '../../utils/resize_video.dart';

class SendFileDialog extends StatefulWidget {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/chat/send_location_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:geolocator/geolocator.dart';
import 'package:matrix/matrix.dart';

import 'package:fluffychat/pages/chat/events/map_bubble.dart';
import 'package:fluffychat/widgets/adaptive_dialog_action.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/adaptive_dialog_action.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';

class SendLocationDialog extends StatefulWidget {
Expand Down
25 changes: 12 additions & 13 deletions lib/pages/chat_access_settings/chat_access_settings_controller.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:flutter/material.dart' hide Visibility;

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

import 'package:fluffychat/pages/chat_access_settings/chat_access_settings_page.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_modal_action_popup.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_ok_cancel_alert_dialog.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/show_text_input_dialog.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';

Expand Down Expand Up @@ -149,14 +151,15 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
);
final capabilities = capabilitiesResult.result;
if (capabilities == null) return;
final newVersion = await showConfirmationDialog<String>(
final newVersion = await showModalActionPopup<String>(
context: context,
title: L10n.of(context).replaceRoomWithNewerVersion,
cancelLabel: L10n.of(context).cancel,
actions: capabilities.mRoomVersions!.available.entries
.where((r) => r.key != roomVersion)
.map(
(version) => AlertDialogAction(
key: version.key,
(version) => AdaptiveModalAction(
value: version.key,
label:
'${version.key} (${version.value.toString().split('.').last})',
),
Expand All @@ -172,7 +175,7 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
cancelLabel: L10n.of(context).cancel,
title: L10n.of(context).areYouSure,
message: L10n.of(context).roomUpgradeDescription,
isDestructiveAction: true,
isDestructive: true,
)) {
return;
}
Expand All @@ -191,15 +194,11 @@ class ChatAccessSettingsController extends State<ChatAccessSettings> {
final input = await showTextInputDialog(
context: context,
title: L10n.of(context).editRoomAliases,
textFields: [
DialogTextField(
prefixText: '#',
suffixText: domain,
hintText: L10n.of(context).alias,
),
],
prefixText: '#',
suffixText: domain,
hintText: L10n.of(context).alias,
);
final aliasLocalpart = input?.singleOrNull?.trim();
final aliasLocalpart = input?.trim();
if (aliasLocalpart == null || aliasLocalpart.isEmpty) return;
final alias = '#$aliasLocalpart:$domain';

Expand Down
Loading

0 comments on commit 8819c40

Please sign in to comment.