flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.13k stars 27.47k forks source link

[go_router] Different widget sizing behavior in ShellRoute #154914

Open ngoc-quoc-huynh opened 1 month ago

ngoc-quoc-huynh commented 1 month ago

Steps to reproduce

The output of the UI differs depending on if I provide the Scaffolds body widget directly in the ShellRoute or via the child parameter from the ShellRouteBuilder method.

  1. Run the example code with initialLocation set to /page1.
  2. Run the example code with initialLocation set to /page2.
  3. Run the example code with initialLocation set to /page3.
  4. Run the example code with initialLocation set to /page4.

Expected results

I would expect that /page1 would result the same UI as in /page2 and /page3 would result the same UI as in /page4.

Actual results

The UI differs in /page1 taking the full size, but /page2 it doesn't. /page3 and /page4 has the same UI as expected.

Code sample

Code sample ```dart import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); static final _config = GoRouter( initialLocation: '/page1', routes: [ // ShellRoute with AppBar and body set to child. ShellRoute( builder: (context, state, child) => Scaffold( appBar: AppBar( title: const Text('Example'), ), body: child, ), routes: [ GoRoute( path: '/page1', builder: (_, __) => const Card.filled(), ), ], ), // ShellRoute with AppBar and body set to Card.filled. ShellRoute( builder: (context, state, child) => Scaffold( appBar: AppBar( title: const Text('Example'), ), body: const Card.filled(), ), routes: [ GoRoute( path: '/page2', builder: (_, __) => const Card.filled(), ), ], ), // ShellRoute without AppBar and body set to child. ShellRoute( builder: (context, state, child) => Scaffold( body: child, ), routes: [ GoRoute( path: '/page3', builder: (_, __) => const Card.filled(), ), ], ), // ShellRoute without AppBar and body set to Card.filled. ShellRoute( builder: (context, state, child) => const Scaffold( body: Card.filled(), ), routes: [ GoRoute( path: '/page4', builder: (_, __) => const Card.filled(), ), ], ), ], ); @override Widget build(BuildContext context) { return MaterialApp.router( routerConfig: _config, ); } } ```

Screenshots or Video

Screenshots / Video demonstration # ShellRoute with AppBar and body set to child (/page1) # ShellRoute with AppBar and body set to Card.filled (/page2) # ShellRoute without AppBar and body set to child (/page3) # ShellRoute with AppBar and body set to child (/page4)

Logs

No response

Flutter Doctor output

Doctor output ```console [✓] Flutter (Channel stable, 3.24.2, on macOS 14.6.1 23G93 darwin-x64, locale de-DE) • Flutter version 3.24.2 on channel stable at /Users/huynh/.asdf/installs/flutter/3.24.2-stable • Upstream repository https://github.com/flutter/flutter.git • Framework revision 4cf269e36d (vor 7 Tagen), 2024-09-03 14:30:00 -0700 • Engine revision a6bd3f1de1 • Dart version 3.5.2 • DevTools version 2.37.2 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/huynh/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/huynh/Library/Android/sdk • Java binary at: /Users/huynh/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2024.1) • Android Studio at /Users/huynh/Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) [✓] IntelliJ IDEA Ultimate Edition (version 2024.2.1) • IntelliJ at /Users/huynh/Applications/IntelliJ IDEA Ultimate.app • Flutter plugin version 81.1.3 • Dart plugin version 242.21829.3 [✓] VS Code (version 1.92.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.94.0 [✓] Connected device (3 available) • iPhone 13 mini (mobile) • 9EC9B697-54E5-49AB-9F44-4D997DFDBE20 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator) • macOS (desktop) • macos • darwin-x64 • macOS 14.6.1 23G93 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 128.0.6613.120 ! Error: Browsing on the local area network for cosee iPhone 12 . Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) [✓] Network resources • All expected network resources are available. • No issues found! ```
darshankawar commented 1 month ago

Thanks for the report. Although I am able to replicate the reported behavior, I am not sure if it is intended or not. Keeping it open for team's tracking.

Stable : 3.24.2
Master: 3.25.0-1.0.pre.319
chunhtai commented 1 month ago

This is a bit tricky that the same container may decided to take up max space vs min space based on its surrounding parent. the navigator seems to always take min space. I am not sure if there is a way to create a proxy box around the navigator so that it will do the right thing