Skip to content

Commit 21027b5

Browse files
committed
feat: 自定义 dialog
1 parent 5de9488 commit 21027b5

7 files changed

Lines changed: 368 additions & 7 deletions

File tree

lib/l10n/app_en.arb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,22 @@
465465

466466
"debugLogs": "Debug Logs",
467467
"debugLogsDescription": "View application logs",
468+
"debugCustomInfoDialog": "Custom Info Dialog",
469+
"debugCustomInfoDialogDescription": "Preview the reusable info dialog with caller-defined actions",
470+
"debugCustomErrorDialog": "Custom Error Dialog",
471+
"debugCustomErrorDialogDescription": "Preview the reusable error dialog with caller-defined actions",
472+
"debugInfoDialogDemoTitle": "Server Profile Updated",
473+
"debugInfoDialogDemoMessage": "A refreshed server profile is available. Choose what to do next.",
474+
"debugErrorDialogDemoTitle": "Message Sync Failed",
475+
"debugErrorDialogDemoMessage": "The current sync task did not finish successfully. You can retry now or open settings to inspect the connection.",
476+
"debugDialogSelectedAction": "Selected action: {action}",
477+
"@debugDialogSelectedAction": {
478+
"placeholders": {
479+
"action": {
480+
"type": "String"
481+
}
482+
}
483+
},
468484

469485
"forumTitle": "Forum",
470486
"forumNotFound": "Forum not found",

lib/l10n/app_localizations.dart

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,60 @@ abstract class AppLocalizations {
24442444
/// **'View application logs'**
24452445
String get debugLogsDescription;
24462446

2447+
/// No description provided for @debugCustomInfoDialog.
2448+
///
2449+
/// In en, this message translates to:
2450+
/// **'Custom Info Dialog'**
2451+
String get debugCustomInfoDialog;
2452+
2453+
/// No description provided for @debugCustomInfoDialogDescription.
2454+
///
2455+
/// In en, this message translates to:
2456+
/// **'Preview the reusable info dialog with caller-defined actions'**
2457+
String get debugCustomInfoDialogDescription;
2458+
2459+
/// No description provided for @debugCustomErrorDialog.
2460+
///
2461+
/// In en, this message translates to:
2462+
/// **'Custom Error Dialog'**
2463+
String get debugCustomErrorDialog;
2464+
2465+
/// No description provided for @debugCustomErrorDialogDescription.
2466+
///
2467+
/// In en, this message translates to:
2468+
/// **'Preview the reusable error dialog with caller-defined actions'**
2469+
String get debugCustomErrorDialogDescription;
2470+
2471+
/// No description provided for @debugInfoDialogDemoTitle.
2472+
///
2473+
/// In en, this message translates to:
2474+
/// **'Server Profile Updated'**
2475+
String get debugInfoDialogDemoTitle;
2476+
2477+
/// No description provided for @debugInfoDialogDemoMessage.
2478+
///
2479+
/// In en, this message translates to:
2480+
/// **'A refreshed server profile is available. Choose what to do next.'**
2481+
String get debugInfoDialogDemoMessage;
2482+
2483+
/// No description provided for @debugErrorDialogDemoTitle.
2484+
///
2485+
/// In en, this message translates to:
2486+
/// **'Message Sync Failed'**
2487+
String get debugErrorDialogDemoTitle;
2488+
2489+
/// No description provided for @debugErrorDialogDemoMessage.
2490+
///
2491+
/// In en, this message translates to:
2492+
/// **'The current sync task did not finish successfully. You can retry now or open settings to inspect the connection.'**
2493+
String get debugErrorDialogDemoMessage;
2494+
2495+
/// No description provided for @debugDialogSelectedAction.
2496+
///
2497+
/// In en, this message translates to:
2498+
/// **'Selected action: {action}'**
2499+
String debugDialogSelectedAction(String action);
2500+
24472501
/// No description provided for @forumTitle.
24482502
///
24492503
/// In en, this message translates to:

lib/l10n/app_localizations_en.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,39 @@ class AppLocalizationsEn extends AppLocalizations {
12451245
@override
12461246
String get debugLogsDescription => 'View application logs';
12471247

1248+
@override
1249+
String get debugCustomInfoDialog => 'Custom Info Dialog';
1250+
1251+
@override
1252+
String get debugCustomInfoDialogDescription =>
1253+
'Preview the reusable info dialog with caller-defined actions';
1254+
1255+
@override
1256+
String get debugCustomErrorDialog => 'Custom Error Dialog';
1257+
1258+
@override
1259+
String get debugCustomErrorDialogDescription =>
1260+
'Preview the reusable error dialog with caller-defined actions';
1261+
1262+
@override
1263+
String get debugInfoDialogDemoTitle => 'Server Profile Updated';
1264+
1265+
@override
1266+
String get debugInfoDialogDemoMessage =>
1267+
'A refreshed server profile is available. Choose what to do next.';
1268+
1269+
@override
1270+
String get debugErrorDialogDemoTitle => 'Message Sync Failed';
1271+
1272+
@override
1273+
String get debugErrorDialogDemoMessage =>
1274+
'The current sync task did not finish successfully. You can retry now or open settings to inspect the connection.';
1275+
1276+
@override
1277+
String debugDialogSelectedAction(String action) {
1278+
return 'Selected action: $action';
1279+
}
1280+
12481281
@override
12491282
String get forumTitle => 'Forum';
12501283

lib/l10n/app_localizations_zh.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,35 @@ class AppLocalizationsZh extends AppLocalizations {
12001200
@override
12011201
String get debugLogsDescription => '查看应用运行日志';
12021202

1203+
@override
1204+
String get debugCustomInfoDialog => '自定义信息框';
1205+
1206+
@override
1207+
String get debugCustomInfoDialogDescription => '预览支持调用方自定义按钮的可复用信息框';
1208+
1209+
@override
1210+
String get debugCustomErrorDialog => '自定义错误框';
1211+
1212+
@override
1213+
String get debugCustomErrorDialogDescription => '预览支持调用方自定义按钮的可复用错误框';
1214+
1215+
@override
1216+
String get debugInfoDialogDemoTitle => '服务器配置已更新';
1217+
1218+
@override
1219+
String get debugInfoDialogDemoMessage => '检测到新的服务器配置,请选择下一步操作。';
1220+
1221+
@override
1222+
String get debugErrorDialogDemoTitle => '消息同步失败';
1223+
1224+
@override
1225+
String get debugErrorDialogDemoMessage => '当前同步任务未成功完成,你可以立即重试,或打开设置检查连接状态。';
1226+
1227+
@override
1228+
String debugDialogSelectedAction(String action) {
1229+
return '已选择操作:$action';
1230+
}
1231+
12031232
@override
12041233
String get forumTitle => '论坛';
12051234

lib/l10n/app_zh.arb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,22 @@
436436

437437
"debugLogs": "调试日志",
438438
"debugLogsDescription": "查看应用运行日志",
439+
"debugCustomInfoDialog": "自定义信息框",
440+
"debugCustomInfoDialogDescription": "预览支持调用方自定义按钮的可复用信息框",
441+
"debugCustomErrorDialog": "自定义错误框",
442+
"debugCustomErrorDialogDescription": "预览支持调用方自定义按钮的可复用错误框",
443+
"debugInfoDialogDemoTitle": "服务器配置已更新",
444+
"debugInfoDialogDemoMessage": "检测到新的服务器配置,请选择下一步操作。",
445+
"debugErrorDialogDemoTitle": "消息同步失败",
446+
"debugErrorDialogDemoMessage": "当前同步任务未成功完成,你可以立即重试,或打开设置检查连接状态。",
447+
"debugDialogSelectedAction": "已选择操作:{action}",
448+
"@debugDialogSelectedAction": {
449+
"placeholders": {
450+
"action": {
451+
"type": "String"
452+
}
453+
}
454+
},
439455

440456
"forumTitle": "论坛",
441457
"forumNotFound": "论坛未找到",

lib/screens/debug/debug_options_screen.dart

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,83 @@
11
import 'package:flutter/material.dart';
22
import 'package:material_symbols_icons/symbols.dart';
33
import '../../l10n/app_localizations.dart';
4+
import '../../widgets/app_alert_dialog.dart';
45
import './talker_log_screen.dart';
56

67
class DebugOptionsScreen extends StatelessWidget {
78
const DebugOptionsScreen({super.key});
89

10+
Future<void> _showInfoDialogPreview(BuildContext context) async {
11+
final l10n = AppLocalizations.of(context)!;
12+
final materialL10n = MaterialLocalizations.of(context);
13+
final result = await showTouchFishInfoDialog<String>(
14+
context,
15+
title: l10n.debugInfoDialogDemoTitle,
16+
message: l10n.debugInfoDialogDemoMessage,
17+
actions: [
18+
TouchFishDialogAction<String>(
19+
label: materialL10n.cancelButtonLabel,
20+
result: materialL10n.cancelButtonLabel,
21+
),
22+
TouchFishDialogAction<String>(
23+
label: l10n.settingsTitle,
24+
result: l10n.settingsTitle,
25+
isPrimary: true,
26+
),
27+
],
28+
);
29+
30+
if (!context.mounted || result == null) return;
31+
_showDialogSelectionSnackBar(context, result);
32+
}
33+
34+
Future<void> _showErrorDialogPreview(BuildContext context) async {
35+
final l10n = AppLocalizations.of(context)!;
36+
final result = await showTouchFishErrorDialog<String>(
37+
context,
38+
title: l10n.debugErrorDialogDemoTitle,
39+
message: l10n.debugErrorDialogDemoMessage,
40+
barrierDismissible: false,
41+
actions: [
42+
TouchFishDialogAction<String>(label: l10n.cancel, result: l10n.cancel),
43+
TouchFishDialogAction<String>(
44+
label: l10n.settingsTitle,
45+
result: l10n.settingsTitle,
46+
),
47+
TouchFishDialogAction<String>(
48+
label: l10n.retry,
49+
result: l10n.retry,
50+
isPrimary: true,
51+
),
52+
],
53+
);
54+
55+
if (!context.mounted || result == null) return;
56+
_showDialogSelectionSnackBar(context, result);
57+
}
58+
59+
void _showDialogSelectionSnackBar(BuildContext context, String action) {
60+
final l10n = AppLocalizations.of(context)!;
61+
final messenger = ScaffoldMessenger.of(context);
62+
messenger
63+
..hideCurrentSnackBar()
64+
..showSnackBar(
65+
SnackBar(content: Text(l10n.debugDialogSelectedAction(action))),
66+
);
67+
}
68+
969
@override
1070
Widget build(BuildContext context) {
1171
final l10n = AppLocalizations.of(context)!;
1272
final colorScheme = Theme.of(context).colorScheme;
1373

1474
return Scaffold(
15-
appBar: AppBar(
16-
title: Text(l10n.accountDebugOptions),
17-
),
75+
appBar: AppBar(title: Text(l10n.accountDebugOptions)),
1876
body: ListView(
1977
children: [
2078
const SizedBox(height: 8),
2179
ListTile(
22-
leading: Icon(
23-
Symbols.terminal,
24-
color: colorScheme.primary,
25-
),
80+
leading: Icon(Symbols.terminal, color: colorScheme.primary),
2681
trailing: const Icon(Symbols.chevron_right),
2782
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
2883
title: Text(l10n.debugLogs),
@@ -36,6 +91,24 @@ class DebugOptionsScreen extends StatelessWidget {
3691
},
3792
),
3893
const Divider(height: 1),
94+
ListTile(
95+
leading: Icon(Symbols.info_rounded, color: colorScheme.primary),
96+
trailing: const Icon(Symbols.chevron_right),
97+
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
98+
title: Text(l10n.debugCustomInfoDialog),
99+
subtitle: Text(l10n.debugCustomInfoDialogDescription),
100+
onTap: () => _showInfoDialogPreview(context),
101+
),
102+
const Divider(height: 1),
103+
ListTile(
104+
leading: Icon(Symbols.error, color: colorScheme.error),
105+
trailing: const Icon(Symbols.chevron_right),
106+
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
107+
title: Text(l10n.debugCustomErrorDialog),
108+
subtitle: Text(l10n.debugCustomErrorDialogDescription),
109+
onTap: () => _showErrorDialogPreview(context),
110+
),
111+
const Divider(height: 1),
39112
],
40113
),
41114
);

0 commit comments

Comments
 (0)