flutter-reaction-button icon indicating copy to clipboard operation
flutter-reaction-button copied to clipboard

Change emoji in reaction button according to the value of another clicked reaction button in a listviewbuilder

Open talbiislam96 opened this issue 3 years ago • 1 comments

I have a listViewBuilder inside of which I dynamically display a mission name and a reaction button in every list item like so :

ListView.builder(

                                itemCount: result.data['allSheets']['timesheets'].length,


                                itemBuilder: (BuildContext context, int index){

                                 var sheets = result.data['allSheets']['timesheets'];

                                 var length = result.data['allSheets']['timesheets'].length;
                                  missionName = timesheet.missionName = result.data['allSheets']['mission']['name'];
                                 missionid = timesheet.missionName = result.data['allSheets']['mission']['id'];
                                 print (missionid);
                                  entries = timesheet.entries = result.data['allSheets']['timesheets'][index]['entriesTimeSheet'];
                                 box.write('missionName', missionName);
                                 box.write('entries', entries);
                                 box.write ('length',length);
                                 print(entries);
                                 int len = box.read ('length');
                                 var ind ;
                                 var ini;

                                 String ent= box.read('entries');

                                 print(len);

                                // box.put('missionName', missionName);
                                 //box.put("entries",entries);

                                 //var name = box.get('missionName');

                                 //print('Name: $name');


                                  return Card(
                                    child:Center(
                                      child: Container(
                                        height: 70,
                                        child: Row(
                                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                          children: <Widget>[
                                            Expanded(child: Text(result.data['allSheets']['mission']['name'])),
                                            SizedBox(width: 30),


                                            FlutterReactionButton(




                                              onReactionChanged: (reaction, index) {

                                                print('reaction selected index: $index');



                                                for (var i = 0; i < result.data['allSheets']['timesheets'].length; i++)
                                                  print (i);
                                                switch (index) {
                                                  case 0:
                                                    for (var j= i+1; j< result.data['allSheets']['timesheets'].length; j++){
                                                      print(j);

                                                      onReactionChanged: (reaction, index){
                                                        index = 0;
                                                      };

                                                    }

                                                    break;
                                                  case 1:

                                                    for (var j= i+1; j< result.data['allSheets']['timesheets'].length; j++){
                                                      index = 1;
                                                    }

                                                    break;
                                                  case 2:

                                                    for (var j= i+1; j< result.data['allSheets']['timesheets'].length; j++){
                                                      index = 2;
                                                    }

                                                    break;
                                                  case 3:

                                                    for (var j= i+1; j< result.data['allSheets']['timesheets'].length; j++){
                                                      index = 3;
                                                    }


                                                    break;

                                                  default:
                                                    entries = timesheet.entries = result.data['allSheets']['timesheets'][index]['entriesTimeSheet'] ;
                                                }











                                                switch (index) {
                                                  case 0:
                                                    entries = "OFF";
                                                    box.write('entries', entries);
                                                    break;
                                                  case 1:
                                                    entries = "NOWORK";
                                                    box.write('entries', entries);
                                                    break;
                                                  case 2:
                                                    entries = "FULLDAY";
                                                    box.write('entries', entries);
                                                    break;
                                                  case 3:
                                                    entries = "HALFDAY";
                                                    box.write('entries', entries);
                                                    break;

                                                  default:
                                                    entries = timesheet.entries = result.data['allSheets']['timesheets'][index]['entriesTimeSheet'] ;
                                                }
                                                print(entries);
                                              },
                                              reactions: <Reaction>[
                                                Reaction(
                                                    icon: Image.asset(
                                                      "assets/icons/close.png",
                                                      height: 50,
                                                      width: 50,
                                                    )),
                                                Reaction(
                                                    icon: Image.asset(
                                                      "assets/icons/nowork.png",
                                                      height: 50,
                                                      width: 50,
                                                    )),
                                                Reaction(
                                                    icon: Image.asset(
                                                      "assets/icons/sunny.png",
                                                      height: 50,
                                                      width: 50,
                                                    )),

                                                Reaction(
                                                    icon: Image.asset(
                                                      "assets/icons/sunrise.png",
                                                      height: 50,
                                                      width: 50,
                                                    )),

                                              ],

                                              initialReaction: Reaction(

                                                icon: Row(
                                                  children: [
                                                    ConditionalBuilder(
                                                      condition: result.data['allSheets']['timesheets'][index]['entriesTimeSheet'] == "HALFDAY",
                                                      builder: (context){
                                                        return Image.asset(
                                                          "assets/icons/sunrise.png",
                                                          height: 50,
                                                          width: 50,
                                                        );
                                                      },

                                                    ),
                                                    ConditionalBuilder(
                                                      condition: result.data['allSheets']['timesheets'][index]['entriesTimeSheet'] == "OFF",
                                                      builder: (context){
                                                        return Image.asset(
                                                          "assets/icons/close.png",
                                                          height: 50,
                                                          width: 50,
                                                        );
                                                      },

                                                    ),
                                                    ConditionalBuilder(
                                                      condition: result.data['allSheets']['timesheets'][index]['entriesTimeSheet'] == "FULLDAY",
                                                      builder: (context){
                                                        return Image.asset(
                                                          "assets/icons/sunny.png",
                                                          height: 50,
                                                          width: 50,
                                                        );
                                                      },

                                                    ),

                                                  ],

                                                ),


                                              ),

                                            )

                                          ],
                                        ),
                                      ),
                                    ),
                                  );

                                }

                            ),




enter image description here

In the picture I attached , you can see the page . I want to change the value of each button according to the other clicked button , example , if I click on the first reaction button and I choose the sunny emoji , the second button's default emoji takes the x emoji , and vice versa didn't know how to do it I tried a switch case inside a for loop but it didn't work . If anyone can help I'd be grateful .

talbiislam96 avatar Sep 23 '21 15:09 talbiislam96

@GeekAbdelouahed Can u please tell me how to proceed with this issue ? I've been stuck for so long and I don't know how to fix it I really need some help thank you

talbiislam96 avatar Nov 18 '21 14:11 talbiislam96