Skip to content

Commit 0e37161

Browse files
committed
chore: Apply changes from version 4.20.9
1 parent 3552bec commit 0e37161

File tree

4 files changed

+216
-95
lines changed

4 files changed

+216
-95
lines changed

lib/components/alert_dialog.dart

Lines changed: 126 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import 'dart:io';
22

33
import 'package:amity_uikit_beta_service/components/custom_dialog.dart';
44
import 'package:amity_uikit_beta_service/l10n/localization_helper.dart';
5+
import 'package:amity_uikit_beta_service/v4/utils/config_provider.dart';
56
import 'package:flutter/cupertino.dart';
67
import 'package:flutter/material.dart';
8+
import 'package:provider/provider.dart';
79

810
import '../utils/navigation_key.dart';
911

@@ -22,23 +24,38 @@ class AmityDialog {
2224
final BuildContext? context =
2325
NavigationService.navigatorKey.currentContext;
2426
if (context != null) {
27+
// Get theme before showing dialog
28+
final appTheme = Provider.of<ConfigProvider>(context, listen: false).getTheme(null, null);
29+
final isDarkMode = appTheme.backgroundColor.computeLuminance() < 0.5;
30+
2531
if (Platform.isIOS) {
2632
// Use CupertinoAlertDialog for iOS
2733
await showCupertinoDialog(
2834
barrierDismissible: isBarrierDismissible(),
2935
context: context,
30-
builder: (BuildContext context) {
31-
return CupertinoAlertDialog(
32-
title: Text(title),
33-
content: Text(message),
34-
actions: <Widget>[
35-
CupertinoDialogAction(
36-
child: Text(context.l10n.general_ok),
37-
onPressed: () {
38-
Navigator.of(context).pop();
39-
},
36+
builder: (BuildContext dialogContext) {
37+
return CupertinoTheme(
38+
data: CupertinoThemeData(
39+
brightness: isDarkMode ? Brightness.dark : Brightness.light,
40+
),
41+
child: CupertinoAlertDialog(
42+
title: Text(
43+
title,
44+
style: TextStyle(color: appTheme.baseColor),
4045
),
41-
],
46+
content: Text(
47+
message,
48+
style: TextStyle(color: appTheme.baseColor),
49+
),
50+
actions: <Widget>[
51+
CupertinoDialogAction(
52+
child: Text(dialogContext.l10n.general_ok),
53+
onPressed: () {
54+
Navigator.of(dialogContext).pop();
55+
},
56+
),
57+
],
58+
),
4259
);
4360
},
4461
);
@@ -47,15 +64,22 @@ class AmityDialog {
4764
await showDialog(
4865
barrierDismissible: isBarrierDismissible(),
4966
context: context,
50-
builder: (BuildContext context) {
67+
builder: (BuildContext dialogContext) {
5168
return AlertDialog(
52-
title: Text(title),
53-
content: Text(message),
69+
backgroundColor: appTheme.backgroundColor,
70+
title: Text(
71+
title,
72+
style: TextStyle(color: appTheme.baseColor),
73+
),
74+
content: Text(
75+
message,
76+
style: TextStyle(color: appTheme.baseColor),
77+
),
5478
actions: <Widget>[
5579
TextButton(
56-
child: Text(context.l10n.general_ok),
80+
child: Text(dialogContext.l10n.general_ok),
5781
onPressed: () {
58-
Navigator.of(context).pop();
82+
Navigator.of(dialogContext).pop();
5983
},
6084
),
6185
],
@@ -76,13 +100,15 @@ class AmityLoadingDialog {
76100
print("show AmityLoadingDialog");
77101
_isDialogShowing = true;
78102
print("set _isDialogShowing: $_isDialogShowing");
103+
final context = NavigationService.navigatorKey.currentContext!;
104+
final appTheme = Provider.of<ConfigProvider>(context, listen: false).getTheme(null, null);
79105
return showDialog<void>(
80-
context: NavigationService.navigatorKey.currentContext!,
106+
context: context,
81107
barrierColor: Colors.transparent,
82108
barrierDismissible:
83109
true, // Set to false to prevent dismissing by tapping outside
84-
builder: (context) {
85-
loadingContext = context;
110+
builder: (dialogContext) {
111+
loadingContext = dialogContext;
86112
return Center(
87113
child: SizedBox(
88114
width: 200,
@@ -91,23 +117,23 @@ class AmityLoadingDialog {
91117
elevation: 0, // Remove shadow/elevation effect
92118
child: Container(
93119
decoration: BoxDecoration(
94-
color: Colors.grey.withOpacity(0.6),
120+
color: appTheme.baseColorShade3.withOpacity(0.9),
95121
borderRadius: BorderRadius.circular(8.0),
96122
),
97123
padding: const EdgeInsets.all(16.0),
98124
child: Column(
99125
mainAxisSize: MainAxisSize.min,
100126
children: [
101-
const CupertinoActivityIndicator(
102-
color: Colors.white,
127+
CupertinoActivityIndicator(
128+
color: appTheme.baseColor,
103129
radius: 20,
104130
),
105131
const SizedBox(height: 16),
106132
Text(
107-
context.l10n.general_loading,
108-
style: const TextStyle(
133+
dialogContext.l10n.general_loading,
134+
style: TextStyle(
109135
fontWeight: FontWeight.bold,
110-
color: Colors.white,
136+
color: appTheme.baseColor,
111137
),
112138
),
113139
],
@@ -143,17 +169,17 @@ class AmityLoadingDialog {
143169
class AmitySuccessDialog {
144170
static Future<void> showTimedDialog(String text,
145171
{BuildContext? context}) async {
146-
// if (context == null) {
147-
// print("Context is null, cannot show dialog");
148-
// return Future.value();
149-
// }
172+
final ctx = context ?? NavigationService.navigatorKey.currentContext!;
173+
final appTheme = Provider.of<ConfigProvider>(ctx, listen: false).getTheme(null, null);
150174

151175
showCupertinoDialog<void>(
152-
context: context ?? NavigationService.navigatorKey.currentContext!,
176+
context: ctx,
153177
barrierDismissible: false,
154-
builder: (BuildContext context) {
178+
builder: (BuildContext dialogContext) {
155179
return TimedDialog(
156180
text: text,
181+
backgroundColor: appTheme.backgroundColor,
182+
textColor: appTheme.baseColor,
157183
);
158184
},
159185
);
@@ -173,30 +199,40 @@ class ConfirmationDialog {
173199
// Set default localized values
174200
final String leftBtnText = leftButtonText ?? context.l10n.general_cancel;
175201
final String rightBtnText = rightButtonText ?? context.l10n.general_confirm;
176-
202+
203+
// Get theme before showing dialog
204+
final appTheme = Provider.of<ConfigProvider>(context, listen: false).getTheme(null, null);
205+
177206
// Check the platform
178207
if (Platform.isAndroid) {
179208
// Android-specific code
180209
return showDialog<void>(
181210
context: context,
182-
builder: (BuildContext context) {
211+
builder: (BuildContext dialogContext) {
183212
return AlertDialog(
184-
title: Text(title),
185-
content: Text(detailText),
213+
backgroundColor: appTheme.backgroundColor,
214+
title: Text(
215+
title,
216+
style: TextStyle(color: appTheme.baseColor),
217+
),
218+
content: Text(
219+
detailText,
220+
style: TextStyle(color: appTheme.baseColor),
221+
),
186222
actions: <Widget>[
187223
TextButton(
188224
child: Text(leftBtnText),
189225
onPressed: () {
190-
Navigator.of(context).pop(); // Close the dialog
226+
Navigator.of(dialogContext).pop();
191227
},
192228
),
193229
TextButton(
194230
onPressed: () {
195-
Navigator.of(context).pop();
231+
Navigator.of(dialogContext).pop();
196232
onConfirm();
197233
},
198234
style: TextButton.styleFrom(
199-
foregroundColor: confrimColor, // Set the text color
235+
foregroundColor: confrimColor,
200236
),
201237
child: Text(rightBtnText),
202238
),
@@ -206,25 +242,34 @@ class ConfirmationDialog {
206242
);
207243
} else if (Platform.isIOS) {
208244
// iOS-specific code
245+
final isDarkMode = appTheme.backgroundColor.computeLuminance() < 0.5;
209246
return showCupertinoDialog(
210247
context: context,
211-
builder: (BuildContext context) {
248+
builder: (BuildContext dialogContext) {
212249
return CupertinoTheme(
213-
data: const CupertinoThemeData(brightness: Brightness.light),
250+
data: CupertinoThemeData(
251+
brightness: isDarkMode ? Brightness.dark : Brightness.light,
252+
),
214253
child: CupertinoAlertDialog(
215-
title: Text(title),
216-
content: Text(detailText),
254+
title: Text(
255+
title,
256+
style: TextStyle(color: appTheme.baseColor),
257+
),
258+
content: Text(
259+
detailText,
260+
style: TextStyle(color: appTheme.baseColor),
261+
),
217262
actions: <Widget>[
218263
CupertinoDialogAction(
219264
child: Text(leftBtnText),
220265
onPressed: () {
221-
Navigator.of(context).pop(); // Close the dialog
266+
Navigator.of(dialogContext).pop();
222267
},
223268
),
224269
CupertinoDialogAction(
225270
textStyle: TextStyle(color: confrimColor),
226271
onPressed: () {
227-
Navigator.of(context).pop();
272+
Navigator.of(dialogContext).pop();
228273
onConfirm();
229274
},
230275
isDefaultAction: true,
@@ -256,42 +301,51 @@ class AmityAlertDialogWithThreeActions {
256301
}) async {
257302
// Set default localized values
258303
final String dismissBtnText = dismissText ?? context.l10n.general_cancel;
259-
304+
305+
// Get theme before showing dialog
306+
final appTheme = Provider.of<ConfigProvider>(context, listen: false).getTheme(null, null);
307+
260308
// Check the platform
261309
if (Platform.isAndroid) {
262310
// Android-specific code
263311
return showDialog<void>(
264312
context: context,
265-
builder: (BuildContext context) {
313+
builder: (BuildContext dialogContext) {
266314
return AlertDialog(
267-
title: Text(title),
268-
content: Text(detailText),
269-
315+
backgroundColor: appTheme.backgroundColor,
316+
title: Text(
317+
title,
318+
style: TextStyle(color: appTheme.baseColor),
319+
),
320+
content: Text(
321+
detailText,
322+
style: TextStyle(color: appTheme.baseColor),
323+
),
270324
actions: <Widget>[
271325
TextButton(
272326
child: Text(dismissBtnText),
273327
onPressed: () {
274328
onDismissRequest();
275-
Navigator.of(context).pop(); // Close the dialog
329+
Navigator.of(dialogContext).pop();
276330
},
277331
),
278332
TextButton(
279333
onPressed: () {
280-
Navigator.of(context).pop();
334+
Navigator.of(dialogContext).pop();
281335
actionOne();
282336
},
283337
style: TextButton.styleFrom(
284-
foregroundColor: Colors.red, // Set the text color
338+
foregroundColor: actionOneColor,
285339
),
286340
child: Text(actionOneText),
287341
),
288342
TextButton(
289343
onPressed: () {
290-
Navigator.of(context).pop();
344+
Navigator.of(dialogContext).pop();
291345
actionTwo();
292346
},
293347
style: TextButton.styleFrom(
294-
foregroundColor: Colors.red, // Set the text color
348+
foregroundColor: actionTwoColor,
295349
),
296350
child: Text(actionTwoText),
297351
),
@@ -304,28 +358,37 @@ class AmityAlertDialogWithThreeActions {
304358
});
305359
} else if (Platform.isIOS) {
306360
// iOS-specific code
361+
final isDarkMode = appTheme.backgroundColor.computeLuminance() < 0.5;
307362
return showCupertinoDialog(
308363
context: context,
309-
builder: (BuildContext context) {
364+
builder: (BuildContext dialogContext) {
310365
return CupertinoTheme(
311-
data: const CupertinoThemeData(brightness: Brightness.light),
366+
data: CupertinoThemeData(
367+
brightness: isDarkMode ? Brightness.dark : Brightness.light,
368+
),
312369
child: CupertinoAlertDialog(
313-
title: Text(title),
314-
content: Text(detailText),
370+
title: Text(
371+
title,
372+
style: TextStyle(color: appTheme.baseColor),
373+
),
374+
content: Text(
375+
detailText,
376+
style: TextStyle(color: appTheme.baseColor),
377+
),
315378
actions: <Widget>[
316379
CupertinoDialogAction(
317-
textStyle: TextStyle(color: actionOneColor),
380+
textStyle: TextStyle(color: actionOneColor),
318381
onPressed: () {
319-
Navigator.of(context).pop();
382+
Navigator.of(dialogContext).pop();
320383
actionOne();
321384
},
322385
isDefaultAction: true,
323386
child: Text(actionOneText),
324387
),
325388
CupertinoDialogAction(
326-
textStyle: TextStyle(color: actionTwoColor ),
389+
textStyle: TextStyle(color: actionTwoColor),
327390
onPressed: () {
328-
Navigator.of(context).pop();
391+
Navigator.of(dialogContext).pop();
329392
actionTwo();
330393
},
331394
isDefaultAction: true,
@@ -335,7 +398,7 @@ class AmityAlertDialogWithThreeActions {
335398
child: Text(dismissBtnText),
336399
onPressed: () {
337400
onDismissRequest();
338-
Navigator.of(context).pop(); // Close the dialog
401+
Navigator.of(dialogContext).pop();
339402
},
340403
),
341404
],

0 commit comments

Comments
 (0)