4/7/5
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:SEFER/controller/home/map_passenger_controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_sound/flutter_sound.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import '../home/map_passenger_controller.dart';
|
||||
|
||||
class AudioController extends GetxController {
|
||||
final recorder = FlutterSoundRecorder();
|
||||
bool isRecoding = false;
|
||||
bool isRecording = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -17,7 +20,13 @@ class AudioController extends GetxController {
|
||||
Future<void> initRecorder() async {
|
||||
final status = await Permission.microphone.request();
|
||||
if (status != PermissionStatus.granted) {
|
||||
// Handle permission denied
|
||||
if (status.isPermanentlyDenied) {
|
||||
// Handle permission permanently denied
|
||||
showPermissionDeniedDialog();
|
||||
} else {
|
||||
// Handle permission denied
|
||||
showPermissionDeniedSnackbar();
|
||||
}
|
||||
return;
|
||||
}
|
||||
await recorder.openRecorder();
|
||||
@@ -25,10 +34,10 @@ class AudioController extends GetxController {
|
||||
}
|
||||
|
||||
Future<void> startRecording() async {
|
||||
await recorder.startRecorder(
|
||||
toFile:
|
||||
'audio_${Get.find<MapPassengerController>().rideId}.wav'); // Specify the file name
|
||||
isRecoding = true;
|
||||
final controller = Get.find<MapPassengerController>();
|
||||
final filePath = 'audio_${controller.rideId}.wav'; // Specify the file name
|
||||
await recorder.startRecorder(toFile: filePath);
|
||||
isRecording = true;
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -37,13 +46,56 @@ class AudioController extends GetxController {
|
||||
final audioFile = File(filePath!);
|
||||
print('Recorded file path: $audioFile');
|
||||
// Now you can send this file to the server
|
||||
isRecoding = false;
|
||||
isRecording = false;
|
||||
update();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
recorder.closeRecorder();
|
||||
recorder.stopRecorder();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void showPermissionDeniedDialog() {
|
||||
showDialog(
|
||||
context: Get.context!,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Microphone Permission'),
|
||||
content: Text('Microphone permission is required to record audio.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
openAppSettings();
|
||||
},
|
||||
child: Text('Open Settings'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text('Cancel'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showPermissionDeniedSnackbar() {
|
||||
Get.snackbar(
|
||||
'Microphone Permission',
|
||||
'Microphone permission is required to record audio.',
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
duration: Duration(seconds: 5),
|
||||
mainButton: TextButton(
|
||||
onPressed: () {
|
||||
openAppSettings();
|
||||
},
|
||||
child: Text(
|
||||
'Open Settings',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user