my_home.dart 747 B

123456789101112131415161718192021222324252627282930313233
  1. import 'package:flutter/material.dart';
  2. class MyHomePage extends StatefulWidget {
  3. final String title;
  4. const MyHomePage({Key? key, required this.title}): super(key: key);
  5. @override
  6. _MyHomeState createState() => _MyHomeState();
  7. }
  8. class _MyHomeState extends State<MyHomePage> {
  9. int _counter = 0;
  10. void _incrementCounter() {
  11. setState(() {
  12. _counter++;
  13. });
  14. }
  15. @override
  16. Widget build(BuildContext context) {
  17. // TODO: implement build
  18. return Scaffold(
  19. appBar: AppBar(title: Text(widget.title)),
  20. body: Text('$_counter'),
  21. floatingActionButton: FloatingActionButton(
  22. onPressed: _incrementCounter,
  23. tooltip: 'Increment',
  24. child: Icon(Icons.add),
  25. ),
  26. );
  27. }
  28. }