Repository: flutter
Issue: Previous route in stack gets rebuilt on every frame when virtual keyboard appears/disappears
Labels: a: text input,framework,f: routes,has reproducible steps,P2,found in release: 3.10,found in release: 3.11,team-framework,triaged-framework

### 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

1. Create a new project with the provided code sample
2. Run the project;
3. Click on red container. You will be navigated to the screen with a form;
4. Click on the form in order to bring it in focus/click Done on the keyboard to remove focus;
5. Look inside the console, First screen is being rebuilt on every frame when keyboard appears/disappears.


Seems like using MediaQuery inside the first screen is somehow broken or I'm not using it correctly

### Expected results

I expect the following results:
 **first screen to not rebuild since keyboard is appearing/disappearing on the second screen**

### Actual results

read above

### Code sample

<details><summary>Code sample</summary>

* First screen
```dart
import 'package:flutter/material.dart';

import 'form_screen.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Builder(builder: (context) {
            print('build');
            return GestureDetector(
              onTap: () {
                Navigator.of(context).push(
                  MaterialPageRoute(
                    builder: (context) => const FormScreen(),
                  ),
                );
              },
              child: Container(
                height: MediaQuery.of(context).size.height / 2,
                width: MediaQuery.of(context).size.width / 2,
                color: Colors.red,
              ),
            );
          }),
        ),
      ),
    );
  }
}
```
* Second screen
```dart
import 'package:flutter/material.dart';

class FormScreen extends StatelessWidget {
  const FormScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: Center(
        child: TextField(),
      ),
    );
  }
}
```
</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>



https://github.com/flutter/flutter/assets/54116985/d8dd43e2-9b92-4291-9b10-800fb2a7e243



</details>


### Logs

<details><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.10.2, on macOS 13.3 22E252 darwin-arm64, locale ru-RU)
    • Flutter version 3.10.2 on channel stable at /Users/gidrokolbaska/Developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 9cd3d0d9ff (7 days ago), 2023-05-23 20:57:28 -0700
    • Engine revision 90fa3ae28f
    • Dart version 3.0.2
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/gidrokolbaska/Library/Android/sdk
    • Platform android-33, build-tools 32.1.0-rc1
    • 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 14.2)
    • Xcode at /Applications/Xcode14.2.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.2

[✓] 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.78.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.64.0

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • 442951FA-0B23-43B4-B975-ADBD0B8D4D4F • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 13.3 22E252
      darwin-arm64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome
      113.0.5672.126

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>