颤振去路由器传递列表动态到参数



我使用go router for flutter应用程序,我可以在活动和工作之间传递字符串参数,现在我想动态传递列表,并得到错误

实参类型'String'不能赋值给形参类型"列表"。(文档)

接收方活动有

class EditUserPage extends StatefulWidget {
final String name;
final List<dynamic> userinformation;

}

在Route builder上,我已经像下面这样传递了我的数据

GoRoute(
path: 'editusers',
name:
'editusers/:name,:userinformation,'
builder: (BuildContext context, GoRouterState state) {
return EditUserPage(
state.params["name"]!,
state.params["userinformation"]!,
)
);

错误出现在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,
});
}
步骤2

builder: (context, state) {
return Screen(
arguments: state.extra as ScreenArguments,
);
},
步骤3

final ScreenArguments arguments;
const Screen({
super.key,
required this.arguments,
});
步骤4

context.pushNamed(
'name',
extra: ScreenArguments(
list:list,
dateTime: dateTime,
),
);

最新更新