Repository: flutter
Issue: MediaQuery.of(context).viewInsets seems to be too large
Labels: a: text input,platform-ios,a: layout,has reproducible steps,P2,found in release: 2.5,found in release: 2.6,team-ios,triaged-ios

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->

1. Execute `flutter run` on the code sample <!-- (see "Code sample" section below) -->
2. Tap one of the three buttons. A dialog should open in which a text field is autofocussed, so the soft keyboard should open as well.
3.  look at the distance between the bottom edge of the dialog and the top edge of the opened keyboard: it is too large

**Expected results:** <!-- what did you want to see? -->
In the dialog that is opened by tapping the TextButton `Show dialog: content wrapped with AnimatedPadding widget` I used `MediaQuery.of(context).viewInsets.bottom` as padding. The dialogs opened by the other buttons open widgets wrapped by `Dialog` or `AlertDialog` which both use `MediaQuery.of(context).viewInsets.bottom` as padding too.

Documentation states `MediaQuery.of(context).viewInsets` is the following:

```
  /// The parts of the display that are completely obscured by system UI,
  /// typically by the device's keyboard.
  ///
  /// When a mobile device's keyboard is visible `viewInsets.bottom`
  /// corresponds to the top of the keyboard.
```

So when using `MediaQuery.of(context).viewInsets.bottom` as padding for the dialog widget, the edges of the soft keyboard and the dialog widget should touch.

**Actual results:** <!-- what did you see? -->
However, there is a large gap between the top edge of the soft keyboard and the bottom edge of the dialog widget. 

![image](https://user-images.githubusercontent.com/39117631/136963486-51baf32c-536e-4261-9517-875d8c5cddbd.png)


<details>
<summary>Code sample</summary>

<!--
      Please create a minimal reproducible sample that shows the problem
      and attach it below between the lines with the backticks.

      To create it you can use `flutter create bug` command and update the `main.dart` file.

      Alternatively, you can use https://dartpad.dev/
      which is capable of creating and running small Flutter apps.

      Without this we will unlikely be able to progress on the issue, and because of that
      we regretfully will have to close it.
-->

The behavior is identical even if you exchange `MyPopupContent` with a simple `TextField`. 

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyPopupContent extends StatelessWidget {
  const MyPopupContent({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Card(
        margin: const EdgeInsets.all(12.0),
        shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(
            Radius.circular(16),
          ),
        ),
        child: Padding(
            padding: const EdgeInsets.all(12.0),
            child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  const Icon(Icons.home),
                  const Text("hello"),
                  const TextField(autofocus: true),
                  ElevatedButton(
                      onPressed: () {}, child: const Text("ElevatedButton"))
                ])));
  }
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Column(
          children: [
            ElevatedButton(
              onPressed: () {
                showDialog(
                    context: context,
                    builder: (context) {
                      return const Dialog(child: MyPopupContent());
                    });
              },
              child:
                  const Text("Show dialog: content wrapped with Dialog widget"),
            ),
            ElevatedButton(
              onPressed: () {
                showDialog(
                    context: context,
                    builder: (context) {
                      return AnimatedPadding(
                          padding: EdgeInsets.only(
                              bottom: MediaQuery.of(context).viewInsets.bottom),
                          duration: const Duration(milliseconds: 100),
                          child: Center(
                              child: Wrap(children: const [MyPopupContent()])));
                    });
              },
              child: const Text(
                  "Show dialog: content wrapped with AnimatedPadding widget"),
            ),
            ElevatedButton(
              onPressed: () {
                showDialog(
                    context: context,
                    builder: (context) {
                      return const AlertDialog(
                        title: Text("AlertDialog"),
                        content: MyPopupContent(),
                      );
                    });
              },
              child: const Text(
                  "Show dialog: content wrapped with AlertDialog widget"),
            ),
          ],
        ),
      ),
    );
  }
}

```

</details>

<details>
  <summary>Logs</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue.
-->

```
```

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
Analyzing simple_example...                                             
No issues found! (ran in 1.7s)

```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel stable, 2.5.2, on macOS 11.2 20D64 darwin-x64, locale en-DE)
    • Flutter version 2.5.2 at /Users/giuseppe/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 3595343e20 (12 days ago), 2021-09-30 12:58:18 -0700
    • Engine revision 6ac856380f
    • Dart version 2.14.3

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/giuseppe/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.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 1.8.0_242-release-1644-b3-6915495)

[✓] IntelliJ IDEA Community Edition (version 2021.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.61.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.27.0

[✓] Connected device (3 available)
    • iPhone 12 Pro Max (mobile)           • EA834277-128A-4C21-B92D-639CB4CDC0AC • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
    • iPod touch (7th generation) (mobile) • 686879B6-FCFA-41AB-8269-60203330E9F0 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
    • Chrome (web)                         • chrome                               • web-javascript • Google Chrome 94.0.4606.81

```

</details>


<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->