simple_async_builder 0.1.0 copy "simple_async_builder: ^0.1.0" to clipboard
simple_async_builder: ^0.1.0 copied to clipboard

Async widget builders made simple. Easy to use `Future` and `Stream` builders.

simple_async_builder #

pub package Dart

Simple Future and Stream builder for Flutter. This package provides AsyncFutureBuilder and AsyncStreamBuilder - more developer-friendly versions of FutureBuilder and StreamBuilder.

This package was inspired by async_builder.

Usage #

This simple code:

AsyncFutureBuilder<int>(
  future: Future<int>.delayed(const Duration(seconds: 2), () => 3),
  builder: (context, value) => Text("Button was clicked $value times"),
)

let's you achieve this:

example-widget

Same result can be achieved using Flutter FutureBuilder:

FutureBuilder<int>(
  future: Future<int>.delayed(const Duration(seconds: 2), () => 3),
  builder: (context, snapshot) {
    switch(snapshot.connectionState) {
      case ConnectionState.none:
        return Text("Error");
      case ConnectionState.waiting:
        return CircularProgressIndicator();
      case ConnectionState.active:
      case ConnectionState.done:
        return Center(child: Text('Button was clicked ${snapshot.data ?? 0} times'));
    }
  }
);

You can find a complete example in example/lib/main.dart

Error reporter #

All elements of AsyncFutureBuilder can be customized:

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

  @override
  Widget build(BuildContext context) {
    final futureClickCount = Future<int>.delayed(const Duration(seconds: 2), () => 3);
    return Scaffold(
      appBar: AppBar(title: const Text('Example')),
      body: AsyncFutureBuilder<int>(
        future: futureClickCount,
        waiting: (context) => Row(children: [CircularProgressIndicator(), Text("Loading...")],),
        builder: (context, value) => Center(child: Text('Button was clicked $value times')),
        error: (context, error, stack) => Text("Ups, something went wrong... $error"),
        reportError: (errorDetail) => reportToFirebase(errorDetail.exception.toString()),
      ),
    );
  }

  void reportToFirebase(Object error) {
    debugPrint(error.toString());
  }
}
7
likes
130
pub points
31%
popularity

Publisher

verified publisherkonwencik.pl

Async widget builders made simple. Easy to use `Future` and `Stream` builders.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

either_dart, flutter

More

Packages that depend on simple_async_builder