StreamBuilder - Flutter

In This post we are going to learn StreamBuilder in flutter

Let's start

Step 1: Create Flutter Application

Step 2: Create dart file and update below code

import 'dart:async';

import 'package:flutter/material.dart';

class StreamBuilderWidget extends StatelessWidget{
  var index = 0;
  StreamSubscription<String> subscription;

  var streamController = StreamController<String>();

  //To Emit the stream
  StreamSink<String> get streamSink  => streamController.sink;

  Stream<String> get streamData =>;


  void onFloatActionButtonPress() {


  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(title: Text("Stream Builder"),
      body: Center(
        child:  StreamBuilder<String>(
            stream: streamData,
            builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
              return Text('Result: ${}');
        floatingActionButton: FloatingActionButton(
            onPressed: onFloatActionButtonPress,
            child: Icon(Icons.add))





Step 3: Update main dart file with below code

void main() => runApp(MyApp());

class MyApp extends StatelessWidget{
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      theme: ThemeData(
      home: StreamBuilderWidget(),



Step 4: Run application

StreamBuilder Flutter