i was using go router for flutter app i can pass String parameters between activities and its working now i want to pass list dynamic and am getting error
The argument type 'String' can't be assigned to the parameter type 'List'. (Documentation)
Receiver activity have
class EditUserPage extends StatefulWidget {
final String name;
final List<dynamic> userinformation;
}
on Route builder i have passed my data like below
GoRoute(
path: 'editusers',
name:
'editusers/:name,:userinformation,'
builder: (BuildContext context, GoRouterState state) {
return EditUserPage(
state.params["name"]!,
state.params["userinformation"]!,
)
);
The error comes on this line state.params["userinformation"]!, The argument type 'String' can't be assigned to the parameter type 'List'.
You can use this method
step 1
class ScreenArguments{
final Key? key;
final List<dynamic> list;
final DateTime dateTime;
ScreenArguments({
this.key,
required this.list,
required this.dateTime,
});
}
step 2
builder: (context, state) {
return Screen(
arguments: state.extra as ScreenArguments,
);
},
step 3
final ScreenArguments arguments;
const Screen({
super.key,
required this.arguments,
});
step 4
context.pushNamed(
'name',
extra: ScreenArguments(
list:list,
dateTime: dateTime,
),
);