Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaffold's Current state isDrawerOpen parameter returns false in PopScope in flutter 3.22.0 but returns true in 3.19.0 #148896

Closed
aakash-pamnani opened this issue May 22, 2024 · 6 comments
Labels
found in release: 3.22 Found to occur in 3.22 found in release: 3.23 Found to occur in 3.23 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. team-framework Owned by Framework team triaged-framework Triaged by Framework team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds

Comments

@aakash-pamnani
Copy link
Contributor

aakash-pamnani commented May 22, 2024

Steps to reproduce

  1. Run the below code on Flutter 3.22.0.
  2. Press the pop button in drawer, the homepage will be popped.
  3. Downgrade flutter to 3.19.0 run flutter downgrade v.3.19.0 and flutter clean
  4. Repeat same steps.
  5. Now the drawer will be closed but app will not pop.

Expected results

_key.currentState?.isDrawerOpen should return true when drawer is open and pop button clicked in version 3.22.0.

Actual results

_key.currentState?.isDrawerOpen is returning false when drawer is open and pop button clicked in version 3.22.0.

Code sample

Code sample
import 'package:flutter/material.dart';

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter App!!',
      home: const MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  GlobalKey<ScaffoldState> _key = new GlobalKey<ScaffoldState>();
  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: false,
      onPopInvoked: (value) async {
        if (_key.currentState?.isDrawerOpen ?? false) {
          _key.currentState?.closeDrawer();
        } else {
          //show exit dialog
        }
      },
      child: Scaffold(
        key: _key,
        appBar: AppBar(
          title: Text("Flutter App"),
        ),
        drawer: Drawer(
          child: Center(
            child: ElevatedButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: Text("pop"),
            ),
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

Logs

Logs

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.22631.3593], locale en-IN)
    • Flutter version 3.19.6 on channel stable at H:\flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (5 weeks ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[√] 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\no-admin\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: H:\All Apps\android studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)
    • 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.7.5)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.7.34202.233
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.3)
    • Android Studio at H:\All Apps\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
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-10027231)

[√] IntelliJ IDEA Community Edition (version 2023.2)
    • IntelliJ at H:\All Apps\idea community\IntelliJ IDEA Community Edition 2022.3.3
    • 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

[√] Connected device (4 available)
    • POCOPHONE F1 (mobile) • 73237c6e • android-arm64  • Android 14 (API 34)
    • Windows (desktop)     • windows  • windows-x64    • Microsoft Windows [Version 10.0.22631.3593]    
    • Chrome (web)          • chrome   • web-javascript • Google Chrome 124.0.6367.208
    • Edge (web)            • edge     • web-javascript • Microsoft Edge 125.0.2535.51

[√] Network resources
    • All expected network resources are available.

• No issues found!
@aakash-pamnani aakash-pamnani changed the title Scaffold's Current state isDrawerOpen parameter returns false in PopScope in flutter 3.22.0 but works in 3.19.0 Scaffold's Current state isDrawerOpen parameter returns false in PopScope in flutter 3.22.0 but returns true in 3.19.0 May 22, 2024
@huycozy huycozy added the in triage Presently being triaged by the triage team label May 23, 2024
@huycozy
Copy link
Member

huycozy commented May 23, 2024

Hi @aakash-pamnani
I checked this on the latest Flutter 3.22.1 but I see isDrawerOpen returns true as expected but the main page is popped. The same result on Flutter 3.19.6.

The only factor I think about is the device you are checking on. Could you try another device to see if the result changes?

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 23, 2024
@aakash-pamnani
Copy link
Contributor Author

The issue is when using with go_router. When i add router in my app it returns false.

Code
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter App!!',
      routerConfig: GoRouter(
        initialLocation: "/",
        routes: [
          GoRoute(
            path: "/",
            builder: (context, state) => const MyHomePage(),
          ),
        ],
      ),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final GlobalKey<ScaffoldState> _key = GlobalKey<ScaffoldState>();
  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: false,
      onPopInvoked: (value) async {
        print("isDrawerOpen: ${_key.currentState?.isDrawerOpen}");

        if (_key.currentState?.isDrawerOpen ?? false) {
          _key.currentState?.closeDrawer();
        } else {
          //show exit dialog
        }
      },
      child: Scaffold(
        key: _key,
        appBar: AppBar(
          title: const Text("Flutter App"),
        ),
        drawer: SizedBox.expand(
          child: Drawer(
            child: Center(
              child: ElevatedButton(
                onPressed: () {
                  Navigator.of(context).pop();
                },
                child: const Text("pop"),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
Device Using GoRouter isDrawerOpen HomePage Popped
Andorid 14 No true yes
Andorid 14 yes false no
Chrome No true yes
Chrome Yes false no

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 24, 2024
@huycozy
Copy link
Member

huycozy commented May 27, 2024

I checked this again on both Android 11 and Android 14 devices on Flutter 3.19.6 but onPopInvoked is never invoked. Perhaps it behaved differently on 3.19.0. Despite that, I can see isDrawerOpen returns false on the latest Flutter stable 3.22.1 and master channel.

Labelling this issue as a go_router's issue to get more insights. May be related to #138737.

flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.22.1, on macOS 14.1 23B74 darwin-x64, locale en-VN)
    • Flutter version 3.22.1 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a14f74ff3a (11 hours ago), 2024-05-22 11:08:21 -0500
    • Engine revision 55eae6864b
    • Dart version 3.4.1
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode15.3.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • 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
    • android-studio-dir = /Applications/Android Studio.app/
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.89.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.88.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 14.1 23B74 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 125.0.6422.76

[✓] Network resources
    • All expected network resources are available.

• No issues found!
[!] Flutter (Channel master, 3.23.0-8.0.pre.8, on macOS 14.1 23B74 darwin-x64, locale en-VN)
    • Flutter version 3.23.0-8.0.pre.8 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8fd8e66de4 (3 hours ago), 2024-05-26 21:49:30 -0400
    • Engine revision 469193ef0e
    • Dart version 3.5.0 (build 3.5.0-191.0.dev)
    • DevTools version 2.36.0-dev.10
    • 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 34.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode15.3.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.2)
    • 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
    • android-studio-dir = /Applications/Android Studio.app/
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] VS Code (version 1.89.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.88.0

[✓] Connected device (3 available)
    • Pixel 7 (mobile) • 2B171FDH20084L • android-arm64  • Android 14 (API 34)
    • macOS (desktop)  • macos          • darwin-x64     • macOS 14.1 23B74 darwin-x64
    • Chrome (web)     • chrome         • web-javascript • Google Chrome 125.0.6422.77

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

@huycozy huycozy added package flutter/packages repository. See also p: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on p: go_router The go_router package team-go_router Owned by Go Router team found in release: 3.22 Found to occur in 3.22 found in release: 3.23 Found to occur in 3.23 and removed in triage Presently being triaged by the triage team labels May 27, 2024
@chunhtai chunhtai added team-framework Owned by Framework team and removed p: go_router The go_router package team-go_router Owned by Go Router team labels Jul 11, 2024
@chunhtai
Copy link
Contributor

This is not related to go_router, cc @justinmc looks like we may have missed something in scaffold

@goderbauer goderbauer added P2 Important issues not at the top of the work list triaged-framework Triaged by Framework team labels Jul 16, 2024
@huycozy
Copy link
Member

huycozy commented Aug 28, 2024

@aakash-pamnani I check this on the latest stable 3.24.1, onPopInvoked has been deprecated. You can use onPopInvokedWithResult instead and I see _key.currentState?.isDrawerOpen return true as expected. Can you confirm this works for you?

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 28, 2024
Copy link

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
Thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
found in release: 3.22 Found to occur in 3.22 found in release: 3.23 Found to occur in 3.23 has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. team-framework Owned by Framework team triaged-framework Triaged by Framework team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds
Projects
None yet
Development

No branches or pull requests

4 participants