fetch_more

I inspired from Felix Angelov's flutter bloc examples

A Flutter package that helps to collect and show data inside a ListView with a limit and fetch more when user needs more data. Also has a RefreshIndicator that sends request with index zero.

FetchMoreBuilder with specify the LoaderWidgets

You don't need to specify LoaderWidgets.

  Widget buildFetchMoreWidget(BuildContext context) {
    return FetchMoreBuilder(
      errorWidget: Center(child: Text('Error Widget')),
      bottomLoaderWidget: Center(child: Text('Bottom Loader')),
      refreshLoaderWidget: Center(child: Text('Refresh Loader')),
      itemBuilder: _itemBuilder,
      dataFetcher: _dataFetcher,
      limit: 20,
     );
  }

FetchMoreBuilder

  Widget buildFetchMoreWidget(BuildContext context) {
    return FetchMoreBuilder(
      itemBuilder: _itemBuilder,
      dataFetcher: _dataFetcher,
      limit: 20,
     );
  }

DataFetcher:

  Future<List<dynamic>> _dataFetcher(int index, int limit,
      [String searchTerm]) async {
    await Future.delayed(Duration(milliseconds: 1000));
    List list = [];
    if (index == 60) {
      // returning empty List tells to the FetchMoreBuilder data finished.
      return list;
    }
    for (int i = 0; i < limit; i++) {
      Random rdm = Random();
      list.add(rdm.nextInt(100));
    }
    return list;
  }

ItemBuilder

  Widget _itemBuilder(BuildContext context, List list, int index) {
    return Card(
      child: Container(
        height: 50,
        child: Center(
          child: Text(
            list.elementAt(index).toString(),
          ),
        ),
      ),
    );
  }

FetchMoreController Usage

    final GlobalKey<FetchMoreBuilderState> _fetchMoreController =
        GlobalKey<FetchMoreBuilderState>();
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: Text('Fetch More Builder'),
          ),
          body: FetchMoreBuilder(
            fetchMoreController: _fetchMoreController,
            itemBuilder: _itemBuilder,
            dataFetcher: _dataFetcher,
            limit: 10,
          ),
          floatingActionButton: Row(
            crossAxisAlignment: CrossAxisAlignment.end,
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              FloatingActionButton(
                child: Icon(Icons.refresh),
                onPressed: () {
                  _fetchMoreController.currentState.refresh();
                },
              ),
              SizedBox(width: 15,),
              FloatingActionButton(
                child: Icon(Icons.get_app),
                onPressed: () {
                  _fetchMoreController.currentState.fetch();
                },
              ),
            ],
          ),
        ),
      );
    }

screenshot

Getting Started

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Libraries

default_bottom_loader
default_error_builder
default_refresh_loader
fetch_more
fetch_more_bloc
fetch_more_builder
fetch_more_event
fetch_more_state

Dart

VM

dart:ffi
Foreign Function Interface for interoperability with the C programming language. [...]

Web

dart:html
HTML elements and other resources for web-based applications that need to interact with the browser and the DOM (Document Object Model). [...]
dart:js
Low-level support for interoperating with JavaScript. [...]
dart:js_util
Utility methods to efficiently manipulate typed JSInterop objects in cases where the name to call is not known at runtime. You should only use these methods when the same effect cannot be achieved with @JS annotations. These methods would be extension methods on JSObject if Dart supported extension methods.