diff --git a/example/lib/main.dart b/example/lib/main.dart index 70a0daa..be00332 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,4 +1,5 @@ import 'package:dcc_toolkit/ui/annotated_text/annotated_text.dart'; +import 'package:dcc_toolkit/ui/native_dialog.dart'; import 'package:example/core/injectable/injectable.dart'; import 'package:example/profile/presentation/cubit/user_cubit.dart'; import 'package:example/profile/presentation/user_page.dart'; @@ -87,6 +88,27 @@ class MyHomePage extends StatelessWidget { ), child: const Text('Get user fails'), ), + ElevatedButton( + onPressed: + () => showNativeDialog( + context, + title: 'Title', + content: 'Content', + actions: [ + DialogAction( + text: 'Action', + onTap: () {}, + textStyle: const TextStyle(color: Colors.green), + ), + DialogAction( + text: 'Action', + onTap: () {}, + textStyle: const TextStyle(color: Colors.red), + ), + ], + ), + child: const Text('Show native dialog'), + ), ], ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 3a3df14..7b50b2c 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -395,10 +395,10 @@ packages: dependency: "direct dev" description: name: json_serializable - sha256: "81f04dee10969f89f604e1249382d46b97a1ccad53872875369622b5bfc9e58a" + sha256: c50ef5fc083d5b5e12eef489503ba3bf5ccc899e487d691584699b4bdefeea8c url: "https://pub.dev" source: hosted - version: "6.9.4" + version: "6.9.5" leak_tracker: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index b871b5b..162d1c6 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -29,7 +29,7 @@ dev_dependencies: flutter_lints: ^5.0.0 freezed: ^3.0.4 injectable_generator: ^2.7.0 - json_serializable: ^6.9.4 + json_serializable: ^6.9.5 flutter: uses-material-design: true diff --git a/lib/common/result/result.dart b/lib/common/result/result.dart index 889a1a8..e055ca8 100644 --- a/lib/common/result/result.dart +++ b/lib/common/result/result.dart @@ -46,7 +46,7 @@ sealed class Result { required TResult Function(T response) success, required TResult Function(Object? error) error, }) { - if (this.isSuccess) { + if (isSuccess) { return success((this as Success).value); } else { return error((this as Failure).error); diff --git a/lib/ui/native_dialog.dart b/lib/ui/native_dialog.dart index c678ee8..8796183 100644 --- a/lib/ui/native_dialog.dart +++ b/lib/ui/native_dialog.dart @@ -39,7 +39,7 @@ Future showNativeDialog( if (dialogContext.mounted) Navigator.of(dialogContext).pop(result); }, isDestructiveAction: action.isDestructiveAction, - child: Text(action.text), + child: Text(action.text, style: action.textStyle), ), ) .toList(), @@ -60,7 +60,7 @@ Future showNativeDialog( final result = await action.onTap(); if (dialogContext.mounted) Navigator.of(dialogContext).pop(result); }, - child: Text(action.text), + child: Text(action.text, style: action.textStyle), ), ) .toList(), @@ -72,7 +72,7 @@ Future showNativeDialog( /// A dialog action which is used to show the actions of a native dialog. Tapping a action will also close the dialog. class DialogAction { /// Creates a [DialogAction]. - const DialogAction({required this.text, required this.onTap, this.isDestructiveAction = false}); + const DialogAction({required this.text, required this.onTap, this.isDestructiveAction = false, this.textStyle}); /// The text of the action. final String text; @@ -82,4 +82,7 @@ class DialogAction { /// Whether the action is a destructive action. This is only used on iOS. final bool isDestructiveAction; + + /// The style of the action text. + final TextStyle? textStyle; }