Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get unlimited scroll? #12

Open
suryakka opened this issue Jun 11, 2020 · 3 comments
Open

how to get unlimited scroll? #12

suryakka opened this issue Jun 11, 2020 · 3 comments

Comments

@suryakka
Copy link

No description provided.

@definev
Copy link

definev commented Aug 10, 2020

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 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;
}
}

@jtkeyva
Copy link

jtkeyva commented Sep 1, 2023

@definev i cannot get this to work. how do you implement this? thank you

@jtkeyva
Copy link

jtkeyva commented Sep 1, 2023

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;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants