modal_bottom_sheet
modal_bottom_sheet copied to clipboard
BottomSheetRoute throws if declared as initial route
I am using modal_bottom_sheet
together with auto_route
package. My routes declaration looks more or less like this:
@MaterialAutoRouter(
routes: [
AutoRoute(
path: '/',
page: EmptyRouterPage,
name: 'RootRoute',
children: [
AutoRoute(
initial: true,
page: HomePage,
),
CustomRoute(
page: EmptyRouterPage,
name: 'OtherFlowRoute',
children: [
CustomRoute(
initial: true,
page: EmptyRouterPage,
name: 'BottomSheetRoute',
customRouteBuilder: buildModalBottomSheetRoute,
children: [
// ... bottom sheet routes
],
),
// ... other flow routes
],
),
],
),
],
)
When I try to navigate to other flow and push modal bottom sheet as the initial route, I get following error:
════════ Exception caught by widgets library ═══════════════════════════════════
The following _CastError was thrown building WillPopScope(dependencies: [_ModalScopeStatus], state: _WillPopScopeState#2ab01):
Null check operator used on a null value
The relevant error-causing widget was
AutoRouter
lib/widgets.dart:36
When the exception was thrown, this was the stack
#0 ModalBottomSheetRoute.createAnimationController
package:modal_bottom_sheet/src/bottom_sheet_route.dart:176
#1 TransitionRoute.install
package:flutter/…/widgets/routes.dart:220
#2 ModalRoute.install
package:flutter/…/widgets/routes.dart:1146
#3 _RouteEntry.handleAdd
package:flutter/…/widgets/navigator.dart:2818
#4 NavigatorState._flushHistoryUpdates
package:flutter/…/widgets/navigator.dart:3813
#5 NavigatorState.restoreState
package:flutter/…/widgets/navigator.dart:3318
#6 RestorationMixin._doRestore
package:flutter/…/widgets/restoration.dart:887
#7 RestorationMixin.didChangeDependencies
package:flutter/…/widgets/restoration.dart:873
#8 NavigatorState.didChangeDependencies
package:flutter/…/widgets/navigator.dart:3336
#9 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4914
#10 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4729
// more stack trace
This is because ModalBottomSheet
attempts to create animation controller before first frame in which case overlay
is still unavailable.
https://github.com/jamesblasco/modal_bottom_sheet/blob/master/lib/src/bottom_sheet_route.dart#L176
Is there any specific reason to use overlay
as TickerProvider
? E.g. bottom sheet from the SDK simply uses navigator
to create the controller:
https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/bottom_sheet.dart#L513
Let me know if I could provide any additional info that would be helpful.
Any update on this? In my case, this was happened when my app was restoring state and the bottom sheet was in the top of the navigation stack.
Same issue. Any update on this?
Same issue here unfortunately
Having this issue as well.
Same issue.
Same issue here
Hi. The issue is on this line https://github.com/jamesblasco/modal_bottom_sheet/blob/39174843294cf19ec8a3a624c32034227cdfd788/modal_bottom_sheet/lib/src/bottom_sheet_route.dart#L183
just put navigator!
instead navigator!.overlay
and it should work
It looks like that's what they do in Flutter ModalBottomSheetRoute.
@override
AnimationController createAnimationController() {
assert(_animationController == null);
if (transitionAnimationController != null) {
_animationController = transitionAnimationController;
willDisposeAnimationController = false;
} else {
_animationController = BottomSheet.createAnimationController(navigator!);
}
return _animationController!;
}
I opened a PR with that change: https://github.com/jamesblasco/modal_bottom_sheet/pull/379