Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
StreamProvider example
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
const appTitle = 'StreamProvider Demo';
return MaterialApp(
title: appTitle,
theme: ThemeData(
home: StreamProvider<int>(
initialData: 0,
builder: (context) {
// Pretend this is loading data and reporting the percent loaded.
return Stream<int>
.periodic(Duration(milliseconds: 100), (count) => count + 1)
child: Scaffold(
appBar: AppBar(
title: Text(appTitle),
body: Center(
child: Column(
children: <Widget>[
builder: (context, percentDone, child) {
if (percentDone < 100) {
return Text("Loading... ($percentDone% done)");
return Text("Done loading!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.