Navjyot Singh
Navjyot Singh

Reputation: 105

How can we pass List through named route in Flutter?

I just wanted to know how I can pass the whole list as an argument through Navigator.pushnamed() in Flutter. Is it possible or not? If I m trying to pass list n its showing The argument type 'List' cannot be assigned to 'String'

Upvotes: 0

Views: 1257

Answers (1)

Ali Bayram
Ali Bayram

Reputation: 7941

The list that you want to pass;

List yourList = [];

pass it through the Navigator;

Navigator.pushNamed(
  context,
  'routeName',
  arguments: yourList,
);

and get your list in target widget;

List _yourListFromArguments;

@override
void didChangeDependencies() {
  _yourListFromArguments = ModalRoute.of(context).settings.arguments;
  super.didChangeDependencies();
}

Upvotes: 0

Related Questions