I want to pass an optional List argument through go_router.
Here’s my class with an optional List<int>
argument:
class Loading extends StatefulWidget {
List<int>? genres;
Loading({Key? key, this.genres}) : super(key: key);
@override
_LoadingState createState() => _LoadingState();
}
And the router:
final GoRouter _router = GoRouter(routes: [
GoRoute(name: 'loading', path: '/', builder: (context, state) {
List<int> genres = state.extra as List;
return Loading(genres: genres);
},
),
...
]);
But it doesn’t work. I get this error message:
A value of type ‘List<dynamic>’ can’t be assigned to a variable of
type ‘List<int>’.
How can I fix that?
2
Answers
Try casting the
state.extra
property to aList<int>
.you can use mapper for pars data if sure it
state.extra
oflist<int>