- Replaced instances of the Logger package with a custom appLogger for consistent logging. - Introduced app_logger.dart to manage logging with file output and storage permissions. - Updated all controllers (e.g., DashboardController, EmployeesScreenController, etc.) to use appLogger for logging messages. - Ensured that logging messages are appropriately categorized (info, warning, error) throughout the application. - Implemented a file logging mechanism to store logs in a designated directory. - Cleaned up old log files to maintain only the most recent logs.
48 lines
1.2 KiB
Dart
48 lines
1.2 KiB
Dart
import 'dart:io';
|
|
import 'dart:typed_data';
|
|
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:marco/helpers/services/app_logger.dart';
|
|
|
|
|
|
|
|
Future<Uint8List?> compressImageToUnder100KB(File file) async {
|
|
int quality = 40;
|
|
Uint8List? result;
|
|
|
|
const int maxWidth = 800;
|
|
const int maxHeight = 800;
|
|
|
|
while (quality >= 10) {
|
|
result = await FlutterImageCompress.compressWithFile(
|
|
file.absolute.path,
|
|
quality: quality,
|
|
minWidth: maxWidth,
|
|
minHeight: maxHeight,
|
|
format: CompressFormat.jpeg,
|
|
);
|
|
|
|
if (result != null) {
|
|
appLogger.i('Quality: $quality, Size: ${(result.lengthInBytes / 1024).toStringAsFixed(2)} KB');
|
|
|
|
if (result.lengthInBytes <= 100 * 1024) {
|
|
return result;
|
|
}
|
|
}
|
|
|
|
quality -= 10;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
Future<File> saveCompressedImageToFile(Uint8List bytes) async {
|
|
final tempDir = await getTemporaryDirectory();
|
|
final filePath = path.join(
|
|
tempDir.path,
|
|
'compressed_${DateTime.now().millisecondsSinceEpoch}.jpg',
|
|
);
|
|
final file = File(filePath);
|
|
return await file.writeAsBytes(bytes);
|
|
}
|