Repository: flutter
Issue: [go_router] Using CupertinoTabScaffold with StatefulShellRoute cause unnecessary builds
Labels: package,has reproducible steps,P3,found in release: 3.13,found in release: 3.17,team-text-input,triaged-text-input

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

Using CupertinoTabScaffold with StatefulShellRoute is causing unnecessary builds when there is a textedit control. Even though a rebuild in itself shouldn't be an issue, this causes the text edit to lose focus and keyboard to disappear which is an issue. The same code with MaterialApp and Scaffold doesn't cause any issues.


Similar issue was reported before for MaterialApp as well:
https://github.com/flutter/flutter/issues/37878

### Expected results

The text field should be kept in focus across rebuilds

### Actual results

The whole scaffold is rebuilt when the text edit is clicked and the text edit lose focus

### Code sample

<details><summary>Code sample</summary>


```
import 'package:flutter/cupertino.dart';
import 'package:go_router/go_router.dart';

final routerConfig = GoRouter(
  debugLogDiagnostics: true,
  initialLocation: '/home',
  routes: [
    StatefulShellRoute.indexedStack(
        builder: (context, state, navigationShell) => NavigationShellScaffold(
              key: GlobalKey(),
              navigationShell: navigationShell,
            ),
        branches: [
          StatefulShellBranch(routes: [
            GoRoute(
              path: '/home',
              builder: (context, state) => const HomePage(),
            ),
          ]),
          StatefulShellBranch(routes: [
            GoRoute(
              path: '/profile',
              builder: (context, state) => const ProfilePage(),
            ),
          ]),
        ]),
  ],
);

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return CupertinoApp.router(
      routerConfig: routerConfig,
      theme: CupertinoThemeData(brightness: MediaQuery.of(context).platformBrightness),
      debugShowCheckedModeBanner: false,
    );
  }
}

class NavigationShellScaffold extends StatelessWidget {
  final StatefulNavigationShell navigationShell;

  const NavigationShellScaffold({super.key, required this.navigationShell});

  @override
  Widget build(BuildContext context) {
    debugPrint("NavigationShellScaffold build");
    return CupertinoTabScaffold(
      tabBar: CupertinoTabBar(currentIndex: navigationShell.currentIndex, onTap: (index) => navigationShell.goBranch(index), items: const [
        BottomNavigationBarItem(label: 'Home', icon: Icon(CupertinoIcons.home)),
        BottomNavigationBarItem(label: 'Profile', icon: Icon(CupertinoIcons.person))
      ]),
      tabBuilder: (_, __) => TapRegion(child: navigationShell, onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus()),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return const Center(
      child: Padding(
        padding: EdgeInsets.all(50),
        child: CupertinoSearchTextField(),
      ),
    );
  }
}

class ProfilePage extends StatelessWidget {
  const ProfilePage({super.key});

  @override
  Widget build(BuildContext context) {
    return const Center(child: Text('Profile Page'));
  }
}
```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

https://github.com/flutter/flutter/assets/8032715/4211ee82-6260-4b33-9928-00f02eba2054

</details>


### Logs

_No response_

### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.13.9, on macOS 14.0 23A344 darwin-x64, locale en-IN)
    • Flutter version 3.13.9 on channel stable at /Users/manu/.flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (9 days ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/manu/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    • CocoaPods version 1.13.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • Android Studio at /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 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.84.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.76.0

[✓] Connected device (3 available)
    • Manu’s iPhone (mobile) • 00008101-000554AA1141001E • ios            • iOS 17.0 21A329
    • macOS (desktop)        • macos                     • darwin-x64     • macOS 14.0 23A344 darwin-x64
    • Chrome (web)           • chrome                    • web-javascript • Google Chrome 119.0.6045.105

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>