mirror of
https://github.com/openfoodfacts/smooth-app.git
synced 2025-08-06 18:25:11 +08:00

* feat/3712 - new mlkit and zxing scanners on flutter 3.7 New files: * `smooth_barcode_scanner_mlkit.dart`: Barcode scanner based on MLKit. * `smooth_barcode_scanner_mockup.dart`: Fake barcode scanner, for tests. * `smooth_barcode_scanner_type.dart`: Barcode scanner types. * `smooth_barcode_scanner_zxing.dart`: Barcode scanner based on ZXing. Deleted files: * `scanner`: removed folder * `camera_controller.dart` * `camera_image_cropper.dart` * `camera_full_getter.dart` * `camera_image_preview.dart` * `camera_modes.dart` * `lifecycle_aware_widget.dart` * `lifecycle_manager.dart` * `scan_flash_toggle.dart` * `scan_visor.dart` * `scanner_overlay.dart` * `user_preferences_dialog_editor.dart` Impacted files: * `app_test.dart`: now uses new enum `SmoothBarcodeScannerType` * `background_task_badge.dart`: now uses flutter 3.7 badge * `basic_test.dart`: now uses new enum `SmoothBarcodeScannerType` * `build.gradle`: upgraded kotlin to 1.8.0 * `camera_helper.dart`: simplified * `camera_scan_page.dart`: simplified * `constant_icons.dart`: added an adaptive "flip camera" icon * `file_cache_manager_impl.dart`: minor 3.7 refactoring * `goldens.dart`: minor 3.7 refactoring * `labeler.yml`: removed references to delete files * `main_fdroid.dart`: now uses new enum `SmoothBarcodeScannerType` * `main_google_play.dart`: now uses new enum `SmoothBarcodeScannerType` * `main_ios.dart`: now uses new enum `SmoothBarcodeScannerType` * `network_config.dart`: minor 3.7 refactoring * `new_product_page.dart`: minor 3.7 refactoring * `onboarding_bottom_bar.dart`: minor 3.7 refactoring * `pubspec.lock`: wtf * `apple_app_store/pubspec.yaml`: minor 3.7 refactoring * `google_play/pubspec.yaml`: minor 3.7 refactoring * `shared/pubspec.yaml`: minor 3.7 refactoring * `uri_store/pubspec.yaml`: minor 3.7 refactoring * `data_importer/pubspec.yaml`: minor 3.7 refactoring * `data_importer_shared/pubspec.yaml`: minor 3.7 refactoring * `smooth_app/pubspec.yaml`: now includes mlkit and zxing scanners; minor 3.7 refactoring; removed now redundant `badge`; minor upgrades * `scan_page.dart`: simplified * `user_preferences.dart`: removed now useless methods * `user_preferences_dev_mode.dart`: removed duration and scan parameter settings * `user_preferences_settings.dart`: removed now useless parameter; minor 3.7 refactoring * feat/3712 - new "no camera found" message Impacted file: * `camera_scan_page.dart`: new "no camera found" message * fix github actions flutter version * feat/3712 - localized "no camera found" message Impacted files: * `app_en.arb`: new label for "no camera found" * `app_fr.arb`: new label for "no camera found" * `camera_scan_page.dart`: localized "no camera found" message --------- Co-authored-by: Marvin M <39344769+M123-dev@users.noreply.github.com>
39 lines
940 B
Dart
39 lines
940 B
Dart
import 'dart:io';
|
|
|
|
import 'package:camera/camera.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
class CameraHelper {
|
|
const CameraHelper._();
|
|
|
|
static List<CameraDescription>? _cameras;
|
|
|
|
/// Mandatory method to call before [findBestCamera]
|
|
static Future<void> init() async {
|
|
if (!isSupported) {
|
|
_cameras = <CameraDescription>[];
|
|
} else {
|
|
_cameras = await availableCameras();
|
|
}
|
|
}
|
|
|
|
/// Returns if the device has more than one camera
|
|
static bool get hasMoreThanOneCamera {
|
|
if (_cameras == null) {
|
|
throw Exception('Please call [init] before!');
|
|
}
|
|
return _cameras!.length > 1;
|
|
}
|
|
|
|
/// Returns if the device has at least one camera
|
|
static bool get hasACamera {
|
|
if (_cameras == null) {
|
|
throw Exception('Please call [init] before!');
|
|
} else {
|
|
return _cameras!.isNotEmpty;
|
|
}
|
|
}
|
|
|
|
static bool get isSupported => kIsWeb || Platform.isAndroid || Platform.isIOS;
|
|
}
|