Main page transitions improvements
This commit is contained in:
@@ -119,6 +119,7 @@ class TbContext {
|
||||
late final IosDeviceInfo? _iosInfo;
|
||||
late final String packageName;
|
||||
TbMainDashboardHolder? _mainDashboardHolder;
|
||||
bool _closeMainFirst = false;
|
||||
|
||||
GlobalKey<ScaffoldMessengerState> messengerKey = GlobalKey<ScaffoldMessengerState>();
|
||||
late final ThingsboardClient tbClient;
|
||||
@@ -401,11 +402,8 @@ class TbContext {
|
||||
transition = TransitionType.native;
|
||||
}
|
||||
}
|
||||
var res = await router.navigateTo(currentState!.context, path, transition: transition, transitionDuration: transitionDuration, replace: replace, clearStack: clearStack);
|
||||
if (isOpenedDashboard) {
|
||||
await _mainDashboardHolder?.closeMain();
|
||||
}
|
||||
return res;
|
||||
_closeMainFirst = isOpenedDashboard;
|
||||
return await router.navigateTo(currentState!.context, path, transition: transition, transitionDuration: transitionDuration, replace: replace, clearStack: clearStack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,7 +420,8 @@ class TbContext {
|
||||
));
|
||||
}
|
||||
|
||||
void pop<T>([T? result, BuildContext? context]) {
|
||||
void pop<T>([T? result, BuildContext? context]) async {
|
||||
await closeMainIfNeeded();
|
||||
var targetContext = context ?? currentState?.context;
|
||||
if (targetContext != null) {
|
||||
router.pop<T>(targetContext, result);
|
||||
@@ -438,12 +437,25 @@ class TbContext {
|
||||
}
|
||||
|
||||
Future<bool> willPop() async {
|
||||
if (await closeMainIfNeeded()) {
|
||||
return true;
|
||||
}
|
||||
if (_mainDashboardHolder != null) {
|
||||
return await _mainDashboardHolder!.dashboardGoBack();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<bool> closeMainIfNeeded() async {
|
||||
if (currentState != null) {
|
||||
if (currentState!.closeMainFirst && _mainDashboardHolder != null) {
|
||||
await _mainDashboardHolder!.closeMain();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<bool?> confirm({required String title, required String message, String cancel = 'Cancel', String ok = 'Ok'}) {
|
||||
return showDialog<bool>(context: currentState!.context,
|
||||
builder: (context) => AlertDialog(
|
||||
@@ -474,6 +486,12 @@ mixin HasTbContext {
|
||||
if (_tbContext.currentState != null) {
|
||||
ModalRoute.of(_tbContext.currentState!.context)?.addScopedWillPopCallback(_tbContext.willPop);
|
||||
}
|
||||
if (_tbContext._closeMainFirst) {
|
||||
_tbContext._closeMainFirst = false;
|
||||
if (_tbContext.currentState != null) {
|
||||
_tbContext.currentState!.closeMainFirst = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setupTbContext(TbContextState currentState) {
|
||||
|
||||
@@ -21,6 +21,7 @@ abstract class TbContextWidget extends StatefulWidget with HasTbContext {
|
||||
abstract class TbContextState<T extends TbContextWidget> extends State<T> with HasTbContext {
|
||||
|
||||
final bool handleLoading;
|
||||
bool closeMainFirst = false;
|
||||
|
||||
TbContextState({this.handleLoading = false});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user