Skip to content

Improve error message for type error in maybePop()/pop() #16987

Description

@artAst

Steps to Reproduce

Create a new project and have this pop-up box:

return showDialog<Null>(
    context: context,
    barrierDismissible: false, // user must tap button!
    child: new AlertDialog(
      title: new Text(title),
      content: new SingleChildScrollView(
        child: new ListBody(
          children: <Widget>[
            new Text(msg)
          ],
        ),
      ),
      actions: <Widget>[
        new FlatButton(
          child: new Text('NO'),
          onPressed: () {
            //Navigator.pop(context, "CANCEL");
            Navigator.maybePop(context, "CANCEL");
          },
        ),
        new FlatButton(
          child: new Text('YES'),
          onPressed: () {
            //Navigator.pop(context, "OK");
            Navigator.maybePop(context, "CANCEL");
          },
        ),
      ],
    ),
  ).then((val){
    return val;
  });

Once the cancel or OK button is clicked, it generates an error

Logs

E/flutter ( 4523): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 4523): type 'String' is not a subtype of type 'Null' of 'result' where
E/flutter ( 4523):   String is from dart:core
E/flutter ( 4523):   Null is from dart:core
E/flutter ( 4523): 
E/flutter ( 4523): #0      _ModalRoute&TransitionRoute&LocalHistoryRoute.didPop (package:flutter/src/widgets/routes.dart)
E/flutter ( 4523): #1      NavigatorState.pop (package:flutter/src/widgets/navigator.dart:1683:15)
E/flutter ( 4523): #2      NavigatorState.maybePop (package:flutter/src/widgets/navigator.dart:1648:9)
E/flutter ( 4523): <asynchronous suspension>
E/flutter ( 4523): #3      Navigator.maybePop (package:flutter/src/widgets/navigator.dart:1024:34)
E/flutter ( 4523): #4      showMainFrameDialogWithCancel.<anonymous closure> (package:myapp/src/util/ScreenUtils.dart:1334:23)
E/flutter ( 4523): #5      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:490:14)
E/flutter ( 4523): #6      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:545:30)
E/flutter ( 4523): #7      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter ( 4523): #8      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
E/flutter ( 4523): #9      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:94:7)
E/flutter ( 4523): #10     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
E/flutter ( 4523): #11     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter ( 4523): #12     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter ( 4523): #13     _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:143:19)
E/flutter ( 4523): #14     _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
E/flutter ( 4523): #15     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
E/flutter ( 4523): #16     _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
E/flutter ( 4523): #17     _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
E/flutter ( 4523): #18     _invoke1 (dart:ui/hooks.dart:134:13)
E/flutter ( 4523): #19     _dispatchPointerDataPacket (dart:ui/hooks.dart:91:5)

Flutter Doctor

[✓] Flutter (Channel dev, v0.3.0, on Mac OS X 10.13.4 17E199, locale en-PH)
    • Flutter version 0.3.0 at /Users/macbook/Documents/flutter
    • Framework revision c73b8a7cf6 (13 days ago), 2018-04-12 16:17:26 -0700
    • Engine revision 8a6e64a8ef
    • Dart version 2.0.0-dev.47.0.flutter-4126459025

[!] Android toolchain - develop for Android devices (Android SDK 26.0.3)
    • Android SDK at /Users/macbook/Library/Android/sdk
    • Android NDK at /Users/macbook/Library/Android/sdk/ndk-bundle
    • Platform android-27, build-tools 26.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

[✓] iOS toolchain - develop for iOS devices (Xcode 9.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.3, Build version 9E145
    • ios-deploy 1.9.2
    • CocoaPods version 1.3.1

[✓] Android Studio (version 2.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] IntelliJ IDEA Community Edition (version 2017.2.5)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 19.1
    • Dart plugin version 172.4343.25

[!] VS Code (version 1.17.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Dart Code extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code

[✓] Connected devices (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.0 (API 24) (emulator)

Activity

  1. zoechi commented on Apr 26, 2018

    @zoechi
    Contributor

    with recent flutter update

    Your Flutter version is already 2 weeks old. Have you tried with a more recent one?

  2. artAst commented on Apr 26, 2018

    @artAst
    Author

    I updated Flutter:

    [✓] Flutter (Channel dev, v0.3.5, on Mac OS X 10.13.4 17E199, locale en-PH)
        • Flutter version 0.3.5 at /Users/macbook/Documents/flutter
        • Framework revision 7ffcd3d22d (5 days ago), 2018-04-24 14:03:41 -0700
        • Engine revision ec611470b5
        • Dart version 2.0.0-dev.48.0.flutter-fe606f890b
    
    [✓] Android toolchain - develop for Android devices (Android SDK 28.0.0-rc1)
        • Android SDK at /Users/macbook/Library/Android/sdk
        • Android NDK at /Users/macbook/Library/Android/sdk/ndk-bundle
        • Platform android-27, build-tools 28.0.0-rc1
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
        • All Android licenses accepted.
    
    [✓] iOS toolchain - develop for iOS devices (Xcode 9.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 9.3, Build version 9E145
        • ios-deploy 1.9.2
        • CocoaPods version 1.3.1
    
    [✓] Android Studio (version 2.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
        • Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
    
    [✓] IntelliJ IDEA Community Edition (version 2017.2.5)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 19.1
        • Dart plugin version 172.4343.25
    
    [!] VS Code (version 1.17.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Dart Code extension not installed; install from
          https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code
    
    [✓] Connected devices (1 available)
        • Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.0 (API 24) (emulator)
    

    But still experiencing the same issue

  3. rodydavis commented on Apr 30, 2018

    @rodydavis
    Contributor

    Just started experiencing this

  4. artAst commented on Apr 30, 2018

    @artAst
    Author

    Still experiencing this issue with Flutter v0.3.5
    any inputs on this for later version releases?

  5. rodydavis commented on Apr 30, 2018

    @rodydavis
    Contributor

    @artAst in the gallery example it uses a enum for the alert types. I wonder if it's something to do with just passing a string.

    enum DialogDemoAction {
      cancel,
      discard,
      disagree,
      agree,
    }

    Then present

    showDemoDialog<DialogDemoAction>(
                    context: context,
                    child: new AlertDialog(
                      content: new Text(
                        _alertWithoutTitleText,
                        style: dialogTextStyle
                      ),
                      actions: <Widget>[
                        new FlatButton(
                          child: const Text('CANCEL'),
                          onPressed: () { Navigator.pop(context, DialogDemoAction.cancel); }
                        ),
                        new FlatButton(
                          child: const Text('DISCARD'),
                          onPressed: () { Navigator.pop(context, DialogDemoAction.discard); }
                        )
                      ]
                    )
                  );
  6. artAst commented on May 1, 2018

    @artAst
    Author

    It did solve the issue. I also passed in the String object and it works as well. Thanks

    This was not present on previous version of flutter with Dart 1.0

  7. Hixie commented on Jun 12, 2018

    @Hixie
    Contributor

    The problem is that you said you were returning a Null (the type argument to showDialog), but then you passed a String.

    We should definitely make these error messages clear.

  8. changed the title [-]Navigator pop or maybe pop error with recent flutter update[/-] [+]Improve error message for type error in maybePop()/pop()[/+] on Jun 12, 2018
  9. added
    c: crashStack traces logged to the console
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: routesNavigator, Router, and related APIs.
    on Jun 12, 2018
  10. added this to the milestone on Jun 12, 2018
  11. added
    P2Important issues not at the top of the work list
    on May 29, 2020
  12. removed this from the milestone on Aug 17, 2020
  13. 9 remaining items

  14. Piinks commented on May 13, 2026

    @Piinks
    Contributor

    Not sure if this is still reproducible, we should check.

  15. puneetkukreja98 commented on May 15, 2026

    @puneetkukreja98
    Contributor

    I have tested the issue and confirmed it still exists. In await showDialog<Null>(, the return type is set as Null, but a String is being returned instead Navigator.maybePop(context, "CANCEL"); . This type mismatch is what is causing the error.

  16. added a commit that references this issue on Jun 3, 2026
    40135be
  17. added a commit that references this issue on Jun 26, 2026
    d164579
  18. github-actions commented on Jul 14, 2026

    @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.

  19. locked as resolved and limited conversation to collaborators on Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2Important issues not at the top of the work lista: error messageError messages from the Flutter frameworkc: crashStack traces logged to the consolef: routesNavigator, Router, and related APIs.found in release: 3.7Found to occur in 3.7found in release: 3.8Found to occur in 3.8frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions