fetch_more 0.1.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

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.

[0.1.5] - 2019-11-09.

  • FetchMoreController created
  • Able to call fetch and refresh function form FetchMoreController
  • Disable to provide bloc out side of the class

[0.1.4] - 2019-10-09.

  • Adding GlobalKey

[0.1.3] - 2019-10-08.

  • Timer stop fix

[0.1.2] - 2019-10-08.

  • Refresh function awaiting fix

[0.1.1] - 2019-10-07.

  • EmptyList Refresh Fixes

[0.1.0] - 2019-10-02.

  • LoaderWidgets added

[0.0.4] - 2019-09-25.

  • Fix for fetching more data When ListView is not scrollable too.

[0.0.3] - 2019-09-20.

  • CircularProgressIndicator hide fix

[0.0.2] - 2019-09-17.

  • README fix
  • screenshot added.

[0.0.1] - 2019-09-17.

  • FetchMoreBuilder implemented.
  • Example added.
  • README added.

example/README.md

example #

import 'dart:math';

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  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();
              },
            ),
          ],
        ),
      ),
    );
  }

  /// You can get your data from the server in this function
  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;
  }

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

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  fetch_more: ^0.1.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:fetch_more/fetch_more.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
54
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/fetch_more.dart.

Run flutter format to format lib/fetch_more.dart.

Maintenance issues and suggestions

Support latest dependencies. (-30 points)

The version constraint in pubspec.yaml does not support the latest published versions for 3 dependencies (bloc, equatable, flutter_bloc).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
bloc ^0.15.0 0.15.0 1.0.0
equatable ^0.5.1 0.5.1 0.6.1
flutter 0.0.0
flutter_bloc ^0.21.0 0.21.0 1.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
provider 3.1.0+1
rxdart 0.22.4
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test