Repository: flutter
Issue: [go_router] Different widget sizing behavior in ShellRoute
Labels: package,has reproducible steps,P2,p: go_router,team-go_router,triaged-go_router,found in release: 3.24,found in release: 3.25

### 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

<details open><summary>Code sample</summary>

```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,
    );
  }
}
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

#  ShellRoute with AppBar and body set to child (/page1)
<img src="https://github.com/user-attachments/assets/515ccca2-1fb1-4008-b5c7-6da8cedff737" height="500" />

# ShellRoute with AppBar and body set to Card.filled (/page2)
<img src="https://github.com/user-attachments/assets/e3016eb5-d437-4ddb-aba6-bce25338dc02" height="500" />


# ShellRoute without AppBar and body set to child (/page3)
<img src="https://github.com/user-attachments/assets/764e9668-b95a-4980-b707-fcaee7f7bd24" height="500" />


# ShellRoute with AppBar and body set to child (/page4)
<img src="https://github.com/user-attachments/assets/63356fd3-e0b2-4d92-aef6-d9ee716a65f7" height="500" />

</details>


### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```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!
```

</details>