Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle nullable timestamps in audio model and service #1320

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions mobile-app/lib/models/learn/challenge_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ class Blank {
class EnglishAudio {
final String fileName;
final String startTime;
final String startTimeStamp;
final String finishTimeStamp;
final String? startTimeStamp;
final String? finishTimeStamp;

const EnglishAudio({
required this.fileName,
Expand All @@ -287,8 +287,8 @@ class EnglishAudio {
return EnglishAudio(
fileName: data['filename'],
startTime: data['startTime'].toString(),
startTimeStamp: data['startTimestamp'].toString(),
finishTimeStamp: data['finishTimestamp'].toString(),
startTimeStamp: data['startTimestamp']?.toString(),
finishTimeStamp: data['finishTimestamp']?.toString(),
);
}
}
9 changes: 6 additions & 3 deletions mobile-app/lib/service/audio/audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ class AudioPlayerHandler extends BaseAudioHandler {
}
}

Duration parseTimeStamp(String timeStamp) {
if (timeStamp == '0') {
Duration parseTimeStamp(String? timeStamp) {
if (timeStamp == null || timeStamp == '0') {
return const Duration(milliseconds: 0);
}

return Duration(
milliseconds: (double.parse(timeStamp) * 1000).round(),
);
Expand Down Expand Up @@ -205,7 +206,9 @@ class AudioPlayerHandler extends BaseAudioHandler {
_audioPlayer.setAudioSource(
ClippingAudioSource(
start: parseTimeStamp(audio.startTimeStamp),
end: parseTimeStamp(audio.finishTimeStamp),
end: audio.finishTimeStamp == null
? null
: parseTimeStamp(audio.finishTimeStamp),
child: AudioSource.uri(
Uri.parse(
returnUrl(audio.fileName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,26 @@ class EnglishView extends StatelessWidget {
),
),
),
Container(
color: const Color(0xFF0a0a23),
margin: const EdgeInsets.all(8),
child: Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Wrap(
children: model.getFillInBlankWidgets(
challenge,
context,
if (challenge.fillInTheBlank != null)
Container(
color: const Color(0xFF0a0a23),
margin: const EdgeInsets.all(8),
child: Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Wrap(
children: model.getFillInBlankWidgets(
challenge,
context,
),
),
),
),
)
],
)
],
),
),
),
Row(
children: [
Expanded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ class InnerAudioWidget extends StatelessWidget {
);

Duration? totalDuration = model.audioService.duration();
int handleTotal = totalDuration?.inMilliseconds ?? 0;
bool bothZero = handleTotal == 0 && position.inMilliseconds == 0;

return Column(
children: [
if (totalDuration != null)
if (!bothZero)
LinearProgressIndicator(
value: position.inMilliseconds / totalDuration.inMilliseconds,
value: position.inMilliseconds / handleTotal,
minHeight: 8,
),
Row(
Expand Down
Loading