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