Async Widgets Handle Streams and Futures

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.

Example Code

file_type_dartlang main.dart
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'dart:async';

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

class MyApp extends StatelessWidget {
 Widget build(BuildContext context) {
   return MaterialApp(
     home: HomeScreen(),

class HomeScreen extends StatelessWidget {

 final Firestore db = Firestore.instance;

 Widget build(BuildContext context) {
   return Scaffold(
     appBar: AppBar(title: Text('Home')),
     body: Center(
       child: StreamBuilder<DocumentSnapshot>(
         stream: db.collection('users').document('mB6sGaFBczfIW50DJyvGDcQWOvW2').snapshots(),
         builder: (context, snapshot) {
           if (snapshot.hasData) {

             var data =;

             return Column(
               mainAxisAlignment: MainAxisAlignment.spaceEvenly,
               children: <Widget>[

                 Text(data['username'], style: Theme.of(context).textTheme.display1,),

           } else {
             return Container();



Ask questions via GitHub below OR chat on Slack #questions