home_page.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import 'package:flutter/material.dart';
  2. class MyHomePage extends StatefulWidget {
  3. const MyHomePage({super.key, required this.title});
  4. final String title;
  5. @override
  6. State<MyHomePage> createState() => _MyHomePageState();
  7. }
  8. class _MyHomePageState extends State<MyHomePage> {
  9. int _counter = 0;
  10. void _incrementCounter() {
  11. setState(() {
  12. _counter++;
  13. });
  14. }
  15. @override
  16. Widget build(BuildContext context) {
  17. return Scaffold(
  18. appBar: AppBar(
  19. backgroundColor: Theme.of(context).colorScheme.inversePrimary,
  20. title: Text(widget.title),
  21. ),
  22. body: Center(
  23. child: Column(
  24. mainAxisAlignment: MainAxisAlignment.center,
  25. children: <Widget>[
  26. const Text(
  27. 'You have pushed the button this many times:',
  28. ),
  29. Text(
  30. '$_counter',
  31. style: Theme.of(context).textTheme.headlineMedium,
  32. ),
  33. ],
  34. ),
  35. ),
  36. floatingActionButton: FloatingActionButton(
  37. onPressed: _incrementCounter,
  38. tooltip: 'Increment',
  39. child: const Icon(Icons.add),
  40. ),
  41. );
  42. }
  43. }