Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the options of collapsable list widgets in Flutter?

I need to have some lists collapse by their topics in my project and am wondering if I'll need to implement this from zero or rather use a component from flutter. Does this component exist?

Thanks in advance :)

like image 488
Jota Renan Avatar asked Mar 17 '18 13:03

Jota Renan


People also ask

How many types of lists are there in Flutter?

A list in Flutter is created using the ListView widget. There are two types of lists: User defines all items inside the list (Roughly equivalent to a ScrollView in Android) User defines one item which is repeated across the list (Equivalent to a RecyclerView)

How do you make an expandable list in Flutter?

Expandable ListView is a type of list view that is used to show multiple types of data based on category and subcategory. Expandable list view is used to expand or collapse the view in list items In a flutter app. We can easily make our own Expandable ListView using the ExpansionTile widget.

How many types of widgets are there in Flutter * 2?

There are broadly two types of widgets in the flutter: Stateless Widget. Stateful Widget.


1 Answers

The Flutter Gallery has two examples that may be relevant for your accordion-like lists.

Expansion Panel Demo & Two-level List Demo

The Expansion Panel demo is probably what you want. If so, take a look at how the demo leverages ExpansionPanel and uses a headerBuilder and body. You can extends this to make the header and bodies as complex as you need. The Gallery demo adds a DemoItem helper class. You can use this pattern or come up with your own design.

Here is a snippet that shows the demo using ExpansionPanelList by passing a callback and the list of DemoItems:

        child: new ExpansionPanelList(
          expansionCallback: (int index, bool isExpanded) {
            setState(() {
              _demoItems[index].isExpanded = !isExpanded;
            });
          },
          children: _demoItems.map((DemoItem<dynamic> item) {
            return new ExpansionPanel(
              isExpanded: item.isExpanded,
              headerBuilder: item.headerBuilder,
              body: item.build()
            );
          }).toList()
        ),

enter image description here

enter image description here

like image 146
Ashton Thomas Avatar answered Oct 03 '22 15:10

Ashton Thomas