简体   繁体   English

是否可以在不使用 itembuilder 的情况下使用 Listview.seperated?

[英]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.我想要一个 Listview.seperated,我可以在其中将元素定义为子元素,而不是使用 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?是否可以在不使用 itembuilder 的情况下使用 Listview.seperated?

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 https://api.flutter.dev/flutter/widgets/ListView/ListView.separated.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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