Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

count total item #160

Open
vohoangtuit opened this issue Aug 3, 2022 · 1 comment
Open

count total item #160

vohoangtuit opened this issue Aug 3, 2022 · 1 comment

Comments

@vohoangtuit
Copy link

vohoangtuit commented Aug 3, 2022

how to count total items in grouped_list ?

@bsolca
Copy link

bsolca commented Sep 19, 2022

Hello @vohoangtuit,

Here is my solution to add the number of items in each group.

final List<MapEntry<String, int>> _textList = [
  const MapEntry('Lorem', 0),
  const MapEntry('ipsum', 1),
  const MapEntry('dolor', 2),
  const MapEntry('sit', 3),
  const MapEntry('amet', 4),
  const MapEntry('consectetur', 5),
  const MapEntry('adipiscing', 6),
  const MapEntry('elit', 7),
  const MapEntry('sed', 8),
  const MapEntry('do', 9),
  const MapEntry('eiusmod', 10),
  const MapEntry('tempor', 11),
  const MapEntry('incididunt', 12),
  const MapEntry('ut', 14),
];
String groupBy(MapEntry<String, int> e) => e.value.isEven ? 'Even' : 'Odd';

Now you can use the groupHeaderBuilder and used the groupBy function to count the number of item in the group.

groupHeaderBuilder: (MapEntry<String, int> e) => Padding(
          padding: const EdgeInsets.all(8.0),
          child: Text(
            '${e.key} with ${_textList.where((test) {
              return groupBy(e) == groupBy(test);
            }).length} elements',
            textAlign: TextAlign.left,
            style: const TextStyle(
              fontSize: 20,
              fontWeight: FontWeight.bold,
              color: Colors.pink,
            ),
          ),
        ),

Result:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants