I’ve migrated my code from flutter navigator to a auto route navigator and I’m facing an issue on dialog pop.
I open a dialog and wait its response to decide if I should pop or not my current page.
The response of my dialog is true then I decide to pop my page.
Then because there is a double chained pop I’m receiving an error (that I wasn’t receiving on flutter Navigator)
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 4817 pos 12: '!_debugLocked': is not true.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2 NavigatorState._pushEntry (package:flutter/src/widgets/navigator.dart:4817:12)
#3 NavigatorState.push (package:flutter/src/widgets/navigator.dart:4774:5)
#4 showDialog (package:flutter/src/material/dialog.dart:1436:65)
final bool? result = await showDialog(
context: context,
builder: (context) => Dialog(
child: ElevatedButton(
onPressed: () => context.router.maybePop(true),
child: Text('test'),
),
),
);
_callAsyncCubitMethod(); // take 5 seconds to finish
if (result == true) {
context.router.maybePop(true);
}
I tried other way to see if it could solve the problem but it didn’t work :
if (result == true) {
WidgetsBinding.instance.addPostFrameCallback((_) async {
context.router.maybePop();
});
}
or
if (result == true) {
Future.delayed(
Duration(seconds: 0),
() {
context.router.maybePop();
},
);
}
Does anyone have an idea on how to solve this problem ?