HussainTaj-W / flutter-package-selection_menu

A flutter widget, highly customizable, to select an item from a list of items.
https://pub.dev/packages/selection_menu
MIT License
34 stars 12 forks source link

enable menu size adaptive height #3

Closed brizaldi closed 4 years ago

brizaldi commented 4 years ago

image

is there a way to set height of the menu so that it can change dynamically depending on the size of the list of items inside it?

HussainTaj-W commented 4 years ago

The default behavior of the DropDown style is to expand to available space. Perhaps I need to rethink this.

Luckily, you can change any part of this widget without needing to edit the source.

In your case, you would like to override ListViewComponent and MenuComponent.

Please check out the complete usage example here (Please copy the code from this file if needed).

Code Highlights

Widget _listViewBuilder(ListViewComponentData data) {
  return ListView.builder(
    itemBuilder: data.itemBuilder,
    itemCount: data.itemCount,
    padding: EdgeInsets.zero,
    shrinkWrap: true, // This here will make the ListView wrap to content.
  );
}

Widget _menuComponentBuilder(MenuComponentData data) {
  return ClipRect(
    child: Column(
      mainAxisSize: MainAxisSize.min, // This will make the column wrap to content.
      children: [data.listView],
    ),
  );
}

SelectionMenu<Rectangle>(
  componentsConfiguration: DropdownComponentsConfiguration(
  listViewComponent: ListViewComponent(builder: _listViewBuilder),
  menuComponent: MenuComponent(builder: _menuComponentBuilder,
  ),
  // Other Properties...
);

Dynamic Resizing Example

I'm glad to see people are still using my work. Thank you. 🌟

HussainTaj-W commented 4 years ago

I assume the issue was resolved, so I'm closing the issue.

Feel free to reopen the issue if the problem persists.

brizaldi commented 4 years ago

i did as you say, and its working now, sorry if this is a little bit out of topic, but how can i remove white padding around ListView?

image

HussainTaj-W commented 4 years ago

I'll add such a feature in the next release (which might take some time.)

Currently, there is a workaround for this. Use AnimationComponent. You can copy the actual DropdownAnimationComponent and edit this line of code.