circle_wheel_scroll
circle_wheel_scroll copied to clipboard
how to get unlimited scroll?
You can implement CircleListWheelChildLoopingListDelegate and you get infinity scroll: class CircleListWheelChildLoopingListDelegate extends CircleListChildDelegate { /// Constructs the delegate from a concrete list of children. CircleListWheelChildLoopingListDelegate({@required this.children}) : assert(children != null);
/// The list containing all children that can be supplied. final List<Widget> children;
@override int get estimatedChildCount => null;
@override int trueIndexOf(int index) => index % children.length;
@override Widget build(BuildContext context, int index) { if (children.isEmpty) return null; return IndexedSemantics( child: children[index % children.length], index: index); }
@override bool shouldRebuild( covariant CircleListWheelChildLoopingListDelegate oldDelegate) { return children != oldDelegate.children; } }
@definev i cannot get this to work. how do you implement this? thank you
ah i got it now:
import 'package:flutter/material.dart';
import 'package:circle_wheel_scroll/circle_wheel_scroll_view.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: Center(
child: WheelExample(),
),
),
);
}
}
class WheelExample extends StatelessWidget {
const WheelExample({super.key});
Widget _buildItem(int i) {
return Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(40),
child: Container(
width: 80,
padding: const EdgeInsets.all(20),
color: Colors.blue[100 * ((i % 8) + 1)],
child: Center(
child: Text(
'${i.toString()}',
),
),
),
),
);
}
@override
Widget build(BuildContext context) {
// Create the list of children
final children = List.generate(20, _buildItem);
// Create the custom delegate with the children
final delegate =
CircleListWheelChildLoopingListDelegate(children: children);
return Scaffold(
appBar: AppBar(
title: const Text('Wheel example'),
),
body: SafeArea(
child: Center(
child: Container(
child: CircleListScrollView.useDelegate(
physics: const CircleFixedExtentScrollPhysics(),
axis: Axis.horizontal,
itemExtent: 80,
radius: MediaQuery.of(context).size.width * 0.6,
onSelectedItemChanged: (int index) =>
print('Current index: $index'),
childDelegate: delegate,
),
),
),
),
);
}
}
class CircleListWheelChildLoopingListDelegate extends CircleListChildDelegate {
/// Constructs the delegate from a concrete list of children.
CircleListWheelChildLoopingListDelegate({required this.children})
: assert(children != null);
/// The list containing all children that can be supplied.
final List children;
@override
int? get estimatedChildCount => null;
@override
int trueIndexOf(int index) => index % children.length;
@override
Widget? build(BuildContext context, int index) {
if (children.isEmpty) return null;
return IndexedSemantics(
child: children[index % children.length], index: index);
}
@override
bool shouldRebuild(
covariant CircleListWheelChildLoopingListDelegate oldDelegate) {
return children != oldDelegate.children;
}
}