marcglasberg / back_button_interceptor

Flutter Package: May be used to intercept the Android back-button, as an alternative to `WillPopScope`.
BSD 2-Clause "Simplified" License
105 stars 21 forks source link

Null check operator used on a null value #25

Closed ddxl123 closed 10 months ago

ddxl123 commented 10 months ago
E/flutter (28395): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
E/flutter (28395): #0      BackButtonInterceptor._errorProcessing.<anonymous closure> (package:back_button_interceptor/src/back_button_interceptor.dart:26:44)
E/flutter (28395): #1      new Future.delayed.<anonymous closure> (dart:async/future.dart:427:39)
E/flutter (28395): #2      Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (28395): #3      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (28395): #4      _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (28395): #5      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
E/flutter (28395): 

back_button_interceptor: ^6.0.2

doctor

[√] Flutter (Channel stable, 3.10.6, on Microsoft Windows [版本 10.0.22621.2134], locale zh-CN)
    • Flutter version 3.10.6 on channel stable at D:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (4 weeks ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\Users\LongPC\AppData\Local\Android\Sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: D:\IntelliJ IDEA 2023.1.4\jbr\bin\java
    • Java version OpenJDK Runtime Environment JBR-17.0.7+7-1000.6-jcef (build 17.0.7+7-b1000.6)
    • All Android licenses accepted.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.5.3)
    • Visual Studio at D:\Microsoft Visual Studio
    • Visual Studio Community 2022 version 17.5.33516.290
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.1)
    • Android Studio at D:\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 11.0.15+0-b2043.56-9505619)

[√] IntelliJ IDEA Ultimate Edition (version 2022.2)
    • IntelliJ at D:\IntelliJ IDEA 2022.2.2
    • Flutter plugin version 72.1.3
    • Dart plugin version 222.4560

[√] IntelliJ IDEA Ultimate Edition (version 2023.2)
    • IntelliJ at D:\IntelliJ IDEA 2023.1.4
    • Flutter plugin version 74.0.5
    • Dart plugin version 232.8660.129

[√] Connected device (3 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
    • Windows (desktop)                  • windows       • windows-x64    • Microsoft Windows [版本 10.0.22621.2134]
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 115.0.1901.200
marcglasberg commented 10 months ago

Thanks for your report.

The Null check operator used on a null value error was thrown by the interceptor you created (in your code). The error message you posted above seems to indicate an error in the back_button_interceptor package because I was catching the error and then throwing it after the async gap with throw error, which doesn't show the correct stacktrace. At the time I created that code, that was the only way to do it.

Recently, a new method Error.throwWithStackTrace(error, stackTrace)) became available, so I just published a new package version that throws the error with the correct stacktrace.

Please update the package to this new version:

   back_button_interceptor : ^7.0.0

And then run your code again. This time, you will get the correct stacktrace that shows where in your code is the problem.

I am closing this issue, but please feel free to ask follow up questions if you need.