Skip to content

Commit e492d25

Browse files
authored
Merge pull request #33 from DutchCodingCompany/feature/native-dialog-textstyle
Add native dialog textstyle
2 parents 4a6f6be + 1b42de1 commit e492d25

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
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
),

example/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,10 @@ packages:
395395
dependency: "direct dev"
396396
description:
397397
name: json_serializable
398-
sha256: "81f04dee10969f89f604e1249382d46b97a1ccad53872875369622b5bfc9e58a"
398+
sha256: c50ef5fc083d5b5e12eef489503ba3bf5ccc899e487d691584699b4bdefeea8c
399399
url: "https://pub.dev"
400400
source: hosted
401-
version: "6.9.4"
401+
version: "6.9.5"
402402
leak_tracker:
403403
dependency: transitive
404404
description:

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dev_dependencies:
2929
flutter_lints: ^5.0.0
3030
freezed: ^3.0.4
3131
injectable_generator: ^2.7.0
32-
json_serializable: ^6.9.4
32+
json_serializable: ^6.9.5
3333

3434
flutter:
3535
uses-material-design: true

lib/common/result/result.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ sealed class Result<T> {
4646
required TResult Function(T response) success,
4747
required TResult Function(Object? error) error,
4848
}) {
49-
if (this.isSuccess) {
49+
if (isSuccess) {
5050
return success((this as Success<T>).value);
5151
} else {
5252
return error((this as Failure<T>).error);

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)