joaopaulofcc

Untitled

Dec 2nd, 2020
1,152
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:mobxteste/counter.dart';
  2. import 'package:flutter/material.dart';
  3.  
  4. void main() {
  5.   runApp(MyApp());
  6. }
  7.  
  8. final counter = Counter();
  9.  
  10. class MyApp extends StatelessWidget {
  11.   // This widget is the root of your application.
  12.   @override
  13.   Widget build(BuildContext context) {
  14.     return MaterialApp(
  15.       title: 'Flutter Demo',
  16.       theme: ThemeData(
  17.         // This is the theme of your application.
  18.         //
  19.         // Try running your application with "flutter run". You'll see the
  20.         // application has a blue toolbar. Then, without quitting the app, try
  21.         // changing the primarySwatch below to Colors.green and then invoke
  22.         // "hot reload" (press "r" in the console where you ran "flutter run",
  23.         // or simply save your changes to "hot reload" in a Flutter IDE).
  24.         // Notice that the counter didn't reset back to zero; the application
  25.         // is not restarted.
  26.         primarySwatch: Colors.blue,
  27.         // This makes the visual density adapt to the platform that you run
  28.         // the app on. For desktop platforms, the controls will be smaller and
  29.         // closer together (more dense) than on mobile platforms.
  30.         visualDensity: VisualDensity.adaptivePlatformDensity,
  31.       ),
  32.       home: MyHomePage(title: 'Flutter Demo Home Page'),
  33.     );
  34.   }
  35. }
  36.  
  37. class MyHomePage extends StatefulWidget {
  38.   MyHomePage({Key key, this.title}) : super(key: key);
  39.  
  40.   // This widget is the home page of your application. It is stateful, meaning
  41.   // that it has a State object (defined below) that contains fields that affect
  42.   // how it looks.
  43.  
  44.   // This class is the configuration for the state. It holds the values (in this
  45.   // case the title) provided by the parent (in this case the App widget) and
  46.   // used by the build method of the State. Fields in a Widget subclass are
  47.   // always marked "final".
  48.  
  49.   final String title;
  50.  
  51.   @override
  52.   _MyHomePageState createState() => _MyHomePageState();
  53. }
  54.  
  55. class _MyHomePageState extends State<MyHomePage> {
  56.   int _counter = 0;
  57.  
  58.   void _incrementCounter() {
  59.     setState(() {
  60.       counter.increment(); // Antes era _counter++;
  61.     });
  62.   }
  63.  
  64.   @override
  65.   Widget build(BuildContext context) {
  66.     // This method is rerun every time setState is called, for instance as done
  67.     // by the _incrementCounter method above.
  68.     //
  69.     // The Flutter framework has been optimized to make rerunning build methods
  70.     // fast, so that you can just rebuild anything that needs updating rather
  71.     // than having to individually change instances of widgets.
  72.     return Scaffold(
  73.       appBar: AppBar(
  74.         // Here we take the value from the MyHomePage object that was created by
  75.         // the App.build method, and use it to set our appbar title.
  76.         title: Text(widget.title),
  77.       ),
  78.       body: Center(
  79.         // Center is a layout widget. It takes a single child and positions it
  80.         // in the middle of the parent.
  81.         child: Column(
  82.           // Column is also a layout widget. It takes a list of children and
  83.           // arranges them vertically. By default, it sizes itself to fit its
  84.           // children horizontally, and tries to be as tall as its parent.
  85.           //
  86.           // Invoke "debug painting" (press "p" in the console, choose the
  87.           // "Toggle Debug Paint" action from the Flutter Inspector in Android
  88.           // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
  89.           // to see the wireframe for each widget.
  90.           //
  91.           // Column has various properties to control how it sizes itself and
  92.           // how it positions its children. Here we use mainAxisAlignment to
  93.           // center the children vertically; the main axis here is the vertical
  94.           // axis because Columns are vertical (the cross axis would be
  95.           // horizontal).
  96.           mainAxisAlignment: MainAxisAlignment.center,
  97.           children: <Widget>[
  98.             Text(
  99.               'You have pushed the button this many times:',
  100.             ),
  101.             Text(
  102.               '${counter.value}', // Antes era $_counter
  103.               style: Theme.of(context).textTheme.headline4,
  104.             ),
  105.           ],
  106.         ),
  107.       ),
  108.       floatingActionButton: FloatingActionButton(
  109.         onPressed: _incrementCounter,
  110.         tooltip: 'Increment',
  111.         child: Icon(Icons.add),
  112.       ), // This trailing comma makes auto-formatting nicer for build methods.
  113.     );
  114.   }
  115. }
RAW Paste Data