Abu*_*ama 1 string router list flutter flutter-web
我正在使用 go router 作为 flutter 应用程序,我可以在活动之间传递字符串参数,现在它正在工作,我想传递动态列表,但出现错误
参数类型“String”无法分配给参数类型“List”。(文档)
接收器活动有
class EditUserPage extends StatefulWidget {
final String name;
final List<dynamic> userinformation;
}
Run Code Online (Sandbox Code Playgroud)
在路线构建器上,我已经传递了如下数据
GoRoute(
path: 'editusers',
name:
'editusers/:name,:userinformation,'
builder: (BuildContext context, GoRouterState state) {
return EditUserPage(
state.params["name"]!,
state.params["userinformation"]!,
)
);
Run Code Online (Sandbox Code Playgroud)
错误出现在这一行 state.params["userinformation"]!, 参数类型“String”无法分配给参数类型“List”。
你可以使用这个方法
步骤1
class ScreenArguments{
final Key? key;
final List<dynamic> list;
final DateTime dateTime;
ScreenArguments({
this.key,
required this.list,
required this.dateTime,
});
}
Run Code Online (Sandbox Code Playgroud)
第2步
builder: (context, state) {
return Screen(
arguments: state.extra as ScreenArguments,
);
},
Run Code Online (Sandbox Code Playgroud)
步骤3
final ScreenArguments arguments;
const Screen({
super.key,
required this.arguments,
});
Run Code Online (Sandbox Code Playgroud)
步骤4
context.pushNamed(
'name',
extra: ScreenArguments(
list:list,
dateTime: dateTime,
),
);
Run Code Online (Sandbox Code Playgroud)