1. import 'package:flutter/material.dart';
    2. void main() {
    3. runApp(MyApp());
    4. }
    5. class MyApp extends StatelessWidget {
    6. // This widget is the root of your application.
    7. @override
    8. Widget build(BuildContext context) {
    9. return MaterialApp(
    10. title: 'Flutter Demo',
    11. theme: ThemeData(
    12. primarySwatch: Colors.blue,
    13. ),
    14. home: MyHomePage(title: 'Flutter Demo Home Page'),
    15. );
    16. }
    17. }
    18. class MyHomePage extends StatefulWidget {
    19. MyHomePage({Key key, this.title}) : super(key: key);
    20. final String title;
    21. @override
    22. _MyHomePageState createState() => _MyHomePageState();
    23. }
    24. class _MyHomePageState extends State<MyHomePage> {
    25. int _counter = 0;
    26. void _incrementCounter() {
    27. setState(() {
    28. _counter++;
    29. });
    30. }
    31. @override
    32. Widget build(BuildContext context) {
    33. return Scaffold(
    34. appBar: AppBar(
    35. title: Text(widget.title),
    36. ),
    37. body: Center(
    38. child: Column(
    39. mainAxisAlignment: MainAxisAlignment.center,
    40. children: <Widget>[
    41. Text(
    42. 'You have pushed the button this many times:',
    43. ),
    44. Text(
    45. '$_counter',
    46. style: Theme.of(context).textTheme.headline4,
    47. ),
    48. ],
    49. ),
    50. ),
    51. floatingActionButton: FloatingActionButton(
    52. onPressed: _incrementCounter,
    53. tooltip: 'Increment',
    54. child: Icon(Icons.add),
    55. ), // This trailing comma makes auto-formatting nicer for build methods.
    56. );
    57. }
    58. }