如何解决如何在 GroupedListView 的 groupSeparatorBuilder 中使用两个元素?
我有一个对象列表 (List<Livematche>
),我想按联赛名称对它们进行分组,我曾经这样做过 GroupedListView 。
groupBy: (element) => element.league.name,
但在 groupSeparatorBuilder(每个列表的标题)中,我想显示联盟的名称和徽标( League.logo)。
在 GroupedListView 中我们只能按一个元素分组?
我的代码:
Livematche class :
class Livematche {
League league;
Localteam localteam;
Matche_time matche_time;
Scores scores;
Visitorteam visitorteam;
//WeatherReport weatherReport;
Livematche(
{this.league,this.localteam,this.matche_time,this.scores,this.visitorteam,//this.weatherReport
});
factory Livematche.fromJson(Map<String,dynamic> jsonData) {
return Livematche(
league: League.fromJson(jsonData["league"]),localteam: Localteam.fromJson(jsonData["localTeam"]),matche_time: Matche_time.fromJson(jsonData["time"]),scores: Scores.fromJson(jsonData["scores"]),visitorteam: Visitorteam.fromJson(jsonData["visitorTeam"]),//weatherReport:
// WeatherReport.fromJson(jsonData["weather_report"]) == Null
// ? Null
//: WeatherReport.fromJson(jsonData["weather_report"])
);
}
}
小部件
return GroupedListView<Livematche,String>(
floatingHeader: true,elements: snapshot.data,groupBy: (element) => element.league.name,itemBuilder: (_,Livematche livematche) {
return Container(
margin: EdgeInsets.only(left: 10,right: 10),color: Colors.blue,child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),child: Container(
color: Colors.blue,//
margin: EdgeInsets.symmetric(vertical: 2.0),child: Row(
mainAxisAlignment: MainAxisAlignment.center,crossAxisAlignment: CrossAxisAlignment.center,children: [
Expanded(
child: Text(
livematche.localteam.name,textAlign: TextAlign.center,style: TextStyle(
color: Colors.white,fontSize: 13.0,),Image.network(
livematche.localteam.logo_path,width: 44.0,Expanded(
child: Text(
"${livematche.scores.localteam_score} - ${livematche.scores.visitorteam_score}",fontSize: 18.0,Image.network(
livematche.visitorteam.logo_path,Expanded(
child: Text(
livematche.visitorteam.name,],//
),);
},groupSeparatorBuilder: (String value) => Padding(
padding: const EdgeInsets.all(1.0),child: Text(
value,style: TextStyle(fontSize: 20,fontWeight: FontWeight.bold),// optional
useStickyGroupSeparators: false,// optional
order: GroupedListOrder.ASC,// optional
);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。