Skip to content

Commit

Permalink
Added 10s progress bar of get ready to next stage
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Apr 16, 2024
1 parent 5f7dd73 commit 72a11e5
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 56 deletions.
18 changes: 9 additions & 9 deletions lib/domain/study_type_abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ extension StudyTypeExtension on StudyType {
}

enum EnergyType {
undefined('undefined', 0),
veryLow('Very Low', 5),
low('Low', 10),
medium('Medium', 25),
high('High', 40),
veryHigh('Very High', 60),
max('Max', 90),
undefined('undefined', Duration.zero),
veryLow('Very Low', Duration(minutes: 5)),
low('Low', Duration(minutes: 10)),
medium('Medium', Duration(minutes: 25)),
high('High', Duration(minutes: 40)),
veryHigh('Very High', Duration(minutes: 60)),
max('Max', Duration(minutes: 90)),
;

const EnergyType(this.previewName, this.minutes);
final int minutes;
const EnergyType(this.previewName, this.duration);
final Duration duration;
final String previewName;
}
1 change: 1 addition & 0 deletions lib/presentation/atoms/atoms.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export 'package:infinite_horizons/presentation/atoms/button_atom.dart';
export 'package:infinite_horizons/presentation/atoms/check_box_atom.dart';
export 'package:infinite_horizons/presentation/atoms/list_tile_atom.dart';
export 'package:infinite_horizons/presentation/atoms/progress_indicator_atom.dart';
export 'package:infinite_horizons/presentation/atoms/separator_atom.dart';
export 'package:infinite_horizons/presentation/atoms/text_atom.dart';
export 'package:infinite_horizons/presentation/atoms/timer_atom.dart';
4 changes: 3 additions & 1 deletion lib/presentation/atoms/list_tile_atom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import 'package:flutter/material.dart';
import 'package:infinite_horizons/presentation/atoms/atoms.dart';

class ListTileAtom extends StatelessWidget {
const ListTileAtom(this.title, this.leading);
const ListTileAtom(this.title, this.leading, {this.subtitle});

final String title;
final String? subtitle;
final Widget leading;

@override
Widget build(BuildContext context) {
return ListTile(
title: TextAtom(title),
subtitle: subtitle == null ? null : TextAtom(subtitle!),
leading: leading,
);
}
Expand Down
52 changes: 52 additions & 0 deletions lib/presentation/atoms/progress_indicator_atom.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';

class ProgressIndicatorAtom extends StatefulWidget {
const ProgressIndicatorAtom(this.totalDuration, this.callback);

/// In Seconds
final Duration totalDuration;
final VoidCallback callback;

@override
State<ProgressIndicatorAtom> createState() => _ProgressIndicatorAtomState();
}

class _ProgressIndicatorAtomState extends State<ProgressIndicatorAtom>
with TickerProviderStateMixin {
late AnimationController controller;

@override
void initState() {
updateProgress();
super.initState();
}

void updateProgress() {
controller = AnimationController(
vsync: this,
duration: widget.totalDuration,
);
controller.addListener(() {
setState(() {});
});
controller.addStatusListener((status) {
if (status == AnimationStatus.completed) {
widget.callback();
}
});
controller.forward();
}

@override
void dispose() {
controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return LinearProgressIndicator(
value: controller.value,
);
}
}
14 changes: 10 additions & 4 deletions lib/presentation/atoms/timer_atom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import 'package:circular_countdown_timer/circular_countdown_timer.dart';
import 'package:flutter/material.dart';

class TimerAtom extends StatelessWidget {
const TimerAtom(this.controller, this.timerMinutes);
const TimerAtom(this.controller, this.timer, this.callback);

final CountDownController controller;
final int timerMinutes;
final Duration timer;
final VoidCallback callback;

void onComplete() {
// TODO: Play complete sound
callback();
}

@override
Widget build(BuildContext context) {
return CircularCountDownTimer(
duration: timerMinutes,
duration: timer.inSeconds,
controller: controller,
width: MediaQuery.of(context).size.width / 2,
height: MediaQuery.of(context).size.height / 2,
Expand All @@ -26,7 +32,7 @@ class TimerAtom extends StatelessWidget {
textFormat: CountdownTextFormat.S,
isReverseAnimation: true,
isReverse: true,
autoStart: false,
onComplete: onComplete,
);
}
}
12 changes: 6 additions & 6 deletions lib/presentation/molecules/energy_selection_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _EnergySelectionMoleculeState extends State<EnergySelectionMolecule> {
const TextAtom('Classic Pomodoro:'),
const SeparatorAtom(),
ListTileAtom(
'${EnergyType.medium.previewName} - ${EnergyType.medium.minutes}m',
'${EnergyType.medium.previewName} - ${EnergyType.medium.duration.inMinutes}m',
Radio<EnergyType>(
value: EnergyType.medium,
groupValue: energy,
Expand All @@ -50,39 +50,39 @@ class _EnergySelectionMoleculeState extends State<EnergySelectionMolecule> {
Column(
children: [
ListTileAtom(
'${EnergyType.max.previewName} - ${EnergyType.max.minutes}m',
'${EnergyType.max.previewName} - ${EnergyType.max.duration.inMinutes}m',
Radio<EnergyType>(
value: EnergyType.max,
groupValue: energy,
onChanged: onChanged,
),
),
ListTileAtom(
'${EnergyType.veryHigh.previewName} - ${EnergyType.veryHigh.minutes}m',
'${EnergyType.veryHigh.previewName} - ${EnergyType.veryHigh.duration.inMinutes}m',
Radio<EnergyType>(
value: EnergyType.veryHigh,
groupValue: energy,
onChanged: onChanged,
),
),
ListTileAtom(
'${EnergyType.high.previewName} - ${EnergyType.high.minutes}m',
'${EnergyType.high.previewName} - ${EnergyType.high.duration.inMinutes}m',
Radio<EnergyType>(
value: EnergyType.high,
groupValue: energy,
onChanged: onChanged,
),
),
ListTileAtom(
'${EnergyType.low.previewName} - ${EnergyType.low.minutes}m',
'${EnergyType.low.previewName} - ${EnergyType.low.duration.inMinutes}m',
Radio<EnergyType>(
value: EnergyType.low,
groupValue: energy,
onChanged: onChanged,
),
),
ListTileAtom(
'${EnergyType.veryLow.previewName} - ${EnergyType.veryLow.minutes}m',
'${EnergyType.veryLow.previewName} - ${EnergyType.veryLow.duration.inMinutes}m',
Radio<EnergyType>(
value: EnergyType.veryLow,
groupValue: energy,
Expand Down
2 changes: 2 additions & 0 deletions lib/presentation/molecules/study_type_selection_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class _StudyTypeSelectionMoleculeState
groupValue: selectedType,
onChanged: onChanged,
),
subtitle: 'Recommended in the morning',
),
ListTileAtom(
StudyType.creatively.previewName,
Expand All @@ -55,6 +56,7 @@ class _StudyTypeSelectionMoleculeState
groupValue: selectedType,
onChanged: onChanged,
),
subtitle: 'Recommended in the evening',
),
],
);
Expand Down
2 changes: 2 additions & 0 deletions lib/presentation/organisms/intro/motivation_organism.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class MotivationOrganism extends StatelessWidget {
case EnergyType.max:
text = "So much energy 🔋⚡🔋⚡🔋⚡🔋\nLet's begin";
}
// TODO: Center the elements on the page
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextAtom(text),
const SeparatorAtom(variant: SeparatorVariant.farAppart),
Expand Down
13 changes: 7 additions & 6 deletions lib/presentation/organisms/intro/tips_organism.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ class TipsOrganism extends StatelessWidget {
},
itemCount: StudyTypeAbstract.instance!.getTips().length,
),
const Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextAtom('Full list'),
],
),
// TODO: Add full list page
// const Row(
// mainAxisAlignment: MainAxisAlignment.end,
// children: [
// TextAtom('Full list'),
// ],
// ),
],
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/presentation/organisms/organisms.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'package:infinite_horizons/presentation/organisms/intro/motivation_organism.dart';
export 'package:infinite_horizons/presentation/organisms/intro/tips_organism.dart';
export 'package:infinite_horizons/presentation/organisms/intro/welcome_organism.dart';
export 'package:infinite_horizons/presentation/organisms/timer_molecule.dart';
46 changes: 46 additions & 0 deletions lib/presentation/organisms/timer_molecule.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:circular_countdown_timer/circular_countdown_timer.dart';
import 'package:flutter/cupertino.dart';
import 'package:infinite_horizons/presentation/atoms/atoms.dart';

class TimerMolecule extends StatelessWidget {
TimerMolecule(this.onComplete, this.duration);

final Duration duration;
final VoidCallback onComplete;

final CountDownController controller = CountDownController();

@override
Widget build(BuildContext context) {
return Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: TimerAtom(
controller,
duration,
onComplete,
),
),
const SeparatorAtom(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ButtonAtom(
variant: ButtonVariant.primary,
onPressed: controller.resume,
text: 'Continue',
),
ButtonAtom(
variant: ButtonVariant.secondary,
onPressed: controller.pause,
text: 'Pause',
),
],
),
],
),
);
}
}
Loading

0 comments on commit 72a11e5

Please sign in to comment.