my_home_page.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import 'package:flutter/material.dart';
  2. class MyHomePage extends StatefulWidget {
  3. MyHomePage({Key key, this.title}) : super(key: key);
  4. final String title;
  5. @override
  6. _MyHomePageState 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. title: Text(widget.title),
  20. ),
  21. body: Center(
  22. child: Column(
  23. mainAxisAlignment: MainAxisAlignment.center,
  24. children: <Widget>[
  25. Text(
  26. '您点击+号多次:',
  27. ),
  28. Text(
  29. '$_counter',
  30. style: Theme.of(context).textTheme.display1,
  31. ),
  32. ],
  33. ),
  34. ),
  35. floatingActionButton: FloatingActionButton(
  36. onPressed: _incrementCounter,
  37. tooltip: 'Increment',
  38. child: Icon(Icons.add),
  39. ), // This trailing comma makes auto-formatting nicer for build methods.
  40. );
  41. }
  42. }