lib/main.dart
import 'package:flutter/material.dart';
// リスト 7.6
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(home: CountPage());
}
}
class CountPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _CountPageState();
}
class _CountPageState extends State<CountPage> {
int count = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('カウント'),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
icon: Icon(Icons.remove),
onPressed: () => setState(() {
count--;
}),
),
Text(count.toString()),
IconButton(
icon: Icon(Icons.add),
onPressed: () => setState(() {
count++;
}),
)
],
)
],
)
),
);
}
}