load_items 0.3.0 copy "load_items: ^0.3.0" to clipboard
load_items: ^0.3.0 copied to clipboard

outdated

Load more items when scrolling to the bottom of a ListView or GridView.

example/lib/main.dart

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

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

class Item {
  int index;
  Item(this.index);
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'load_items',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

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

class _MyHomePageState extends State<MyHomePage> {
  final scrollToTop = ChangeNotifier();

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          title: const Text('load_items'),
          bottom: const TabBar(
            tabs: [
              Tab(icon: Icon(Icons.list)),
              Tab(icon: Icon(Icons.grid_3x3)),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          child: const Icon(Icons.arrow_upward),
          onPressed: () {
            scrollToTop.notifyListeners();
          },
        ),
        body: TabBarView(
          children: [
            LoadItems<Item>(
              type: LoadItemsType.list,
              itemBuilder: itemBuilder,
              itemsLoader: itemsLoader,
              scrollToTopListenable: scrollToTop,
            ),
            LoadItems<Item>(
              type: LoadItemsType.grid,
              itemBuilder: itemBuilder,
              itemsLoader: itemsLoader,
              gridCrossAxisCount: 3,
              scrollToTopListenable: scrollToTop,
            ),
          ],
        ),
      ),
    );
  }

  Widget itemBuilder(BuildContext ctx, item, int index) {
    return ListTile(
      title: SizedBox(
        width: 100,
        height: 100,
        child: ColoredBox(
          color: Colors.redAccent,
          child: Center(
            child: Text('Item ${item.index}'),
          ),
        ),
      ),
    );
  }

  Future<List<Item>> itemsLoader(List currentItems) async {
    await Future.delayed(const Duration(milliseconds: 750));
    return List.generate(16, (i) => Item(currentItems.length + i));
  }
}
6
likes
0
points
34
downloads

Publisher

verified publisherapptakk.com

Weekly Downloads

Load more items when scrolling to the bottom of a ListView or GridView.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on load_items