step 10 : fix permission load pertama kali, hide camera scaner
This commit is contained in:
@@ -41,16 +41,26 @@ class RekamScreen extends HookConsumerWidget {
|
||||
final userId = currentUser?.model.userId ?? "";
|
||||
final awalan = useState("Info :");
|
||||
|
||||
final isPermissionsGranted = useState<bool>(false);
|
||||
|
||||
// Fungsi untuk meminta izin dan menunggu sampai diberikan
|
||||
Future<void> requestPermissions() async {
|
||||
await Permission.microphone.request();
|
||||
await Permission.storage.request();
|
||||
final microphoneStatus = await Permission.microphone.request();
|
||||
final storageStatus = await Permission.storage.request();
|
||||
|
||||
if (microphoneStatus.isGranted && storageStatus.isGranted) {
|
||||
isPermissionsGranted.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() {
|
||||
Future<void> initRecorder() async {
|
||||
await requestPermissions();
|
||||
await recorder.value.openRecorder();
|
||||
await player.value.openPlayer();
|
||||
|
||||
if (isPermissionsGranted.value) {
|
||||
await recorder.value.openRecorder();
|
||||
await player.value.openPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
initRecorder();
|
||||
@@ -69,6 +79,7 @@ class RekamScreen extends HookConsumerWidget {
|
||||
ref.read(barcodeX.notifier).state = barcodes.barcodes.first;
|
||||
qrCodeStr.value = scannedBarcode;
|
||||
awalan.value = "QrCode : ";
|
||||
isRekam.value = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +134,6 @@ class RekamScreen extends HookConsumerWidget {
|
||||
try {
|
||||
await recorder.value.stopRecorder();
|
||||
isSelesaiRekam.value = false;
|
||||
isRekam.value = false;
|
||||
|
||||
// panggil fungsi untuk kirim ke BE
|
||||
if (audioPath.value.isNotEmpty) {
|
||||
@@ -221,9 +231,6 @@ class RekamScreen extends HookConsumerWidget {
|
||||
);
|
||||
} else if (next is UploadRekamStateDone) {
|
||||
ref.read(barcodeX.notifier).state = Barcode();
|
||||
isRekam.value = false;
|
||||
isSelesaiRekam.value = false;
|
||||
|
||||
isLoadingUpload.value = false;
|
||||
ref.read(selectedVoiceIdx.notifier).state = next.model[0].Voice2text_ID;
|
||||
|
||||
@@ -261,6 +268,21 @@ class RekamScreen extends HookConsumerWidget {
|
||||
return () {};
|
||||
}, [isLoadingUpload.value]);
|
||||
|
||||
if (!isPermissionsGranted.value) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 20),
|
||||
Text("Meminta izin..."),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Constant.bgGrey,
|
||||
bottomNavigationBar: BottomAppBar(
|
||||
@@ -294,7 +316,7 @@ class RekamScreen extends HookConsumerWidget {
|
||||
),
|
||||
const Spacer(),
|
||||
ElevatedButton(
|
||||
onPressed: qrCodeStr.value.isEmpty
|
||||
onPressed: (isRekam.value == false)
|
||||
? null
|
||||
: () async {
|
||||
if (!isSelesaiRekam.value) {
|
||||
@@ -304,9 +326,9 @@ class RekamScreen extends HookConsumerWidget {
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: qrCodeStr.value.isNotEmpty
|
||||
? Constant.bgButton
|
||||
: Constant.bgGrey,
|
||||
backgroundColor: (isRekam.value == false)
|
||||
? Constant.bgGrey
|
||||
: Constant.bgButton,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
@@ -315,12 +337,21 @@ class RekamScreen extends HookConsumerWidget {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.mic, size: 20, color: Constant.textWhite),
|
||||
Icon(
|
||||
Icons.mic,
|
||||
size: 20,
|
||||
color: (isRekam.value == false)
|
||||
? Constant.textBlack
|
||||
: Constant.textWhite,
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Text(
|
||||
judulTombol.value,
|
||||
style: Constant.titleButton500(context: context)
|
||||
.copyWith(color: Constant.textWhite),
|
||||
style: Constant.titleButton500(context: context).copyWith(
|
||||
color: (isRekam.value == false)
|
||||
? Constant.textBlack
|
||||
: Constant.textWhite,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -339,7 +370,7 @@ class RekamScreen extends HookConsumerWidget {
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
if (!isRekam.value)
|
||||
if (awalan.value == "Info :")
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: Constant.getActualYPhone(
|
||||
@@ -358,8 +389,10 @@ class RekamScreen extends HookConsumerWidget {
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.symmetric(vertical: 10),
|
||||
color: Constant.inputanGrey,
|
||||
child: Text("${awalan.value} ${qrCodeStr.value}",
|
||||
style: TextStyle(color: Colors.white)),
|
||||
child: Text(
|
||||
"${awalan.value} ${qrCodeStr.value}",
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user