Skip to content

Commit

Permalink
pop progress dialog with navigatorKey (apache#25255)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkhan.nausharipov committed Feb 13, 2023
1 parent 12882fb commit 7626f8f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,13 @@ class _Info extends StatelessWidget {
}
}

class _Buttons extends StatefulWidget {
class _Buttons extends StatelessWidget {
final VoidCallback closeOverlayCallback;

const _Buttons({
required this.closeOverlayCallback,
});

@override
State<_Buttons> createState() => _ButtonsState();
}

class _ButtonsState extends State<_Buttons> {
@override
Widget build(BuildContext context) {
final authNotifier = GetIt.instance.get<AuthNotifier>();
Expand All @@ -123,25 +118,26 @@ class _ButtonsState extends State<_Buttons> {
_IconLabel(
onTap: () async {
await authNotifier.logOut();
widget.closeOverlayCallback();
closeOverlayCallback();
},
iconPath: Assets.svg.profileLogout,
label: 'ui.signOut'.tr(),
),
const BeamDivider(),
_IconLabel(
onTap: () async {
widget.closeOverlayCallback();
closeOverlayCallback();
final confirmed = await ConfirmDialog.show(
context: context,
confirmButtonText: 'ui.deleteMyAccount'.tr(),
subtitle: 'dialogs.deleteAccountWarning'.tr(),
title: 'ui.deleteTobAccount'.tr(),
);
if (confirmed && mounted) {
await BeamOverlays.showProgressOverlay(
this.context,
authNotifier.deleteAccount(),
if (confirmed) {
ProgressDialog.show(
future: authNotifier.deleteAccount(),
navigatorKey:
GetIt.instance.get<BeamRouterDelegate>().navigatorKey!,
);
}
},
Expand Down
15 changes: 8 additions & 7 deletions learning/tour-of-beam/frontend/lib/locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import 'package:app_state/app_state.dart';
import 'package:get_it/get_it.dart';
import 'package:playground_components/playground_components.dart';

import 'auth/notifier.dart';
import 'cache/content_tree.dart';
Expand Down Expand Up @@ -52,12 +53,12 @@ void _initializeCaches() {
}

void _initializeState() {
GetIt.instance.registerSingleton(AppNotifier());
GetIt.instance.registerSingleton(
PageStack(
bottomPage: WelcomePage(),
createPage: PageFactory.createPage,
routeInformationParser: TobRouteInformationParser(),
),
final pageStack = PageStack(
bottomPage: WelcomePage(),
createPage: PageFactory.createPage,
routeInformationParser: TobRouteInformationParser(),
);
GetIt.instance.registerSingleton(AppNotifier());
GetIt.instance.registerSingleton(pageStack);
GetIt.instance.registerSingleton(BeamRouterDelegate(pageStack));
}
2 changes: 1 addition & 1 deletion learning/tour-of-beam/frontend/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void main() async {
const englishLocale = Locale('en');

final pageStack = GetIt.instance.get<PageStack>();
final routerDelegate = BeamRouterDelegate(pageStack);
final routerDelegate = GetIt.instance.get<BeamRouterDelegate>();
final routeInformationParser = TobRouteInformationParser();
final backButtonDispatcher = PageStackBackButtonDispatcher(pageStack);

Expand Down
4 changes: 2 additions & 2 deletions learning/tour-of-beam/frontend/lib/pages/tour/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ class TourNotifier extends ChangeNotifier with PageStateMixin<void> {
}

@override
void dispose() {
Future<void> dispose() async {
_unitContentCache.removeListener(_onUnitChanged);
contentTreeController.removeListener(_onUnitChanged);
_appNotifier.removeListener(_onAppNotifierChanged);
_authNotifier.removeListener(_onUnitProgressChanged);
super.dispose();
await super.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export 'src/widgets/bubble.dart';
export 'src/widgets/clickable.dart';
export 'src/widgets/complexity.dart';
export 'src/widgets/dialogs/confirm.dart';
export 'src/widgets/dialogs/progress.dart';
export 'src/widgets/divider.dart';
export 'src/widgets/header_icon_button.dart';
export 'src/widgets/loading_error.dart';
Expand All @@ -72,7 +73,6 @@ export 'src/widgets/output/output_tab.dart';
export 'src/widgets/output/output_tabs.dart';
export 'src/widgets/overlay/body.dart';
export 'src/widgets/overlay/opener.dart';
export 'src/widgets/overlay/overlays.dart';
export 'src/widgets/overlay/widget.dart';
export 'src/widgets/reset_button.dart';
export 'src/widgets/run_or_cancel_button.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,42 @@
* limitations under the License.
*/

import 'dart:async';

import 'package:flutter/material.dart';

import '../../../playground_components.dart';
class ProgressDialog extends StatelessWidget {
const ProgressDialog();

static void show({
required Future future,
required GlobalKey<NavigatorState> navigatorKey,
}) {
var shown = true;
unawaited(
showDialog(
context: navigatorKey.currentContext!,
builder: (_) => const ProgressDialog(),
).whenComplete(() {
shown = false;
}),
);
unawaited(
future.whenComplete(() {
if (shown) {
navigatorKey.currentState!.pop();
}
}),
);
}

/// Groups common overlays.
class BeamOverlays {
/// Shows an overlay with [CircularProgressIndicator]
/// until [future] completes.
static Future<void> showProgressOverlay(
BuildContext context,
Future future,
) async {
final closeNotifier = PublicNotifier();
showOverlay(
context: context,
closeNotifier: closeNotifier,
barrierDismissible: false,
positioned: Positioned.fill(
child: Container(
alignment: Alignment.center,
color: Theme.of(context).dialogBackgroundColor.withOpacity(0.2),
child: const CircularProgressIndicator(),
),
@override
Widget build(BuildContext context) {
return const Dialog(
backgroundColor: Colors.transparent,
child: Center(
child: CircularProgressIndicator(),
),
);
await future;
closeNotifier.notifyPublic();
}
}

0 comments on commit 7626f8f

Please sign in to comment.