From 6fe98c2fab9441c92ae69770702343de2d81c4b2 Mon Sep 17 00:00:00 2001 From: Junsuk Oh Date: Fri, 27 Sep 2024 14:42:06 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=99=84=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 8e94089..fa92b60 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -59,15 +59,17 @@ class _MyHomePageState extends State { void _incrementCounter() { setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. _counter++; }); } + // 새로운 메서드 추가: 카운터 감소 + void _decrementCounter() { + setState(() { + _counter--; + }); + } + @override Widget build(BuildContext context) { // This method is rerun every time setState is called, for instance as done @@ -115,11 +117,23 @@ class _MyHomePageState extends State { ], ), ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. + floatingActionButton: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + // 감소 버튼 추가 + FloatingActionButton( + onPressed: _decrementCounter, + tooltip: 'Decrement', + child: const Icon(Icons.remove), + ), + const SizedBox(width: 10), // 버튼 간격 + FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + ], + ), ); } }