1

I want to dropdownlist but i'm not able to do following things.

  • change the width of the dropdownbutton
  • make the dropdownlist to start at the dropdownbutton's height , not above it as default
  • adjust the height of the dropdownmenuitem

Want i want is

enter image description here enter image description here

What i have is

enter image description here enter image description here

The code goes like

                                                child: ButtonTheme(
                                                  alignedDropdown: true,
                                                  child: DropdownButtonHideUnderline(
                                                    child: DropdownButton<String>(
                                                        // isDense: true,
                                                        // isExpanded: true,
                                                        itemHeight: null,
                                                        // menuMaxHeight: 10,
                                                        alignment: AlignmentDirectional.center,
                                                        elevation: 0,
                                                        value: selectedQuantity,
                                                        selectedItemBuilder: (BuildContext context) {
                                                          return _dropDownQuantities.map<Widget>((String item) {
                                                            return Container(
                                                              alignment: Alignment.center,
                                                              // color: Colors.green,
                                                              child: Text(
                                                                'Qty: $item',
                                                                style: TextStyle(fontSize: 14),
                                                              ),
                                                            );
                                                          }).toList();
                                                        },
                                                        items: _dropDownQuantities.map((e) {
                                                          return DropdownMenuItem(
                                                            alignment: AlignmentDirectional.topStart,
                                                            child: Container(
                                                                child: Column(
                                                              children: [Container(child: Text(e))],
                                                            )),
                                                            value: e,
                                                          );
                                                        }).toList(),
                                                        hint: Text("Qty: 1 "),
                                                        onChanged: (value) {
                                                          setState(() {
                                                            selectedQuantity = value!;
                                                          });
                                                        }),
                                                  ),
                                                ),
krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88

1 Answers1

1

Use DropdownButton2 to achieve that.

  1. Use buttonWidth property to change the width of the dropdownbutton.
  2. Use offset property to change the position of the dropdown menu. You should add button's height to the dy offset to make it start at the dropdownbutton's height like this: Offset(0.0, "button's height")
  3. Use itemHeight property to adjust the height of the dropdownmenuitem.

Disclaimer: I am the author of the package mentioned above.

Ahmed Elsayed
  • 538
  • 1
  • 4
  • 11
  • Thank you ! , Do you know to stop animation of the menuItems rendering, if the menuItems contains 1,2,3,4,5 then as of now by default 1 2 3 4 5 are displayed in a sequence with the animation, I want every number to be loaded at once , Is it possible ? – krishnaacharyaa May 12 '22 at 02:55
  • You'll need to edit the package file. Replace the lines at 182,183 with this: opacity = CurvedAnimation(parent: widget.route.animation!, curve: Interval(0.0, 0.0)); Also, to stop the animation of the menu itself update the curve values at lines 273 and 278 to 0.0. – Ahmed Elsayed May 13 '22 at 21:14