Skip to content

Commit

Permalink
ci: Return to entrypoint based scanner (#3874)
Browse files Browse the repository at this point in the history
* ci: Return to entrypoint based scanner

* Update basic_test.dart
  • Loading branch information
M123-dev committed Apr 14, 2023
1 parent 8187e40 commit 1734a20
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 146 deletions.
4 changes: 2 additions & 2 deletions packages/smooth_app/integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void main() {

await app.launchSmoothApp(
scanner: SmoothBarcodeScannerType.mockup,
appStore: const MockedAppStore(),
appFlavour: 'test-runner',
store: const MockedAppStore(),
flavour: 'test-runner',
screenshots: true,
);
await tester.pumpAndSettle();
Expand Down
15 changes: 0 additions & 15 deletions packages/smooth_app/lib/data_models/user_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:smooth_app/data_models/product_preferences.dart';
import 'package:smooth_app/pages/onboarding/onboarding_flow_navigator.dart';
import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart';
import 'package:smooth_app/pages/scan/smooth_barcode_scanner_type.dart';
import 'package:smooth_app/themes/color_schemes.dart';

/// User choice regarding the picture source.
Expand Down Expand Up @@ -88,8 +87,6 @@ class UserPreferences extends ChangeNotifier {
static const String _TAG_IN_APP_REVIEW_ALREADY_DISPLAYED =
'inAppReviewAlreadyAsked';

static const String _DEV_MODE_SCANNING_ENGINE = 'devModeScanningEngine';

Future<void> init(final ProductPreferences productPreferences) async {
if (_sharedPreferences.getBool(_TAG_INIT) != null) {
return;
Expand Down Expand Up @@ -299,16 +296,4 @@ class UserPreferences extends ChangeNotifier {
await _sharedPreferences.setString(_TAG_USER_PICTURE_SOURCE, source.tag);
notifyListeners();
}

SmoothBarcodeScannerType scanningEngine() {
final String name =
_sharedPreferences.getString(_DEV_MODE_SCANNING_ENGINE) ?? 'mlkit';
return SmoothBarcodeScannerType.values.singleWhere(
(SmoothBarcodeScannerType element) => element.name == name);
}

Future<void> setScanningEngine(final SmoothBarcodeScannerType source) async {
await _sharedPreferences.setString(_DEV_MODE_SCANNING_ENGINE, source.name);
notifyListeners();
}
}
4 changes: 2 additions & 2 deletions packages/smooth_app/lib/entrypoints/android/main_fdroid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import 'package:smooth_app/pages/scan/smooth_barcode_scanner_type.dart';
void main() {
launchSmoothApp(
scanner: SmoothBarcodeScannerType.zxing,
appStore: URIAppStore(
store: URIAppStore(
Uri.parse(
'https://f-droid.org/fr/packages/openfoodfacts.github.scrachx.openfood/',
),
),
appFlavour: 'zxing-uri',
flavour: 'zxing-uri',
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:smooth_app/pages/scan/smooth_barcode_scanner_type.dart';
void main() {
launchSmoothApp(
scanner: SmoothBarcodeScannerType.mlkit,
appStore: GooglePlayStore(),
appFlavour: 'ml-play',
store: GooglePlayStore(),
flavour: 'ml-play',
);
}
4 changes: 2 additions & 2 deletions packages/smooth_app/lib/entrypoints/ios/main_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:smooth_app/pages/scan/smooth_barcode_scanner_type.dart';
void main() {
launchSmoothApp(
scanner: SmoothBarcodeScannerType.mlkit,
appStore: AppleAppStore('588797948'),
appFlavour: 'ml-ios',
store: AppleAppStore('588797948'),
flavour: 'ml-ios',
);
}
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/helpers/analytics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class AnalyticsHelper {
// To set a uniform sample rate
options.tracesSampleRate = 1.0;
options.beforeSend = _beforeSend;
options.environment = flavour;
options.environment = appFlavour;
},
appRunner: appRunner,
);
Expand Down
38 changes: 18 additions & 20 deletions packages/smooth_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,45 +52,47 @@ void main() {
}
}

late bool _screenshots;
late String flavour;
late final bool _screenshots;

late final String appFlavour;
late final SmoothBarcodeScannerType scannerType;
late final AppStore appStore;

Future<void> launchSmoothApp({
required SmoothBarcodeScannerType scanner,
required AppStore appStore,
required String appFlavour,
required AppStore store,
required String flavour,
final bool screenshots = false,
}) async {
_screenshots = screenshots;
scannerType = scanner;
appStore = store;
appFlavour = flavour;

if (_screenshots) {
await _init1(appStore);
runApp(SmoothApp(scanner, appStore));
await _init1();
runApp(const SmoothApp());
return;
}
final WidgetsBinding widgetsBinding =
WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);

flavour = appFlavour;

if (kReleaseMode) {
await AnalyticsHelper.initSentry(
appRunner: () => runApp(SmoothApp(scanner, appStore)));
appRunner: () => runApp(const SmoothApp()));
} else {
runApp(
DevicePreview(
enabled: true,
builder: (_) => SmoothApp(scanner, appStore),
builder: (_) => const SmoothApp(),
),
);
}
}

class SmoothApp extends StatefulWidget {
const SmoothApp(this.scanner, this.appStore);

final SmoothBarcodeScannerType scanner;
final AppStore appStore;
const SmoothApp();

// This widget is the root of your application
@override
Expand All @@ -112,7 +114,7 @@ bool _init1done = false;
// Had to split init in 2 methods, for test/screenshots reasons.
// Don't know why, but some init codes seem to freeze the test.
// Now we run them before running the app, during the tests.
Future<bool> _init1(AppStore appStore) async {
Future<bool> _init1() async {
if (_init1done) {
return false;
}
Expand Down Expand Up @@ -167,7 +169,7 @@ class _SmoothAppState extends State<SmoothApp> {
}

Future<bool> _init2() async {
await _init1(widget.appStore);
await _init1();
systemDarkmodeOn = brightness == Brightness.dark;
if (!mounted) {
return false;
Expand Down Expand Up @@ -216,10 +218,6 @@ class _SmoothAppState extends State<SmoothApp> {
provide<ContinuousScanModel>(_continuousScanModel),
provide<SmoothAppDataImporter>(_appDataImporter),
provide<PermissionListener>(_permissionListener),
// TODO(m123): Re-add engine split
/*Provider<SmoothBarcodeScannerType>.value(
value: widget.scanner,
),*/
],
builder: _buildApp,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _UserPreferencesDebugInfoState extends State<UserPreferencesDebugInfo> {

infos.putIfAbsent('Version', () => packageInfo.version);
infos.putIfAbsent('BuildNumber', () => packageInfo.buildNumber);
infos.putIfAbsent('Flavour', () => flavour);
infos.putIfAbsent('Flavour', () => appFlavour);
infos.putIfAbsent('PackageName', () => packageInfo.packageName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import 'package:smooth_app/pages/onboarding/onboarding_flow_navigator.dart';
import 'package:smooth_app/pages/preferences/abstract_user_preferences.dart';
import 'package:smooth_app/pages/preferences/user_preferences_dev_debug_info.dart';
import 'package:smooth_app/pages/preferences/user_preferences_page.dart';
import 'package:smooth_app/pages/scan/smooth_barcode_scanner_type.dart';
import 'package:smooth_app/query/product_query.dart';

/// Full page display of "dev mode" for the preferences page.
Expand Down Expand Up @@ -81,37 +80,6 @@ class UserPreferencesDevMode extends AbstractUserPreferences {

@override
List<Widget> getBody() => <Widget>[
ListTile(
title: const Text('Barcode scanning engine'),
trailing: DropdownButton<SmoothBarcodeScannerType>(
value: userPreferences.scanningEngine(),
elevation: 16,
onChanged: (SmoothBarcodeScannerType? newValue) async {
if (newValue != null) {
await userPreferences.setScanningEngine(newValue);
}
setState(() {});
},
items: const <DropdownMenuItem<SmoothBarcodeScannerType>>[
DropdownMenuItem<SmoothBarcodeScannerType>(
value: SmoothBarcodeScannerType.mlkit,
child: Text('ML Kit'),
),
DropdownMenuItem<SmoothBarcodeScannerType>(
value: SmoothBarcodeScannerType.zxing,
child: Text('Zxing'),
),
DropdownMenuItem<SmoothBarcodeScannerType>(
value: SmoothBarcodeScannerType.awesome,
child: Text('Awesome'),
),
DropdownMenuItem<SmoothBarcodeScannerType>(
value: SmoothBarcodeScannerType.mockup,
child: Text('Mockup'),
),
],
),
),
SwitchListTile(
title: Text(
appLocalizations.contribute_develop_dev_mode_title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class UserPreferencesFaq extends AbstractUserPreferences {
),
),
Text(
'${packageInfo.version}+${packageInfo.buildNumber}-$flavour',
'${packageInfo.version}+${packageInfo.buildNumber}-$appFlavour',
style: themeData.textTheme.titleSmall,
)
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class _RateUs extends StatelessWidget {
}

String getImagePath() {
final String appFlavour = flavour;
String imagePath = '';
switch (appFlavour) {
case 'zxing-uri':
Expand Down
16 changes: 5 additions & 11 deletions packages/smooth_app/lib/pages/scan/camera_scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/helpers/app_helper.dart';
import 'package:smooth_app/helpers/camera_helper.dart';
import 'package:smooth_app/helpers/haptic_feedback_helper.dart';
import 'package:smooth_app/main.dart';
//import 'package:smooth_app/pages/scan/smooth_barcode_scanner_awesome.dart';
import 'package:smooth_app/pages/scan/smooth_barcode_scanner_mlkit.dart';
import 'package:smooth_app/pages/scan/smooth_barcode_scanner_mockup.dart';
Expand All @@ -18,9 +19,7 @@ import 'package:smooth_app/pages/scan/smooth_barcode_scanner_zxing.dart';

/// A page showing the camera feed and decoding barcodes.
class CameraScannerPage extends StatefulWidget {
const CameraScannerPage(this.scannerType);

final SmoothBarcodeScannerType scannerType;
const CameraScannerPage();

@override
CameraScannerPageState createState() => CameraScannerPageState();
Expand Down Expand Up @@ -53,25 +52,20 @@ class CameraScannerPageState extends State<CameraScannerPage>
}

@override
String get traceTitle => '${widget.scannerType}_page';
String get traceTitle => '${scannerType}_page';

@override
String get traceName => 'Opened ${widget.scannerType}_page';
String get traceName => 'Opened ${scannerType}_page';

@override
Widget build(BuildContext context) {
final SmoothBarcodeScannerType prefsScanner =
_userPreferences.scanningEngine();

if (!CameraHelper.hasACamera) {
return Center(
child: Text(AppLocalizations.of(context).permission_photo_none_found),
);
}

// TODO(m123): Re-add scanning engine
//switch (widget.scannerType) {
switch (prefsScanner) {
switch (scannerType) {
case SmoothBarcodeScannerType.mlkit:
return SmoothBarcodeScannerMLKit(_onNewBarcodeDetected);
case SmoothBarcodeScannerType.zxing:
Expand Down
23 changes: 7 additions & 16 deletions packages/smooth_app/lib/pages/scan/scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/continuous_scan_model.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/helpers/permission_helper.dart';
import 'package:smooth_app/pages/scan/camera_scan_page.dart';
import 'package:smooth_app/pages/scan/smooth_barcode_scanner_type.dart';
import 'package:smooth_app/widgets/smooth_product_carousel.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

Expand Down Expand Up @@ -48,11 +46,6 @@ class _ScanPageState extends State<ScanPage> {
return const Center(child: CircularProgressIndicator.adaptive());
}

final UserPreferences prefs = context.watch<UserPreferences>();

// TODO(m123): Scanning engine
/*final SmoothBarcodeScannerType scannerType =
context.read<SmoothBarcodeScannerType>();*/
return SmoothScaffold(
brightness: Brightness.light,
body: SafeArea(
Expand All @@ -71,22 +64,20 @@ class _ScanPageState extends State<ScanPage> {
return EMPTY_WIDGET;
case DevicePermissionStatus.granted:
// TODO(m123): change
return const CameraScannerPage(
SmoothBarcodeScannerType.mockup);
return const CameraScannerPage();
default:
return const _PermissionDeniedCard();
}
},
),
),
if (prefs.scanningEngine() != SmoothBarcodeScannerType.awesome)
const Expanded(
flex: _carouselHeightPct,
child: Padding(
padding: EdgeInsetsDirectional.only(bottom: 10),
child: SmoothProductCarousel(containSearchCard: true),
),
const Expanded(
flex: _carouselHeightPct,
child: Padding(
padding: EdgeInsetsDirectional.only(bottom: 10),
child: SmoothProductCarousel(containSearchCard: true),
),
),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ class _SmoothBarcodeScannerMLKitState extends State<SmoothBarcodeScannerMLKit>
}
},
),
const Align(
alignment: Alignment.topCenter,
child: Text(
'ML Kit',
style: TextStyle(color: Colors.red),
),
),
const Center(
child: Padding(
padding: EdgeInsets.all(_cornerPadding),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ class _SmoothBarcodeScannerZXingState extends State<SmoothBarcodeScannerZXing> {
child: SmoothBarcodeScannerVisor(),
),
),
const Align(
alignment: Alignment.topCenter,
child: Text(
'ZXing',
style: TextStyle(color: Colors.red),
),
),
const Align(
alignment: Alignment.topCenter,
child: ScanHeader(),
Expand Down

0 comments on commit 1734a20

Please sign in to comment.