0

Currently have 7 GestureDetectors and Containers inside a SingleChildScrollView to represent a guitar neck and notes. Inside each container Gesture Detector, I add the item index to a list, and using this list I can cause an item to change color, indicating that it's been selected. Everything works fine right now, except the fact that I've got to refresh the application for my containers to update the selected items.

Here is my Gesture Detector and Container code

GestureDetector(
               onTap: () {
                                if(selectedHighE.contains(index)){
                                  selectedHighE.remove(index);
                                  print("removed " + index.toString() + " from " + selectedHighE.toString());
                                }else{
                                  selectedHighE.add(index);
                                  print("added " + index.toString() + " to " + selectedHighE.toString());
                                };
                              },
                              child: Container(
                                  width: 50,
                                  height: 35,
                                  alignment: Alignment.center,
                                  decoration: BoxDecoration(
                                      color: _change(hiENotes, index, selectedHighE),
                                      border: Border.all(
                                          color:
                                          _borderColor(hiENotes, index))),
                                  child: Text(hiENotes[index],
                                      style: TextStyle(
                                          color: _textColor(hiENotes, index),
                                          fontSize: size))),
                            ),

So, my intention is that the _change() will use the index of the current item, and the list of currently selected items, to determine if a container should be changed or not. However, as I've stated, the functionality is there I just need some method of refreshing the child Container after the onTap().

Thanks in advance

Luke Browne
  • 131
  • 1
  • 7
  • 1
    Did you forget to call setState? – WSBT Jan 27 '22 at 18:35
  • That was it, I knew there was something different about how I was doing it now compared to earlier. Thanks a million dude – Luke Browne Jan 27 '22 at 18:41
  • OK you can close this question, it's a little bit too trivial :D – WSBT Jan 27 '22 at 18:51
  • @user1032613 what if my widget is outside the build? setstate will not work in that case – Ali Punjabi Jan 28 '22 at 13:57
  • 1
    @RajaEhtisham That would be a whole new topic on "state management", and there are hundreds of options such as "lift state up", "change notifier", "stream", "provider", "bloc", "riverpod" and many many more. If you need help on any specific one, please ask a new question. – WSBT Jan 28 '22 at 17:19
  • @user1032613 i posted a question about state managment, if you could help me with this question i would really appreciate it https://stackoverflow.com/questions/70993176/flutter-riverpod-for-local-and-global-variables – LearnFlutter Feb 04 '22 at 23:19

0 Answers0