mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-23 20:49:26 +01:00
fix: Record voice messages
This commit is contained in:
parent
586380ed2f
commit
f8cc559ab3
@ -356,13 +356,13 @@ class ChatController extends State<Chat> {
|
||||
|
||||
void voiceMessageAction() async {
|
||||
if (await Record().hasPermission() == false) return;
|
||||
final result = await showDialog<Map>(
|
||||
final result = await showDialog<RecordingResult>(
|
||||
context: context,
|
||||
useRootNavigator: false,
|
||||
builder: (c) => const RecordingDialog(),
|
||||
);
|
||||
if (result == null) return;
|
||||
final audioFile = File(result['path']);
|
||||
final audioFile = File(result.path);
|
||||
final file = MatrixAudioFile(
|
||||
bytes: audioFile.readAsBytesSync(),
|
||||
name: audioFile.path,
|
||||
@ -373,7 +373,7 @@ class ChatController extends State<Chat> {
|
||||
room.sendFileEvent(file, inReplyTo: replyEvent, extraContent: {
|
||||
'info': {
|
||||
...file.info,
|
||||
'duration': result['duration'],
|
||||
'duration': result.duration,
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
@ -73,6 +73,16 @@ class _RecordingDialogState extends State<RecordingDialog> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _stopAndSend() async {
|
||||
_recorderSubscription?.cancel();
|
||||
await _audioRecorder.stop();
|
||||
Navigator.of(context, rootNavigator: false)
|
||||
.pop<RecordingResult>(RecordingResult(
|
||||
path: _recordedPath,
|
||||
duration: _duration.inMilliseconds,
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const maxDecibalWidth = 64.0;
|
||||
@ -130,14 +140,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
|
||||
),
|
||||
if (error != true)
|
||||
CupertinoDialogAction(
|
||||
onPressed: () async {
|
||||
_recorderSubscription?.cancel();
|
||||
await _audioRecorder.stop();
|
||||
Navigator.of(context, rootNavigator: false).pop<Map>({
|
||||
'path': _recordedPath,
|
||||
'duration': _duration.inMilliseconds,
|
||||
});
|
||||
},
|
||||
onPressed: _stopAndSend,
|
||||
child: Text(L10n.of(context).send.toUpperCase()),
|
||||
),
|
||||
],
|
||||
@ -157,12 +160,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
|
||||
),
|
||||
if (error != true)
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
_recorderSubscription?.cancel();
|
||||
await _audioRecorder.stop();
|
||||
Navigator.of(context, rootNavigator: false)
|
||||
.pop<String>(_recordedPath);
|
||||
},
|
||||
onPressed: _stopAndSend,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
@ -176,3 +174,24 @@ class _RecordingDialogState extends State<RecordingDialog> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RecordingResult {
|
||||
final String path;
|
||||
final int duration;
|
||||
|
||||
const RecordingResult({
|
||||
@required this.path,
|
||||
@required this.duration,
|
||||
});
|
||||
|
||||
factory RecordingResult.fromJson(Map<String, dynamic> json) =>
|
||||
RecordingResult(
|
||||
path: json['path'],
|
||||
duration: json['duration'],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'path': path,
|
||||
'duration': duration,
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user