Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BottomSheetRoute throws if declared as initial route #228

Closed
tomwyr opened this issue Mar 21, 2022 · 8 comments · Fixed by #379 or sodality-tech/modal_bottom_sheet#1
Closed

BottomSheetRoute throws if declared as initial route #228

tomwyr opened this issue Mar 21, 2022 · 8 comments · Fixed by #379 or sodality-tech/modal_bottom_sheet#1

Comments

@tomwyr
Copy link

tomwyr commented Mar 21, 2022

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.

@mrhabibi
Copy link

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.

@guenth39
Copy link

Same issue. Any update on this?

@janknips
Copy link

Same issue here unfortunately

@pgulegin
Copy link

Having this issue as well.

@taiseidev
Copy link

Same issue.

@talhakerpicci
Copy link

Same issue here

@vasilich6107
Copy link

Hi.
The issue is on this line

just put navigator! instead navigator!.overlay and it should work

kvenn added a commit to sodality-tech/modal_bottom_sheet that referenced this issue Nov 7, 2023
@kvenn
Copy link
Contributor

kvenn commented Nov 7, 2023

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: #379

jamesblasco pushed a commit that referenced this issue Nov 8, 2023
TasnimAnas pushed a commit to TasnimAnas/modal_bottom_sheet that referenced this issue Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants