SHARE
TWEET

Untitled

a guest Sep 18th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2. import 'package:increment_app/bloc/counter.dart';
  3. import 'package:flutter_bloc/flutter_bloc.dart';
  4.  
  5. void main() => runApp(BlocProvider(
  6.       builder: (BuildContext context) => CounterBloc(),
  7.       child: MyApp(),
  8.     ));
  9.  
  10. class MyApp extends StatelessWidget {
  11.   @override
  12.   Widget build(BuildContext context) {
  13.     return MaterialApp(
  14.       title: 'Flutter Demo',
  15.       theme: ThemeData(
  16.         primarySwatch: Colors.blue,
  17.       ),
  18.       home: MyHomePage(title: 'Flutter Demo Home Page'),
  19.     );
  20.   }
  21. }
  22.  
  23. class MyHomePage extends StatefulWidget {
  24.   MyHomePage({Key key, this.title}) : super(key: key);
  25.  
  26.   final String title;
  27.  
  28.   @override
  29.   _MyHomePageState createState() => _MyHomePageState();
  30. }
  31.  
  32. class _MyHomePageState extends State<MyHomePage> {
  33.   @override
  34.   Widget build(BuildContext context) {
  35.     final counterBloc = BlocProvider.of<CounterBloc>(context);
  36.     return BlocBuilder(
  37.         bloc: counterBloc,
  38.         builder: (BuildContext context, CounterState state) {
  39.           final counter = (state as UpdateCounterState).counter;
  40.           return Scaffold(
  41.             appBar: AppBar(
  42.               title: Text(widget.title),
  43.             ),
  44.             body: Center(
  45.               child: Column(
  46.                 mainAxisAlignment: MainAxisAlignment.center,
  47.                 children: <Widget>[
  48.                   Text(
  49.                     'You have pushed the button this many times:',
  50.                   ),
  51.                   Text(
  52.                     '$counter',
  53.                     style: Theme.of(context).textTheme.display1,
  54.                   ),
  55.                 ],
  56.               ),
  57.             ),
  58.             floatingActionButton: Row(mainAxisAlignment: MainAxisAlignment.end,
  59.               children: <Widget>[
  60.                 FloatingActionButton(
  61.                   onPressed: () =>
  62.                       counterBloc.dispatch(IncrementCounter(counter)),
  63.                   tooltip: 'Increment',
  64.                   child: Icon(Icons.add),
  65.                 ),
  66.                 Padding(padding: EdgeInsets.only(left: 20),), // เพิ่มช่องว่าระหว่างปุ่ม
  67.                 FloatingActionButton(
  68.                   onPressed: () =>
  69.                       counterBloc.dispatch(DecrementCounter(counter)),    // ทำหน้าที่ส่ง DecrementCounter(counter) แทน
  70.                   tooltip: 'Decrement',
  71.                   child: Icon(Icons.remove),
  72.                 ),
  73.               ],
  74.             ),
  75.           );
  76.         });
  77.   }
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top