I’m using the Record
5.1.0 package in my Flutter application to record audio. The code works fine on Android, but I’m having issues on Linux Desktop. Specifically, the recorded file does not seem to exist on Linux, while it does on Android.
Here is the relevant code:
import 'package:record/record.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:io';
final record = Record();
Future<void> startRecording() async {
if (await record.hasPermission()) {
final tempDir = await getTemporaryDirectory();
await record.start(path: '${tempDir.path}/voice.m4a');
}
}
Future<File?> stopRecording() async {
final path = await record.stop();
if (path != null) {
final recordedFile = File(path);
return recordedFile;
}
return null;
}
void main() async {
await startRecording();
// Record audio for some time
final recordedFile = await stopRecording();
if (recordedFile != null && recordedFile.existsSync()) {
print('File exists at: ${recordedFile.path}');
} else {
print('File does not exist.');
}
}
-
On Android: The recorded file exists, and
recordedFile.existsSync()
returnstrue
. -
On Linux Desktop: The recorded file does not exist, and
recordedFile.existsSync()
returnsfalse
.
Why is the recorded file not being created or found on Linux Desktop, and how can I resolve this issue to ensure the file exists as expected?