Skip to content

Commit

Permalink
fix: Pop loading dialog before build is finished (#1182)
Browse files Browse the repository at this point in the history
* fix: Pop loading dialog before build is finished

* Update image_crop_page.dart
  • Loading branch information
M123-dev authored Mar 4, 2022
1 parent 05081ab commit d7b36bd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/smooth_app/lib/generic_lib/loading_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_action_button.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
Expand Down Expand Up @@ -61,7 +62,6 @@ class LoadingDialog<T> {
future.then<void>(
(final T value) => _popDialog(context, value),
);
// TODO(monsieurtanuki): is that safe? If the future finishes before the "return" call?
return _getDialog(context, title);
},
);
Expand All @@ -72,8 +72,11 @@ class LoadingDialog<T> {
return;
}
_popEd = true;
// Here we use the root navigator so that we can pop dialog while using multiple navigators.
Navigator.of(context, rootNavigator: true).pop(value);
// To avoid returning before the alertDialog is build
SchedulerBinding.instance?.addPostFrameCallback((_) {
// Here we use the root navigator so that we can pop dialog while using multiple navigators.
Navigator.of(context, rootNavigator: true).pop(value);
});
}

/// Displayed dialog during future.
Expand Down

0 comments on commit d7b36bd

Please sign in to comment.