You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
Dart
37 lines
1.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
typedef ScrollCallback = void Function(ScrollNotification notification, ScrollController controller, int itemCount);
|
|
|
|
extension ListViewSeparatedExtension on ListView {
|
|
static Widget separatedWithScrollListener({
|
|
required IndexedWidgetBuilder itemBuilder,
|
|
required IndexedWidgetBuilder separatorBuilder,
|
|
required int itemCount,
|
|
bool shrinkWrap = false,
|
|
EdgeInsetsGeometry padding = EdgeInsets.zero,
|
|
ScrollCallback? onScroll,
|
|
ScrollController? controller,
|
|
ScrollPhysics? physics,
|
|
}) {
|
|
final ScrollController _scrollController = controller ?? ScrollController();
|
|
|
|
return NotificationListener<ScrollNotification>(
|
|
onNotification: (ScrollNotification notification) {
|
|
if (onScroll != null) {
|
|
onScroll(notification, _scrollController, itemCount);
|
|
}
|
|
return false;
|
|
},
|
|
child: ListView.separated(
|
|
controller: _scrollController,
|
|
itemBuilder: itemBuilder,
|
|
padding: padding,
|
|
separatorBuilder: separatorBuilder,
|
|
physics: physics,
|
|
shrinkWrap: shrinkWrap,
|
|
itemCount: itemCount,
|
|
),
|
|
);
|
|
}
|
|
}
|