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

Null check operator error in _LoginCardState._submit #468

Open
vargab95 opened this issue Nov 28, 2023 · 0 comments
Open

Null check operator error in _LoginCardState._submit #468

vargab95 opened this issue Nov 28, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@vargab95
Copy link

Describe the bug
I've enable Firebase Crashlytics in my android app which detected a failed null check. My guess is that, await _submitController.reverse(); is called in an async gap and when it is called, the widget is not mounted anymore.

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Null check operator used on a null value
       at AnimationController.stop(animation_controller.dart:778)
       at AnimationController._animateToInternal(animation_controller.dart:598)
       at AnimationController.reverse(animation_controller.dart:495)
       at _LoginCardState._submit(login_card.dart:218)

In my opinion the fix would be to check whether the context is still mounted before calling _submitController.reverse(), like the following.

diff --git a/lib/src/widgets/cards/login_card.dart b/lib/src/widgets/cards/login_card.dart
index 8db3355..e3b1ef2 100644
--- a/lib/src/widgets/cards/login_card.dart
+++ b/lib/src/widgets/cards/login_card.dart
@@ -215,7 +215,9 @@ class _LoginCardState extends State<_LoginCard> with TickerProviderStateMixin {
       }
     });
 
-    await _submitController.reverse();
+    if (mounted) {
+      await _submitController.reverse();
+    }
 
     if (!DartHelper.isNullOrEmpty(error)) {
       showErrorToast(context, messages.flushbarTitleError, error!);

To Reproduce
Steps to reproduce the behavior:

  1. Go to the login page
  2. Fill the email and username with invalid credentials
  3. Click on login
  4. Push the back button of the phone to leave the screen before the result comes back
  5. Check the error log for errors

You may have to repeat it a few times as pushing the back button have to take place in exactly the right moment, however I could reproduce it several times with the described method.

Expected behavior
Do not crash on the null check.

Information (please complete the following information):

  • Device: OnePlus8Pro (emulated)
  • Platform: Android
  • Flutter version: maybe 3.16.0
  • Package version 4.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant