You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.1KB

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