Home > Net >  How to Store Selected Values in ListViewBuilder and passing to next screen
How to Store Selected Values in ListViewBuilder and passing to next screen

Time:02-17

Is There any Option to Store Selected Values in List View and passsing to the Next Screen like the Selected Value is Stored in Variable we pass that variable to next screen

CodePudding user response:

You should have a List in which you will save selected values, something like this:

List<Object> values=[];

later, when you select any item:

onTap: () {
values.add("item #X");
}

and when you want to show next screen, you should pass your list as an argument.

Navigator.pushNamed(
      context,
      NewRoute,
      arguments: values,
    );

or maybe you would want to create a class to handle better your arguments, something like this https://docs.flutter.dev/cookbook/navigation/navigate-with-arguments

CodePudding user response:

Try this..

 ListView.builder(
        itemCount: myData.length,
        itemBuilder: (context,index){
        return ListTile(
          onTap: (){
            Navigator.pushNamed(context, 'secondScreen',arguments: myData[index]);
          },
        );
      },
      ),
  • Related