Comments (5)
@CripyIce Can you provide an example of your code. I've testet it with your example from the last issue.
This works perfectly fine for me.
from grouped_list.
@Dimibe here is an example:
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<String> _contacts = List();
@override
void initState() {
super.initState();
_contacts.addAll(List.generate(40, (index) => "שיראל$index"));
_contacts.addAll(List.generate(40, (index) => "איתן$index"));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Grouped List Test"),
),
body: Scrollbar(
child: GroupedListView<String, String>(
elements: _contacts,
itemBuilder: (context, element) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
title: Text(element),
),
);
},
order: GroupedListOrder.ASC,
groupBy: (element) => element.substring(0, 1),
separator: Divider(
height: 0.0,
indent: 16.0,
endIndent: 16.0,
),
useStickyGroupSeparators: true,
groupSeparatorBuilder: (value) => Container(
padding:
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
width: MediaQuery.of(context).size.width,
color: Color(0xffF7F7F7),
child: Text(
value,
style: TextStyle(
fontSize: 18.0,
color: Colors.red,
fontWeight: FontWeight.bold,
),
),
),
),
),
);
}
}
from grouped_list.
Fixed in version 2.2.0
from grouped_list.
Hi @Dimibe , sorry for the late response I think I've figured it out in a way.
When using GroupedListView<String, String>
everything works great, but when using GroupedListView<MyContact, String>
with a custom class the error appears.
import 'package:flutter/material.dart';
import 'package:grouped_list/grouped_list.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final list = [
MyContact('חוזרדט'),
MyContact('הננ'),
MyContact('קפעד'),
MyContact('רטחוגכג'),
MyContact('ישבצאנ'),
MyContact('צרנתרפה'),
MyContact('מזחטרנוסת'),
MyContact('בבס'),
MyContact('ינו'),
MyContact('ובסשפזעשוטכק'),
MyContact('פעט'),
MyContact('שהבדד'),
MyContact('גחחקדמדע'),
MyContact('זבדדקטחרפאטעהר'),
MyContact('קגבר'),
MyContact('מאיר'),
MyContact('נגכחיתבזנשנכ'),
MyContact('דנזהמטסכסשמשפד'),
MyContact('ור'),
MyContact('עמאאטגכאק'),
MyContact('שוסקמט'),
MyContact('שקקרק'),
MyContact('רערב'),
MyContact('בשהזעשכזטחא'),
MyContact('וטקהעכטנכתרט'),
MyContact('אמ'),
MyContact('אואהשרשבנפזכ'),
MyContact('סעמרטשזדיטלעפ'),
MyContact('אשטתלטלמלשדעת'),
MyContact('טנוכשע'),
MyContact('ירהצע'),
MyContact('וזפלקשבקסצבזצ'),
MyContact('צאוקבשערזחקראו'),
MyContact('מעתטשוזשזל'),
MyContact('עלהפבמאאצקננזב'),
MyContact('קרגפלנזנחקחג'),
MyContact('נחקבההססחועא'),
MyContact('יחעדכע'),
MyContact('צלשירעסס'),
MyContact('שסצעבצרצ'),
MyContact('מחפשנזגשש'),
MyContact('כגק'),
MyContact('בזאעיזעדכפאנגק'),
MyContact('אצחנ'),
MyContact('סר'),
MyContact('תסעו'),
MyContact('רצכגגזהמשח'),
MyContact('כצצקחבכרמ'),
MyContact('טצשזרעה'),
MyContact('הצשדחצשלחכזמ'),
MyContact('תז'),
MyContact('לפהחניטסמת'),
MyContact('קבזתהמכגילנרזד'),
MyContact('הלצ'),
MyContact('טtest'),
MyContact('עזצהעעוגעבאגאח'),
MyContact('נטטוצצ'),
MyContact('תחנהרטזאאייקזה'),
MyContact('ומצכסוספע'),
MyContact('טללקק'),
MyContact('כסצדלבנדנטפיד'),
MyContact('דהחזכסס'),
MyContact('תוגגגטש'),
MyContact('ריסאיקחבכפשקעג'),
MyContact('צלטגטפ'),
MyContact('צד'),
MyContact('תוחלזלחצאגדז'),
MyContact('עת'),
MyContact('קיאזגוכמבא'),
MyContact('בבדעקבע'),
MyContact('כמט'),
MyContact('האנזצפסט'),
MyContact('לפצבחדכמצענארת'),
MyContact('קשסדאמד'),
MyContact('ננרק'),
MyContact('קעסהתפגעגשדק'),
MyContact('קטטקבמזקהכימנ'),
MyContact('זחקצהדא'),
MyContact('וכהצ'),
MyContact('בקשסילנצ'),
MyContact('הלאולשעיטיוסנ'),
MyContact('קגמסדק'),
MyContact('נלחיהינתטאחפלע'),
MyContact('יכח'),
MyContact('ירק'),
MyContact('לנרזצפגזטאקצ'),
MyContact('בגטצלתלדטחדפ'),
MyContact('פואלבאגלא'),
MyContact('בששלר'),
MyContact('וגחגתכו'),
MyContact('ררסדתששגבנפרפנ'),
MyContact('נתקסר'),
MyContact('רצצ'),
MyContact('סמי'),
MyContact('חזחקיד'),
MyContact('טחטרנצנ'),
MyContact('אסכדהסבוגוס'),
MyContact('סלפסאזכעיבקתנע'),
MyContact('יב'),
MyContact('גבבסיתזרדנטרב')
];
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Grouped List Test"),
),
body: Scrollbar(
child: GroupedListView<MyContact, String>(
elements: list,
itemBuilder: (context, element) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
title: Text(element.name),
),
);
},
order: GroupedListOrder.ASC,
groupBy: (element) => element.name.substring(0, 1),
separator: Divider(
height: 0.0,
indent: 16.0,
endIndent: 16.0,
),
useStickyGroupSeparators: true,
groupSeparatorBuilder: (value) => Container(
padding:
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
width: MediaQuery.of(context).size.width,
color: Color(0xffF7F7F7),
child: Text(
value,
style: TextStyle(
fontSize: 18.0,
color: Colors.red,
fontWeight: FontWeight.bold,
),
),
),
),
),
);
}
}
class MyContact {
final String name;
MyContact(this.name);
}
Note - scroll down until you encounter טtest
and you will see the issue.
from grouped_list.
Yeah the problem is that your Class MyContact is not comparable. So you need to implement the Comparable interface in your class and it will work. e.g.
class MyContact implements Comparable {
final String name;
MyContact(this.name);
@override
int compareTo(other) {
return name.compareTo(other.name);
}
}
from grouped_list.
Related Issues (20)
- Is there a way to get the index of an item inside the group? HOT 2
- A GlobalKey can only be specified on one widget at a time in the widget tree. HOT 1
- 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
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.