Giter Club home page Giter Club logo

Comments (5)

Dimibe avatar Dimibe commented on August 10, 2024

@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.

CripyIce avatar CripyIce commented on August 10, 2024

@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.

Dimibe avatar Dimibe commented on August 10, 2024

Fixed in version 2.2.0

from grouped_list.

CripyIce avatar CripyIce commented on August 10, 2024

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.

Dimibe avatar Dimibe commented on August 10, 2024

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)

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.