Flutter DropdownButtonFormField not updating

Viewed 24

I have an 'Add' link in my dropdown, which navigates to a form to do an add, and then sets the state afterwards, adding the new item to the dropdown. At least that's the way it was working; I tried to refactor to reuse this dropdown (it has some logic attached to it), and it no longer works...

Before, working: The dropdown was added in a single stateful widget, and this code set the state:

TextButton(
  child: Text(linkText),
  onPressed: () {
    Navigator.pop(aidingDropdownKey.currentContext!);
    Navigator.push(context,
            MaterialPageRoute(builder: (context) => linkDest))
        .then((_) => setState(() {}));
  },
)

Now, the dropdown is in its own StatefulWidget, and the DropdownMenuItem with the 'Add' link is in its own class. The code that tries to set the state looks like this:

TextButton(
  child: Text(text),
  onPressed: () {
    if (poppee != null) {
      Navigator.pop(poppee);
    }
    Navigator.push(context,
            MaterialPageRoute(builder: (context) => dest))
        .then((_) {
      var afterClosed = afterLinkClosed;
      if (afterClosed != null) {
        afterClosed();
      }
    });
  },
)

and

DropdownLabel(
  "NTRIP Services",
  linkText: "Add",
  linkDest: const NtripForm(),
  linkPoppee: widget.aidingKey?.currentContext,
  afterLinkClosed: () {
    _logger.d("after link callback called");
    setState(() {});
  },
)

Through logging, I can see my dropdown's build method is getting called, and the new menu item is created, but the UI isn't updating; the new item isn't showing.

Why wouldn't the UI update in this case?

0 Answers
Related