Dimibe / grouped_list

A Flutter ListView in which items can be grouped into sections.
https://pub.dev/packages/grouped_list
MIT License
391 stars 107 forks source link

Footer widget doesn't work as intended #194

Open zigapovhe opened 9 months ago

zigapovhe commented 9 months ago

Describe the bug Footer is only visible at the end of GroupedListView, and as such, doesn't really give any added value to the package. It should add footer widget to the end of each section.

Expected behavior Based on this issue https://github.com/Dimibe/grouped_list/issues/28, the expected behavior would be, to see footer widget at the end of each section (group)

Information:

I've used the code from your example.dart file Screenshot 2023-10-09 at 21 59 33 Screenshot 2023-10-09 at 22 05 19

import 'package:flutter/material.dart';
import 'package:grouped_list/grouped_list.dart';

void main() => runApp(const MyApp());

List _elements = [
  {'name': 'John', 'group': 'Team A'},
  {'name': 'Will', 'group': 'Team B'},
  {'name': 'Beth', 'group': 'Team A'},
  {'name': 'Miranda', 'group': 'Team B'},
  {'name': 'Mike', 'group': 'Team C'},
  {'name': 'Danny', 'group': 'Team C'},
];

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Grouped List View Example'),
        ),
        body: _createGroupedListView(),
      ),
    );
  }

  _createGroupedListView() {
    return GroupedListView<dynamic, String>(
      elements: _elements,
      footer: Container(color: Colors.red, child: const Text('This is footer widget')),
      groupBy: (element) => element['group'],
      groupComparator: (value1, value2) => value2.compareTo(value1),
      itemComparator: (item1, item2) => item1['name'].compareTo(item2['name']),
      order: GroupedListOrder.DESC,
      useStickyGroupSeparators: true,
      groupSeparatorBuilder: (String value) => Padding(
        padding: const EdgeInsets.all(8.0),
        child: Text(
          value,
          textAlign: TextAlign.center,
          style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
        ),
      ),
      itemBuilder: (c, element) {
        return Card(
          elevation: 8.0,
          margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
          child: SizedBox(
            child: ListTile(
              contentPadding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
              leading: const Icon(Icons.account_circle),
              title: Text(element['name']),
              trailing: const Icon(Icons.arrow_forward),
            ),
          ),
        );
      },
    );
  }
}
zigapovhe commented 9 months ago

Can be closed, as I've fixed it in my own fork. @Dimibe If you want, I can make a PR for it, but for me, it does the job: https://github.com/zigapovhe/grouped_list/commit/96e800f627c0e537e0b7543ec76ad2544c79d3f5

Dimibe commented 9 months ago

@zigapovhe: I would appreciate it if you could open a PR. I will then decide if I want to add the feature to the package or not. Thanks in advance!