Skip to content

Commit 28c2993

Browse files
committed
Add native dialog textstyle
1 parent 4a6f6be commit 28c2993

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

example/lib/main.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:dcc_toolkit/ui/annotated_text/annotated_text.dart';
2+
import 'package:dcc_toolkit/ui/native_dialog.dart';
23
import 'package:example/core/injectable/injectable.dart';
34
import 'package:example/profile/presentation/cubit/user_cubit.dart';
45
import 'package:example/profile/presentation/user_page.dart';
@@ -87,6 +88,27 @@ class MyHomePage extends StatelessWidget {
8788
),
8889
child: const Text('Get user fails'),
8990
),
91+
ElevatedButton(
92+
onPressed:
93+
() => showNativeDialog(
94+
context,
95+
title: 'Title',
96+
content: 'Content',
97+
actions: [
98+
DialogAction(
99+
text: 'Action',
100+
onTap: () {},
101+
textStyle: const TextStyle(color: Colors.green),
102+
),
103+
DialogAction(
104+
text: 'Action',
105+
onTap: () {},
106+
textStyle: const TextStyle(color: Colors.red),
107+
),
108+
],
109+
),
110+
child: const Text('Show native dialog'),
111+
),
90112
],
91113
),
92114
),

lib/ui/native_dialog.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Future<T?> showNativeDialog<T>(
3939
if (dialogContext.mounted) Navigator.of(dialogContext).pop(result);
4040
},
4141
isDestructiveAction: action.isDestructiveAction,
42-
child: Text(action.text),
42+
child: Text(action.text, style: action.textStyle),
4343
),
4444
)
4545
.toList(),
@@ -60,7 +60,7 @@ Future<T?> showNativeDialog<T>(
6060
final result = await action.onTap();
6161
if (dialogContext.mounted) Navigator.of(dialogContext).pop(result);
6262
},
63-
child: Text(action.text),
63+
child: Text(action.text, style: action.textStyle),
6464
),
6565
)
6666
.toList(),
@@ -72,7 +72,7 @@ Future<T?> showNativeDialog<T>(
7272
/// A dialog action which is used to show the actions of a native dialog. Tapping a action will also close the dialog.
7373
class DialogAction<T> {
7474
/// Creates a [DialogAction].
75-
const DialogAction({required this.text, required this.onTap, this.isDestructiveAction = false});
75+
const DialogAction({required this.text, required this.onTap, this.isDestructiveAction = false, this.textStyle});
7676

7777
/// The text of the action.
7878
final String text;
@@ -82,4 +82,7 @@ class DialogAction<T> {
8282

8383
/// Whether the action is a destructive action. This is only used on iOS.
8484
final bool isDestructiveAction;
85+
86+
/// The style of the action text.
87+
final TextStyle? textStyle;
8588
}

0 commit comments

Comments
 (0)