Skip to content

Commit

Permalink
fix desktop crash
Browse files Browse the repository at this point in the history
  • Loading branch information
waozixyz committed Nov 18, 2023
1 parent 695422d commit 19b166c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 38 deletions.
27 changes: 19 additions & 8 deletions lib/screens/exercise/exercise_step1.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:inner_breeze/providers/user_provider.dart';
import 'package:inner_breeze/shared/breeze_style.dart';
Expand Down Expand Up @@ -136,13 +135,12 @@ class _ExerciseStep1State extends State<ExerciseStep1> {
),
SizedBox(height: 200),
StopSessionButton(),
if (!kReleaseMode)
TextButton(
child: Text('Skip'),
onPressed: () {
_navigateToNextExercise();
},
)
TextButton(
child: Text('Skip'),
onPressed: () {
skipCountdown();
},
),
],
),
),
Expand All @@ -156,4 +154,17 @@ class _ExerciseStep1State extends State<ExerciseStep1> {

super.dispose();
}


void skipCountdown() {
if (breathsDone < 0) {
breathCycleTimer?.cancel();
setState(() {
breathsDone = 1;
});
startBreathCounting();
} else {
_navigateToNextExercise();
}
}
}
10 changes: 1 addition & 9 deletions lib/screens/exercise/exercise_step2.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:inner_breeze/providers/user_provider.dart';
import 'package:inner_breeze/widgets/stop_session.dart';
Expand Down Expand Up @@ -90,7 +89,7 @@ class _ExerciseStep2State extends State<ExerciseStep2> {
_navigateToNextExercise();
},
child: Text(
'Stop Hold',
'Finish Hold',
style: TextStyle(
fontSize: 18.0,
),
Expand All @@ -101,13 +100,6 @@ class _ExerciseStep2State extends State<ExerciseStep2> {
StopSessionButton(
onStopSessionPressed: _onStopSessionPressed,
),
if (!kReleaseMode)
TextButton(
child: Text('Skip'),
onPressed: () {
_navigateToNextExercise();
},
)
],
),
),
Expand Down
14 changes: 6 additions & 8 deletions lib/screens/exercise/exercise_step3.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:inner_breeze/providers/user_provider.dart';
import 'package:inner_breeze/shared/breeze_style.dart';
Expand Down Expand Up @@ -95,13 +94,12 @@ class _ExerciseStep3State extends State<ExerciseStep3> {
),
SizedBox(height: 200),
StopSessionButton(),
if (!kReleaseMode)
TextButton(
child: Text('Skip'),
onPressed: () {
_navigateToNextExercise();
},
),
TextButton(
child: Text('Skip'),
onPressed: () {
_navigateToNextExercise();
},
),
],
),
),
Expand Down
20 changes: 7 additions & 13 deletions lib/widgets/animated_circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class AnimatedCircleState extends State<AnimatedCircle>
late Animation<double> _radiusAnimation;
late AudioPlayer _audioPlayer;
late AudioSession _audioSession;

bool _isInitialized = false;

Future<AudioSession> _configureAudioSession() async {
Expand All @@ -50,18 +49,15 @@ class AnimatedCircleState extends State<AnimatedCircle>
void initState() {
super.initState();

_audioPlayer = AudioPlayer();
_controller = AnimationController(
vsync: this,
duration: widget.tempoDuration,
);
_radiusAnimation = Tween<double>(begin: 40, end: 72).animate(_controller);

_configureAudioSession().then((session) {
_audioSession = session;

_controller = AnimationController(
vsync: this,
duration: widget.tempoDuration,
);

_radiusAnimation = Tween<double>(begin: 40, end: 72).animate(_controller);

_audioPlayer = AudioPlayer();

_audioSession.interruptionEventStream.listen((event) {
if (event.begin) {
if (event.type == AudioInterruptionType.pause || event.type == AudioInterruptionType.unknown) {
Expand Down Expand Up @@ -208,10 +204,8 @@ class BreathingCircle extends CustomPainter {

String? displayText = innerText;

// Try to parse the innerText as an integer
int? numberValue = int.tryParse(innerText ?? '');

// If the parsed value is a number and is less than 0, update the displayText to its absolute value
if (numberValue != null && numberValue < 0) {
displayText = numberValue.abs().toString();
}
Expand Down

0 comments on commit 19b166c

Please sign in to comment.