Skip to content

Commit 440d0b0

Browse files
author
darkhan.nausharipov
committed
addressing review comments (apache#25255)
1 parent 6005103 commit 440d0b0

5 files changed

Lines changed: 62 additions & 47 deletions

File tree

learning/tour-of-beam/frontend/lib/components/profile/user_menu.dart

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,18 @@ class _Info extends StatelessWidget {
8989
}
9090
}
9191

92-
class _Buttons extends StatelessWidget {
92+
class _Buttons extends StatefulWidget {
9393
final VoidCallback closeOverlayCallback;
9494

9595
const _Buttons({
9696
required this.closeOverlayCallback,
9797
});
9898

99+
@override
100+
State<_Buttons> createState() => _ButtonsState();
101+
}
102+
103+
class _ButtonsState extends State<_Buttons> {
99104
@override
100105
Widget build(BuildContext context) {
101106
final authNotifier = GetIt.instance.get<AuthNotifier>();
@@ -118,30 +123,27 @@ class _Buttons extends StatelessWidget {
118123
_IconLabel(
119124
onTap: () async {
120125
await authNotifier.logOut();
121-
closeOverlayCallback();
126+
widget.closeOverlayCallback();
122127
},
123128
iconPath: Assets.svg.profileLogout,
124129
label: 'ui.signOut'.tr(),
125130
),
126131
const BeamDivider(),
127132
_IconLabel(
128-
onTap: () {
129-
closeOverlayCallback();
130-
showDialog(
133+
onTap: () async {
134+
widget.closeOverlayCallback();
135+
final confirmed = await ConfirmDialog.show(
131136
context: context,
132-
builder: (context) => ActionApprovalDialog(
133-
actionLabel: 'ui.deleteMyAccount'.tr(),
134-
bodyText: 'dialogs.deleteAccountWarning'.tr(),
135-
title: 'ui.deleteTobAccount'.tr(),
136-
onActionPressed: () async {
137-
Navigator.pop(context);
138-
await BeamOverlays.showProgressOverlay(
139-
context,
140-
authNotifier.deleteAccount,
141-
);
142-
},
143-
),
137+
confirmButtonText: 'ui.deleteMyAccount'.tr(),
138+
subtitle: 'dialogs.deleteAccountWarning'.tr(),
139+
title: 'ui.deleteTobAccount'.tr(),
144140
);
141+
if (confirmed && mounted) {
142+
await BeamOverlays.showProgressOverlay(
143+
this.context,
144+
authNotifier.deleteAccount(),
145+
);
146+
}
145147
},
146148
iconPath: Assets.svg.profileDelete,
147149
label: 'ui.deleteMyAccount'.tr(),

learning/tour-of-beam/frontend/lib/pages/tour/widgets/solution_button.dart

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,20 @@ class SolutionButton extends StatelessWidget {
4343
: null,
4444
),
4545
),
46-
onPressed: () {
46+
onPressed: () async {
4747
// TODO(nausharipov): resolve the conflict with save user code
4848
if (tourNotifier.isShowingSolution) {
4949
tourNotifier.toggleShowingSolution();
5050
} else {
51-
showDialog(
51+
final confirmed = await ConfirmDialog.show(
5252
context: context,
53-
builder: (context) => ActionApprovalDialog(
54-
bodyText: 'pages.tour.solveYourself'.tr(),
55-
actionLabel: 'pages.tour.showSolution'.tr(),
56-
title: 'pages.tour.solution'.tr(),
57-
onActionPressed: () {
58-
Navigator.pop(context);
59-
tourNotifier.toggleShowingSolution();
60-
},
61-
),
53+
confirmButtonText: 'pages.tour.showSolution'.tr(),
54+
subtitle: 'pages.tour.solveYourself'.tr(),
55+
title: 'pages.tour.solution'.tr(),
6256
);
57+
if (confirmed) {
58+
tourNotifier.toggleShowingSolution();
59+
}
6360
}
6461
},
6562
icon: SvgPicture.asset(Assets.svg.solution),

playground/frontend/playground_components/lib/playground_components.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export 'src/util/string.dart';
6060
export 'src/widgets/bubble.dart';
6161
export 'src/widgets/clickable.dart';
6262
export 'src/widgets/complexity.dart';
63-
export 'src/widgets/dialogs/action_approval.dart';
63+
export 'src/widgets/dialogs/confirm.dart';
6464
export 'src/widgets/divider.dart';
6565
export 'src/widgets/header_icon_button.dart';
6666
export 'src/widgets/loading_error.dart';

playground/frontend/playground_components/lib/src/widgets/dialogs/action_approval.dart renamed to playground/frontend/playground_components/lib/src/widgets/dialogs/confirm.dart

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,34 @@ import 'package:flutter/material.dart';
2121

2222
import '../../../playground_components.dart';
2323

24-
/// Dialog to approve or cancel user actions.
25-
class ActionApprovalDialog extends StatelessWidget {
26-
final String actionLabel;
27-
final VoidCallback onActionPressed;
24+
class ConfirmDialog extends StatelessWidget {
25+
final String confirmButtonText;
26+
2827
final String title;
29-
final String? bodyText;
28+
final String? subtitle;
3029

31-
const ActionApprovalDialog({
32-
required this.actionLabel,
33-
required this.onActionPressed,
30+
const ConfirmDialog({
31+
required this.confirmButtonText,
3432
required this.title,
35-
this.bodyText,
33+
this.subtitle,
3634
});
3735

36+
static Future<bool> show({
37+
required BuildContext context,
38+
required String title,
39+
required String? subtitle,
40+
required String confirmButtonText,
41+
}) async {
42+
return await showDialog(
43+
context: context,
44+
builder: (context) => ConfirmDialog(
45+
confirmButtonText: confirmButtonText,
46+
title: title,
47+
subtitle: subtitle,
48+
),
49+
);
50+
}
51+
3852
@override
3953
Widget build(BuildContext context) {
4054
return Dialog(
@@ -52,25 +66,27 @@ class ActionApprovalDialog extends StatelessWidget {
5266
title,
5367
style: Theme.of(context).textTheme.headlineMedium,
5468
),
55-
if (bodyText != null)
69+
if (subtitle != null)
5670
Padding(
5771
padding: const EdgeInsets.only(top: BeamSizes.size8),
58-
child: Text(bodyText!),
72+
child: Text(subtitle!),
5973
),
6074
const SizedBox(height: BeamSizes.size8),
6175
Row(
6276
mainAxisAlignment: MainAxisAlignment.end,
6377
children: [
6478
TextButton(
6579
onPressed: () {
66-
Navigator.pop(context);
80+
Navigator.pop(context, false);
6781
},
6882
child: const Text('dialogs.cancel').tr(),
6983
),
7084
const SizedBox(width: BeamSizes.size8),
7185
TextButton(
72-
onPressed: onActionPressed,
73-
child: Text(actionLabel),
86+
onPressed: () {
87+
Navigator.pop(context, true);
88+
},
89+
child: Text(confirmButtonText),
7490
),
7591
],
7692
),

playground/frontend/playground_components/lib/src/widgets/overlay/overlays.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import 'package:flutter/material.dart';
2020

2121
import '../../../playground_components.dart';
2222

23-
/// Shows different types of overlays.
23+
/// Groups common overlays.
2424
class BeamOverlays {
25-
/// Undismissable overlay of a progress indicator.
25+
/// Shows an overlay until future completes.
2626
static Future<void> showProgressOverlay(
2727
BuildContext context,
28-
Future Function() future,
28+
Future future,
2929
) async {
3030
final closeNotifier = PublicNotifier();
3131
showOverlay(
@@ -40,7 +40,7 @@ class BeamOverlays {
4040
),
4141
),
4242
);
43-
await future();
43+
await future;
4444
closeNotifier.notifyPublic();
4545
}
4646
}

0 commit comments

Comments
 (0)