refactor: Use adaptive dialog action
This commit is contained in:
parent
416cdc139f
commit
d1e211adee
9 changed files with 60 additions and 25 deletions
|
|
@ -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/matrix_sdk_extensions/matrix_file_extension.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
import 'package:fluffychat/utils/size_string.dart';
|
import 'package:fluffychat/utils/size_string.dart';
|
||||||
|
import 'package:fluffychat/widgets/adaptive_dialog_action.dart';
|
||||||
import '../../utils/resize_video.dart';
|
import '../../utils/resize_video.dart';
|
||||||
|
|
||||||
class SendFileDialog extends StatefulWidget {
|
class SendFileDialog extends StatefulWidget {
|
||||||
|
|
@ -288,14 +289,12 @@ class SendFileDialogState extends State<SendFileDialog> {
|
||||||
title: Text(sendStr),
|
title: Text(sendStr),
|
||||||
content: contentWidget,
|
content: contentWidget,
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
onPressed: () {
|
onPressed: () =>
|
||||||
// just close the dialog
|
Navigator.of(context, rootNavigator: false).pop(),
|
||||||
Navigator.of(context, rootNavigator: false).pop();
|
|
||||||
},
|
|
||||||
child: Text(L10n.of(context).cancel),
|
child: Text(L10n.of(context).cancel),
|
||||||
),
|
),
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
onPressed: _send,
|
onPressed: _send,
|
||||||
child: Text(L10n.of(context).send),
|
child: Text(L10n.of(context).send),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import 'package:geolocator/geolocator.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/pages/chat/events/map_bubble.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';
|
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||||
|
|
||||||
class SendLocationDialog extends StatefulWidget {
|
class SendLocationDialog extends StatefulWidget {
|
||||||
|
|
@ -114,12 +115,12 @@ class SendLocationDialogState extends State<SendLocationDialog> {
|
||||||
title: Text(L10n.of(context).shareLocation),
|
title: Text(L10n.of(context).shareLocation),
|
||||||
content: contentWidget,
|
content: contentWidget,
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
||||||
child: Text(L10n.of(context).cancel),
|
child: Text(L10n.of(context).cancel),
|
||||||
),
|
),
|
||||||
if (position != null)
|
if (position != null)
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
onPressed: isSending ? null : sendAction,
|
onPressed: isSending ? null : sendAction,
|
||||||
child: Text(L10n.of(context).send),
|
child: Text(L10n.of(context).send),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
import 'package:fluffychat/utils/adaptive_bottom_sheet.dart';
|
||||||
import '../../widgets/avatar.dart';
|
import '../../widgets/avatar.dart';
|
||||||
import '../user_bottom_sheet/user_bottom_sheet.dart';
|
import '../user_bottom_sheet/user_bottom_sheet.dart';
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import 'package:flutter_linkify/flutter_linkify.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.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/layouts/login_scaffold.dart';
|
||||||
import 'package:fluffychat/widgets/matrix.dart';
|
import 'package:fluffychat/widgets/matrix.dart';
|
||||||
import '../../config/themes.dart';
|
import '../../config/themes.dart';
|
||||||
|
|
@ -107,7 +108,7 @@ class HomeserverPickerView extends StatelessWidget {
|
||||||
text: L10n.of(context).homeserverDescription,
|
text: L10n.of(context).homeserverDescription,
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
onPressed: () => launchUrl(
|
onPressed: () => launchUrl(
|
||||||
Uri.https('servers.joinmatrix.org'),
|
Uri.https('servers.joinmatrix.org'),
|
||||||
),
|
),
|
||||||
|
|
@ -115,7 +116,7 @@ class HomeserverPickerView extends StatelessWidget {
|
||||||
L10n.of(context).discoverHomeservers,
|
L10n.of(context).discoverHomeservers,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
onPressed: Navigator.of(context).pop,
|
onPressed: Navigator.of(context).pop,
|
||||||
child: Text(L10n.of(context).close),
|
child: Text(L10n.of(context).close),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:matrix/encryption.dart';
|
import 'package:matrix/encryption.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
|
import 'package:fluffychat/widgets/adaptive_dialog_action.dart';
|
||||||
import 'package:fluffychat/widgets/avatar.dart';
|
import 'package:fluffychat/widgets/avatar.dart';
|
||||||
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
import 'package:fluffychat/widgets/future_loading_dialog.dart';
|
||||||
|
|
||||||
|
|
@ -150,7 +151,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
buttons.add(
|
buttons.add(
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
child: Text(
|
child: Text(
|
||||||
L10n.of(context).submit,
|
L10n.of(context).submit,
|
||||||
),
|
),
|
||||||
|
|
@ -158,7 +159,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
buttons.add(
|
buttons.add(
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
child: Text(
|
child: Text(
|
||||||
L10n.of(context).skip,
|
L10n.of(context).skip,
|
||||||
),
|
),
|
||||||
|
|
@ -320,7 +321,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
buttons.add(
|
buttons.add(
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
child: Text(
|
child: Text(
|
||||||
L10n.of(context).close,
|
L10n.of(context).close,
|
||||||
),
|
),
|
||||||
|
|
@ -343,7 +344,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
buttons.add(
|
buttons.add(
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
child: Text(
|
child: Text(
|
||||||
L10n.of(context).close,
|
L10n.of(context).close,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import 'package:matrix/matrix.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
|
import 'package:fluffychat/widgets/adaptive_dialog_action.dart';
|
||||||
|
|
||||||
class ErrorReporter {
|
class ErrorReporter {
|
||||||
final BuildContext context;
|
final BuildContext context;
|
||||||
|
|
@ -34,17 +35,17 @@ class ErrorReporter {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
child: Text(L10n.of(context).close),
|
child: Text(L10n.of(context).close),
|
||||||
),
|
),
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
onPressed: () => Clipboard.setData(
|
onPressed: () => Clipboard.setData(
|
||||||
ClipboardData(text: text),
|
ClipboardData(text: text),
|
||||||
),
|
),
|
||||||
child: Text(L10n.of(context).copy),
|
child: Text(L10n.of(context).copy),
|
||||||
),
|
),
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
onPressed: () => launchUrl(
|
onPressed: () => launchUrl(
|
||||||
AppConfig.newIssueUrl.resolveUri(
|
AppConfig.newIssueUrl.resolveUri(
|
||||||
Uri(
|
Uri(
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,21 @@
|
||||||
extension SizeString on num {
|
extension SizeString on num {
|
||||||
String get sizeString {
|
String get sizeString {
|
||||||
var size = toDouble();
|
var size = toDouble();
|
||||||
if (size < 1000000) {
|
if (size < 1000) {
|
||||||
|
return '${size.round()} Bytes';
|
||||||
|
}
|
||||||
|
if (size < 1000 * 1000) {
|
||||||
size = size / 1000;
|
size = size / 1000;
|
||||||
size = (size * 10).round() / 10;
|
size = (size * 10).round() / 10;
|
||||||
return '${size.toString()} KB';
|
return '${size.toString()} KB';
|
||||||
} else if (size < 1000000000) {
|
}
|
||||||
|
if (size < 1000 * 1000 * 1000) {
|
||||||
size = size / 1000000;
|
size = size / 1000000;
|
||||||
size = (size * 10).round() / 10;
|
size = (size * 10).round() / 10;
|
||||||
return '${size.toString()} MB';
|
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';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
lib/widgets/adaptive_dialog_action.dart
Normal file
28
lib/widgets/adaptive_dialog_action.dart
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ import 'package:async/async.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/utils/localized_exception_extension.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
|
/// 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.
|
/// will be dismissed and the value will be returned when the future completes.
|
||||||
|
|
@ -120,7 +121,7 @@ class LoadingDialogState<T> extends State<LoadingDialog> {
|
||||||
actions: exception == null
|
actions: exception == null
|
||||||
? null
|
? null
|
||||||
: [
|
: [
|
||||||
TextButton(
|
AdaptiveDialogAction(
|
||||||
onPressed: () => Navigator.of(context).pop<Result<T>>(
|
onPressed: () => Navigator.of(context).pop<Result<T>>(
|
||||||
Result.error(
|
Result.error(
|
||||||
exception,
|
exception,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue