Skip to content

Commit

Permalink
fix breathing circle
Browse files Browse the repository at this point in the history
  • Loading branch information
waozixyz committed Apr 25, 2024
1 parent d6fbcfa commit 96f3c2f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/widgets/breathing_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:localization/localization.dart';
import 'package:provider/provider.dart';
import 'package:inner_breeze/models/preferences.dart';

enum BreathingTempo {slow, medium, fast, rapid}
enum BreathingTempo { slow, medium, fast, rapid }

class BreathingConfiguration extends StatefulWidget {
@override
Expand All @@ -15,7 +15,7 @@ class BreathingConfiguration extends StatefulWidget {
class BreathingConfigurationState extends State<BreathingConfiguration> {
int breaths = 30;
int volume = 100;
Duration tempoDuration = Duration(milliseconds: 1668);
Duration tempoDuration = Duration(milliseconds: 1668);
String animationCommand = 'repeat';

@override
Expand All @@ -26,14 +26,16 @@ class BreathingConfigurationState extends State<BreathingConfiguration> {

Future<void> _loadUserPreferences() async {
final userProvider = Provider.of<UserProvider>(context, listen: false);
final prefs = await userProvider.loadUserPreferences(['breaths', 'tempo', 'volume']);

final prefs =
await userProvider.loadUserPreferences(['breaths', 'tempo', 'volume']);

setState(() {
tempoDuration = Duration(milliseconds: prefs.tempo);
breaths = prefs.breaths;
volume = prefs.volume;
});
}

Duration computeTempoDuration(double value) {
int millis = (3000 - value * 666).toInt().clamp(1000, 3000);
return Duration(milliseconds: millis);
Expand Down Expand Up @@ -74,7 +76,8 @@ class BreathingConfigurationState extends State<BreathingConfiguration> {
}

String capitalizeEnumValue(String enumValue) {
return enumValue[0].toUpperCase() + enumValue.substring(1, enumValue.length);
return enumValue[0].toUpperCase() +
enumValue.substring(1, enumValue.length);
}

@override
Expand All @@ -83,6 +86,7 @@ class BreathingConfigurationState extends State<BreathingConfiguration> {

return Column(
children: [
SizedBox(height: 90),
Center(
child: AnimatedCircle(
tempoDuration: tempoDuration,
Expand All @@ -92,7 +96,7 @@ class BreathingConfigurationState extends State<BreathingConfiguration> {
},
),
),
SizedBox(height: 190),
SizedBox(height: 90),
Text(
'tempo_label'.i18n(),
style: TextStyle(
Expand All @@ -103,7 +107,8 @@ class BreathingConfigurationState extends State<BreathingConfiguration> {
Slider(
min: 0,
max: 3,
label: capitalizeEnumValue(BreathingTempo.values[sliderValue.round()].name),
label: capitalizeEnumValue(
BreathingTempo.values[sliderValue.round()].name),
divisions: 3,
value: sliderValue.clamp(0.0, 3.0),
onChanged: (dynamic value) {
Expand Down

0 comments on commit 96f3c2f

Please sign in to comment.