how to create stream in flutter code example

Example 1: flutter stream stop listen

// Pre-declare variable (can't be final, though).
StreamSubscription<Map<PlaceParam, dynamic>> subscription;
subscription = stream.listen((event) {
  .... subscription.cancel();
});

Example 2: streams flutter

void messagesStream()async{
     await for( var snapshot in _firestore.collection('messages').snapshots()){
       for (var message in snapshot.documents) {
      print(message.data);
    };
  }
  //can be used for chat app

Tags:

Misc Example