infinite_widgets 1.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new60

infinite_widgets #

Infinite layout widgets like lists, grids...

Infinite list #

InfiniteListView has same attributes as a normal flutter ListView widget.

InfiniteListView.separated(
        itemBuilder: (context, index) {
          return Text('$index', style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold));
        },
        itemCount: _data.length, // Current itemCount you have
        hasNext: _data.length < 200, // let the widget know if you have more data to show or not
        nextData: this.loadNextData, // callback called when end to the list is reach and hasNext is true
        separatorBuilder: (context, index) => Divider(height: 1),
      ),
    );

You can specify the last loading row by providing loadingWidget.

You can interact with the trigger to load additional data by default it's 300 but you can override it with scrollThreshold.

Infinite grid #

InfiniteGridView has same attributes as a normal flutter GridView widget.

InfiniteGridView(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
        itemBuilder: (context, index) {
          return Text('$index', style: TextStyle(color: Colors.white));
        },
        itemCount: _data.length, // Current itemCount you have
        hasNext: _data.length < 200, // let the widget know if you have more data to show or not
        nextData: this.loadNextData, // callback called when end to the list is reach and hasNext is true
      ),
    );

You can specify the last loading row by providing loadingWidget.

You can interact with the trigger to load additional data by default it's 300 but you can override it with scrollThreshold.

[1.0.0] - 27/01/2019

  • initial release.

example/README.md

example #

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

void main() {
  print('app started');
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      routes: {
        '/': (context) => MyHomePage(title: 'Flutter Demo Home Page'),
        '/list': (context) => InfiniteListExample(),
        '/grid': (context) => InfiniteGridExample(),
      },
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;

  const MyHomePage({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            RaisedButton(
              onPressed: () {
                Navigator.pushNamed(context, '/list');
              },
              child: Text('Infinite list'),
            ),
            RaisedButton(
              onPressed: () {
                Navigator.pushNamed(context, '/grid');
              },
              child: Text('Infinite grid'),
            ),
          ],
        ),
      ),
    );
  }
}

class InfiniteListExample extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _InfiniteListExampleState();
  }
}

class _InfiniteListExampleState extends State<InfiniteListExample> {
  List<int> _data = [];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Infinite list'),
      ),
      body: InfiniteListView.separated(
        itemBuilder: (context, index) {
          return Padding(
            padding: const EdgeInsets.all(12.0),
            child: Text('$index', style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
          );
        },
        itemCount: _data.length,
        hasNext: _data.length < 200,
        nextData: this.loadNextData,
        separatorBuilder: (context, index) => Divider(height: 1),
      ),
    );
  }

  loadNextData() {
    final initialIndex = _data.length;
    final finalIndex = _data.length + 10;
    print('load data from ${_data.length}');

    Future.delayed(Duration(seconds: 3), () {
      for (var i = initialIndex; i < finalIndex; ++i) {
        _data.add(i);
      }
      print('${_data.length} data now');
      setState(() {});
    });
  }
}

class InfiniteGridExample extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _InfiniteGridExampleState();
  }
}

class _InfiniteGridExampleState extends State<InfiniteGridExample> {
  List<int> _data = [];

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Infinite grid'),
      ),
      body: InfiniteGridView(
        gridDelegate:
            SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
        itemBuilder: (context, index) {
          return Padding(
            padding: const EdgeInsets.all(4.0),
            child: Container(
              color: Colors.grey,
              child: Center(
                child: Padding(
                  padding: const EdgeInsets.all(12.0),
                  child: Text('$index', style: TextStyle(color: Colors.white)),
                ),
              ),
            ),
          );
        },
        itemCount: _data.length,
        hasNext: _data.length < 200,
        nextData: this.loadNextData,
      ),
    );
  }

  loadNextData() {
    final initialIndex = _data.length;
    final finalIndex = _data.length + 10;
    print('load data from ${_data.length}');

    Future.delayed(Duration(seconds: 3), () {
      for (var i = initialIndex; i < finalIndex; ++i) {
        _data.add(i);
      }
      print('${_data.length} data now');
      setState(() {});
    });
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  infinite_widgets: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:infinite_widgets/infinite_widgets.dart';
  
Version Uploaded Documentation Archive
1.0.1 Jan 27, 2019 Go to the documentation of infinite_widgets 1.0.1 Download infinite_widgets 1.0.1 archive
1.0.0 Jan 27, 2019 Go to the documentation of infinite_widgets 1.0.0 Download infinite_widgets 1.0.0 archive
0.0.1 Jan 27, 2019 Go to the documentation of infinite_widgets 0.0.1 Download infinite_widgets 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.13+1
  • Flutter: 1.2.1

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test