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

How do I set the component that is displayed when the itemsList is empty? #1

Closed HyggeBo7 closed 5 years ago

HyggeBo7 commented 5 years ago

How do I set the component that is displayed when the itemsList is empty?

Can I add a adaptive height based on the itemsList data?

image

HussainTaj-W commented 5 years ago

How do I set the component that is displayed when the itemsList is empty?

Currently, a component for this specific task does not exist. When itemsList is empty an empty ListView is shown when DialogComponentsConfiguration or DropdownComponentsConfiguration is used.

You can use the ListViewComponent to achieve the required effect.

Widget _listViewBuilder(ListViewComponentData data) {
  if (data.itemCount == 0) {
    return Center(
      child: Text("There is nothing here."),
    );
  }
  return ListView.builder(
    itemBuilder: data.itemBuilder,
    itemCount: data.itemCount,
    padding: EdgeInsets.zero,
  );
}

Complete example here. An empty list example

Can I add an adaptive height based on the itemsList data?

Yes.

Widget itemBuilder(
    BuildContext context, Rectangle rectangle, OnItemTapped onItemTapped) {
  return Container(
    height: rectangle.size,
    //...
  );
}

Complete example here. A variable widget high list item example

HyggeBo7 commented 5 years ago

Thank you