diff --git a/packages/smooth_app/android/app/src/main/AndroidManifest.xml b/packages/smooth_app/android/app/src/main/AndroidManifest.xml
index 0f5b3628cb8..a960ca2050d 100644
--- a/packages/smooth_app/android/app/src/main/AndroidManifest.xml
+++ b/packages/smooth_app/android/app/src/main/AndroidManifest.xml
@@ -54,5 +54,9 @@
+
diff --git a/packages/smooth_app/lib/pages/image_crop_page.dart b/packages/smooth_app/lib/pages/image_crop_page.dart
index 5c563421b5e..07cfdfa8764 100644
--- a/packages/smooth_app/lib/pages/image_crop_page.dart
+++ b/packages/smooth_app/lib/pages/image_crop_page.dart
@@ -1,109 +1,45 @@
import 'dart:io';
-import 'dart:typed_data';
-
-import 'package:crop_your_image/crop_your_image.dart';
import 'package:flutter/material.dart';
+import 'package:image_cropper/image_cropper.dart';
import 'package:image_picker/image_picker.dart';
-import 'package:path_provider/path_provider.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/themes/theme_provider.dart';
Future startImageCropping(BuildContext context) async {
- final Uint8List? bytes = await pickImage();
-
- if (bytes == null) {
- return null;
- }
-
- return Navigator.push(
- context,
- MaterialPageRoute(
- builder: (BuildContext context) => ImageCropPage(imageBytes: bytes),
- ),
- );
-}
-
-Future pickImage() async {
+ final bool isDarktheme =
+ Provider.of(context, listen: false).isDarkMode(context);
+ final Color? themeColor = isDarktheme
+ ? Colors.black
+ : Theme.of(context).appBarTheme.backgroundColor;
final ImagePicker picker = ImagePicker();
-
final XFile? pickedXFile = await picker.pickImage(
source: ImageSource.camera,
);
if (pickedXFile == null) {
- // User didn't pick any image.
return null;
}
-
- return pickedXFile.readAsBytes();
-}
-
-// build circular progress bar widget
-Widget buildCircularProgressBar() {
- return const Center(
- child: CircularProgressIndicator(),
+ final File? croppedFile = await ImageCropper().cropImage(
+ sourcePath: pickedXFile.path,
+ aspectRatioPresets: [
+ CropAspectRatioPreset.square,
+ CropAspectRatioPreset.ratio3x2,
+ CropAspectRatioPreset.original,
+ CropAspectRatioPreset.ratio4x3,
+ CropAspectRatioPreset.ratio16x9
+ ],
+ androidUiSettings: AndroidUiSettings(
+ toolbarTitle: 'Edit Photo', // TODO(ashaan): Localize
+ initAspectRatio: CropAspectRatioPreset.original,
+ lockAspectRatio: false,
+ statusBarColor: themeColor,
+ toolbarColor: themeColor,
+ toolbarWidgetColor: Colors.white,
+ activeControlsWidgetColor: Theme.of(context).colorScheme.primary,
+ backgroundColor: themeColor,
+ ),
+ iosUiSettings: const IOSUiSettings(
+ minimumAspectRatio: 1.0,
+ ),
);
-}
-
-class ImageCropPage extends StatefulWidget {
- const ImageCropPage({Key? key, required this.imageBytes}) : super(key: key);
-
- final Uint8List imageBytes;
-
- @override
- State createState() => _ImageCropPageState();
-}
-
-class _ImageCropPageState extends State {
- bool isCropping = false;
- @override
- Widget build(BuildContext context) {
- final CropController _controller = CropController();
- final ThemeData theme = Theme.of(context);
- context.watch();
- return Scaffold(
- body: isCropping
- ? buildCircularProgressBar()
- : Crop(
- image: widget.imageBytes,
- controller: _controller,
- onCropped: (Uint8List image) async {
- final Directory tempDir = await getTemporaryDirectory();
- final String tempPath = tempDir.path;
- final String filePath = '$tempPath/upload_img_file.tmp';
- final File file = await File(filePath).writeAsBytes(image);
- setState(() {
- isCropping = false;
- });
- Navigator.pop(context, file);
- },
- initialSize: 0.5,
- baseColor: theme.colorScheme.primary,
- maskColor: Colors.white.withAlpha(100),
- cornerDotBuilder: (double size, EdgeAlignment edgeAlignment) =>
- DotControl(color: theme.colorScheme.primary),
- ),
- bottomNavigationBar: BottomAppBar(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- IconButton(
- icon: const Icon(Icons.cancel_outlined),
- onPressed: () {
- Navigator.pop(context);
- },
- ),
- IconButton(
- icon: const Icon(Icons.done),
- onPressed: () {
- _controller.crop();
- setState(() {
- isCropping = true;
- });
- },
- )
- ],
- ),
- ),
- );
- }
+ return croppedFile;
}
diff --git a/packages/smooth_app/pubspec.lock b/packages/smooth_app/pubspec.lock
index 83feed6d228..7721df3dda7 100644
--- a/packages/smooth_app/pubspec.lock
+++ b/packages/smooth_app/pubspec.lock
@@ -148,13 +148,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
- crop_your_image:
- dependency: "direct main"
- description:
- name: crop_your_image
- url: "https://pub.dartlang.org"
- source: hosted
- version: "0.7.2"
cross_file:
dependency: transitive
description:
@@ -422,6 +415,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
+ image_cropper:
+ dependency: "direct main"
+ description:
+ name: image_cropper
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.5.0"
image_picker:
dependency: "direct main"
description:
diff --git a/packages/smooth_app/pubspec.yaml b/packages/smooth_app/pubspec.yaml
index 6d691040e1b..1d0a961253b 100644
--- a/packages/smooth_app/pubspec.yaml
+++ b/packages/smooth_app/pubspec.yaml
@@ -29,8 +29,8 @@ dependencies:
matomo_forever: ^1.0.0+1
modal_bottom_sheet: ^2.0.1
openfoodfacts: ^1.14.0
-# openfoodfacts:
-# path: ../../../openfoodfacts-dart
+ # openfoodfacts:
+ # path: ../../../openfoodfacts-dart
package_info_plus: ^1.4.0
permission_handler: ^9.2.0
photo_view: ^0.13.0
@@ -43,7 +43,6 @@ dependencies:
visibility_detector: ^0.2.2
camera: ^0.9.4+16
percent_indicator: ^4.0.0
- crop_your_image: ^0.7.2
mailto: ^2.0.0
flutter_native_splash: ^2.1.1
# Fork from cli1005 with iOS fix cf: https://github.com/openfoodfacts/smooth-app/issues/1155
@@ -51,10 +50,9 @@ dependencies:
git:
url: https://github.com/cli1005/google_ml_barcode_scanner.git
ref: master
+ image_cropper: ^1.5.0
auto_size_text: ^3.0.0
-
-
dev_dependencies:
flutter_launcher_icons: ^0.9.2
flutter_test: