Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
talbiislam96 opened this issue Sep 23, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@talbiislam96
Copy link

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
Copy link
Author

@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

@GeekAbdelouahed GeekAbdelouahed self-assigned this Oct 20, 2023
@GeekAbdelouahed GeekAbdelouahed added the enhancement New feature or request label Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants