Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,9 @@ class AlarmScreenPreparationInfoBloc extends Bloc<
await getPreparationByScheduleIdUseCase(event.scheduleId);

final List<PreparationStepEntity> steps = prepEntity.preparationStepList;
final int totalPreparationTime =
steps.fold(0, (sum, step) => sum + step.preparationTime.inSeconds);

final int totalRemainingTime = totalPreparationTime;
final List<bool> preparationCompleted =
List<bool>.filled(steps.length, false);

final int preparationRemainingTime =
steps.isNotEmpty ? steps[0].preparationTime.inSeconds : 0;

emit(AlarmScreenPreparationLoadSuccess(
preparationSteps: steps,
currentIndex: 0,
preparationRemainingTime: preparationRemainingTime,
totalPreparationRemainingTime: totalRemainingTime,
preparationCompleted: preparationCompleted,
schedule: event.schedule,
));
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,12 @@ class AlarmScreenPreparationInfoLoadInProgress
class AlarmScreenPreparationLoadSuccess
extends AlarmScreenPreparationInfoState {
final List<PreparationStepEntity> preparationSteps;
final int currentIndex;
final int preparationRemainingTime; // 현재 준비단계의 남은 시간
final int totalPreparationRemainingTime; // 준비 시간 중 남은 시간
final List<bool> preparationCompleted;
final ScheduleEntity schedule;

const AlarmScreenPreparationLoadSuccess(
{required this.preparationSteps,
required this.currentIndex,
required this.preparationRemainingTime,
required this.totalPreparationRemainingTime,
required this.preparationCompleted,
required this.schedule});

/// preparation 내 준비시간 총합 (Getter)
int get totalPreparationTime {
return preparationSteps.fold<int>(
0, (sum, step) => sum + step.preparationTime.inSeconds);
}
const AlarmScreenPreparationLoadSuccess({
required this.preparationSteps,
required this.schedule,
});

/// 지금부터 몇분 뒤에 나가야하는지에 대한 시간. alarm screen 최상단에서 표시.
int get beforeOutTime {
Expand All @@ -46,42 +33,23 @@ class AlarmScreenPreparationLoadSuccess
return remainingDuration.inSeconds;
}

/// 🔹 지각 여부 (Getter)
/// 지각 여부 (Getter)
bool get isLate => beforeOutTime < 0;

// 그래프 비율 계산용 (남은 준비시간 / 총 준비시간)
double get progress => totalPreparationTime == 0
? 0.0
: 1.0 - (totalPreparationRemainingTime / totalPreparationTime);

AlarmScreenPreparationLoadSuccess copyWith({
List<PreparationStepEntity>? preparationSteps,
int? currentIndex,
int? preparationRemainingTime,
int? totalRemainingTime,
List<bool>? preparationCompleted,
ScheduleEntity? schedule,
}) {
return AlarmScreenPreparationLoadSuccess(
preparationSteps: preparationSteps ?? this.preparationSteps,
currentIndex: currentIndex ?? this.currentIndex,
preparationRemainingTime:
preparationRemainingTime ?? this.preparationRemainingTime,
totalPreparationRemainingTime:
totalRemainingTime ?? totalPreparationRemainingTime,
preparationCompleted: preparationCompleted ?? this.preparationCompleted,
schedule: schedule ?? this.schedule,
);
}

@override
List<Object?> get props => [
preparationSteps,
currentIndex,
preparationRemainingTime,
totalPreparationRemainingTime,
preparationCompleted,
schedule,
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:on_time_front/presentation/alarm/bloc/alarm_screen/alarm_timer/alarm_timer_bloc.dart';
import 'package:on_time_front/presentation/alarm/components/alarm_screen/alarm_graph_component.dart';
import 'package:on_time_front/presentation/alarm/components/alarm_graph_component.dart';

class AlarmGraphAnimator extends StatefulWidget {
const AlarmGraphAnimator({super.key});
final double progress;

const AlarmGraphAnimator({
super.key,
required this.progress,
});

@override
_AlarmGraphAnimatorState createState() => _AlarmGraphAnimatorState();
Expand Down Expand Up @@ -39,6 +42,14 @@ class _AlarmGraphAnimatorState extends State<AlarmGraphAnimator>
super.dispose();
}

@override
void didUpdateWidget(covariant AlarmGraphAnimator oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.progress != widget.progress) {
_animateToNewProgress(widget.progress);
}
}

void _animateToNewProgress(double newProgress) {
_progressAnimation = Tween<double>(
begin: previousProgress,
Expand All @@ -54,20 +65,14 @@ class _AlarmGraphAnimatorState extends State<AlarmGraphAnimator>

@override
Widget build(BuildContext context) {
return BlocBuilder<AlarmTimerBloc, AlarmTimerState>(
builder: (context, timerState) {
_animateToNewProgress(timerState.progress);

return AnimatedBuilder(
animation: _progressAnimation,
builder: (context, child) {
return CustomPaint(
size: const Size(230, 115),
painter: AlarmGraphComponent(
progress: _progressAnimation.value,
),
);
},
return AnimatedBuilder(
animation: _progressAnimation,
builder: (context, child) {
return CustomPaint(
size: const Size(230, 115),
painter: AlarmGraphComponent(
progress: _progressAnimation.value,
),
);
},
);
Expand Down

This file was deleted.

Loading