Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ class _MyHomePageState extends State<MyHomePage> {

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
Expand Down Expand Up @@ -115,11 +117,23 @@ class _MyHomePageState extends State<MyHomePage> {
],
),
),
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),
),
],
),
Comment on lines +120 to +136
Copy link

@coderabbitai coderabbitai bot Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

카운터가 음수 값을 가질 수 있습니다.

현재 _decrementCounter 메서드에는 카운터가 음수가 되는 것을 방지하는 로직이 없습니다. 음수가 허용되지 않도록 하려면, 다음과 같이 수정하는 것이 좋습니다:

void _decrementCounter() {
  setState(() {
    if (_counter > 0) {
      _counter--;
    }
  });
}
🔗 Analysis chain

UI 구현이 잘 되었습니다. 음수 값 처리에 대한 고려가 필요할 수 있습니다.

플로팅 액션 버튼의 새로운 구현이 매우 좋습니다. 증가와 감소 기능을 위한 두 개의 버튼을 제공하여 사용자 경험을 향상시켰습니다. Row 위젯과 SizedBox를 사용한 레이아웃 구성도 적절합니다.

다만, 현재 구현에서는 카운터가 음수 값을 가질 수 있습니다. 이것이 의도된 동작인지 확인해 주세요. 만약 음수 값을 허용하지 않으려면, _decrementCounter 메서드에 조건을 추가하는 것이 좋겠습니다. 예를 들어:

void _decrementCounter() {
  setState(() {
    if (_counter > 0) {
      _counter--;
    }
  });
}

이 변경이 필요한지 확인하기 위해 다음 스크립트를 실행해 보세요:

이 스크립트의 결과를 바탕으로 음수 값 처리에 대한 로직 추가 여부를 결정하시기 바랍니다.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there's any logic to prevent negative counter values

rg --type dart "void _decrementCounter\(\)" -A 5 lib/

Length of output: 217

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

과제에 음수를 처리하는 로직은 고려하지 않음

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junsuk5, 알겠습니다. 과제에서는 음수 처리 로직을 고려하지 않으셨군요. 확인했습니다.

(_/)
( T_T)


✏️ Learnings added
Learnt from: junsuk5
PR: SeSAC-Flutter-6/homework_check_test#2
File: lib/main.dart:120-136
Timestamp: 2024-09-27T07:51:02.742Z
Learning: 과제에서는 음수 처리 로직을 고려하지 않습니다.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

);
}
}