An rx stream builder widget that is able to pre-populate a flutter StreamBuilder with data from an rx stream if the stream is either a value or a replay observable.

Overview

flutter_rx_stream_builder

A new Flutter package project.

Getting Started

An rx stream builder widget that is able to pre-populate a flutter StreamBuilder with data from an rx stream if the stream is either a value or a replay observable. For example the RX stream is a BehaviorSubject or a ReplaySubject.

This will slightly improve the performance as the first frame will be rendered with data rather than waiting for the stream to emit data.

A normal dart stream can also be passed to this widget and it will behave exactly the same way as a normal Flutter StreamBuilder

Text(snapshot.data), ); }">
Widget build(BuildContext context) {
  return RxStreamBuilder(
      stream: BehaviorSubject.seeded("Hello"),
      builder: (context, snapshot) => Text(snapshot.data),
  );
}

For a more complex example see the example project

The below changes the applications theme every two seconds

import 'package:flutter/material.dart';
import 'dart:math' as math;
import 'package:rxdart/rxdart.dart';
import 'package:flutter_rx_stream_builder/flutter_rx_stream_builder.dart';

class RandomThemeManager {
  final Subject _themeData = BehaviorSubject.seeded(
      ThemeData.light().copyWith(primaryColor: Colors.yellow));

  Observable get themeData => _themeData;

  void initialise() {
    Observable.fromIterable(Iterable.generate(5000, (n) => n))
        .interval(const Duration(seconds: 2))
        .map((_) => ThemeData.light().copyWith(
            primaryColor:
                Color((math.Random().nextDouble() * 0xFFFFFF).toInt() << 0)
                    .withOpacity(1.0)))
        .listen((theme) => _themeData.add(theme));
  }
}

void main() {
  final themeManager = RandomThemeManager();
  themeManager.initialise();
  runApp(MyApp(themeManager.themeData));
}

class MyApp extends StatelessWidget {
  final Observable _themeData$;

  const MyApp(this._themeData$, {Key key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return RxStreamBuilder(
      stream: _themeData$,
      builder: (context, snapshot) => MaterialApp(
            title: 'RxStreamBuilder Demo',
            theme: snapshot.data,
            home: MyHomePage(title: 'Rx StreamBuilder Demo Page'),
          ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
You might also like...

This is a template repository for starting flutter apps with some pre build codes.

flutter_mobile_template A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you

Nov 16, 2022

A customizable carousel slider for Flutter. Supports infinite sliding, custom indicators, and custom animations with many pre-built indicators and animations.

A customizable carousel slider for Flutter. Supports infinite sliding, custom indicators, and custom animations with many pre-built indicators and animations.

Flutter Carousel Slider A customizable carousel slider for flutter Screenshots Installing dependencies: flutter_carousel_slider: ^1.0.8 Demo Demo a

Nov 6, 2022

Flutter package for Android and iOS allow you to show a wide range of hyperlinks either in the input field or in an article view

Flutter package for Android and iOS allow you to show a wide range of hyperlinks either in the input field or in an article view

Tagtly package help you to detect a lot of hyperlink text such as.. email, url, social media tags, hashtag and more either when user type in text field or when appear a text read only.

Jul 25, 2022

:end: A dart package to append either `&` or `and` at the end of a List.

And Game A dart package to append either & or and at the end of a List. Features Appends & or and at the end of the list. Available as method or exten

Sep 24, 2021

A package of pre-built `TextInputFormatter` objects

text_formatters A package of pre-built TextInputFormatter objects to use with Flutter's TextField or TextFormField widgets. Formatters UppercaseInputF

Jul 24, 2020

The Integration Test Helper has pre-configured methods that allow for faster test deployment for end to end (e2e) test coverage.

The Integration Test Helper has pre-configured methods that allow for faster test deployment for end to end (e2e) test coverage.

The Integration Test Helper has pre-configured methods that allow for faster test deployment for end to end (e2e) test coverage (using Android and iOS

Apr 7, 2022

Kids Restaurant is an app that helps people to decide what to cook either for breakfast

Kids Restaurant is an app that helps people to decide what to cook either for breakfast

Kids Restaurant is an app that helps people to decide what to cook either for breakfast, lunch, or dinner, the app gives the user variety of recipes in each section and allows the user to display the recipes written or as a video.

Dec 19, 2022

Data Migrator - provide a universal translator for data by being portable, diverse, and efficient in migrating and converting data across discrete schemas

Data Migrator - provide a universal translator for data by being portable, diverse, and efficient in migrating and converting data across discrete schemas

Data Migrator - provide a universal translator for data by being portable, diverse, and efficient in migrating and converting data across discrete schemas

Jan 2, 2023

Lightweight and blazing fast key-value database written in pure Dart.

Lightweight and blazing fast key-value database written in pure Dart.

Fast, Enjoyable & Secure NoSQL Database Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by Bitcask. Documenta

Dec 30, 2022
Releases(2.0.1)
Owner
Jon Samwell
Full-stack developer (frontend & Flutter specialist) with key interests in user experience, security, and end-to-end testing
Jon Samwell
Csv to list for web - Convert a CSV into a list in order to populate a firebase database

My goal is to convert a CSV into a list in order to populate a firebase database

null 0 Jan 26, 2022
Form builder image picker - Form builder image picker for flutter

form_builder_image_picker Field for picking image(s) from Gallery or Camera for

Ferri Sutanto 0 Jan 28, 2022
Responsive-Ui-builder - The responsive ui builder package contains widgets that helps you to create your UI responsive

Responsive Ui Builder Getting Started The responsive ui builder package contains

null 0 Feb 1, 2022
A pragmatic StreamBuilder with sensible defaults

DataStreamBuilder A pragmatic StreamBuilder with sensible defaults. ?? The problem with StreamBuilder StreamBuilder is an essential tool to work with

Flutter Igniter 17 Dec 16, 2021
This library allows you to create editable tables and spreadsheets with ease, either by providing initial row and column count to display an empty table or use it with predefined rows and column data sets.

Editable ⚡️ A highly customizable, editable table package for Flutter projects. Specs This package allows you to create editable tables and spreadshee

Godwin Asuquo 94 Dec 7, 2022
Rooftop - A photos and videos application which is able to show curated content from Pexel database on the press of a button

rooftop RoofTop is a photos and videos application which is able to show curated

null 2 Feb 7, 2022
A mobile client for the public apis repository, 1400+ free apis to use able to be navigated through your phone :)

Public APIs mobile app Your assistant app that will help you discover and pick the next API for your next development project What it contains, you sa

Gwhyyy 4 Dec 25, 2022
Jannis 0 Jan 29, 2022
Pre-defined setup to start developing flutter project with stacked architecture.

un_official A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if t

Aashish Jha 0 Dec 27, 2021