简体   繁体   中英

Is it possible to have a Listview.seperated without having to use a itembuilder?

I want to have a Listview.seperated where I can define the elements as children instead of using the itembuilder. I found a way in the code I posted below which allows me to sort of insert it as if is a children array. But this way I have to manually change the item count. Is there any other way without having to store the array somewhere in a field?

child: ListView.separated
(
  itemCount: 3,
  separatorBuilder: (BuildContext context, int index) => Divider(height: 1.0), 
  itemBuilder: (BuildContext context, int index)
  {
    [
      ListTile(
        title: Text('Group Name'),
      ),
      ListTile(
        title: Text('Leave Group'),
      ),
      ListTile(
        title: Text('Invite Member'),
      )
    ][index];
  }
)

Is it possible to have a Listview.seperated without having to use a itembuilder?

The answer is no , because:

ListView.separated constructor
ListView.separated(
{Key key,
Axis scrollDirection: Axis.vertical,
bool reverse: false,
ScrollController controller,
bool primary,
ScrollPhysics physics,
bool shrinkWrap: false,
EdgeInsetsGeometry padding,
@required IndexedWidgetBuilder itemBuilder,
@required IndexedWidgetBuilder separatorBuilder,
@required int itemCount,
bool addAutomaticKeepAlives: true,
bool addRepaintBoundaries: true,
bool addSemanticIndexes: true,
double cacheExtent}
)

this is the part that you are interested in:

@required IndexedWidgetBuilder itemBuilder,
@required IndexedWidgetBuilder separatorBuilder,
@required int itemCount,

https://api.flutter.dev/flutter/widgets/ListView/ListView.separated.html

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