emptiable_list 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

emptiable_list #

Container for a list-displaying widget, that can display a placeholder-widget when the list is empty.

Can be handy if you are displaying stream of lists in a widget, that supports animations and must remain in widget hierarchy when empty in order to preserve animation states (for example https://pub.dev/packages/animated_stream_list).

EmptiableList always keeps both placeholder and list widgets in a widget tree, thus both of them can have animated transitions. What EmptiableList does, is it keeps both widgets on top of each other, only changing their transparency.

Getting Started #

Create list with placeholder:

Widget build(BuildContext context) {
  return EmptiableList(
            listStream: stream,
            placeholder: Center(child: Text('No items =(')),
            list: AnimatedStreamList(
                streamList: controller.stream,
                itemBuilder: _createItem,
                itemRemovedBuilder: _createItem
            )
  );
}

[1.1.0]

  • While waiting for a first version of a list from a listStream, EmptiableList will display initializingPlaceholder.

[1.0.1]

  • Added documentation.

[1.0.0] Initial release

example/lib/main.dart

import 'dart:async';

import 'package:animated_stream_list/animated_stream_list.dart';
import 'package:emptiable_list/emptiable_list.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(ExampleApp());
}

class ExampleApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ExampleAppState();
  }
}

class _ExampleAppState extends State<ExampleApp> {
  final title = 'Emptiable list example';
  final controller = StreamController<List<String>>.broadcast();
  final items = <String>[];

  @override
  void initState() {
    _initializeListAfterADelay();
  }

  @override
  void dispose() {
    controller.close();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
          actions: <Widget>[
            IconButton(
                icon: Icon(Icons.add),
                onPressed: _add
            ),
            IconButton(
                icon: Icon(Icons.remove),
                onPressed: _remove
            )
          ],
        ),
        body: EmptiableList(
            listStream: controller.stream,
            initializingPlaceholder: Center(child: Text('Loading...')),
            placeholder: Center(child: Text('No items =(')),
            list: AnimatedStreamList(
                streamList: controller.stream,
                itemBuilder: _createItem,
                itemRemovedBuilder: _createItem
            )
        ),
      ),
    );
  }

  Widget _createItem(String item, int index, BuildContext context, Animation<double> animation) {
    return SizeTransition(sizeFactor: animation, child: Text(item));
  }

  void _add() {
    items.add('Item');
    controller.add(items);
  }

  void _remove() {
    items.removeLast();
    controller.add(items);
  }

  void _initializeListAfterADelay() async {
    await Future.delayed(Duration(seconds: 2));
    controller.add(items);
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  emptiable_list: ^1.1.0

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:emptiable_list/emptiable_list.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
25
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]
62
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/emptiable_list.dart. (-0.50 points)

Analysis of lib/emptiable_list.dart reported 1 hint:

line 54 col 8: This method overrides a method annotated as @mustCallSuper in 'State', but doesn't invoke the overridden method.

Dependencies

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