Skip to content

Commit 1954861

Browse files
authored
fix: time grid 칸 누를 때마다 위로 올라가는 문제 해결 (#156)
1 parent 21c90e3 commit 1954861

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

frontend/ongi/lib/screens/health/exercise_record_detail_screen.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,6 @@ class _ExerciseRecordDetailScreenState
390390
bottom: 20,
391391
child: Center(
392392
child: TimeGrid(
393-
key: ValueKey(
394-
"${selectedDate.year}-${selectedDate.month}-${selectedDate.day}-${selected.length}-${selected.hashCode}",
395-
),
396393
initialSelected: selected,
397394
cellColor: Colors.white,
398395
cellSelectedColor: AppColors.ongiOrange,

frontend/ongi/lib/widgets/time_grid.dart

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,19 @@ class TimeGrid extends StatefulWidget {
2525
class _TimeGridState extends State<TimeGrid> {
2626
late Set<int> _selected;
2727
static const int _startHour = 6;
28+
late ScrollController _scrollController;
2829

2930
@override
3031
void initState() {
3132
super.initState();
3233
_selected = widget.initialSelected.toSet();
34+
_scrollController = ScrollController();
35+
}
36+
37+
@override
38+
void dispose() {
39+
_scrollController.dispose();
40+
super.dispose();
3341
}
3442

3543
@override
@@ -52,6 +60,7 @@ class _TimeGridState extends State<TimeGrid> {
5260
final hours = List<int>.generate(24, (i) => (_startHour + i) % 24);
5361

5462
return SingleChildScrollView(
63+
controller: _scrollController,
5564
child: Column(
5665
children: [
5766
for (var hour in hours)
@@ -75,12 +84,25 @@ class _TimeGridState extends State<TimeGrid> {
7584
GestureDetector(
7685
onTap: widget.onValueChanged != null ? () {
7786
final idx = hour * 6 + seg;
87+
final currentScrollOffset = _scrollController.hasClients
88+
? _scrollController.offset
89+
: 0.0;
90+
7891
setState(() {
79-
if (_selected.contains(idx))
92+
if (_selected.contains(idx)) {
8093
_selected.remove(idx);
81-
else
94+
} else {
8295
_selected.add(idx);
83-
widget.onValueChanged?.call(_selected.toList()..sort());
96+
}
97+
});
98+
99+
widget.onValueChanged?.call(_selected.toList()..sort());
100+
101+
// 스크롤 위치 복원
102+
WidgetsBinding.instance.addPostFrameCallback((_) {
103+
if (_scrollController.hasClients) {
104+
_scrollController.jumpTo(currentScrollOffset);
105+
}
84106
});
85107
} : null,
86108
child: Container(

0 commit comments

Comments
 (0)