-
Notifications
You must be signed in to change notification settings - Fork 41
/
dialogs.dart
136 lines (129 loc) · 3.98 KB
/
dialogs.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// This source code is a part of Project Violet.
// Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License.
import 'package:flutter/material.dart';
import 'package:violet/locale/locale.dart';
import 'package:violet/settings/settings.dart';
const defaultTitle = 'Project Violet';
Future<void> showOkDialog(BuildContext context, String message,
[String? title]) async {
await showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(title ?? defaultTitle),
content: SelectableText(message),
actions: [
TextButton(
style: TextButton.styleFrom(foregroundColor: Settings.majorColor),
onPressed: () {
Navigator.pop(context);
},
child: Text(Translations.of(context).trans('ok')),
),
],
),
);
}
Future<bool> showOkCancelDialog({
required BuildContext context,
String? titleText,
String? contentText,
WidgetBuilder? contentBuilder,
EdgeInsetsGeometry? contentPadding,
String? okText,
String? cancelText,
VoidCallback? onOkPressed,
VoidCallback? onCancelPressed,
bool useRootNavigator = true,
}) async {
assert((contentText != null && contentBuilder == null) ||
(contentText == null && contentBuilder != null));
return await showDialog(
context: context,
useRootNavigator: useRootNavigator,
builder: (context) => AlertDialog(
title: Text(titleText ?? defaultTitle),
content: contentText != null
? Text(contentText)
: Builder(builder: contentBuilder!),
contentPadding: contentPadding!,
actions: [
TextButton(
style: TextButton.styleFrom(foregroundColor: Settings.majorColor),
onPressed: () {
if (onOkPressed != null) {
onOkPressed();
} else {
Navigator.pop(context, true);
}
},
child: Text(okText ?? Translations.of(context).trans('ok')),
),
TextButton(
style: TextButton.styleFrom(foregroundColor: Settings.majorColor),
onPressed: () {
if (onCancelPressed != null) {
onCancelPressed();
} else {
Navigator.pop(context, false);
}
},
child: Text(cancelText ?? Translations.of(context).trans('cancel')),
),
],
),
);
}
Future<bool> showYesNoDialog(BuildContext context, String message,
[String? title]) async {
final result = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(title ?? defaultTitle),
content: Text(message),
actions: [
TextButton(
style: TextButton.styleFrom(foregroundColor: Settings.majorColor),
onPressed: () {
Navigator.pop(context, true);
},
child: Text(Translations.of(context).trans('yes')),
),
TextButton(
style: TextButton.styleFrom(foregroundColor: Settings.majorColor),
onPressed: () {
Navigator.pop(context, false);
},
child: Text(Translations.of(context).trans('no')),
),
],
),
);
return result ?? false;
}
Future<bool?> showYesNoCancelDialog(BuildContext context, String message,
[String? title]) async {
final result = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(title ?? defaultTitle),
content: Text(message),
actions: [
TextButton(
style: TextButton.styleFrom(foregroundColor: Settings.majorColor),
onPressed: () {
Navigator.pop(context, true);
},
child: Text(Translations.of(context).trans('yes')),
),
TextButton(
style: TextButton.styleFrom(foregroundColor: Settings.majorColor),
onPressed: () {
Navigator.pop(context, false);
},
child: Text(Translations.of(context).trans('no')),
),
],
),
);
return result;
}