|
|
|
|
@ -12,15 +12,17 @@ import 'package:test_sa/extensions/context_extension.dart';
|
|
|
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/sound/sound_player.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../new_views/app_style/app_color.dart';
|
|
|
|
|
import '../../../new_views/common_widgets/app_text_form_field.dart';
|
|
|
|
|
|
|
|
|
|
class RecordSound extends StatefulWidget {
|
|
|
|
|
final Function(String) onRecord;
|
|
|
|
|
final Function(String) onStop;
|
|
|
|
|
final bool enabled;
|
|
|
|
|
|
|
|
|
|
const RecordSound({Key key, @required this.onRecord, this.enabled = true}) : super(key: key);
|
|
|
|
|
const RecordSound({Key key, @required this.onRecord, this.onStop, this.enabled = true}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<RecordSound> createState() => _RecordSoundState();
|
|
|
|
|
@ -31,6 +33,7 @@ class _RecordSoundState extends State<RecordSound> {
|
|
|
|
|
|
|
|
|
|
bool _recorderIsOpened = false;
|
|
|
|
|
bool _recording = false;
|
|
|
|
|
bool _played = false;
|
|
|
|
|
String _record;
|
|
|
|
|
Artboard _rive;
|
|
|
|
|
Timer _timer;
|
|
|
|
|
@ -96,7 +99,11 @@ class _RecordSoundState extends State<RecordSound> {
|
|
|
|
|
}
|
|
|
|
|
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_timeController.text = ((timer?.tick ?? 0) / 60)?.toStringAsFixed(2);
|
|
|
|
|
String recordTime = ((timer?.tick ?? 0) / 60)?.toStringAsFixed(2)?.replaceFirst(".", ":");
|
|
|
|
|
if (recordTime.length == 4 || recordTime.length == 7) {
|
|
|
|
|
recordTime = "0$recordTime";
|
|
|
|
|
}
|
|
|
|
|
_timeController.text = recordTime;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
_rive.addController(SimpleAnimation('recording'));
|
|
|
|
|
@ -149,29 +156,36 @@ class _RecordSoundState extends State<RecordSound> {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Stack(
|
|
|
|
|
alignment: AlignmentDirectional.centerEnd,
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
AppTextFormField(
|
|
|
|
|
enable: false,
|
|
|
|
|
controller: _timeController,
|
|
|
|
|
labelText: context.translation.recordVoice,
|
|
|
|
|
initialValue: (_timeController?.text?.isEmpty ?? true) ? "00:00" : _timeController?.text,
|
|
|
|
|
suffixIcon: (_recording ? "record".toLottieAsset(height: 24) : (_record != null ? "trash" : "mic").toSvgAsset(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20, height: 24))
|
|
|
|
|
.paddingOnly(end: 16),
|
|
|
|
|
Stack(
|
|
|
|
|
alignment: AlignmentDirectional.centerEnd,
|
|
|
|
|
children: [
|
|
|
|
|
AppTextFormField(
|
|
|
|
|
enable: false,
|
|
|
|
|
controller: _timeController,
|
|
|
|
|
labelText: context.translation.recordVoice,
|
|
|
|
|
initialValue: (_timeController?.text?.isEmpty ?? true) ? "00:00" : _timeController?.text,
|
|
|
|
|
suffixIcon:
|
|
|
|
|
(_recording ? "record".toLottieAsset(height: 24) : (_record != null ? "trash" : "mic").toSvgAsset(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20, height: 24))
|
|
|
|
|
.paddingOnly(end: 16),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 50.toScreenHeight, width: 50.toScreenWidth).onPress(() {
|
|
|
|
|
if (_recording) {
|
|
|
|
|
_stopRecording();
|
|
|
|
|
} else if (_record != null) {
|
|
|
|
|
_timeController?.text = "00:00";
|
|
|
|
|
widget.onRecord(null);
|
|
|
|
|
_record = null;
|
|
|
|
|
setState(() {});
|
|
|
|
|
} else {
|
|
|
|
|
_startRecording();
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 50.toScreenHeight, width: 50.toScreenWidth).onPress(() {
|
|
|
|
|
if (_recording) {
|
|
|
|
|
_stopRecording();
|
|
|
|
|
} else if (_record != null) {
|
|
|
|
|
_timeController?.text = "00:00";
|
|
|
|
|
widget.onRecord(null);
|
|
|
|
|
_record = null;
|
|
|
|
|
setState(() {});
|
|
|
|
|
} else {
|
|
|
|
|
_startRecording();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (_record != null) 8.height,
|
|
|
|
|
if (_record != null) ASoundPlayer(audio: _record),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|