SchabanBo / qlevar_router

Manage you project Routes. Create nested routes. Simply navigation without context to your pages. Change only one sub widget in your page when navigating to new route.
MIT License
87 stars 22 forks source link

replaceLastName with nested navigation #153

Open BarashkovaElena opened 2 months ago

BarashkovaElena commented 2 months ago

I cannot figure out how to make replaceLastName work with nested navigation, need some help on that. There is a root navigator and a a nested navigator. I want to open a page inside a tab in the nested navigator and then replace it with another page. I perform the following steps:

  1. Open nested navigation page. Stack tree initially looks like this:
    
    Key [-1] (Root)
    Key [2] (bottom_bar_page)

Key [20] (bottom_bar_page) Key [3] (home)

2. Open nested page over the home tab. Stack tree becomes this:

Key [-1] (Root) Key [2] (bottom_bar_page)

Key [20] (bottom_bar_page) Key [3] (home) Key [4] (internal)

3. Call QR.navigatorOf(bottomBarPageName).replaceLastName(dtoPageName);
Stack tree becomes this:

Key [-1] (Root) Key [2] (bottom_bar_page)

Key [20] (bottom_bar_page) Key [4] (internal) Key [3] (home) Key [6] (dto)


This is not correct, because "internal" page should not be in the stack. It should contain only "home" and "dto".
I need to get this stack:

Key [-1] (Root) Key [2] (bottom_bar_page)

Key [20] (bottom_bar_page) Key [3] (home) Key [6] (dto)


If I call replaceLastNamed on the root navigation, then the app crashes:

2 NavigatorState.initState (package:flutter/src/widgets/navigator.dart:3577:14)

3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5618:55)

4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5463:5)

... Normal element mounting (48 frames)

52 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4340:16)

53 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6904:36)

54 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6916:32)

... Normal element mounting (380 frames)

434 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4340:16)

435 MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6904:36)

436 Element.updateChild (package:flutter/src/widgets/framework.dart:3849:18)

437 Element.updateChildren (package:flutter/src/widgets/framework.dart:4036:32)

438 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6929:17)

439 Element.updateChild (package:flutter/src/widgets/framework.dart:3827:15)

440 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5512:16)

441 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5650:11)



How to get the desired stack tree?