step 19 : hapus loading, tambahkan grayscale upload foto, show foto kalau sudah di foto
This commit is contained in:
@@ -122,13 +122,21 @@ class ScanScreen extends HookConsumerWidget {
|
||||
// Rotate gambar setelah cropping
|
||||
File rotatedImage = await rotateImage(cropped);
|
||||
|
||||
// Convert to grayscale
|
||||
Uint8List bytes = await rotatedImage.readAsBytes();
|
||||
img.Image? coloredImage = img.decodeImage(bytes);
|
||||
if (coloredImage != null) {
|
||||
img.Image grayscaleImage = img.grayscale(coloredImage);
|
||||
rotatedImage.writeAsBytesSync(img.encodeJpg(grayscaleImage));
|
||||
}
|
||||
|
||||
// Simpan hasil yang sudah di-crop dan di-rotate
|
||||
capturedImage.value = image;
|
||||
croppedImage.value = rotatedImage;
|
||||
|
||||
// post ke BE
|
||||
Uint8List bytes = await croppedImage.value!.readAsBytes();
|
||||
String base64String = base64Encode(bytes);
|
||||
Uint8List finalBytes = await croppedImage.value!.readAsBytes();
|
||||
String base64String = base64Encode(finalBytes);
|
||||
ref.read(uploadScanProvider.notifier).uploadScan(
|
||||
host: host,
|
||||
base64File: base64String,
|
||||
@@ -184,22 +192,6 @@ class ScanScreen extends HookConsumerWidget {
|
||||
return () {};
|
||||
}, [isLoadingUpload.value]);
|
||||
|
||||
// loading proses image useEffect
|
||||
useEffect(() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (isLoading.value == true) {
|
||||
snackbarWidget(
|
||||
context,
|
||||
'Sedang Proses Gambar...',
|
||||
snackbarType.warning,
|
||||
// Duration(seconds: 5),
|
||||
Duration(days: 1),
|
||||
);
|
||||
}
|
||||
});
|
||||
return () {};
|
||||
}, [isLoading.value]);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
@@ -229,7 +221,7 @@ class ScanScreen extends HookConsumerWidget {
|
||||
backgroundColor: Colors.black.withOpacity(0.5),
|
||||
body: Stack(
|
||||
children: [
|
||||
if (cameraController.value != null)
|
||||
if (cameraController.value != null && croppedImage.value == null)
|
||||
FutureBuilder<void>(
|
||||
future: initializeControllerFuture.value,
|
||||
builder: (context, snapshot) {
|
||||
@@ -240,19 +232,39 @@ class ScanScreen extends HookConsumerWidget {
|
||||
}
|
||||
},
|
||||
),
|
||||
// bingkai foto
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: OverlayPainter(),
|
||||
// jika sudah ada foto
|
||||
if (croppedImage.value != null) ...[
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 300,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Image.file(
|
||||
croppedImage.value!,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
// bingkai foto
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: OverlayPainter(),
|
||||
),
|
||||
),
|
||||
],
|
||||
// loading
|
||||
if (isLoading.value)
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(color: Colors.white),
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user