flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.16k stars 27.46k forks source link

PopupMenuButton retains wrong position on layout change #152475

Open aleripe opened 3 months ago

aleripe commented 3 months ago

Steps to reproduce

  1. Run the attached minimal sample on any platform
  2. Tap an overflow icon button to reveal the overflow menu
  3. Rotate the screen from portrait to landscape or vice versa

Expected results

The overflow menu hides after rotation or recalculates its right position based on its anchor

Actual results

The overflow menu is still visible, but in the wrong position

Code sample

Code sample ```dart import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'PopupMenuButton position', theme: ThemeData( primarySwatch: Colors.blue, ), home: const HomePageView(), ); } } class HomePageView extends StatefulWidget { const HomePageView({super.key}); @override State createState() => _HomePageViewState(); } class _HomePageViewState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('PopupMenuButton position')), body: OrientationBuilder(builder: (context, orientation) { int tileCount = orientation == Orientation.portrait ? 2 : 5; return Padding( padding: const EdgeInsets.all(8), child: GridView.count( crossAxisCount: tileCount, crossAxisSpacing: 8, mainAxisSpacing: 8, childAspectRatio: 1, children: List.generate(17, (index) { return GridTile( footer: GridTileBar( title: Text( 'Item $index', style: TextStyle( color: Theme.of(context).colorScheme.onPrimaryContainer, ), ), trailing: PopupMenuButton( itemBuilder: (context) { return [ const PopupMenuItem( child: Text('Archive'), ), const PopupMenuItem( child: Text('Edit'), ), const PopupMenuItem( child: Text('Delete'), ) ]; }, ), ), child: Ink( decoration: BoxDecoration( color: Theme.of(context).colorScheme.primaryContainer, borderRadius: const BorderRadius.all( Radius.circular(8), ), ), width: 175, height: 250, ), ); }), ), ); }), ); } } ```

Screenshots or Video

No response

Logs

Logs ```console Running Gradle task 'assembleDebug'... √ Built build\app\outputs\flutter-apk\app-debug.apk Installing build\app\outputs\flutter-apk\app-debug.apk... D/FlutterFileDialogPlugin(24349): onAttachedToEngine - IN D/FlutterFileDialogPlugin(24349): doOnAttachedToEngine - IN D/FlutterFileDialogPlugin(24349): doOnAttachedToEngine - OUT D/FlutterFileDialogPlugin(24349): onAttachedToEngine - OUT D/FlutterFileDialogPlugin(24349): onAttachedToActivity D/FlutterFileDialogPlugin(24349): doOnAttachedToActivity - IN D/FlutterFileDialogPlugin(24349): doOnAttachedToActivity - OUT Debug service listening on ws://127.0.0.1:56853/L-wxvMvU6kE=/ws Syncing files to device Pixel Fold... D/ProfileInstaller(24349): Installing profile for it.returntrue.novelist D/VRI[MainActivity](24349): visibilityChanged oldVisibility=true newVisibility=false I/ImeTracker(24349): it.returntrue.novelist:2c275c54: onRequestShow at ORIGIN_CLIENT reason SHOW_SOFT_INPUT fromUser false D/InputMethodManager(24349): showSoftInput() view=io.flutter.embedding.android.FlutterView{113df2b VFE...... .F....ID 0,0-2208,1756 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT D/InputConnectionAdaptor(24349): The input method toggled cursor monitoring on D/InsetsController(24349): show(ime(), fromIme=true) W/InteractionJankMonitor(24349): Initializing without READ_DEVICE_CONFIG permission. enabled=false, interval=1, missedFrameThreshold=3, frameTimeThreshold=64, package=it.returntrue.novelist I/ImeTracker(24349): it.returntrue.novelist:2c275c54: onShown D/InputConnectionAdaptor(24349): The input method toggled cursor monitoring off D/InsetsController(24349): hide(ime(), fromIme=true) W/WindowOnBackDispatcher(24349): sendCancelIfRunning: isInProgress=falsecallback=ImeCallback=ImeOnBackInvokedCallback@70107678 Callback=android.window.IOnBackInvokedCallback$Stub$Proxy@935dc34 I/ImeTracker(24349): it.returntrue.novelist:42f354f: onRequestHide at ORIGIN_CLIENT reason HIDE_SOFT_INPUT_ON_ANIMATION_STATE_CHANGED fromUser false I/ImeTracker(24349): com.google.android.inputmethod.latin:8f8da5d4: onHidden I/ImeTracker(24349): it.returntrue.novelist:d8a3be57: onRequestHide at ORIGIN_CLIENT reason HIDE_SOFT_INPUT fromUser false D/VRI[MainActivity](24349): visibilityChanged oldVisibility=true newVisibility=false ```

Flutter Doctor output

Doctor output ```console [√] Flutter (Channel stable, 3.22.3, on Microsoft Windows [Versione 10.0.19045.4651], locale it-IT) • Flutter version 3.22.3 on channel stable at C:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision b0850beeb2 (12 days ago), 2024-07-16 21:43:41 -0700 • Engine revision 235db911ba • Dart version 3.4.4 • DevTools version 2.34.3 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users\Alessandro\AppData\Local\Android\sdk • Platform android-34, build-tools 34.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [!] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.4) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.8.34408.163 X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components: MSVC v142 - VS 2019 C++ x64/x86 build tools - If there are multiple build tool versions available, install the latest C++ CMake tools for Windows Windows 10 SDK [√] Android Studio (version 2024.1) • Android Studio at C:\Program Files\Android\Android Studio • 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 • android-studio-dir = C:\Program Files\Android\Android Studio • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314) [√] VS Code (version 1.71.2) • VS Code at C:\Users\Alessandro\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.48.0 [√] Connected device (4 available) • Pixel Fold (mobile) • 35181FDHS00206 • android-arm64 • Android 14 (API 34) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Versione 10.0.19045.4651] • Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.185 • Edge (web) • edge • web-javascript • Microsoft Edge 127.0.2651.74 [√] Network resources • All expected network resources are available. ```
danagbemava-nc commented 3 months ago

Reproducible using the code sample provided above.

https://github.com/user-attachments/assets/a369c3a2-bc01-46f4-95b8-448d99916378

flutter doctor -v ``` [!] Flutter (Channel stable, 3.22.3, on macOS 14.5 23F79 darwin-arm64, locale en-GB) • Flutter version 3.22.3 on channel stable at /Users/nexus/dev/sdks/flutter ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision b0850beeb2 (12 days ago), 2024-07-16 21:43:41 -0700 • Engine revision 235db911ba • Dart version 3.4.4 • DevTools version 2.34.3 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. ``` ``` [✓] Flutter (Channel master, 3.24.0-1.0.pre.324, on macOS 14.5 23F79 darwin-arm64, locale en-GB) • Flutter version 3.24.0-1.0.pre.324 on channel master at /Users/nexus/dev/sdks/flutters • Upstream repository https://github.com/flutter/flutter.git • Framework revision 9d5ede0f5a (6 hours ago), 2024-07-29 01:28:40 -0400 • Engine revision 2cf3986cae • Dart version 3.6.0 (build 3.6.0-88.0.dev) • DevTools version 2.37.1 ```