diff --git a/example/lib/chat_example.dart b/example/lib/chat_example.dart index 353d93e..72e614e 100644 --- a/example/lib/chat_example.dart +++ b/example/lib/chat_example.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -97,7 +96,7 @@ List get getOlderMessages => [ ]; class MyApp extends StatefulWidget { - const MyApp({Key? key}) : super(key: key); + const MyApp({super.key}); @override State createState() => _MyAppState(); @@ -268,7 +267,7 @@ class _ChatTimelineState extends State { } class FakeMessageTextField extends StatelessWidget { - const FakeMessageTextField({Key? key}) : super(key: key); + const FakeMessageTextField({super.key}); @override Widget build(BuildContext context) { @@ -302,12 +301,12 @@ class FakeMessageTextField extends StatelessWidget { maxLines: 8, decoration: InputDecoration( prefixIcon: IconButton( - onPressed: () => null, + onPressed: () {}, icon: Icon(Icons.camera_alt_outlined, color: Theme.of(context).primaryColor), ), suffixIcon: IconButton( - onPressed: () => null, + onPressed: () {}, icon: Icon(Icons.send, color: Theme.of(context).primaryColor), ), ), diff --git a/example/lib/example.dart b/example/lib/example.dart index d855ed7..106c427 100644 --- a/example/lib/example.dart +++ b/example/lib/example.dart @@ -13,7 +13,7 @@ List _elements = [ ]; class MyApp extends StatelessWidget { - const MyApp({Key? key}) : super(key: key); + const MyApp({super.key}); @override Widget build(BuildContext context) { @@ -48,7 +48,7 @@ class MyApp extends StatelessWidget { style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), ), - itemBuilder: (c, element) { + itemBuilder: (c, element, prevElement) { return Card( elevation: 8.0, margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0), diff --git a/example/lib/section_example.dart b/example/lib/section_example.dart index 06cb158..5c02796 100644 --- a/example/lib/section_example.dart +++ b/example/lib/section_example.dart @@ -13,7 +13,7 @@ List _elements = [ ]; class MyApp extends StatelessWidget { - const MyApp({Key? key}) : super(key: key); + const MyApp({super.key}); @override Widget build(BuildContext context) { @@ -48,7 +48,7 @@ class MyApp extends StatelessWidget { style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), ), - itemBuilder: (c, element) { + itemBuilder: (c, element, prevElement) { return Card( elevation: 8.0, margin: const EdgeInsets.symmetric(horizontal: 10.0), diff --git a/example/lib/silver_example.dart b/example/lib/silver_example.dart index 407aeae..ecf609c 100644 --- a/example/lib/silver_example.dart +++ b/example/lib/silver_example.dart @@ -13,7 +13,7 @@ List _elements = [ ]; class MyApp extends StatelessWidget { - const MyApp({Key? key}) : super(key: key); + const MyApp({super.key}); @override Widget build(BuildContext context) { diff --git a/example/lib/stream_example.dart b/example/lib/stream_example.dart index b0df384..cb2b1ec 100644 --- a/example/lib/stream_example.dart +++ b/example/lib/stream_example.dart @@ -15,7 +15,7 @@ List _elements = []; int counter = 1; class MyApp extends StatelessWidget { - const MyApp({Key? key}) : super(key: key); + const MyApp({super.key}); @override Widget build(BuildContext context) { @@ -57,7 +57,7 @@ class MyApp extends StatelessWidget { order: GroupedListOrder.DESC, useStickyGroupSeparators: true, groupSeparatorBuilder: (int groupValue) => _createGroupHeader(groupValue), - itemBuilder: (ctx, element) => _createItem(element.name), + itemBuilder: (ctx, element, prevElement) => _createItem(element.name), ); } diff --git a/lib/grouped_list.dart b/lib/grouped_list.dart index 182947a..11d8902 100644 --- a/lib/grouped_list.dart +++ b/lib/grouped_list.dart @@ -60,7 +60,8 @@ class GroupedListView extends StatefulWidget { /// Called to build children for the list with /// 0 <= element < elements.length. - final Widget Function(BuildContext context, T element)? itemBuilder; + final Widget Function(BuildContext context, T element, T? prevElement)? + itemBuilder; /// Called to build the children for the list where the current element /// depends of the previous and next elements @@ -290,7 +291,11 @@ class _GroupedListViewState extends State> { void initState() { _controller = widget.controller ?? ScrollController(); if (widget.useStickyGroupSeparators) { - _controller.addListener(_scrollListener); + _controller.addListener(() { + WidgetsBinding.instance.addPostFrameCallback((_) { + _scrollListener(); + }); + }); } super.initState(); } @@ -425,6 +430,7 @@ class _GroupedListViewState extends State> { : widget.itemBuilder!( context, _sortedElements[index], + index > 0 ? _sortedElements[index - 1] : null, ), ); diff --git a/test/grouped_list_test.dart b/test/grouped_list_test.dart index 3ca46ab..9dc0198 100644 --- a/test/grouped_list_test.dart +++ b/test/grouped_list_test.dart @@ -26,7 +26,7 @@ void main() { order: GroupedListOrder.ASC, groupSeparatorBuilder: (dynamic element) => SizedBox(height: 50, child: Text('$element')), - itemBuilder: (_, dynamic element) => SizedBox( + itemBuilder: (_, dynamic element, dynamic prevElement) => SizedBox( height: 100, child: Text(element['name']), ),