Skip to content

Instantly share code, notes, and snippets.

@9jaswag
Created January 4, 2019 11:11
Show Gist options
  • Save 9jaswag/69c2179fc3a062eb14954a1ca7f727d9 to your computer and use it in GitHub Desktop.
Save 9jaswag/69c2179fc3a062eb14954a1ca7f727d9 to your computer and use it in GitHub Desktop.
counter bloc demo
import 'package:bloc_counter/counter_provider.dart';
import 'package:flutter/material.dart';
import 'package:bloc_counter/counter_bloc.dart';
class Counter extends StatefulWidget {
@override
_CounterState createState() => _CounterState();
}
class _CounterState extends State<Counter> {
@override
void dispose() {
bloc.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: bloc.getCount,
initialData: CounterProvider().count,
builder: (context, snapshot) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'${snapshot.data}',
style: Theme.of(context).textTheme.display1,
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment