如何在 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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...