Dropdown menu always open below the button "as long as it's possible otherwise it'll open to the
end of the screen" and you can edit its position by using the offset parameter.
You can control how (button, button's icon, dropdown menu and menu items) will be displayed "read
Options below".
You can align (hint & value) and customize them.
You can edit the scrollbar's radius,thickness and isAlwaysShow.
You can set max height for the dropdown menu & it'll become scrollable if there are more items.
If you pass Null to dropdownMaxHeight parameter or didn't use it, the dropdown menu will take max
height possible for the items and will become scrollable if there are more items.
If you have long scrollable list, the dropdown menu will auto scroll to current selected item and
show it at the middle of the menu if possible.
Wrap DropdownButton2 with DropdownButtonHideUnderline to hide the underline.
A Custom widget of the DropdownButton2 below to make it more reusable. You can customize it to
your needs and use it throughout all your app easily as shown in the examples.
You can use DropdownButton2 with items of different heights like dividers as shown in the
examples.
You can use DropdownButton2 as Multiselect Dropdown with Checkboxes as shown in the examples.
You can use DropdownButton2 as Searchable Dropdown as shown in the examples.
You can use DropdownButton2 as a popup menu button by using the parameter customButton. You can
pass Icon,Image or any widget and customize it as shown in the examples.
You can also use DropdownButtonFormField2 the same way with all options above and use it inside
Form as shown in the examples.
Use decoration parameter for the DropdownButtonFormField2 to add borders, label and more.
You can customize DropdownButtonFormField2 width by wrapping it with Padding or with SizedBox and
give it the width you want.
When my dropdown button is very close to the tabar,
The menu will be covered by the tabbar and cannot be displayed.
Use dropdown on a scrollable form, which happens when the dropdown scrolls to the bottom
I've recently started work on a new mobile app and I am using the dropdown_button2 widget. For the most part it works great, better than the widget provided by Flutter, but there's one issue that's annoying me a bit.
I'm trying to center the label text (the selected value) but the problem is when I use an Icon whilst trying to center the text, the alignment.center takes into account the icon when centering which results into the following.
Technicaly it has centered both elements, but I want the icon to be on the far right whilst having the text be centered with the cog icon just above. I'm not sure if this is somehow possible, but I've tried for a couple of hours now to try and center it but it doesn't seem to be possible at the moment.
I've tried adding some padding so that the text is centered but what happens then is the list of elements has more spacing on the left than on the right.
.
And I've also tried removing the icon from the widget and putting it inside a row with dropdown_button2 but what happens then is when I click on the icon, it doesn't open the dropdown menu.
======== Exception caught by widgets library =======================================================
The following assertion was thrown building DropdownButton2(dirty, state: _DropdownButton2State#5ac76):
No Material widget found.
DropdownButton2 widgets require a Material widget ancestor.
In material design, most widgets are conceptually "printed" on a sheet of material. In Flutter's material library, that material is represented by the Material widget. It is the Material widget that renders ink splashes, for instance. Because of this, many material library widgets require that there be a Material widget in the tree above them.
To introduce a Material widget, you can either directly include one, or use a widget that contains Material itself, such as a Card, Dialog, Drawer, or Scaffold.
I have started using with my design all going well but when I started giving margins to dropdown it's sets well but when I see the listed items doesn't get the outer margin they always stick to the start not aligned with the main box
By using a dialog you it can be seen that the background turns black transparent when a modal is opened.
Can we have the same using dropdown_button2 ?
Dropdown menu appears but having the ability to blur the background would be helpful.
Thanks
hello. I use your dropdown_button2 v.1.0.7 library, it is very cool and convenient. Thanks to it, very convenient and beautiful menus are obtained. But I noticed such a nuance, I need to make the dividers in the menu equal to the width of the menu, and the edges of the menu rounded. These are the conditions of the application design. If I do this, then when scrolling through the menu, the list separators go beyond the menu boundaries. Can this be fixed? Thanks.
Goal:
I need to pass the _isMenuOpen attribute to my custom customButton.
Solution i found:
I use onTap/onMenuClose to set a state in my CustomDropdown widget (statefull), and i pass it to my customButton.
Sugestion:
Is there a better way to achieve this?
If not, is it possible to be acomplished with a single callback, that receives the actual _isMenuOpen value so i can ensure that my state and dropdown_button2 state are the same?
Changing the customButton from expecting a Widget to expecting a function that return a Widget and returns the _isMenuOpen as a parameter: customButton: (isOpen) => MyWidget(isOpen),
If we have rounded corners on dropDown, scrollbar is partically outside of dropDown. Usually we have "clipBehavior" on widgets to control it. Are we have something to fix it for DropdownButtonFormField2?
Padding(
padding: const EdgeInsets.fromLTRB(40, 20, 40, 20),
child: DropdownButtonFormField2(
decoration: InputDecoration(
//Add isDense true and zero Padding.
//Add Horizontal padding using buttonPadding and Vertical padding by increasing buttonHeight instead of add Padding here so that The whole TextField Button become clickable, and also the dropdown menu open under The whole TextField Button.
isDense: true,
contentPadding: EdgeInsets.zero,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
),
//Add more decoration as you want here
//Add label If you want but add hint outside the decoration to be aligned in the button perfectly.
),
isExpanded: true,
value: selectedCountry,
icon: Icon(
Icons.arrow_drop_down,
color: Colors.white,
),
iconSize: 30,
buttonHeight: 48,
buttonPadding:
const EdgeInsets.only(left: 20, right: 10),
dropdownDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
),
items: countries.map((CountryItem country) {
return DropdownMenuItem<CountryItem>(
value: country,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.asset(
"assets/images/flags/" +
country.code +
".png",
height: 20,
width: 25,
),
SizedBox(
width: 10,
),
Text(country.name),
],
),
);
}).toList(),
onChanged: (CountryItem? country) {
setState(() {
selectedCountry = country;
});
},
onSaved: (value) {},
),
),
dropdownOverButton, dropdownFullScreen and offset aren't working either. Any ideas?
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 3.1.0-0.0.pre.939, on Fedora Linux 36 (Workstation Edition) 5.17.8-300.fc36.x86_64, locale de_DE.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✗] Linux toolchain - develop for Linux desktop
✗ clang++ is required for Linux development.
It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from https://releases.llvm.org/
✗ CMake is required for Linux development.
It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from https://cmake.org/download/
✗ ninja is required for Linux development.
It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from
https://github.com/ninja-build/ninja/releases
✗ GTK 3.0 development libraries are required for Linux development.
They are likely available from your distribution (e.g.: apt install libgtk-3-dev)
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.67.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 2 categories.
There's an issue with the label text, where it should appear at the beginning of the field, but it's significantly offset from the left side in my case. Notice in the screenshot how the dropdown buttons' labels are closer to the start of the field, but the DropdownButtonFormField2's label is offset:
I'm using dropdown button inside of futureBuilder, but when I try to select some option whole widget tree rebuilds. How to avoid rebuilding of whole widget tree.
However I am not able to use it in my app.
Whenever I import it I get the following error during build
Can you see the stack trace and if possible help me with it.
Thanks
Stack Trace
/C:/Installs/flutter_windows_1.22.2-stable/flutter/.pub-cache/hosted/pub.dartlang.org/dropdown_button2-1.0.7/lib/dropdown_button2.dart:172:20: Error: Type 'ShortcutActivator' not found.
static const Map<ShortcutActivator, Intent> _webShortcuts =
^^^^^^^^^^^^^^^^^
/C:/Installs/flutter_windows_1.22.2-stable/flutter/.pub-cache/hosted/pub.dartlang.org/dropdown_button2-1.0.7/lib/dropdown_button2.dart:173:8: Error: 'ShortcutActivator' isn't a type.
<ShortcutActivator, Intent>{
^^^^^^^^^^^^^^^^^
/C:/Installs/flutter_windows_1.22.2-stable/flutter/.pub-cache/hosted/pub.dartlang.org/dropdown_button2-1.0.7/lib/dropdown_button2.dart:176:5: Error: Method not found: 'SingleActivator'.
SingleActivator(LogicalKeyboardKey.arrowDown):
^^^^^^^^^^^^^^^
/C:/Installs/flutter_windows_1.22.2-stable/flutter/.pub-cache/hosted/pub.dartlang.org/dropdown_button2-1.0.7/lib/dropdown_button2.dart:178:5: Error: Method not found: 'SingleActivator'.
SingleActivator(LogicalKeyboardKey.arrowUp):
^^^^^^^^^^^^^^^
/C:/Installs/flutter_windows_1.22.2-stable/flutter/.pub-cache/hosted/pub.dartlang.org/dropdown_button2-1.0.7/lib/dropdown_button2.dart:172:20: Error: 'ShortcutActivator' isn't a type.
static const Map<ShortcutActivator, Intent> _webShortcuts =
^^^^^^^^^^^^^^^^^
/C:/Installs/flutter_windows_1.22.2-stable/flutter/.pub-cache/hosted/pub.dartlang.org/dropdown_button2-1.0.7/lib/dropdown_button2.dart:222:26: Error: The getter 'enabled' isn't defined for the class 'DropdownMenuItem<T>'.
- 'DropdownMenuItem' is from 'package:flutter/src/material/dropdown.dart' ('/C:/Installs/flutter_windows_1.22.2-stable/flutter/packages/flutter/lib/src/material/dropdown.dart').
package:flutter/…/material/dropdown.dart:1
Try correcting the name to the name of an existing getter, or defining a getter or field named 'enabled'.
if (dropdownMenuItem.enabled) {
^^^^^^^
/C:/Installs/flutter_windows_1.22.2-stable/flutter/.pub-cache/hosted/pub.dartlang.org/dropdown_button2-1.0.7/lib/dropdown_button2.dart:233:36: Error: The getter 'enabled' isn't defined for the class 'DropdownMenuItem<T>'.
- 'DropdownMenuItem' is from 'package:flutter/src/material/dropdown.dart' ('/C:/Installs/flutter_windows_1.22.2-stable/flutter/packages/flutter/lib/src/material/dropdown.dart').
package:flutter/…/material/dropdown.dart:1
Try correcting the name to the name of an existing getter, or defining a getter or field named 'enabled'.
if (kIsWeb && dropdownMenuItem.enabled) {
^^^^^^^
/C:/Installs/flutter_windows_1.22.2-stable/flutter/.pub-cache/hosted/pub.dartlang.org/dropdown_button2-1.0.7/lib/dropdown_button2.dart:1314:26: Error: The getter 'enabled' isn't defined for the class 'DropdownMenuItem<T>'.
- 'DropdownMenuItem' is from 'package:flutter/src/material/dropdown.dart' ('/C:/Installs/flutter_windows_1.22.2-stable/flutter/packages/flutter/lib/src/material/dropdown.dart').
package:flutter/…/material/dropdown.dart:1
Try correcting the name to the name of an existing getter, or defining a getter or field named 'enabled'.
item.enabled && item.value == widget.value)
^^^^^^^
Flutter doctor output
[√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19043.1415], locale en-IN)
• Flutter version 2.2.3 at C:\Installs\flutter_windows_1.22.2-stable\flutter
• Framework revision f4abaa0735 (6 months ago), 2021-07-01 12:46:11 -0700
• Engine revision 241c87ad80
• Dart version 2.13.4
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\kohli\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] IntelliJ IDEA Community Edition (version 2020.3)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.2
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
[√] VS Code (version 1.63.2)
• VS Code at C:\Users\kohli\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.29.0
[√] Connected device (3 available)
• sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.110
• Edge (web) • edge • web-javascript • Microsoft Edge 96.0.1054.34
• No issues found!
It was working perfectly yesterday night, but this morning, I was faced with this error, after building it on debug mode.
Please check for this issue, thanks. Hope it will be resolved in the next update. Great package right here
Thank you for implementing the iconOnClickoption. I would like to ask for another one with a similar function.
I want to change the button text style when the button is clicked like the iconOnClick option.
For example, the color of the button text is red when the menu is on.
I have changed DropdownButton2 to DropdownButtonFormField2 and found that DropdownButtonHideUnderline is not working with DropdownButtonFormField2. It has been working well with DropdownButton2.
The dropdown items always when the width is reduced are located fixed in a predetermined position how can it be centered?.
and it is possible to reverse the animation effect when the menu is closed
In Dropdown2 items if we add DropdownButton2( dropdownWidth: MediaQuery.of(context).size.width * 0.6, buttonWidth: MediaQuery.of(context).size.width * 0.6, ... DropdownMenuItem<String>( child: Text( list[i], style: GoogleFonts.inter(), overflow: TextOverflow.ellipsis, maxLines: 1, ), value: list[i], ), ...
and one of the item has like 200 characters then DropdownMenuItem rendered it with overflow type ellipses but button width will show error of renderFlex overflow.
@AhmedLSayed9 Hello, I have a small question/remark. If you do not set the width of the button and dropdownlist, then the width of the button is taken as the maximum width of the child element from the list (correct me if I'm wrong). But at the same time, the dropdownlist has some paddings or margins (I did not find their variables) that are not added to this width.
As a result, it turns out that this element does not completely fit into the dropdown and is cut off. If the list of items is static, then this is easily solved by setting specific sizes, but if the list for the dropdown comes from the server and can change, then a problem appears.
This error appears in my output every time I click on a drop down from this library. There isn't anything fancy on my drop down. This happens on Windows and Web. The error itself does not affect the functioning of the drop down, however it is quite annoying to see it every time I click something. If there is a way to silence it or to solve the problem, please let me know.
static const Map<ShortcutActivator, Intent> _webShortcuts =
<ShortcutActivator, Intent>{
// On the web, up/down don't change focus, *except* in a <select>
// element, which is what a dropdown emulates.
SingleActivator(LogicalKeyboardKey.arrowDown):
DirectionalFocusIntent(TraversalDirection.down),
SingleActivator(LogicalKeyboardKey.arrowUp):
DirectionalFocusIntent(TraversalDirection.up),
};
** error: The name 'ShortcutActivator' isn't a type so it can't be used as a type argument.
Try correcting the name to an existing type, or defining a type named 'ShortcutActivator'
Hi, I want to make the DropdownButtonFormField to be long press in order to open the dropdown menu, but the openWithLongPress seems not working. I still able to tap it when openWithLongPress is true and long press is nothing happen. Where did I do wrong? Any help will be appreciated. Thanks.