step 9 : clock in & clock out selfie sudah bisa, need fix at clear camera controller after take photo
This commit is contained in:
@@ -16,9 +16,11 @@ import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
// import 'package:geolocator/geolocator.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:image_picker_web/image_picker_web.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:location/location.dart';
|
||||
import 'package:mobkit_dashed_border/mobkit_dashed_border.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
// import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
import '../../app/constant.dart';
|
||||
@@ -35,7 +37,6 @@ 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';
|
||||
@@ -55,22 +56,19 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
|
||||
final positionLatitude = useState<String>("");
|
||||
final positionLongitude = useState<String>("");
|
||||
// final tTransactionCurrentDistance = useState<String>("NULL");
|
||||
|
||||
final fileData = useState<XFile?>(null);
|
||||
final fileDataBase64 = useState<String>("");
|
||||
final filePath = useState<String>("");
|
||||
final isImage = useState(false);
|
||||
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);
|
||||
// final imgPhotoWeb = ref.read(imgPhotoWebProvider);
|
||||
|
||||
getBase64() async {
|
||||
// List<int> imageBytes = await fileData.value?.readAsBytes();
|
||||
@@ -94,47 +92,23 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
|
||||
pickImage() async {
|
||||
if (kIsWeb) {
|
||||
// final shared = await SharedPreferences.getInstance();
|
||||
// final imageBase64 = shared.getString("base64Image");
|
||||
// final imagePathNew = shared.getString("imagePath");
|
||||
try {
|
||||
final path =
|
||||
await ref.read(cameraControllerProvider.notifier).takePicture();
|
||||
imageUrl.value = path;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => CameraPage(
|
||||
fileDataBase64Param: fileDataBase64,
|
||||
filePathParam: filePath,
|
||||
),
|
||||
),
|
||||
);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -782,46 +756,51 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: InkWell(
|
||||
onTap: () async {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) =>
|
||||
CameraPage(),
|
||||
),
|
||||
);
|
||||
onTap: () {
|
||||
pickImage();
|
||||
},
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// Icon(
|
||||
// Icons.upload_outlined,
|
||||
// color: Constant.textOrange,
|
||||
// ),
|
||||
child: Container(
|
||||
width: Constant.getActualXPhone(
|
||||
context: context, x: 390),
|
||||
height: Constant.getActualYPhone(
|
||||
context: context,
|
||||
y: isImage.value ? 200 : 83),
|
||||
decoration: BoxDecoration(
|
||||
color: Constant.bgUploadFile,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
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,
|
||||
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),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Upload File',
|
||||
style: Constant.titleH2_400_12(
|
||||
context: context)
|
||||
.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Constant.textOrange),
|
||||
)
|
||||
],
|
||||
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 ...[
|
||||
@@ -833,18 +812,75 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
? Center(
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: PresensiSelfieUploadAreaWebWidget(
|
||||
isLoading: isLoadingAddressUserLocation,
|
||||
isImage: isImage,
|
||||
fileData: fileData,
|
||||
fileDataBase64: fileDataBase64,
|
||||
pickFile: pickFile,
|
||||
pickImage: pickImage,
|
||||
: InkWell(
|
||||
onTap: () {
|
||||
pickImage();
|
||||
},
|
||||
child: Container(
|
||||
width: Constant.getActualXPhone(
|
||||
context: context, x: 390),
|
||||
height: Constant.getActualYPhone(
|
||||
context: context,
|
||||
y: isImage.value ? 200 : 83),
|
||||
decoration: BoxDecoration(
|
||||
color: Constant.bgUploadFile,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
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),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
]
|
||||
],
|
||||
],
|
||||
|
||||
// gambar selfie
|
||||
if (fileDataBase64.value.isNotEmpty) ...[
|
||||
SizedBox(
|
||||
height: Constant.getActualYPhone(context: context, y: 40),
|
||||
),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height:
|
||||
Constant.getActualYPhone(context: context, y: 200),
|
||||
child: Image.network(
|
||||
filePath.value,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Spacer(),
|
||||
|
||||
// button clock in dan clock out
|
||||
@@ -924,9 +960,8 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
token,
|
||||
"Clock In");
|
||||
|
||||
// print(
|
||||
// fileDataBase64.value,
|
||||
// );
|
||||
print(
|
||||
"proses imageX: ${fileDataBase64.value}");
|
||||
},
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
|
||||
Reference in New Issue
Block a user