Skip to content

Null check operator used on a null value in PlatformView.  #96384

Description

@rahul-bst

setState(() { _platformViewCreated = true; });

setState is called when element is null.

Stacktrace received on crashlytics:

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Null check operator used on a null value. Error thrown null.
       at State.setState(framework.dart:1108)
       at _PlatformViewLinkState._onPlatformViewCreated(platform_view.dart:889)
       at AndroidViewController.create(platform_views.dart:752)

Activity

  1. changed the title [-]Null check operator used on a null value. [/-] [+]Null check operator used on a null value in PlatformView. [/+] on Jan 10, 2022
  2. darshankawar commented on Jan 10, 2022

    @darshankawar
    Member

    @rahul-bst
    Can you provide your flutter doctor -v and possibly a complete minimal reproducible code sample that would throw this exception ?

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 10, 2022
  4. rahul-bst commented on Jan 10, 2022

    @rahul-bst
    Author

    Hi,

    The app is built with Github Action on random remote machine where we use flutter v2.2.1. We have crashlytics added where we got this issue reported.

    flutter doctor of my machine doesn't matter much but here it goes:

    [✓] Flutter (Channel unknown, 2.2.1, on macOS 11.6.2 20G314 darwin-x64, locale en-GB)
        • Flutter version 2.2.1 at /Users/rahul/Library/flutter/flutter221/flutter2
        • Framework revision 02c026b03c (8 months ago), 2021-05-27 12:24:44 -0700
        • Engine revision 0fdb562ac8
        • Dart version 2.13.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc4)
        • Android SDK at /Users/rahul/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0-rc4
        • ANDROID_HOME = /Users/rahul/Library/Android/sdk
        • Java binary at: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
        • Java version Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 13.0, Build version 13A233
        • CocoaPods version 1.11.2
    
    [!] Android Studio (version 2020.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
        ✗ Unable to find bundled Java version.
        • Try updating or re-installing Android Studio.
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.3)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • 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
    
    [✓] VS Code (version 1.63.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.26.0
    
    [✓] Connected device (1 available)
        • macOS (desktop) • macos • darwin-x64 • macOS 11.6.2 20G314 darwin-x64
        ! Error: Rahul’s iPhone is not connected. Xcode will continue when Rahul’s iPhone is connected. (code -13)
    
    ! Doctor found issues in 1 category.
    

    I looked at the source code in master branch as well and it definitely has potential for the bug. By the time, _onPlatformViewCreated is called, the Widget might be disposed leading to above mentioned error.

    I don't have steps to reproduce it right now, but if the explanation is insufficient I can come up with set of steps to reproduce it.

    Thanks for the reply.

    Regards,
    Rahul K

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 10, 2022
  6. darshankawar commented on Jan 11, 2022

    @darshankawar
    Member

    Thanks for the update. It could be a possibililty that the widget has gone away by the time you call setState?
    You can check https://master-api.flutter.dev/flutter/widgets/State/mounted.html and confirm the widget is mounted for the first time but the main thing to confirm if the widget is still mounted after it goes past any async calls ?

  7. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 11, 2022
  8. Moncader commented on Jan 12, 2022

    @Moncader
    Contributor

    @darshankawar
    We have the coming up on Sentry/Crashlytics as well on Flutter 2.8.1 (stable).

    The problem is obvious by just static code analyzing.

    PlatformView's created callbacks get called from here:

    This is an async function with an await in it. It's normal for an element to be in a different state before and after an await happens and a mounted check is always required before calling setState after an await like this.

    The problem stems from the fact that this issues's crash line
    https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/platform_view.dart#L898
    expects this to only ever be called when not disposed (which it should not).

  9. github-actions commented on Feb 1, 2022

    @github-actions

    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.

  10. Moncader commented on Feb 1, 2022

    @Moncader
    Contributor

    @darshankawar
    Why did actions close this automatically?

    We've given a direct view in to the problem and how to fix it.

  11. darshankawar commented on Feb 1, 2022

    @darshankawar
    Member

    @Moncader
    Since this issue has waiting label and there wasn't any response from original author for 21 days, the bot automatically closed it.
    But I am reopening this and labeling based on your findings.

  12. added
    a: null-safetySupport for Dart's null safety feature
    frameworkflutter/packages/flutter repository. See also f: labels.
    a: productionIssues experienced in live production apps
    and removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    in triagePresently being triaged by the triage team
    on Feb 1, 2022
  13. added
    a: platform-viewsEmbedding Android/iOS views in Flutter apps
    P2Important issues not at the top of the work list
    on Feb 2, 2022
  14. added a commit that references this issue on Feb 8, 2023
    ec289f1
  15. added
    r: fixedIssue is closed as already fixed in a newer version
    on Feb 9, 2023
  16. added a commit that references this issue on Feb 15, 2023
    a12e242
  17. github-actions commented on Mar 3, 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.

  18. locked as resolved and limited conversation to collaborators on Mar 3, 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

    P2Important issues not at the top of the work lista: null-safetySupport for Dart's null safety featurea: platform-viewsEmbedding Android/iOS views in Flutter appsa: productionIssues experienced in live production appsframeworkflutter/packages/flutter repository. See also f: labels.r: 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