Flutter/Dart Null Safety on _formKey.currentState.validate()?
1,070
Here's the first;
(_formKey.currentState!.validate())
And the next;
late Future<File> file;
![Meggy](https://i.stack.imgur.com/rxCWY.jpg?s=256&g=1)
Author by
Meggy
I'm a self-taught novice stumbling like a drunk through php, javascript, mysql, drupal and flutter.
Updated on December 29, 2022Comments
-
Meggy over 1 year
I've just updated my minimum sdk in pubspec.yaml;
sdk: ">=2.12.0 <3.0.0"
Now I have to change all my variables by declaring ? on all Strings and integers.
But what shall I do with the formkey?
if (_formKey.currentState.validate())
Here's what Android Studio tells me but I'm not sure where to put the ?
The method 'validate' can't be unconditionally invoked because the receiver can be 'null'. Try making the call conditional (using '?.') or adding a null check to the target ('!').
Any idea how I should convert this line to null safety?
And how about this?
Future<File> file;
-
nvoigt about 3 yearsThat might be valid for your specific piece of code, but this is not a general rule. For someone else, with the exact snippet of code in another context than your program, it might be wrong.