Comments (2)
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):
- Group by the element itself then the element will available in the groupSeparator function.
- 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'),
];
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.
@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)
- Is there a way to draw a widget at the end of the last item? HOT 1
- Can separator be set to null? Because after setting itemExtent, the height doubles
- Ui Freezing when too many items are loaded in the list-LazyLoading feature request
- ItemComparator function doesn't work if you set groupComparator function HOT 1
- Wrong sticky header on first display of scrolled list HOT 3
- Support for container group HOT 1
- Feature Request: Custom Header Location HOT 1
- Bad state: Cannot add event after closing
- Element Position HOT 1
- Get first and / or last index of each group
- useStickyGroupSeparators
- Implicit animations for items when data source changes HOT 1
- index for group headers and separators HOT 1
- Highlight current group separator HOT 2
- Footer widget doesn't work as intended HOT 2
- Hide Separator if only one group HOT 1
- "primary" parameter doesn't work
- Sticky header not updated on web HOT 1
- Pagination support? HOT 2
- How do I apply it to the data model?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grouped_list.