4

How can I achieve this where a nested Navigator widget in a Column wraps the child content.

enter image description here

This crashes the app

 Column(
    children: [
       Text("First Text"),
       Navigator(
         key: _navigatorKey,
         initialRoute: widget.setupPageRoute,
         onGenerateRoute: _onGenerateRoute,
     ),
       Text("Second Text"),
    ],
 ),

with error

'package:flutter/src/widgets/overlay.dart': Failed assertion: line 720 pos 12: 'constraints.biggest.isFinite': is not true.

but adding a Flexible around the Navigator doesnt respect the flex and it just expands.

    Column(
            children: [
               Text("First Text"),
               Flexible(
                child: Navigator(
                  key: _navigatorKey,
               initialRoute:widget.setupPageRoute,
                 onGenerateRoute: _onGenerateRoute,
             ),
),
               Text("Second Text"),
            ],
         ),

enter image description here

Any ideas on how this can be solved? Thanks in advance

Bolaji
  • 556
  • 1
  • 6
  • 11
  • may be this help https://stackoverflow.com/questions/48098085/nesting-routes-with-flutter – Abhijith Aug 28 '21 at 13:47
  • Thanks @Abhijith I dont have a problem with the way the navigation route works, only how it fits with the rest of widget around it. Which is not what the link asnwered. – Bolaji Aug 28 '21 at 13:52
  • try this https://stackoverflow.com/questions/55716230/how-to-do-nested-navigation-in-flutter – Abhijith Aug 28 '21 at 13:56
  • Still not, unfortunately. That link talks about how to do multiple nested navigation with bottom bar. Still more about how to do navigator routing, not about how the Navigator itself sits in the layout. – Bolaji Aug 28 '21 at 14:07
  • Hi! @Bolaji did you find any solution to that? I'm also actually facing the same issue but In my case navigator is wrapped with CustomScrollView. – Mehroze Zaidi Jan 30 '23 at 10:35

1 Answers1

0

Before the issue got fixed, you can wrap IntrinsicHeight outside of the Navigator.

You only need to be careful with the notice in the document:

This class is relatively expensive, because it adds a speculative layout pass before the final layout phase. Avoid using it where possible. In the worst case, this widget can result in a layout that is O(N²) in the depth of the tree.

Column(
  children: [
    Text("First Text"),
    IntrinsicHeight (
      child: Navigator(
        key: _navigatorKey,
        initialRoute:widget.setupPageRoute,
        onGenerateRoute: _onGenerateRoute,
      ),
    ),
    Text("Second Text"),
  ],
)
yellowgray
  • 4,006
  • 6
  • 28