infinity_scroll_shell 0.0.1 copy "infinity_scroll_shell: ^0.0.1" to clipboard
infinity_scroll_shell: ^0.0.1 copied to clipboard

A Flutter widget that simplifies infinite scrolling implementation with built-in data fetching and scroll-to-top functionality.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:infinity_scroll_shell/infinity_scroll_shell.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool _isLoading = false;

  final List<String> _list = List.generate(
    50,
    (index) => "$index",
  ).toList();

  Future<void> _maxScrollExtentObserverFn() async {
    if (_isLoading) return;
    _isLoading = true;
    setState(() {});
    final addList =
        List.generate(10, (index) => "${_list.length + index}").toList();
    _list.addAll(addList);
    setState(() {});
    await Future.delayed(const Duration(milliseconds: 100));
    _isLoading = false;
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: InfinityScrollShell(
        maxScrollExtentObserverFn: _maxScrollExtentObserverFn,
        child: ListView.builder(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemCount: _list.length,
          itemBuilder: (context, index) {
            final text = _list[index];
            return Container(
              alignment: Alignment.center,
              padding: const EdgeInsets.symmetric(vertical: 12),
              child: Text(
                text,
                style: const TextStyle(fontSize: 20),
              ),
            );
          },
        ),
      ),
    );
  }
}
8
likes
160
pub points
0%
popularity

Publisher

unverified uploader

A Flutter widget that simplifies infinite scrolling implementation with built-in data fetching and scroll-to-top functionality.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on infinity_scroll_shell