백품타에 일시정지/재개 기능 추가

진행 중일 때 일시정지하면 그 구간은 누적 시간에서 빠지고, 재개하면
다시 이어서 잰다. 상태를 idle/running/paused 3가지로 나눠서 관리.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-16 14:49:48 +09:00
co-authored by Claude Sonnet 5
parent 93104362be
commit 094ce2292c
2 changed files with 178 additions and 108 deletions
+91 -54
View File
@@ -60,10 +60,10 @@ class _StudyTimerScreenState extends State<StudyTimerScreen> {
return '$m분';
}
Future<void> _toggle() async {
final (success, message) = _controller.isRunning
? await _controller.stop()
: await _controller.start();
Future<void> _runAction(
Future<(bool success, String message)> Function() action,
) async {
final (success, message) = await action();
if (!mounted) return;
AppNotice.show(
context,
@@ -92,6 +92,7 @@ class _StudyTimerScreenState extends State<StudyTimerScreen> {
listenable: _controller,
builder: (context, _) {
final bool isRunning = _controller.isRunning;
final bool isPaused = _controller.isPaused;
return Scaffold(
backgroundColor: AppPalette.mist,
appBar: AppBar(
@@ -117,7 +118,11 @@ class _StudyTimerScreenState extends State<StudyTimerScreen> {
mainAxisSize: MainAxisSize.min,
children: [
Text(
isRunning ? '지금 공부 중이에요' : '공부를 시작해볼까요?',
isRunning
? '지금 공부 중이에요'
: isPaused
? '일시정지 중이에요'
: '공부를 시작해볼까요?',
style: const TextStyle(
fontSize: 15,
color: Colors.grey,
@@ -126,60 +131,14 @@ class _StudyTimerScreenState extends State<StudyTimerScreen> {
const SizedBox(height: 12),
Text(
_formatHMS(_controller.liveElapsedSeconds),
style: const TextStyle(
style: TextStyle(
fontSize: 52,
fontWeight: FontWeight.bold,
color: AppPalette.ink,
color: isPaused ? Colors.grey : AppPalette.ink,
),
),
const SizedBox(height: 36),
GestureDetector(
onTap: _controller.isBusy ? null : _toggle,
child: Container(
width: 140,
height: 140,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: isRunning
? Colors.red[400]
: AppPalette.ink,
boxShadow: [
BoxShadow(
color:
(isRunning ? Colors.red : AppPalette.ink)
.withValues(alpha: 0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: Center(
child: _controller.isBusy
? const CircularProgressIndicator(
color: Colors.white,
)
: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
isRunning
? Icons.stop_rounded
: Icons.play_arrow_rounded,
color: Colors.white,
size: 36,
),
Text(
isRunning ? '공부 종료' : '공부 시작',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
),
_buildActionButtons(isRunning, isPaused),
const SizedBox(height: 40),
Row(
mainAxisAlignment: MainAxisAlignment.center,
@@ -209,6 +168,84 @@ class _StudyTimerScreenState extends State<StudyTimerScreen> {
);
}
Widget _buildActionButtons(bool isRunning, bool isPaused) {
if (!isRunning && !isPaused) {
return _circleButton(
size: 140,
icon: Icons.play_arrow_rounded,
label: '공부 시작',
color: AppPalette.ink,
onTap: () => _runAction(_controller.start),
);
}
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_circleButton(
size: 110,
icon: isPaused ? Icons.play_arrow_rounded : Icons.pause_rounded,
label: isPaused ? '재개' : '일시정지',
color: isPaused ? AppPalette.ink : Colors.amber[700]!,
onTap: () =>
_runAction(isPaused ? _controller.resume : _controller.pause),
),
const SizedBox(width: 20),
_circleButton(
size: 110,
icon: Icons.stop_rounded,
label: '공부 종료',
color: Colors.red[400]!,
onTap: () => _runAction(_controller.stop),
),
],
);
}
Widget _circleButton({
required double size,
required IconData icon,
required String label,
required Color color,
required VoidCallback onTap,
}) {
return GestureDetector(
onTap: _controller.isBusy ? null : onTap,
child: Container(
width: size,
height: size,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: color,
boxShadow: [
BoxShadow(
color: color.withValues(alpha: 0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: Center(
child: _controller.isBusy
? const CircularProgressIndicator(color: Colors.white)
: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, color: Colors.white, size: size > 120 ? 36 : 28),
Text(
label,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: size > 120 ? 14 : 12.5,
),
),
],
),
),
),
);
}
Widget _statBox(String label, String value) {
return Container(
width: 100,