Home > Back-end >  When I run the app, this error is coming again and again until I close the app
When I run the app, this error is coming again and again until I close the app

Time:11-15

Null check operator used on a null value

When the exception was thrown, this was the stack:

#0      StatefulElement.state (package:flutter/src/widgets/framework.dart:4999:44)
#1      Navigator.of (package:flutter/src/widgets/navigator.dart:2543:47)
#2      Navigator.pushReplacement (package:flutter/src/widgets/navigator.dart:2105:22)
#3      Splashservice.isLogin.<anonymous closure> (package:shridungargarh/service/splashservice.dart:15:19)
#4      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15)
#5      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1104:9)

Does Flutter need to be updated

CodePudding user response:

Error Explanation: Bang operator(!) means that in flutter, when you use this operator, you are completely sure that variable is not going to be null in any case.

There are two ways to resolve it -

  1. Use if conditional to confirm that variable is not null
  2. Use null-aware or if-null operator ?? like
String get strVariable => _strVariable ?? 'emptyStringOrDefaultString';

Since you didn't provide any code; So before using ! make sure your variable is not null.

CodePudding user response:

Null check operator used on a null value

Reason : this error show when you used ! this symbol with variable which means that variable will never be null i.e. it will always contain some data But in your project this variable doesn't have any data so that's why it shows this error

Solution : 1.print that variable in console and you will see the null data as output 2. remove ! symbol from the variable

Give up vote if this helps you

  • Related