Compare commits

..

No commits in common. "dc8918e519fcb9719297488f147582a3c232dd7f" and "5cfe6897c6e1e82a418e765cf5374b8d961b2ed0" have entirely different histories.

6 changed files with 24 additions and 80 deletions

View File

@ -1,8 +1,3 @@
import 'dart:io';
import 'package:image_picker/image_picker.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:stacked/stacked.dart';
import 'package:waveform_recorder/waveform_recorder.dart';
import 'package:yimaru_app/ui/common/enmus.dart';
@ -42,22 +37,6 @@ class VoiceRecorderService with ListenableServiceMixin {
final file = _waveController.file;
print('RECORDED $file');
if (file == null) return null;
await _saveRecordedAudio(file);
// return file.path;
String? voice = await _saveRecordedAudio(file);
return voice;
}
Future<String?> _saveRecordedAudio(XFile? file) async {
late File voice;
final voiceName = basename(file?.name ?? '');
final Directory appDir = await getApplicationDocumentsDirectory();
final localImagePath = join(appDir.path, voiceName);
voice = File(localImagePath);
//voice.writeAsBytes(await file?.);
return voice.path;
return file.path;
}
}

View File

@ -62,5 +62,4 @@ enum StateObjects {
coursePracticeQuestion,
coursePracticeQuestions,
recordLearnPracticeAnswer,
finishLearnPracticeQuestion
}

View File

@ -167,7 +167,6 @@ class LearnPracticeViewModel extends ReactiveViewModel {
Future<void> _playAudio(
{required Map<String, dynamic> answer, required Voice voice}) async {
if (voice == Voice.recorded) {
print(answer['recorded_voice_answer']);
await _audioPlayerService.playLocal(answer['recorded_voice_answer']);
} else {
await _audioPlayerService.playUrl(answer['sample_voice_answer']);
@ -215,24 +214,18 @@ class LearnPracticeViewModel extends ReactiveViewModel {
}
Future<void> nextQuestion(
{required int index, required LearnQuestion question}) async =>
await runBusyFuture(_nextQuestion(index: index, question: question),
busyObject: StateObjects.finishLearnPracticeQuestion);
Future<void> _nextQuestion(
{required int index, required LearnQuestion question}) async {
await stopRecording();
_answers.add({
'busy_object': question.id.toString(),
'sample_text_answer': question.audioCorrectAnswerText,
'sample_voice_answer': question.sampleAnswerVoicePrompt,
'recorded_voice_answer': await _voiceRecorderService.getRecordedAudio(),
'recorded_voice_answer': _voiceRecorderService.getRecordedAudio(),
});
if (index != _questions.length) {
_questionSetController.nextPage(
curve: Curves.easeInOutCubic,
duration: const Duration(milliseconds: 350),
);
duration: const Duration(milliseconds: 350),
curve: Curves.easeInOutCubic);
await playVoicePrompt(_questions[index]);
} else {
goTo(3);

View File

@ -5,7 +5,6 @@ import 'package:stacked/stacked.dart';
import 'package:waveform_recorder/waveform_recorder.dart';
import 'package:yimaru_app/ui/views/learn_practice/learn_practice_viewmodel.dart';
import 'package:yimaru_app/ui/widgets/cancel_learn_practice_sheet.dart';
import 'package:yimaru_app/ui/widgets/custom_circular_progress_indicator.dart';
import 'package:yimaru_app/ui/widgets/custom_linear_progress_indicator.dart';
import 'package:yimaru_app/ui/widgets/page_loading_indicator.dart';
import 'package:yimaru_app/ui/widgets/wave_wrapper.dart';
@ -71,6 +70,7 @@ class InteractLearnPracticeScreen
children: [
_buildBodyColumnWrapper(context: context, viewModel: viewModel),
_buildProgressIndicatorState(viewModel),
_buildPageLoadingIndicatorState(viewModel)
],
);
@ -139,9 +139,7 @@ class InteractLearnPracticeScreen
viewModel.player.state == PlayerState.playing
? _buildListeningLabel()
: VoiceRecordingState.recording == viewModel.recordingState
? viewModel.busy(StateObjects.finishLearnPracticeQuestion)
? const SizedBox(height: 20)
: _buildSpeakingLabel()
? _buildSpeakingLabel()
: const SizedBox(height: 20);
Widget _buildListeningLabel() => Text(
@ -151,7 +149,7 @@ class InteractLearnPracticeScreen
);
Widget _buildSpeakingLabel() => Text(
'You\'re speaking...',
'You\'re is speaking...',
style: style14P400,
textAlign: TextAlign.center,
);
@ -160,11 +158,8 @@ class InteractLearnPracticeScreen
WaveWrapper(height: 200, child: _buildSpinnerState(viewModel));
Widget _buildSpinnerState(LearnPracticeViewModel viewModel) =>
viewModel.busy(StateObjects.recordLearnPracticeAnswer) ||
viewModel.busy(StateObjects.finishLearnPracticeQuestion)
? Container()
: viewModel.player.state == PlayerState.playing
? _buildSpinner()
viewModel.player.state == PlayerState.playing
? _buildSpinner()
: VoiceRecordingState.recording == viewModel.recordingState &&
viewModel.waveController.isRecording
? _buildSpeakingSpinnerColumn(viewModel)
@ -189,6 +184,7 @@ class InteractLearnPracticeScreen
Widget _buildSpeakingSpinner(LearnPracticeViewModel viewModel) =>
WaveformRecorder(
height: 35,
onRecordingStopped: () {},
waveColor: kcPrimaryColor,
durationTextStyle: style14P600,
controller: viewModel.waveController,
@ -225,7 +221,7 @@ class InteractLearnPracticeScreen
[
_buildActionLabel(),
verticalSpaceMedium,
_buildButtonRowContainer(context: context, viewModel: viewModel),
_buildButtonsRowWrapper(context: context, viewModel: viewModel),
verticalSpaceMedium,
];
@ -235,27 +231,6 @@ class InteractLearnPracticeScreen
textAlign: TextAlign.center,
);
Widget _buildButtonRowContainer(
{required BuildContext context,
required LearnPracticeViewModel viewModel}) =>
SizedBox(
height: 75,
width: double.maxFinite,
child: _buildButtonRowState(context: context, viewModel: viewModel),
);
Widget _buildButtonRowState(
{required BuildContext context,
required LearnPracticeViewModel viewModel}) =>
viewModel.busy(StateObjects.learnPracticeQuestion) ||
viewModel.busy(StateObjects.finishLearnPracticeQuestion)
? _buildProgressIndicator(kcPrimaryColor)
: _buildButtonsRowWrapper(context: context, viewModel: viewModel);
Widget _buildProgressIndicator(Color color) => Center(
child: CustomCircularProgressIndicator(color: color),
);
Widget _buildButtonsRowWrapper(
{required BuildContext context,
required LearnPracticeViewModel viewModel}) =>
@ -293,12 +268,7 @@ class InteractLearnPracticeScreen
);
Widget _buildMicButtonWrapper(LearnPracticeViewModel viewModel) =>
Expanded(child: _buildMicButtonState(viewModel));
Widget _buildMicButtonState(LearnPracticeViewModel viewModel) =>
viewModel.busy(StateObjects.recordLearnPracticeAnswer)
? _buildProgressIndicator(kcPrimaryColor)
: _buildMicButton(viewModel);
Expanded(child: _buildMicButton(viewModel));
Widget _buildMicButton(LearnPracticeViewModel viewModel) => ElevatedButton(
style: ButtonStyle(
@ -365,11 +335,7 @@ class InteractLearnPracticeScreen
Widget _buildProgressIndicatorState(LearnPracticeViewModel viewModel) =>
viewModel.recordingState == VoiceRecordingState.pending
? viewModel.busy(StateObjects.finishLearnPracticeQuestion) ||
viewModel.busy(StateObjects.learnPracticeQuestion) ||
viewModel.busy(StateObjects.recordLearnPracticeAnswer)
? Container()
: _buildProgressIndicatorWrapper(viewModel)
? _buildProgressIndicatorWrapper(viewModel)
: Container();
Widget _buildProgressIndicatorWrapper(LearnPracticeViewModel viewModel) =>
@ -383,12 +349,17 @@ class InteractLearnPracticeScreen
Widget _buildProgressIndicatorSpacer(LearnPracticeViewModel viewModel) =>
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: _buildLinearProgressIndicator(viewModel),
child: _buildProgressIndicator(viewModel),
);
Widget _buildLinearProgressIndicator(LearnPracticeViewModel viewModel) =>
Widget _buildProgressIndicator(LearnPracticeViewModel viewModel) =>
CustomLinearProgressIndicator(
activeColor: kcPrimaryColor,
progress: viewModel.progress,
backgroundColor: kcVeryLightGrey);
Widget _buildPageLoadingIndicatorState(LearnPracticeViewModel viewModel) =>
viewModel.busy(StateObjects.learnPracticeQuestion)
? const PageLoadingIndicator()
: Container();
}

View File

@ -46,5 +46,7 @@ class LearnPracticeResultsWrapper
itemBuilder: (context, index) => _buildResult(viewModel.answers[index]),
);
Widget _buildResult(Map<String, dynamic> answer) => LearnPracticeResultCard(answer: answer);
Widget _buildResult(Map<String, dynamic> answer) => LearnPracticeResultCard(
answer: answer,
);
}

View File

@ -1,5 +1,5 @@
name: yimaru_app
version: 0.1.10+12
version: 0.1.9+11
publish_to: 'none'
description: A new Flutter project.