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/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<SendFileDialog> {
|
|||
title: Text(sendStr),
|
||||
content: contentWidget,
|
||||
actions: <Widget>[
|
||||
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),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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<SendLocationDialog> {
|
|||
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),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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<KeyVerificationDialog> {
|
|||
),
|
||||
);
|
||||
buttons.add(
|
||||
TextButton(
|
||||
AdaptiveDialogAction(
|
||||
child: Text(
|
||||
L10n.of(context).submit,
|
||||
),
|
||||
|
|
@ -158,7 +159,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||
),
|
||||
);
|
||||
buttons.add(
|
||||
TextButton(
|
||||
AdaptiveDialogAction(
|
||||
child: Text(
|
||||
L10n.of(context).skip,
|
||||
),
|
||||
|
|
@ -320,7 +321,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||
],
|
||||
);
|
||||
buttons.add(
|
||||
TextButton(
|
||||
AdaptiveDialogAction(
|
||||
child: Text(
|
||||
L10n.of(context).close,
|
||||
),
|
||||
|
|
@ -343,7 +344,7 @@ class KeyVerificationPageState extends State<KeyVerificationDialog> {
|
|||
],
|
||||
);
|
||||
buttons.add(
|
||||
TextButton(
|
||||
AdaptiveDialogAction(
|
||||
child: Text(
|
||||
L10n.of(context).close,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
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: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<T> extends State<LoadingDialog> {
|
|||
actions: exception == null
|
||||
? null
|
||||
: [
|
||||
TextButton(
|
||||
AdaptiveDialogAction(
|
||||
onPressed: () => Navigator.of(context).pop<Result<T>>(
|
||||
Result.error(
|
||||
exception,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue