I get a linter error but don't know how to fix it
final FoodScreenArguments args = ModalRoute.of(context).settings.arguments;
A value of type Object
can't be assigned to a variable of type FoodScreenArguments
.
Try changing the type of the variable, or casting the right-hand type to FoodScreenArguments
.
Try changing the type of the variable, or casting the right-hand type to FoodScreenArguments . Unlike java's parentheses casting (), in flutter, it uses as keyword.
Unlike java's parentheses casting (), in flutter, it uses as keyword. Here is an example from my code where I am printing a variable of class.
One of the other casting keywords, which lives particularly on Iterables, is cast<T>. It gives you a new list which appears to be of the type List<T>, so that you can use it in places where the analyzer expects List<T>, but it doesn't actually change the types of the elements.
Most languages just use the sub- to a supertype. Dart's assignment compatibility rules also allow assigning from a super- to a subtype. needing any kind of explicit cast. So there's no *static* warning here.
Easiest way :
final args = ModalRoute.of(context).settings.arguments as FoodScreenArguments ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With