refactor: Use adaptive dialog action
This commit is contained in:
parent
416cdc139f
commit
d1e211adee
9 changed files with 60 additions and 25 deletions
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
Add a link
Reference in a new issue