flutterdartdropdownbutton

Flutter: additional items in dropdown menu items


How can I add two additional items in list in dropdown items? One textfield for search and one for text button. enter image description here


Solution

  • The key point using button on DropdownButton is to set enabled: false on DropdownMenuItem. and for the constraints you can use top-level LayoutBuilder.

    DropdownButton(
      items: [
        DropdownMenuItem(
          child: SizedBox(width: 200, child: CupertinoTextField()),
          enabled: false,
          value: "search",
        ),
        DropdownMenuItem(
          child: SizedBox(
            width: 200,
            child: TextButton(
              onPressed: () {
                //if you like to close uncomment below line
                // Navigator.of(context).pop();
              },
              child: Text("tap"),
            ),
          ),
          enabled: false,
          value: "search",
        ),
        DropdownMenuItem(
          child: Text("a"),
          value: "a",
        ),
      ],
      onChanged: (value) {},
    ),