Advertisement
Guest User

main

a guest
Jul 11th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.58 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_counter/counter_block.dart';
  3. import 'package:flutter_counter/counter_event.dart';
  4.  
  5. void main() => runApp(MyApp());
  6.  
  7. class MyApp extends StatelessWidget {
  8.   @override
  9.   Widget build(BuildContext context) {
  10.     return MaterialApp(
  11.       title: 'Flutter Demo',
  12.       theme: ThemeData(
  13.         primarySwatch: Colors.blue,
  14.       ),
  15.       home: MyHomePage(title: 'Flutter Demo Home Page'),
  16.     );
  17.   }
  18. }
  19.  
  20. class MyHomePage extends StatefulWidget {
  21.   MyHomePage({Key key, this.title}) : super(key: key);
  22.   final String title;
  23.   @override
  24.   _MyHomePageState createState() => _MyHomePageState();
  25. }
  26.  
  27. class _MyHomePageState extends State<MyHomePage> {
  28.   final _bloc = CounterBloc();
  29.  
  30.   @override
  31.   Widget build(BuildContext context) {
  32.     return Scaffold(
  33.       appBar: AppBar(
  34.         title: Text(widget.title),
  35.       ),
  36.       body: Center(
  37.         child: StreamBuilder(
  38.           stream: _bloc.counter,
  39.           initialData: 0,
  40.           builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
  41.             return Column(
  42.               mainAxisAlignment: MainAxisAlignment.center,
  43.               children: <Widget>[
  44.                 Text(
  45.                   'You have pushed the button this many times:',
  46.                 ),
  47.                 Text(
  48.                   '${snapshot.data}',
  49.                   style: Theme.of(context).textTheme.display1,
  50.                 ),
  51.               ],
  52.             );
  53.           },
  54.         ),
  55.       ),
  56.       floatingActionButton: Row(
  57.         mainAxisAlignment: MainAxisAlignment.end,
  58.         children: <Widget>[
  59.           FloatingActionButton(
  60.             onPressed: () => _bloc.counterEventSink.add(IncrementEvent()),
  61.             tooltip: 'Increment',
  62.             child: Icon(Icons.add),
  63.           ),
  64.           SizedBox(width: 10),
  65.           FloatingActionButton(
  66.             onPressed: () => _bloc.counterEventSink.add(DecrementEvent()),
  67.             tooltip: 'Decrement',
  68.             child: Icon(Icons.remove),
  69.           ),
  70.           SizedBox(width: 10),
  71.           FloatingActionButton(
  72.             onPressed: () => _bloc.counterEventSink.add(MultiplyBy3Event()),
  73.             tooltip: 'Multiply',
  74.             child: Text('x'),
  75.           ),
  76.           SizedBox(width: 10),
  77.           FloatingActionButton(
  78.             onPressed: () => _bloc.counterEventSink.add(DivideBy2Event()),
  79.             tooltip: 'Divide',
  80.             child: Text('/'),
  81.           ),
  82.         ],
  83.       ),
  84.     );
  85.   }
  86.  
  87.   @override
  88.   void dispose() {
  89.     super.dispose();
  90.     _bloc.dispose();
  91.   }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement