rxdart_builders 1.0.1

rxdart_builders #

About #

Rxdart_builder is a simple wrapper library for common rxdart Stream constructors. The goal is to provide a Flutter-friendly way of creating Widgets, as opposed to combining StreamBuilder and a Stream constructor.

This package is totally optional, you can just use direct rxdart constructors if you prefer to.

Using rxdart_builders instead of StreamBuilder makes your UI more expressive, the difference in approach is best described via a few examples:

Example with combineLatest, pure rxdart #

Widget build(BuildContext context) => StreamBuilder(
    stream: Rx.combineLatest2(
        Stream.periodic(const Duration(seconds: 1), (i) => i),
        Stream.periodic(const Duration(seconds: 2), (i) => i),
        (int a, int b) => [a, b]),
    initialData: [-1, null],
    builder: (context, AsyncSnapshot<List<int>> snapshot) =>
        Text('${snapshot.data.first}, ${snapshot.data.last}'),

Example with combineLatest, rxdart_builders #

Here there is no need to write a handler which combines the events into one single event, the builder method will list as AsyncSnapshot for each individual event instead.

Widget build(BuildContext context) => CombineLatest2Builder(
    streamA: Stream.periodic(const Duration(seconds: 1), (i) => i),
    streamB: Stream.periodic(const Duration(seconds: 2), (i) => i),
    initialDataA: -1,
        (context, AsyncSnapshot<int> snapshotA, AsyncSnapshot<int> snapshotB) =>
            Text('${snapshotA.data}, ${snapshotB.data}'),

Example with retry, pure rxdart #

Widget build(BuildContext context) => StreamBuilder(
    stream: Rx.retry(() => userStream, 3),
    builder: (context, AsyncSnapshot<User> snapshot) {
        if (snapshot.hasError) {
          return Text('Oops!');

        return Text('OK');

Example with retry, rxdart_builders #

For convenience, you can optionally use a retryErrorBuilder, should the retry have failed for count amount of times.

Widget build(BuildContext context) => RetryBuilder(
    count: 3,
    streamFactory: () => userStream,
    builder: (context, AsyncSnapshot<User> snapshot) => Text('OK'),
    retryErrorBuilder: (context, AsyncSnapshot<User> snapshot) => Text('Oops!'),

Complete list of builders #

  • CombineLatestNBuilder, where N is the amount of streams you combine
  • ConcatBuilder
  • ConcatEagerBuilder
  • DeferBuilder
  • ForkJoinBuilder
  • MergeBuilder
  • RaceBuilder
  • RepeatBuilder
  • RetryBuilder
  • RetryWhenBuilder
  • SwitchLatestBuilder
  • ZipNBuilder, where N is the amount of streams you combine

[1.0.1] - 02/01/2020.

  • formatting

[1.0.0] - 02/01/2020.

  • This initial release exposes a number of rxdart Rx constructors as Flutter builder widgets.


example #

Rxdart builders example

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

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

Use this package as a library

1. Depend on it

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

  rxdart_builders: ^1.0.1

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:rxdart_builders/rxdart_builders.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
rxdart ^0.23.1 0.23.1
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
pedantic ^1.8.0