zoo*_* xu 29 variables casting object dart flutter
我收到 linter 错误,但不知道如何修复它
final FoodScreenArguments args = ModalRoute.of(context).settings.arguments;
Run Code Online (Sandbox Code Playgroud)
类型的值Object不能分配给类型的变量FoodScreenArguments。
尝试更改变量的类型,或将右侧类型转换为FoodScreenArguments.
Kab*_*uda 42
最简单的方法:
final args = ModalRoute.of(context).settings.arguments as FoodScreenArguments ;
Run Code Online (Sandbox Code Playgroud)
与java的括号强制转换()不同,在flutter中,它使用as关键字。这是我的代码中的一个示例,其中我正在打印类的变量。
debugPrint("rht: List size ${((albumList1.first) as AlbumData).title}");
Run Code Online (Sandbox Code Playgroud)