Skip to content

MediaQuery.paddingOf does not rebuild when value changes #116842

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

Activity

  1. moffatman commented on Dec 11, 2022

    @moffatman
    Contributor

    What's the expected output vs actual? I thought keyboard area was represented by viewInsets, not padding?

  2. moffatman commented on Dec 11, 2022

    @moffatman
    Contributor

    Ah you're right, I forgot to handle padding in updateShouldNotifyDependent.

  3. b3nni97 commented on Dec 11, 2022

    @b3nni97
    Author

    Awesome, with the new MediaQuery API the performance has improved significantly, great work :)

  4. changed the title [-][iOS] MediaQuery.paddingOf does not rebuild when value changes[/-] [+]MediaQuery.paddingOf does not rebuild when value changes[/+] on Dec 11, 2022
  5. danagbemava-nc commented on Dec 12, 2022

    @danagbemava-nc
    Member

    Issue is reproducible using the sample and steps provided above.

    updated sample
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          home: Home(),
        );
      }
    }
    
    class Home extends StatelessWidget {
      final bool useMediaQueryOf = false;
    
      const Home({super.key});
    
      @override
      Widget build(BuildContext context) {
        if (useMediaQueryOf) {
          print('using MediaQuery.of() ${MediaQuery.of(context).padding}');
        } else {
          print('using MediaQuery.paddingOf() ${MediaQuery.paddingOf(context)}');
        }
    
        return Scaffold(
          appBar: AppBar(),
          body: ListView.builder(
            itemBuilder: (_, ndx) {
              return const TextField();
            },
          ),
        );
      }
    }
    flutter doctor -v
    [!] Flutter (Channel master, 3.7.0-5.0.pre.25, on macOS 13.0.1 22A400 darwin-arm64, locale en-GB)
        • Flutter version 3.7.0-5.0.pre.25 on channel master at /Users/nexus/dev/sdks/flutters
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 92aebc953d (86 minutes ago), 2022-12-11 22:24:23 -0500
        • Engine revision 922546c919
        • Dart version 3.0.0 (build 3.0.0-12.0.dev)
        • DevTools version 2.20.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14B47b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.3)
        • 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.13+0-b1751.21-8125866)
    
    [✓] VS Code (version 1.74.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.54.0
    
    [✓] Connected device (3 available)
        • iPhone 14 Pro (mobile) • 4F72110C-F38B-4CF9-93C4-4D6042148D28 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator)
        • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.0.1 22A400 darwin-arm64
        • Chrome (web)           • chrome                               • web-javascript • Google Chrome 108.0.5359.98
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    
  6. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Dec 12, 2022
  7. github-actions commented on Mar 5, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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