step 8 : fix issue camera prevent hardware karena OBS terinstall
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
import 'dart:convert';
|
||||
import 'package:camera/camera.dart';
|
||||
import 'package:camera_web/camera_web.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:absensi_sas/repository/googleapis_repository.dart';
|
||||
import 'package:absensi_sas/screen/presensi/presensi_clock_in_provider.dart';
|
||||
import 'package:absensi_sas/screen/presensi/presensi_clock_out_provider.dart';
|
||||
import 'package:absensi_sas/widget/custom_drawer.dart';
|
||||
import 'package:dart_nominatim/dart_nominatim.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
// import 'package:geocoding/geocoding.dart';
|
||||
// import 'package:geolocator/geolocator.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
@@ -20,6 +23,7 @@ import 'package:mobkit_dashed_border/mobkit_dashed_border.dart';
|
||||
|
||||
import '../../app/constant.dart';
|
||||
import '../../app/route.dart';
|
||||
import '../../provider/camera_controller_provider.dart';
|
||||
import '../../provider/current_check_distance_provider.dart';
|
||||
import '../../provider/current_check_jam_presensi_provider.dart';
|
||||
import '../../provider/current_user_provider.dart';
|
||||
@@ -27,12 +31,15 @@ import '../../widget/custom_dialog_presensi_selfie_sukses.dart';
|
||||
import '../../widget/real_date.dart';
|
||||
import '../../widget/real_time.dart';
|
||||
import '../../widget/sankbar_widget.dart';
|
||||
import 'camera_page.dart';
|
||||
import 'check_distance_provider.dart';
|
||||
import 'check_presensi_jam_provider.dart';
|
||||
import 'googleapis_provider.dart';
|
||||
import 'presensi_selfie_upload_area.dart';
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'presensi_selfie_upload_area_web.dart';
|
||||
|
||||
class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
const PresensiSelfieScreen({super.key});
|
||||
|
||||
@@ -56,10 +63,15 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
final fileEkstension = useState("");
|
||||
final fileSize = useState(0);
|
||||
final fileName = useState("");
|
||||
List<CameraDescription> cameras;
|
||||
|
||||
Location location = new Location();
|
||||
LocationData _locationData;
|
||||
|
||||
final controller = ref.watch(cameraControllerProvider);
|
||||
final isInited = useState(false);
|
||||
final imageUrl = useState<String?>(null);
|
||||
|
||||
getBase64() async {
|
||||
// List<int> imageBytes = await fileData.value?.readAsBytes();
|
||||
if (fileData.value != null) {
|
||||
@@ -79,38 +91,50 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
}
|
||||
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
pickImage() async {
|
||||
final XFile? pickedFile = await _picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
// maxWidth set untuk width image
|
||||
maxWidth: 640,
|
||||
// maxHeight set untuk width image
|
||||
maxHeight: 480);
|
||||
if (pickedFile != null) {
|
||||
final tmpFile = FilePickerResult([
|
||||
PlatformFile(
|
||||
name: pickedFile.name,
|
||||
size: await pickedFile.length(),
|
||||
path: pickedFile.path,
|
||||
)
|
||||
]);
|
||||
if (await pickedFile.length() > 10000000) {
|
||||
SanckbarWidget(context, "File tidak boleh lebih dari 10 MB",
|
||||
snackbarType.warning);
|
||||
} else {
|
||||
fileData.value = pickedFile;
|
||||
isImage.value = true;
|
||||
fileEkstension.value = tmpFile.files.single.extension ?? "";
|
||||
DateTime now = new DateTime.now();
|
||||
fileName.value =
|
||||
"IMG-${now.year}${now.month}${now.day}.${tmpFile.files.single.extension ?? ''}";
|
||||
}
|
||||
|
||||
// final Directory appDocumentsDir =
|
||||
// await getApplicationDocumentsDirectory();
|
||||
// print(appDocumentsDir);
|
||||
// await pickedFile!.saveTo(appDocumentsDir.path);
|
||||
await getBase64();
|
||||
pickImage() async {
|
||||
if (kIsWeb) {
|
||||
try {
|
||||
final path =
|
||||
await ref.read(cameraControllerProvider.notifier).takePicture();
|
||||
imageUrl.value = path;
|
||||
} catch (e) {
|
||||
SanckbarWidget(
|
||||
context, "Failed to take picture", snackbarType.warning);
|
||||
}
|
||||
} else {
|
||||
final XFile? pickedFile = await _picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
// maxWidth set untuk width image
|
||||
maxWidth: 640,
|
||||
// maxHeight set untuk width image
|
||||
maxHeight: 480);
|
||||
if (pickedFile != null) {
|
||||
final tmpFile = FilePickerResult([
|
||||
PlatformFile(
|
||||
name: pickedFile.name,
|
||||
size: await pickedFile.length(),
|
||||
path: pickedFile.path,
|
||||
)
|
||||
]);
|
||||
if (await pickedFile.length() > 10000000) {
|
||||
SanckbarWidget(context, "File tidak boleh lebih dari 10 MB",
|
||||
snackbarType.warning);
|
||||
} else {
|
||||
fileData.value = pickedFile;
|
||||
isImage.value = true;
|
||||
fileEkstension.value = tmpFile.files.single.extension ?? "";
|
||||
DateTime now = new DateTime.now();
|
||||
fileName.value =
|
||||
"IMG-${now.year}${now.month}${now.day}.${tmpFile.files.single.extension ?? ''}";
|
||||
}
|
||||
|
||||
// final Directory appDocumentsDir =
|
||||
// await getApplicationDocumentsDirectory();
|
||||
// print(appDocumentsDir);
|
||||
// await pickedFile!.saveTo(appDocumentsDir.path);
|
||||
await getBase64();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +196,7 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
isLoadingAddressUserLocation.value = true;
|
||||
// Mendapatkan posisi pengguna
|
||||
// LocationPermission permission = await Geolocator.requestPermission();
|
||||
final permission = await location.hasPermission();
|
||||
final permission = await location.hasPermission();
|
||||
|
||||
if (permission == PermissionStatus.denied) {
|
||||
isLoadingAddressUserLocation.value = false;
|
||||
@@ -757,13 +781,48 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
? Center(
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: PresensiSelfieUploadAreaWidget(
|
||||
isLoading: isLoadingAddressUserLocation,
|
||||
isImage: isImage,
|
||||
fileData: fileData,
|
||||
fileDataBase64: fileDataBase64,
|
||||
pickFile: pickFile,
|
||||
pickImage: pickImage,
|
||||
: InkWell(
|
||||
onTap: () async {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) =>
|
||||
CameraPage(),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// Icon(
|
||||
// Icons.upload_outlined,
|
||||
// color: Constant.textOrange,
|
||||
// ),
|
||||
|
||||
Image.asset(
|
||||
'images/camera_selfie.png', // Path gambar untuk "Check In"
|
||||
width: Constant.getActualXPhone(
|
||||
context: context, x: 24),
|
||||
height: Constant.getActualYPhone(
|
||||
context: context, y: 24),
|
||||
),
|
||||
SizedBox(
|
||||
height: Constant.getActualYPhone(
|
||||
context: context,
|
||||
y: 4,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Upload File',
|
||||
style: Constant.titleH2_400_12(
|
||||
context: context)
|
||||
.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Constant.textOrange),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
// gambar icon presensi clock out
|
||||
@@ -774,7 +833,7 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
? Center(
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: PresensiSelfieUploadAreaWidget(
|
||||
: PresensiSelfieUploadAreaWebWidget(
|
||||
isLoading: isLoadingAddressUserLocation,
|
||||
isImage: isImage,
|
||||
fileData: fileData,
|
||||
|
||||
Reference in New Issue
Block a user