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