ListView.builder() builds all items in an ExpansionTile

Viewed 412

In a list of expansion tile widgets, I'm trying to build a list (200+ items) when any expansion tile is opened. When i open the expansion tile it builds all the 200 items at once, giving a jank. I'm using Listview.builder so I'm not expecting this behavior. Here's a code snippet.

ListView.builder(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemCount: 100,
      itemBuilder: (context, i) {
        final _expansionTileKey = GlobalKey();
        return ExpansionTile(
          initiallyExpanded: false,
          textColor: Colors.black,
          key: _expansionTileKey,
          onExpansionChanged: (value) =>
              widget.onExpansionChanged(_expansionTileKey),
          trailing: Icon(
            Icons.keyboard_arrow_down,
          ),
          subtitle: Text(
            "$i - $i",
          ),
          title: Text(
            '$i',
          ),
          children: <Widget>[
            StreamBuilder<List<T>>(
              stream: _bloc.stream,
              builder: (context, snapshot) {
                return ListView.separated(
                  shrinkWrap: true,
                  itemCount: _bloc.length,
                  itemBuilder: (_, index) {
                    return Container(
                      color: Colors.white,
                      child: Text("$index"),
                    );
                  },
                  separatorBuilder: (_, i) => Padding(
                    padding: const EdgeInsets.only(left: 8, right: 8),
                    child: const Divider(
                      height: 1,
                    ),
                  ),
                );
              },
            )
          ],
        );
      },
    ),
0 Answers
Related