在ListTile中添加3个文本,更改每列的背景色,并在此列表中添加搜索



我如何在下面的列表视图中添加搜索是否可以在我的ListTile中添加3个文本?如果可以,我该怎么做。我该如何更改列表中的背景色,一次为蓝色,另一次为绿色等等。。。。。。感谢您的帮助

body: StreamBuilder<List>(
stream: _streamController.stream,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData)
return ListView(
children: [
for (Map document in snapshot.data)
Card(
elevation: 10.6,
color: Colors.blue,
child: new ListTile(
title: Text(document['title1'],   textScaleFactor: 1.2, style: TextStyle(color:Colors.white),),
subtitle: Text(document['title2'], textScaleFactor: 1.2, style: TextStyle(color:Colors.white),),
leading: new IconButton(
icon: Icon(Icons.headset, color: Colors.white),
onPressed: () {
//***//
},
),
),
),
],
);
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator()
],
),
);
},
),
  • 要在ListView中开始搜索,您可以查看:https://blog.usejournal.com/flutter-search-in-listview-1ffa40956685

    或者使用SearchDelegatehttps://api.flutter.dev/flutter/material/SearchDelegate-class.html

  • ListTiles只将小部件作为前导、标题、副标题和尾部。所以你可以把你想要的东西放进去!

ListTile(
title: Column(
children: [
Text('abc'),
Text('def'),
//etc,
],
),
subtitle: Column(
children: [
Text('123'),
Text('456'),
//etc,
],
),
),
  • 要更改颜色,请查看Listview.builder。它使用IndexWidgetBuilder,它提供了一个索引,这样你就可以使用索引来检查它是均匀的还是不均匀的,以设置首选颜色。https://api.flutter.dev/flutter/widgets/ListView/ListView.builder.html

最新更新