0

i have code dropdown menu, but i will parsing list item to make a dropdown menu template so I just change the list item section.

                child: DropdownButton<String>(
                  isExpanded: true,
                  icon: Icon(Icons.keyboard_arrow_down),
                  value: dropdownValue,
                  onChanged: (String newValue) {
                    setState(() {
                      dropdownValue = newValue;
                    });
                  },
                  items: <String>['Instagram', 'Two', 'Free', 'Four']
                      .map<DropdownMenuItem<String>>((String value) {
                    return DropdownMenuItem<String>(
                      value: value,
                      child: Text(value),
                    );
                  }).toList(),
1
  • Can you share example list? Also, please explain more. Commented Jul 5, 2019 at 7:02

1 Answer 1

1

Is this what you are trying to do?

class DropDownTest extends StatefulWidget {
  @override
  _DropDownTestState createState() => _DropDownTestState();
}

class _DropDownTestState extends State<DropDownTest> {
  MenuItem dropdownValue;

  @override
  Widget build(BuildContext context) {
    return DropdownButton<MenuItem>(
        isExpanded: true,
        icon: Icon(Icons.keyboard_arrow_down),
        value: dropdownValue,
        onChanged: (MenuItem newValue) {
          setState(() {
            dropdownValue = newValue;
          });
        },
        items: items.map<DropdownMenuItem<MenuItem>>((MenuItem value) {
          return DropdownMenuItem<MenuItem>(
            value: value,
            child: Text(value.name),
          );
        }).toList());
  }
}

class MenuItem {
  final int id;
  final String name;

  const MenuItem(this.id, this.name);
}

const List<MenuItem> items = [
  MenuItem(1, 'ONE'),
  MenuItem(2, 'TWO'),
  MenuItem(3, 'THREE'),
  MenuItem(4, 'FOUR'),
];
Sign up to request clarification or add additional context in comments.

4 Comments

sorri dude, how if i have 2 Items list?
@BadaiArdiat You can merge them, but if you have different list of different objects, create another question because it's very different thing from this topic. It's about Abstraction.
ok sir, i create new topic stackoverflow.com/questions/56899410/…
@BadaiArdiat I mean, if your Object Types are same you don't need to create another question, but if they are different type of objects and if you want to merge them inside one DropDown, yes create the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.