Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

listview - flutter: how to group items by header and subheaders using GroupedListView

I found a package that allows me to group/filter a list based on two criteria. However, it doesn't print the courses under the correct heading and also prints the entire list multiple times. Modifying group comparator and item comparator fields didn't help. Not sure how to fix

`

        body: GroupedListView<dynamic, String>(
          shrinkWrap: true,
          elements: _elements,
          groupBy: (element1) => element1['subjectName'],
          groupComparator: (value1, value2) => value2.compareTo(value1),
          //itemComparator: (item1, item2) =>
              //item1['subjectName'].compareTo(item2['subjectName']),
          order: GroupedListOrder.DESC,
          useStickyGroupSeparators: true,
          groupSeparatorBuilder: (String value) => Padding(
            padding: const EdgeInsets.all(4.0),
            child: Text(
              value,
              textAlign: TextAlign.center,
              style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
            ),
          ),
          
            itemBuilder: (c, element) {
              return GroupedListView<dynamic, String>(
                  shrinkWrap: true,
                  elements: _elements,
                  groupBy: (element) => element['courseName'],
                  groupComparator: (value1, value2) =>
                      value2.compareTo(value1),
                  itemComparator: (item1, item2) => item1['subjectName']
                  .compareTo(item2['subjectName']),
                  order: GroupedListOrder.DESC,
                  useStickyGroupSeparators: true,
                  groupSeparatorBuilder: (String value) => Padding(
                        padding: const EdgeInsets.all(2.0),
                        child: Text(
                          value,
                          textAlign: TextAlign.left,
                          //style: TextStyle(
                          //   fontSize: 20, fontWeight: FontWeight.bold),
                        ),
                      ),
                  itemBuilder: (c, element) {
                    return Container(
                        child: Column(children: <Widget>[
                      ListTile(
                        contentPadding: EdgeInsets.symmetric(
                            horizontal: 20.0, vertical: 5.0),
                        // leading: Icon(Icons.account_circle),
                        title: Text(element['courseSection'],
                            textAlign: TextAlign.left),
                        //trailing: Icon(Icons.arrow_forward),
                      ),
                      // ListTile(title: Text(element['courseSection'])),
                    ]));
                  

});})));}`

question from:https://stackoverflow.com/questions/65849108/flutter-how-to-group-items-by-header-and-subheaders-using-groupedlistview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...