// Wrap it in an if statement e.g
if (snapshot.hasData) {
//Put your code here
}
else {
return const CircularProgressIndicator();
}
For example:
String? foo; // Nullable String
void main() {
var len = foo!.length; // Runtime error: Null check operator used on a null value
}
Solutions:
You need to find out where you're using the bang operator in your code. Once you are there, you can use any of the following solutions:
Use a local variable
var f = foo;
if (f != null) {
var len = f.length; // Safe
}
Use ?. and ??
var len = foo?.length ?? 0; // Provide a default value if foo was null.