A null safety error is shown in the dart file. How to fix this?
[UPDATE]
After I made any of the suggested changes below. I get this error. How do I fix this?
CodePudding user response:
An additional question mark '?' along with a data type means that the value to be returned or to be assigned can be either of data type or null as well. For example, if its int a;
, then 'a' can only take integers value and 'null' wont be allowed at any cost. int? a;
will let 'a' hold 'null' value along with integers.
Thus, In your update function of ProxyProvider2, since there might be a chance of returning null as the value (as per the ternary condition), thus, you must mention so by replacing Future<List<Place>>
(no null value allowed) with Future<List<Place>>?
(null value allowed).
Hope it helps!
CodePudding user response:
The problem is that on your return condition you have a case that you return null
while your closure is Future<List<Place>>
which doesn't support this. Try changing the closure to Future<List<Place>>?
but I don't know how this will effect the rest of your code.
Instead of null
you can try returning an empty array Future.value([])
.
CodePudding user response:
A ghetto fix to this problem would to just return a future with an empty list if there's no position given.
return this instead of the null you're returning.
Future.value(List<int>.empty())
In a more proper fix, you should change the required type to Future<List<Place>>?
so that you can return the null
.