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

Using removeRouteBelow and then push from a Drawer causes an error #25601

Closed
MichaelPriebe opened this issue Dec 20, 2018 · 7 comments

Comments

@MichaelPriebe
Copy link

commented Dec 20, 2018

Steps to Reproduce

Follow the instructions inside this example app here: https://pastebin.com/raw/YWrNu02Y

example

Notes:
I am using while (navigator.canPop()) navigator.removeRouteBelow(route); to remove all routes below the current route, and then push a new one, when going back to the old route which now has a Drawer because it has no routes behind it, and pushing a new route from the Drawer, it errors.

Logs

[+8597 ms] I/flutter (18185): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
[  +11 ms] I/flutter (18185): The following assertion was thrown while finalizing the widget tree:
[        ] I/flutter (18185): setState() or markNeedsBuild() called when widget tree was locked.
[        ] I/flutter (18185): This Scaffold widget cannot be marked as needing to build because the framework is locked.
[        ] I/flutter (18185): The widget on which setState() or markNeedsBuild() was called was:
[        ] I/flutter (18185):   Scaffold(state: ScaffoldState#f4f25(tickers: tracking 1 ticker))
[   +1 ms] I/flutter (18185):
[   +4 ms] I/flutter (18185): When the exception was thrown, this was the stack:
[  +21 ms] I/flutter (18185): #0      Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:3502:9)
[        ] I/flutter (18185): #1      Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:3511:6)
[        ] I/flutter (18185): #2      State.setState (package:flutter/src/widgets/framework.dart:1146:14)
[        ] I/flutter (18185): #3      ScaffoldState._drawerOpenedCallback (package:flutter/src/material/scaffold.dart:1073:5)
[        ] I/flutter (18185): #4      DrawerControllerState.close (package:flutter/src/material/drawer.dart:351:14)
[        ] I/flutter (18185): #5      DrawerControllerState._handleHistoryEntryRemoved (package:flutter/src/material/drawer.dart:256:5)
[        ] I/flutter (18185): #6      LocalHistoryEntry._notifyRemoved (package:flutter/src/widgets/routes.dart:305:7)
[        ] I/flutter (18185): #7      _ModalRoute&TransitionRoute&LocalHistoryRoute.removeLocalHistoryEntry (package:flutter/src/widgets/routes.dart:466:11)
[        ] I/flutter (18185): #8      LocalHistoryEntry.remove (package:flutter/src/widgets/routes.dart:299:12)
[        ] I/flutter (18185): #9      DrawerControllerState.dispose (package:flutter/src/material/drawer.dart:213:20)
[        ] I/flutter (18185): #10     StatefulElement.unmount (package:flutter/src/widgets/framework.dart:3900:12)
[        ] I/flutter (18185): #11     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1709:13)
[        ] I/flutter (18185): #12     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
[        ] I/flutter (18185): #13     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
[        ] I/flutter (18185): #14     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
[  +15 ms] I/flutter (18185): #15     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1707:7)
[        ] I/flutter (18185): #16     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:3755:14)
[        ] I/flutter (18185): #17     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1705:13)
[        ] I/flutter (18185): #18     ListIterable.forEach (dart:_internal/iterable.dart:39:13)
[        ] I/flutter (18185): #19     _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:1718:25)
[        ] I/flutter (18185): #20     BuildOwner.finalizeTree.<anonymous closure> (package:flutter/src/widgets/framework.dart:2372:27)
[        ] I/flutter (18185): #21     BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2204:15)
[        ] I/flutter (18185): #22     BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:2371:7)
[        ] I/flutter (18185): #23     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame
(package:flutter/src/widgets/binding.dart:678:18)
[        ] I/flutter (18185): #24     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback
(package:flutter/src/rendering/binding.dart:219:5)
[        ] I/flutter (18185): #25     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
[        ] I/flutter (18185): #26     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
[        ] I/flutter (18185): #27     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
[        ] I/flutter (18185): #28     _invoke (dart:ui/hooks.dart:154:13)
[        ] I/flutter (18185): #29     _drawFrame (dart:ui/hooks.dart:143:3)
[        ] I/flutter (18185): ════════════════════════════════════════════════════════════════════════════════════════════════════
Analyzing testing...
No issues found! (ran in 36.7s)
[√] Flutter (Channel beta, v1.0.0, on Microsoft Windows [Version 10.0.17134.472], locale en-US)
    • Flutter version 1.0.0 at C:\flutter
    • Framework revision 5391447fae (3 weeks ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)
@zoechi

This comment has been minimized.

Copy link
Contributor

commented Dec 20, 2018

Looks similar to #25047

@MichaelPriebe

This comment has been minimized.

Copy link
Author

commented Dec 20, 2018

Why is the Scaffold disposing? Does it do that when a new route is over it?

@zoechi

This comment has been minimized.

Copy link
Contributor

commented Dec 20, 2018

@HansMuller might know more

@MichaelPriebe

This comment has been minimized.

Copy link
Author

commented Dec 21, 2018

Does not seem like removeRouteBelow is entirely the culprit. I had the problem using pushReplacement as well. Popping the drawer when clicking on the widget that pushes a new route fixes the problem, but I would rather not do that.

@HansMuller

This comment has been minimized.

Copy link
Contributor

commented Jan 2, 2019

The problem here, as with #25047, is that the Scaffold is being rebuilt without the drawer which causes the drawer to be disposed. The problem can be avoided popping the route first:

IconButton(
  icon: Icon(Icons.cake),
  onPressed: () async {
    NavigatorState navigator = Navigator.of(context);
    Navigator.of(context).pop(); // Added
    Route route = ModalRoute.of(context);
    while (navigator.canPop()) navigator.removeRouteBelow(route);
    await navigator.push(
      MaterialPageRoute(
        builder: (BuildContext context) => MyHomePageThree(),
      ),
    );
    // Removed setState(), the page will be rebuilt automatically
    _instructions = '<- Click';
  },
),
@MichaelPriebe

This comment has been minimized.

Copy link
Author

commented Jan 3, 2019

I think it was my adding of a drawer if there are no routes behind it that was making it crash. I created a special button to display the back button if there's a route immediately below, or a menu button if not, and the drawer is always present so technically you can open it with a slide if the back button is present. Would be cool if this was the default behavior of the implied button when using BOTH a drawer and a route below.

@HansMuller HansMuller self-assigned this Mar 27, 2019

@HansMuller

This comment has been minimized.

Copy link
Contributor

commented Apr 3, 2019

I'm closing this because unfortunately there's no "fix"; one must pop a route whose scaffold includes a drawer, before rebuilding it without the drawer. See #25601 (comment)

@HansMuller HansMuller closed this Apr 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.