Skip to content

thanhdatvo/customized_streams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CustomizedStreams

About

CustomizedStreams adds additional capabilities to Dart Streams and StreamControllers.

CustomizedStreams provides a number of additional Subjects that help transfrom type and value of stream.

Usage

Transform stream from one type to another type

import 'package:customized_streams/customized_streams.dart';

Stream<int> _transformCountLength(String text) async* {
  yield text.length;
}

void main() {
  var ts =
      TransformerSubject<String, int>(_transformCountLength);
  ts.outputStream.listen((data) {
    print("Length of " +
        ts.inputValue +
        " is " +
        data.toString()); // Print: Length of HelloWorld is 11
  }, onDone: () {
    ts.dispose();
  });
  ts.add("Hello World");
}

Defered stream: new stream will initialized with latest value

import 'package:customized_streams/customized_streams.dart';

Stream<int> _transformCountLength(String text) async* {
  yield text.length;
}

void main() async {
  var ts = TransformerSubject<String, int>(_transformCountLength);
  var inputStream1 = ts.inputStream;
  inputStream1.listen((data) {
    print(data); // ["Hello", "World", "Developer"]
  });
  ts.add("Hello");
  ts.add("World");
  await Future.delayed(Duration(seconds: 1));
  var inputStream2 = ts.inputStream;
  inputStream2.listen((data) {
    print(data); // ["World", "Developer"]
  }, onDone: () {
    ts.dispose();
  });

  ts.add("Developer");
}

Flutter Example

Install Flutter

In order to run the flutter example, you must have Flutter installed. For installation instructions, view the online documentation.

Run the app

  1. Open up an Android Emulator, the iOS Simulator, or connect an appropriate mobile device for debugging.
  2. Open up a terminal
  3. cd into the example directory
  4. Run flutter doctor to ensure you have all Flutter dependencies working.
  5. Run flutter packages get
  6. Run flutter run

Changelog

Refer to the Changelog to get all release notes.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published