diff --git a/lib/pages/chat/send_file_dialog.dart b/lib/pages/chat/send_file_dialog.dart index 121c215d6..8d7fcaad0 100644 --- a/lib/pages/chat/send_file_dialog.dart +++ b/lib/pages/chat/send_file_dialog.dart @@ -14,6 +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 '../../utils/resize_video.dart'; class SendFileDialog extends StatefulWidget { @@ -288,14 +289,12 @@ class SendFileDialogState extends State { title: Text(sendStr), content: contentWidget, actions: [ - TextButton( - onPressed: () { - // just close the dialog - Navigator.of(context, rootNavigator: false).pop(); - }, + AdaptiveDialogAction( + onPressed: () => + Navigator.of(context, rootNavigator: false).pop(), child: Text(L10n.of(context).cancel), ), - TextButton( + AdaptiveDialogAction( onPressed: _send, child: Text(L10n.of(context).send), ), diff --git a/lib/pages/chat/send_location_dialog.dart b/lib/pages/chat/send_location_dialog.dart index bb5c9155b..31a311f72 100644 --- a/lib/pages/chat/send_location_dialog.dart +++ b/lib/pages/chat/send_location_dialog.dart @@ -8,6 +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/future_loading_dialog.dart'; class SendLocationDialog extends StatefulWidget { @@ -114,12 +115,12 @@ class SendLocationDialogState extends State { title: Text(L10n.of(context).shareLocation), content: contentWidget, actions: [ - TextButton( + AdaptiveDialogAction( onPressed: Navigator.of(context, rootNavigator: false).pop, child: Text(L10n.of(context).cancel), ), if (position != null) - TextButton( + AdaptiveDialogAction( onPressed: isSending ? null : sendAction, child: Text(L10n.of(context).send), ), diff --git a/lib/pages/chat_details/participant_list_item.dart b/lib/pages/chat_details/participant_list_item.dart index c77407b91..b71f37310 100644 --- a/lib/pages/chat_details/participant_list_item.dart +++ b/lib/pages/chat_details/participant_list_item.dart @@ -1,9 +1,9 @@ -import 'package:fluffychat/config/app_config.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:matrix/matrix.dart'; +import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/utils/adaptive_bottom_sheet.dart'; import '../../widgets/avatar.dart'; import '../user_bottom_sheet/user_bottom_sheet.dart'; diff --git a/lib/pages/homeserver_picker/homeserver_picker_view.dart b/lib/pages/homeserver_picker/homeserver_picker_view.dart index 71ca58fd3..4aa4d2929 100644 --- a/lib/pages/homeserver_picker/homeserver_picker_view.dart +++ b/lib/pages/homeserver_picker/homeserver_picker_view.dart @@ -5,6 +5,7 @@ import 'package:flutter_linkify/flutter_linkify.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:fluffychat/config/app_config.dart'; +import 'package:fluffychat/widgets/adaptive_dialog_action.dart'; import 'package:fluffychat/widgets/layouts/login_scaffold.dart'; import 'package:fluffychat/widgets/matrix.dart'; import '../../config/themes.dart'; @@ -107,7 +108,7 @@ class HomeserverPickerView extends StatelessWidget { text: L10n.of(context).homeserverDescription, ), actions: [ - TextButton( + AdaptiveDialogAction( onPressed: () => launchUrl( Uri.https('servers.joinmatrix.org'), ), @@ -115,7 +116,7 @@ class HomeserverPickerView extends StatelessWidget { L10n.of(context).discoverHomeservers, ), ), - TextButton( + AdaptiveDialogAction( onPressed: Navigator.of(context).pop, child: Text(L10n.of(context).close), ), diff --git a/lib/pages/key_verification/key_verification_dialog.dart b/lib/pages/key_verification/key_verification_dialog.dart index 2767b18a5..8d195149b 100644 --- a/lib/pages/key_verification/key_verification_dialog.dart +++ b/lib/pages/key_verification/key_verification_dialog.dart @@ -9,6 +9,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:matrix/encryption.dart'; import 'package:matrix/matrix.dart'; +import 'package:fluffychat/widgets/adaptive_dialog_action.dart'; import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/future_loading_dialog.dart'; @@ -150,7 +151,7 @@ class KeyVerificationPageState extends State { ), ); buttons.add( - TextButton( + AdaptiveDialogAction( child: Text( L10n.of(context).submit, ), @@ -158,7 +159,7 @@ class KeyVerificationPageState extends State { ), ); buttons.add( - TextButton( + AdaptiveDialogAction( child: Text( L10n.of(context).skip, ), @@ -320,7 +321,7 @@ class KeyVerificationPageState extends State { ], ); buttons.add( - TextButton( + AdaptiveDialogAction( child: Text( L10n.of(context).close, ), @@ -343,7 +344,7 @@ class KeyVerificationPageState extends State { ], ); buttons.add( - TextButton( + AdaptiveDialogAction( child: Text( L10n.of(context).close, ), diff --git a/lib/utils/error_reporter.dart b/lib/utils/error_reporter.dart index 28e7b374a..72cfb83a2 100644 --- a/lib/utils/error_reporter.dart +++ b/lib/utils/error_reporter.dart @@ -8,6 +8,7 @@ import 'package:matrix/matrix.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:fluffychat/config/app_config.dart'; +import 'package:fluffychat/widgets/adaptive_dialog_action.dart'; class ErrorReporter { final BuildContext context; @@ -34,17 +35,17 @@ class ErrorReporter { ), ), actions: [ - TextButton( + AdaptiveDialogAction( onPressed: () => Navigator.of(context).pop(), child: Text(L10n.of(context).close), ), - TextButton( + AdaptiveDialogAction( onPressed: () => Clipboard.setData( ClipboardData(text: text), ), child: Text(L10n.of(context).copy), ), - TextButton( + AdaptiveDialogAction( onPressed: () => launchUrl( AppConfig.newIssueUrl.resolveUri( Uri( diff --git a/lib/utils/size_string.dart b/lib/utils/size_string.dart index 930a97f9a..315033076 100644 --- a/lib/utils/size_string.dart +++ b/lib/utils/size_string.dart @@ -1,18 +1,21 @@ extension SizeString on num { String get sizeString { var size = toDouble(); - if (size < 1000000) { + if (size < 1000) { + return '${size.round()} Bytes'; + } + if (size < 1000 * 1000) { size = size / 1000; size = (size * 10).round() / 10; return '${size.toString()} KB'; - } else if (size < 1000000000) { + } + if (size < 1000 * 1000 * 1000) { size = size / 1000000; size = (size * 10).round() / 10; return '${size.toString()} MB'; - } else { - size = size / 1000000000; - size = (size * 10).round() / 10; - return '${size.toString()} GB'; } + size = size / 1000 * 1000 * 1000 * 1000; + size = (size * 10).round() / 10; + return '${size.toString()} GB'; } } diff --git a/lib/widgets/adaptive_dialog_action.dart b/lib/widgets/adaptive_dialog_action.dart new file mode 100644 index 000000000..3df21c33b --- /dev/null +++ b/lib/widgets/adaptive_dialog_action.dart @@ -0,0 +1,28 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class AdaptiveDialogAction extends StatelessWidget { + final VoidCallback? onPressed; + final Widget child; + + const AdaptiveDialogAction({ + super.key, + required this.onPressed, + required this.child, + }); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + switch (theme.platform) { + case TargetPlatform.android: + case TargetPlatform.fuchsia: + case TargetPlatform.linux: + case TargetPlatform.windows: + return TextButton(onPressed: onPressed, child: child); + case TargetPlatform.iOS: + case TargetPlatform.macOS: + return CupertinoDialogAction(onPressed: onPressed, child: child); + } + } +} diff --git a/lib/widgets/future_loading_dialog.dart b/lib/widgets/future_loading_dialog.dart index bd042487f..3df0cf8c0 100644 --- a/lib/widgets/future_loading_dialog.dart +++ b/lib/widgets/future_loading_dialog.dart @@ -6,6 +6,7 @@ import 'package:async/async.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:fluffychat/utils/localized_exception_extension.dart'; +import 'package:fluffychat/widgets/adaptive_dialog_action.dart'; /// Displays a loading dialog which reacts to the given [future]. The dialog /// will be dismissed and the value will be returned when the future completes. @@ -120,7 +121,7 @@ class LoadingDialogState extends State { actions: exception == null ? null : [ - TextButton( + AdaptiveDialogAction( onPressed: () => Navigator.of(context).pop>( Result.error( exception,