refactor: Use adaptive dialog action

This commit is contained in:
Krille 2024-10-18 15:49:46 +02:00
commit d1e211adee
No known key found for this signature in database
GPG key ID: E067ECD60F1A0652
9 changed files with 60 additions and 25 deletions

View 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);
}
}
}

View file

@ -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,