Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 3332 - refactored the new crop page UI and added a camera #3402

Merged
merged 10 commits into from
Dec 8, 2022
28 changes: 6 additions & 22 deletions packages/app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ PODS:
- Flutter
- camera (0.0.1):
- Flutter
- connectivity_plus (0.0.1):
- Flutter
- ReachabilitySwift
- data_importer (0.0.1):
- Flutter
- KeychainAccess
Expand Down Expand Up @@ -66,6 +63,8 @@ PODS:
- TOCropViewController (~> 2.6.1)
- image_picker_ios (0.0.1):
- Flutter
- in_app_review (0.2.0):
- Flutter
- integration_test (0.0.1):
- Flutter
- iso_countries (0.0.1):
Expand Down Expand Up @@ -104,7 +103,6 @@ PODS:
- Flutter
- PromisesObjC (2.1.1)
- Protobuf (3.21.7)
- ReachabilitySwift (5.0.0)
- Realm (10.31.0):
- Realm/Headers (= 10.31.0)
- Realm/Headers (10.31.0)
Expand All @@ -124,18 +122,13 @@ PODS:
- sqflite (0.0.2):
- Flutter
- FMDB (>= 2.7.5)
- task_manager (0.0.1):
- Flutter
- TOCropViewController (2.6.1)
- url_launcher_ios (0.0.1):
- Flutter
- workmanager (0.0.1):
- Flutter

DEPENDENCIES:
- audioplayers_darwin (from `.symlinks/plugins/audioplayers_darwin/ios`)
- camera (from `.symlinks/plugins/camera/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- data_importer (from `.symlinks/plugins/data_importer/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- Flutter (from `Flutter`)
Expand All @@ -147,6 +140,7 @@ DEPENDENCIES:
- google_mlkit_commons (from `.symlinks/plugins/google_mlkit_commons/ios`)
- image_cropper (from `.symlinks/plugins/image_cropper/ios`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- in_app_review (from `.symlinks/plugins/in_app_review/ios`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- iso_countries (from `.symlinks/plugins/iso_countries/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
Expand All @@ -156,9 +150,7 @@ DEPENDENCIES:
- share_plus (from `.symlinks/plugins/share_plus/ios`)
- shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- task_manager (from `.symlinks/plugins/task_manager/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- workmanager (from `.symlinks/plugins/workmanager/ios`)

SPEC REPOS:
trunk:
Expand All @@ -177,7 +169,6 @@ SPEC REPOS:
- nanopb
- PromisesObjC
- Protobuf
- ReachabilitySwift
- Realm
- RealmSwift
- Sentry
Expand All @@ -188,8 +179,6 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/audioplayers_darwin/ios"
camera:
:path: ".symlinks/plugins/camera/ios"
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/ios"
data_importer:
:path: ".symlinks/plugins/data_importer/ios"
device_info_plus:
Expand All @@ -212,6 +201,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/image_cropper/ios"
image_picker_ios:
:path: ".symlinks/plugins/image_picker_ios/ios"
in_app_review:
:path: ".symlinks/plugins/in_app_review/ios"
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
iso_countries:
Expand All @@ -230,17 +221,12 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/shared_preferences_ios/ios"
sqflite:
:path: ".symlinks/plugins/sqflite/ios"
task_manager:
:path: ".symlinks/plugins/task_manager/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
workmanager:
:path: ".symlinks/plugins/workmanager/ios"

SPEC CHECKSUMS:
audioplayers_darwin: 387322cb364026a1782298c982693b1b6aa9fa1b
camera: 9993f92f2c793e87b65e35f3a23c70582afb05b1
connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e
data_importer: ab8c74aaf553878170aed03c03626d5820c5cb1f
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
Expand All @@ -259,6 +245,7 @@ SPEC CHECKSUMS:
GTMSessionFetcher: 5595ec75acf5be50814f81e9189490412bad82ba
image_cropper: 60c2789d1f1a78c873235d4319ca0c34a69f2d98
image_picker_ios: b786a5dcf033a8336a657191401bfdf12017dabb
in_app_review: 4a97249f7a2f539a0f294c2d9196b7fe35e49541
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
iso_countries: eb09d40f388e4c65e291e0bb36a701dfe7de6c74
KeychainAccess: c0c4f7f38f6fc7bbe58f5702e25f7bd2f65abf51
Expand All @@ -272,18 +259,15 @@ SPEC CHECKSUMS:
permission_handler_apple: 44366e37eaf29454a1e7b1b7d736c2cceaeb17ce
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
Protobuf: f4128517d7a42302e106cc3afe614ee3a7513e94
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
Realm: 10df7d86e1ca09d9948fdce2faa3fc623fb092c6
RealmSwift: aecc52389574be4d451bf6cb1b08824eaa17dad0
Sentry: dd29c18c32b0af9269949f079cf631d581ca76ca
sentry_flutter: 544b23de27343d0cd12d8d16b0fac71dc884f0e6
share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68
shared_preferences_ios: 548a61f8053b9b8a49ac19c1ffbc8b92c50d68ad
sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904
task_manager: 84b4c39309350abc13eebd79f9d073061391205c
TOCropViewController: edfd4f25713d56905ad1e0b9f5be3fbe0f59c863
url_launcher_ios: 839c58cdb4279282219f5e248c3321761ff3c4de
workmanager: 0afdcf5628bbde6924c21af7836fed07b42e30e6

PODFILE CHECKSUM: aa97d8b016d7264ad0a1ef5c44765133ae787bc4

Expand Down
83 changes: 0 additions & 83 deletions packages/smooth_app/lib/pages/crop_helper.dart

This file was deleted.

121 changes: 7 additions & 114 deletions packages/smooth_app/lib/pages/image_crop_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/helpers/camera_helper.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/crop_helper.dart';
import 'package:smooth_app/pages/product/confirm_and_upload_picture.dart';
import 'package:smooth_app/tmp_crop_image/new_crop_page.dart';

/// Picks an image file from gallery or camera.
Future<XFile?> _pickImageFile(final State<StatefulWidget> widget) async {
Future<XFile?> pickImageFile(final State<StatefulWidget> widget) async {
final UserPictureSource? source = await _getUserPictureSource(widget.context);
if (source == null) {
return null;
Expand Down Expand Up @@ -81,12 +79,13 @@ Future<UserPictureSource?> _getUserPictureSource(
);
}

/// Lets the user pick a picture, crop it, and save it.
Future<File?> confirmAndUploadNewPicture(
final State<StatefulWidget> widget, {
required final ImageField imageField,
required final String barcode,
}) async {
final File? croppedPhoto = await startNewImageCropping(widget, imageField);
final XFile? croppedPhoto = await pickImageFile(widget);
if (croppedPhoto == null) {
return null;
}
Expand All @@ -96,118 +95,12 @@ Future<File?> confirmAndUploadNewPicture(
return Navigator.push<File>(
widget.context,
MaterialPageRoute<File>(
builder: (BuildContext context) => ConfirmAndUploadPicture(
builder: (BuildContext context) => CropPage(
barcode: barcode,
imageField: imageField,
initialPhoto: croppedPhoto,
inputFile: File(croppedPhoto.path),
),
fullscreenDialog: true,
),
);
}

/// Crops an image picked from the gallery or camera.
Future<File?> startNewImageCropping(
final State<StatefulWidget> widget,
final ImageField imageField,
) async =>
_startImageCropping(widget, imageField);

/// Crops an existing image.
Future<File?> startExistingImageCropping(
final State<StatefulWidget> widget,
final ImageField imageField,
final File? existingImage,
) async =>
_startImageCropping(widget, imageField, existingImage: existingImage);

/// Crops an image, either existing or picked from the gallery or camera.
Future<File?> _startImageCropping(
final State<StatefulWidget> widget,
final ImageField imageField, {
final File? existingImage,
}) async {
// Show a loading page on the Flutter side
final NavigatorState navigator = Navigator.of(widget.context);
final CropHelper cropHelper = CropHelper.getCurrent(widget.context);
await _showScreenBetween(navigator);

if (!widget.mounted) {
return null;
}
final String sourceImagePath;
if (existingImage != null) {
sourceImagePath = existingImage.path;
} else {
final XFile? pickedXFile = await _pickImageFile(widget);
if (pickedXFile == null) {
await _hideScreenBetween(navigator);
return null;
}
sourceImagePath = pickedXFile.path;
}

if (!widget.mounted) {
return null;
}
final String? croppedPath = await cropHelper.getCroppedPath(
widget.context,
sourceImagePath,
pageTitle: getImagePageTitle(
AppLocalizations.of(widget.context),
imageField,
),
);

await _hideScreenBetween(navigator);

if (croppedPath == null) {
return null;
}

return File(croppedPath);
}

Future<void> _showScreenBetween(NavigatorState navigator) {
return ((NavigatorState navigator) async {
navigator.push<dynamic>(
MaterialPageRoute<dynamic>(
settings: _LoadingPage._settings,
builder: (_) => const _LoadingPage(),
),
);
}).call(navigator);
}

Future<void> _hideScreenBetween(NavigatorState navigator) async {
return ((NavigatorState navigator) async {
return navigator.pop((Route<dynamic> route) {
// Remove the screen, only if it's the loading screen
if (route.settings == _LoadingPage._settings) {
return true;
}
return false;
});
}).call(navigator);
}

/// A screen being displayed once an image is taken, but the cropper is not yet
/// visible
class _LoadingPage extends StatelessWidget {
const _LoadingPage({
Key? key,
}) : super(key: key);

static const RouteSettings _settings = RouteSettings(name: 'loading_page');

@override
Widget build(BuildContext context) {
return const SizedBox.expand(
child: ColoredBox(
color: Colors.black,
child: Center(
child: CircularProgressIndicator.adaptive(),
),
),
);
}
}
Loading