3

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;
Meggy
  • 1,491
  • 3
  • 28
  • 63

1 Answers1

2

Here's the first;

(_formKey.currentState!.validate())

And the next;

 late Future<File> file;
Meggy
  • 1,491
  • 3
  • 28
  • 63
  • That 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. – nvoigt May 19 '21 at 06:02