I want first ExpansionTile's item default is open. I want to When I click another item, current item is will close. How can I do it?

后端 未结 2 1869
孤独总比滥情好
孤独总比滥情好 2021-01-23 15:25
 body: Container(color: Colors.white,
          child: SingleChildScrollView(
              child : Column( 
                children : [
                  Padding(paddi         


        
2条回答
  •  悲&欢浪女
    2021-01-23 15:48

    Instead of initiallyExpanded: false, you can use initiallyExpanded: index == 0. By doing this you will check the index of your item and if it is 0, it will be expanded initially.

     ListView.builder(itemCount: 10, itemBuilder: (context, index) {
          return ExpansionTile(
            initiallyExpanded: index == 0,
            title: Text('Title #$index'), 
            children:  [
              Text('Expansion #$index'),
            ],
          );
        }),
    

    To collapse ExpandedTile after choosing item you can check following links

    Flutter - Collapsing ExpansionTile after choosing an item

    Flutter- ExpansionTile expand and collapse on click

提交回复
热议问题