Stream Example In Flutter

Stream Example In Flutter :

Stream Example In Flutter
import 'dart:async';
import 'dart:convert';
import 'dart:io';

main() {
  var data = [1, 2, 3, 4, 5]; // some sample data
  var stream = new Stream.fromIterable(data); // create the stream

  // subscribe to the streams events
/*
  stream.listen((value) {       //
    print("Received: $value");  // onData handler
  });
*/
  
  //Flutter stream listen
  stream.listen((value) => print("listen: $value"),
      onError: (err) => print("error: $err"), onDone: () => print("done"));

  //File read flutter using Stream transform
  File file = new File("D://FlutterTutorial.txt");
  file
      .openRead()
      .transform(utf8.decoder) // use a UTF8.decoder
      .listen((String data) => print(data), // output the data
          onError: (error) => print("Error, could not open file"),
          onDone: () => print("Finished reading data"));
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful applicationFor more information about Flutter. visit www.fluttertutorial.in