- Added a floating action button to the Layout widget for better accessibility. - Updated the left bar navigation items for clarity and consistency. - Introduced Daily Progress Report and Daily Task Planning screens with comprehensive UI. - Implemented filtering and refreshing functionalities in task planning. - Improved user experience with better spacing and layout adjustments. - Updated pubspec.yaml to include new dependencies for image handling and path management.
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:logger/logger.dart';
|
|
|
|
final logger = Logger();
|
|
|
|
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) {
|
|
logger.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);
|
|
}
|