Coder Social home page Coder Social logo

Comments (2)

Dimibe avatar Dimibe commented on July 30, 2024 3

Hi @deezaster, there were several questions like yours, but I have some concerns because of backwards compatibility. I'm trying to provide an easy solution for this in the future. Currently there is a work around which you can try (only works if your data are real objects):

  1. Group by the element itself then the element will available in the groupSeparator function.
  2. Override the compareTo method in your element's class and group by the value you like.

Code from the Widget:

GroupedListView<Element, Element>(
          elements: _elements,
          groupBy: (element) => element,
          groupSeparatorBuilder: (Element element) => Text(
            element.groupName,
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
          ),
          [...]
),

Code from the elements class:

class Element implements Comparable {
  String groupName;
  int groupIndex;
  String name;

  Element(this.groupIndex, this.groupName, this.name);

  @override
  int compareTo(other) {
    int compareResult = groupIndex.compareTo(other.groupIndex);
    // if result is 0 both items are in the same group, so sort them according their name.
    if (compareResult == 0) {
      compareResult = name.compareTo(other.name);
    }
    return compareResult;
  }

  @override
  bool operator ==(Object other) => other is Element && other.groupIndex == groupIndex;

  @override
  int get hashCode => groupIndex.hashCode;
}

The data for the list widget:

List _elements = <Element>[
  Element(1, 'Team One', 'John'),
  Element(2, 'Team Two', 'Will'),
  Element(1, 'Team One', 'Beth'),
  Element(2, 'Team Two', 'Miranda'),
  Element(3, 'Team Three', 'Mike'),
  Element(3, 'Team Three', 'Danny'),
];

The result:
image

I aware this is not a small solution but currently the only one which solves your request.

Hopefully this will help you

Best regards

from grouped_list.

Dimibe avatar Dimibe commented on July 30, 2024

@deezaster I've created a new package which depends on scrollable_positioned_list. In this package the groupSeparatorBuilder takes the whole element as argument.
Maybe you want to try it out: https://github.com/Dimibe/sticky_grouped_list

from grouped_list.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.