Skip to content

MediaQuery.paddingOf does not rebuild when value changes #116842

@b3nni97

Description

@b3nni97

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Press on a text field to open the keyboard
  3. In the console, the value of paddingOf(context) was output 1 time, although this value should change during the keyboard animation.
  4. If the useMediaQueryOf in _HomeState is set to true (Restart the App after this) and you then click on a text field you will see the output several times in the console.

Expected results:
MediaQuery.paddingOf(context) should rebuild if the value changes.

Actual results:
MediaQuery.paddingOf(context) does not rebuild if the value changes.

@moffatman

Code sample
void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
      showPerformanceOverlay: true,
    );
  }
}

class Home extends StatelessWidget {
  bool useMediaQueryOf = false;

  @override
  Widget build(BuildContext context) {
    if (useMediaQueryOf) {
      print(MediaQuery.of(context).padding);
    } else {
      print(MediaQuery.paddingOf(context));
    }

    return Scaffold(
      appBar: AppBar(),
      body: ListView.builder(
        itemBuilder: (_, ndx) {
          return TextField();
        },
      ),
    );
  }
}
Logs
[✓] Flutter (Channel master, 3.7.0-4.0.pre.62, on macOS 12.6 21G115 darwin-arm64, locale en-US)
    • Flutter version 3.7.0-4.0.pre.62 on channel master at 
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision be5c389e6c (23 hours ago), 2022-12-09 20:52:32 -0500
    • Engine revision faae28965a
    • Dart version 3.0.0 (build 3.0.0-3.0.dev)
    • DevTools version 2.20.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    found in release: 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions