0

I have a list which has select option:

GestureDetector(
                                  onTap: () {
                                    toggleIndexDay(sunIndex);
                                    confirmed = true;
                                  },
                                  child: Card(

and toggle instance:

void toggleIndexDay(int i) {
    if (selectionDayIndexes.contains(i))
      setState(() => selectionDayIndexes.remove(i));
    else
      setState(() => selectionDayIndexes.add(i));
  }

this allow me to select and unselect element in the list. Now I have another instance called ConfirmSelection which Allow me to display a confirmation Button, but I dont know how to hide if in the List there is nothing Selected. to display the button this is my code:

bool confirmed = false;

action on the button above with confirmed = true; and in the widget:

floatingActionButton: (confirmed == true)
            ? FloatingActionButton( etc...

but how to hide if no item i the list is selected?

  • `floatingActionButton: confirmed == true ? FloatingActionButton() : null` –  Dec 15 '20 at 10:16
  • Does this answer your question? [Show/hide widgets in Flutter programmatically](https://stackoverflow.com/questions/44489804/show-hide-widgets-in-flutter-programmatically) – Yadu Dec 15 '20 at 10:49

1 Answers1

0

You can check if there's an item or not in the List with isEmpty or isNotEmpty properties.

floatingActionButton: selectionDayIndexes.isEmpty ? Container() : FloatingActionButton(),
Federick Jonathan
  • 2,726
  • 2
  • 13
  • 26