简体   繁体   中英

Flutter - how to make nested list views?

I want to make a nested list view in the following manner

在此处输入图片说明

How can I do this? I only want the nested list view for one of the radio tiles not all of them.

I tried including both ListView builder in another List however there was rendering problem.

My code:

Column(

      children: <Widget>[
        .....

        Expanded(
          child:

          ListView.builder(
            padding: EdgeInsets.all(0.0),
            itemCount: tasks.length,
            itemBuilder: (context, index) {

              return RadioListTile<String>(

               //contentPadding: EdgeInsets.symmetric(horizontal: 16.0),
                title:  Text(tasks[index], style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.w400)),
                value: tasks[index],
                groupValue: selectedRadio,
                onChanged: (val){
                    setSelectedRadio(val);
                }
              );
            },
          ),
        ),

      ],
    );

You cannot build a ListView inside a ListView as you will confuse the scroll behaviour. You should use List widget that does not scroll, such as Column .

ListView.builder(
  padding: EdgeInsets.all(0.0),
  itemCount: tasks.length,
  itemBuilder: (context, index) {
    if (// single RadioListTile) {
      return RadioListTile<String>(
        title:  Text(tasks[index], style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.w400)),
        value: tasks[index],
        groupValue: selectedRadio,
        onChanged: (val) => setSelectedRadio(val),
      );
    }
    else if (// nested RadioListTile) {
      return Column(
        children: <Widget>[
          // RadioListTile1,
          // RadioListTile2,
          // RadioListTile3,
        ],
      );
    }
  },
),

You can totally include a list view inside of another list view. But the inside list view has to have shrinkWrap set to true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM