1

I have one filtering dropdown. I have one button on another page. When I click this button on another page, how can I return to other options of the dropdown on the other page?

DropdownPage

CustomDropdownButton<bool>(
        hintText: "Select Filter",
        value: controller.selectedFilter.value,
        items: [
          DropdownMenuItem<bool>(
            child: Text("Sales"),
            value: true,
          ),
          DropdownMenuItem<bool>(
            child: Text("Refunds"),
            value: false,
          )
        ],
        onChanged: (bool selectedFilter) {
          controller.selectedFilter.value = selectedFilter;
        },
      )

Otherpage (button is here, this dropdown on another page)

Expanded(
              child: ElevatedButton(
                  onPressed: () {
                    // return dropdown other value (this dropdown on another page).
                  },
                  child: Text("Update")),
            )

Thank you,

Codeguru
  • 31
  • 6

1 Answers1

1

Assuming you are navigating to your other page in ElevatedButton.onPressed you can await for the navagitor

onPressed: () {
      // return dropdown other value (this dropdown on another page).
      final result = Navigator.of(context).push(...);
},

and from your CustomDropdownButton

onChanged: (bool selectedFilter) {
      controller.selectedFilter.value = selectedFilter;
      Navigator.of(context).pop(selectedFilter);
},

Read more about this from the official recipe https://docs.flutter.dev/cookbook/navigation/returning-data

Raouf Rahiche
  • 28,948
  • 10
  • 85
  • 77