Coder Social home page Coder Social logo

stream_mixin's Introduction

stream_mixin

State management using stream to avoid use of flutter's State/setState/StatefulWidget, boosting the performance and code separation.

Breaking change in 2.0.0 and 3.0.0. Check the changelog.

The Intention

The intention for this package is to use stream instead of flutter's state for streaming data from the controller/adapter/service class to the widgets, which results in better performance and cleaner code.

Basic example

A basic example of a counter service that increments the count and streams the count to the widget

class Counter with StreamMixin<int> {
  increment() {
    update((lastUpdate ?? 0) + 1);
  }
}

/// You can either create a global instance of Counter or create a
/// singleton (recommented) like class by adding the following in Counter class
/// ```dart
///   Counter._();
///   static Counter instance = Counter._();
/// ```
final counter = Counter();

anywhereInTheApp() {
  counter.increment();
}

Widget someWidget() {
  return StreamBuilder<int>(
    stream: counter.onChange,
    builder: (cxt, snap) => Text((snap.data ?? 0).toString()),
  );
}

Contribute ❤️

There are couple of ways in which you can contribute.

  • Propose any feature, enhancement
  • Report a bug
  • Fix a bug
  • Participate in a discussion and help in decision making
  • Write and improve some documentation. Documentation is super critical and - its importance cannot be overstated!
  • Send in a Pull Request 🙂

stream_mixin's People

Contributors

arnold-parge avatar

Stargazers

 avatar Alexander Schneider avatar Kyle Tse avatar  avatar kawa1214 avatar Enikuomehin Adejuwon avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.