|
|
|
|
@ -83,27 +83,19 @@ class _FamilyCardsState extends State<FamilyCards> {
|
|
|
|
|
false, // Don't show files option, only camera and gallery
|
|
|
|
|
(base64String, file) async {
|
|
|
|
|
try {
|
|
|
|
|
print('=== Starting image processing ===');
|
|
|
|
|
print('File path: ${file.path}');
|
|
|
|
|
print('File exists: ${await file.exists()}');
|
|
|
|
|
print('Original file size: ${await file.length() / 1024} KB');
|
|
|
|
|
|
|
|
|
|
// Compress and resize the image
|
|
|
|
|
print('Calling compressAndResizeImage...');
|
|
|
|
|
final compressedFile = await ImageCompressionHelper.compressAndResizeImage(file);
|
|
|
|
|
|
|
|
|
|
File finalFile;
|
|
|
|
|
String finalBase64;
|
|
|
|
|
|
|
|
|
|
if (compressedFile == null) {
|
|
|
|
|
print('⚠️ Compression failed - using original file as fallback');
|
|
|
|
|
|
|
|
|
|
// Fallback: use original image if compression fails
|
|
|
|
|
final originalSize = await file.length();
|
|
|
|
|
final maxSize = 1048576; // 1MB
|
|
|
|
|
|
|
|
|
|
if (originalSize > maxSize) {
|
|
|
|
|
print('❌ Original file is too large: ${originalSize / 1024} KB');
|
|
|
|
|
if (mounted) {
|
|
|
|
|
Utils.showToast(
|
|
|
|
|
LocaleKeys.imageSizeTooLarge.tr(context: context),
|
|
|
|
|
@ -111,8 +103,6 @@ class _FamilyCardsState extends State<FamilyCards> {
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print('✅ Using original file (${originalSize / 1024} KB)');
|
|
|
|
|
finalFile = file;
|
|
|
|
|
var bytes = await file.readAsBytes();
|
|
|
|
|
finalBase64 = base64.encode(bytes);
|
|
|
|
|
@ -120,10 +110,8 @@ class _FamilyCardsState extends State<FamilyCards> {
|
|
|
|
|
// Check compressed file size
|
|
|
|
|
final fileSize = await compressedFile.length();
|
|
|
|
|
final maxSize = 1048576; // 1MB
|
|
|
|
|
print('✅ Compression successful: ${fileSize / 1024} KB');
|
|
|
|
|
|
|
|
|
|
if (fileSize > maxSize) {
|
|
|
|
|
print('❌ Compressed file still too large');
|
|
|
|
|
if (mounted) {
|
|
|
|
|
Utils.showToast(
|
|
|
|
|
LocaleKeys.imageSizeTooLarge.tr(context: context),
|
|
|
|
|
@ -137,22 +125,16 @@ class _FamilyCardsState extends State<FamilyCards> {
|
|
|
|
|
finalBase64 = base64.encode(bytes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print('Converting to base64... Length: ${finalBase64.length}');
|
|
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_selectedImage = finalFile;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
print('📤 Starting upload...');
|
|
|
|
|
// Upload the image
|
|
|
|
|
_uploadImage(finalBase64);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print('=== Image processing complete ===');
|
|
|
|
|
} catch (e, stackTrace) {
|
|
|
|
|
print('❌ Error in _pickImage: $e');
|
|
|
|
|
print('Stack trace: $stackTrace');
|
|
|
|
|
if (mounted) {
|
|
|
|
|
Utils.showToast(
|
|
|
|
|
LocaleKeys.failedToProcessImage.tr(context: context),
|
|
|
|
|
@ -901,6 +883,7 @@ class _FamilyCardsState extends State<FamilyCards> {
|
|
|
|
|
: Expanded(
|
|
|
|
|
child: CustomButton(
|
|
|
|
|
height: 40.h,
|
|
|
|
|
fontSize: 14.f,
|
|
|
|
|
text: LocaleKeys.acceptLbl.tr(),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
navigationService.pop();
|
|
|
|
|
@ -917,6 +900,7 @@ class _FamilyCardsState extends State<FamilyCards> {
|
|
|
|
|
Expanded(
|
|
|
|
|
child: CustomButton(
|
|
|
|
|
height: 40.h,
|
|
|
|
|
fontSize: 14.f,
|
|
|
|
|
text: profile.status == FamilyFileEnum.active.toInt ? LocaleKeys.removeMember.tr() : LocaleKeys.rejectView.tr(),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
navigationService.pop();
|
|
|
|
|
|