From d1ce1e3ba721a3d66949d8765a1134dbfc85f771 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Sun, 29 Oct 2023 09:32:06 +0100 Subject: [PATCH] refactor: Make file dialog adaptive and adjust design --- lib/pages/chat/chat.dart | 14 +++++----- lib/pages/chat/send_file_dialog.dart | 33 +++++++++++++----------- lib/pages/chat/send_location_dialog.dart | 19 +------------- 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 8bda7266..bfdd10a2 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -149,7 +149,7 @@ class ChatController extends State { ); } - await showDialog( + await showAdaptiveDialog( context: context, useRootNavigator: false, builder: (c) => SendFileDialog( @@ -490,7 +490,7 @@ class ChatController extends State { ), ); if (result == null || result.files.isEmpty) return; - await showDialog( + await showAdaptiveDialog( context: context, useRootNavigator: false, builder: (c) => SendFileDialog( @@ -508,7 +508,7 @@ class ChatController extends State { } void sendImageFromClipBoard(Uint8List? image) async { - await showDialog( + await showAdaptiveDialog( context: context, useRootNavigator: false, builder: (c) => SendFileDialog( @@ -533,7 +533,7 @@ class ChatController extends State { ); if (result == null || result.files.isEmpty) return; - await showDialog( + await showAdaptiveDialog( context: context, useRootNavigator: false, builder: (c) => SendFileDialog( @@ -556,7 +556,7 @@ class ChatController extends State { final file = await ImagePicker().pickImage(source: ImageSource.camera); if (file == null) return; final bytes = await file.readAsBytes(); - await showDialog( + await showAdaptiveDialog( context: context, useRootNavigator: false, builder: (c) => SendFileDialog( @@ -580,7 +580,7 @@ class ChatController extends State { ); if (file == null) return; final bytes = await file.readAsBytes(); - await showDialog( + await showAdaptiveDialog( context: context, useRootNavigator: false, builder: (c) => SendFileDialog( @@ -688,7 +688,7 @@ class ChatController extends State { } void sendLocationAction() async { - await showDialog( + await showAdaptiveDialog( context: context, useRootNavigator: false, builder: (c) => SendLocationDialog(room: room), diff --git a/lib/pages/chat/send_file_dialog.dart b/lib/pages/chat/send_file_dialog.dart index 57ddf0a2..28c6bf53 100644 --- a/lib/pages/chat/send_file_dialog.dart +++ b/lib/pages/chat/send_file_dialog.dart @@ -4,6 +4,7 @@ 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/config/app_config.dart'; import 'package:fluffychat/utils/localized_exception_extension.dart'; import 'package:fluffychat/utils/size_string.dart'; import '../../utils/resize_image.dart'; @@ -84,29 +85,31 @@ class SendFileDialogState extends State { mainAxisSize: MainAxisSize.min, children: [ Flexible( - child: Image.memory( - widget.files.first.bytes, - fit: BoxFit.contain, + child: Material( + borderRadius: BorderRadius.circular(AppConfig.borderRadius), + elevation: + Theme.of(context).appBarTheme.scrolledUnderElevation ?? 4, + shadowColor: Theme.of(context).appBarTheme.shadowColor, + child: Image.memory( + widget.files.first.bytes, + fit: BoxFit.contain, + height: 256, + ), ), ), - Row( - children: [ - Checkbox( - value: origImage, - onChanged: (v) => setState(() => origImage = v ?? false), - ), - InkWell( - onTap: () => setState(() => origImage = !origImage), - child: Text('${L10n.of(context)!.sendOriginal} ($sizeString)'), - ), - ], + SwitchListTile.adaptive( + value: origImage, + contentPadding: EdgeInsets.zero, + onChanged: (v) => setState(() => origImage = v), + title: Text(L10n.of(context)!.sendOriginal), + subtitle: Text(sizeString), ), ], ); } else { contentWidget = Text('$fileName ($sizeString)'); } - return AlertDialog( + return AlertDialog.adaptive( title: Text(sendStr), content: contentWidget, actions: [ diff --git a/lib/pages/chat/send_location_dialog.dart b/lib/pages/chat/send_location_dialog.dart index 182362b5..b2a99004 100644 --- a/lib/pages/chat/send_location_dialog.dart +++ b/lib/pages/chat/send_location_dialog.dart @@ -9,7 +9,6 @@ import 'package:geolocator/geolocator.dart'; import 'package:matrix/matrix.dart'; import 'package:fluffychat/pages/chat/events/map_bubble.dart'; -import 'package:fluffychat/utils/platform_infos.dart'; class SendLocationDialog extends StatefulWidget { final Room room; @@ -111,23 +110,7 @@ class SendLocationDialogState extends State { ], ); } - if (PlatformInfos.isCupertinoStyle) { - return CupertinoAlertDialog( - title: Text(L10n.of(context)!.shareLocation), - content: contentWidget, - actions: [ - CupertinoDialogAction( - onPressed: Navigator.of(context, rootNavigator: false).pop, - child: Text(L10n.of(context)!.cancel), - ), - CupertinoDialogAction( - onPressed: isSending ? null : sendAction, - child: Text(L10n.of(context)!.send), - ), - ], - ); - } - return AlertDialog( + return AlertDialog.adaptive( title: Text(L10n.of(context)!.shareLocation), content: contentWidget, actions: [