Skip to content

Commit

Permalink
feat: Migration to Flutter 3.0 / Dart 2.17 (#2307)
Browse files Browse the repository at this point in the history
* Migration to Flutter 3 / Dart 2.17 (enums migrated)

* Dart 2.17 (Super initializers)

* Remove all new super.key

* indice -> idx
  • Loading branch information
g123k authored Jun 20, 2022
1 parent 210a130 commit ee82d91
Show file tree
Hide file tree
Showing 32 changed files with 145 additions and 142 deletions.
4 changes: 2 additions & 2 deletions packages/data_importer/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version: 1.0.0
publish_to: none

environment:
sdk: ">=2.16.0 <3.0.0"
flutter: ">=2.5.0"
sdk: ">=2.17.0 <3.0.0"
flutter: ">=3.0.0"

dependencies:
flutter:
Expand Down
3 changes: 2 additions & 1 deletion packages/data_importer_shared/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ description: A starting point for Dart libraries or applications.
publish_to: none

environment:
sdk: '>=2.16.0 <3.0.0'
sdk: ">=2.17.0 <3.0.0"
flutter: ">=3.0.0"

dev_dependencies:
flutter_lints: ^1.0.0
Expand Down
10 changes: 3 additions & 7 deletions packages/smooth_app/lib/cards/category_cards/null_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import 'package:smooth_app/cards/category_cards/abstract_cache.dart';
/// Empty image cache: the url was null, there is not much we can display.
class NullCache extends AbstractCache {
const NullCache({
final double? width,
final double? height,
}) : super(
null,
width: width,
height: height,
);
super.width,
super.height,
}) : super(null);

@override
Widget build(BuildContext context) => getDefaultUnknown();
Expand Down
15 changes: 5 additions & 10 deletions packages/smooth_app/lib/cards/category_cards/raster_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ import 'package:smooth_app/cards/category_cards/raster_async_asset.dart';
/// Widget that displays a png/jpeg from network (and cache while waiting).
class RasterCache extends AbstractCache {
const RasterCache(
final String iconUrl, {
final double? width,
final double? height,
final bool displayAssetWhileWaiting = true,
}) : super(
iconUrl,
width: width,
height: height,
displayAssetWhileWaiting: displayAssetWhileWaiting,
);
super.iconUrl, {
super.width,
super.height,
super.displayAssetWhileWaiting = true,
});

@override
Widget build(BuildContext context) {
Expand Down
15 changes: 5 additions & 10 deletions packages/smooth_app/lib/cards/category_cards/svg_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ import 'package:smooth_app/cards/category_cards/svg_async_asset.dart';
/// Widget that displays a svg from network (and cache while waiting).
class SvgCache extends AbstractCache {
const SvgCache(
final String? iconUrl, {
final double? width,
final double? height,
super.iconUrl, {
super.width,
super.height,
this.color,
final bool displayAssetWhileWaiting = true,
}) : super(
iconUrl,
width: width,
height: height,
displayAssetWhileWaiting: displayAssetWhileWaiting,
);
super.displayAssetWhileWaiting = true,
});

final Color? color;

Expand Down
35 changes: 22 additions & 13 deletions packages/smooth_app/lib/data_models/product_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,28 @@ enum ProductListType {
}

extension ProductListTypeExtension on ProductListType {
static const Map<ProductListType, String> _keys = <ProductListType, String>{
ProductListType.HTTP_SEARCH_KEYWORDS: 'http/search/keywords',
ProductListType.HTTP_SEARCH_CATEGORY: 'http/search/category',
ProductListType.HTTP_USER_CONTRIBUTOR: 'http/user/contributor',
ProductListType.HTTP_USER_INFORMER: 'http/user/informer',
ProductListType.HTTP_USER_PHOTOGRAPHER: 'http/user/photographer',
ProductListType.HTTP_USER_TO_BE_COMPLETED: 'http/user/to_be_completed',
ProductListType.SCAN_SESSION: 'scan_session',
ProductListType.HISTORY: 'history',
ProductListType.USER: 'user',
};

String get key => _keys[this]!;
String get key {
switch (this) {
case ProductListType.HTTP_SEARCH_KEYWORDS:
return 'http/search/keywords';
case ProductListType.HTTP_SEARCH_CATEGORY:
return 'http/search/category';
case ProductListType.SCAN_SESSION:
return 'scan_session';
case ProductListType.HTTP_USER_CONTRIBUTOR:
return 'http/user/contributor';
case ProductListType.HTTP_USER_INFORMER:
return 'http/user/informer';
case ProductListType.HTTP_USER_PHOTOGRAPHER:
return 'http/user/photographer';
case ProductListType.HTTP_USER_TO_BE_COMPLETED:
return 'http/user/to_be_completed';
case ProductListType.HISTORY:
return 'history';
case ProductListType.USER:
return 'user';
}
}
}

class ProductList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ class SmoothActionButtonsBar extends StatelessWidget {
const SmoothActionButtonsBar({
this.positiveAction,
this.negativeAction,
Key? key,
}) : assert(positiveAction != null || negativeAction != null,
'At least one action must be passed!'),
super(key: key);
super.key,
}) : assert(positiveAction != null || negativeAction != null,
'At least one action must be passed!');

const SmoothActionButtonsBar.single({
required SmoothActionButton action,
Expand Down
7 changes: 5 additions & 2 deletions packages/smooth_app/lib/generic_lib/smooth_html_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import 'package:fwfh_selectable_text/fwfh_selectable_text.dart';
import 'package:smooth_app/helpers/launch_url_helper.dart';

class SmoothHtmlWidget extends StatelessWidget {
const SmoothHtmlWidget(this.htmlString,
{this.textStyle, this.isSelectable = true});
const SmoothHtmlWidget(
this.htmlString, {
this.textStyle,
this.isSelectable = true,
});

final String htmlString;
final TextStyle? textStyle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/helpers/extension_on_text_helper.dart';

class SmoothErrorCard extends StatefulWidget {
const SmoothErrorCard(
{Key? key, required this.errorMessage, required this.tryAgainFunction})
: super(key: key);
const SmoothErrorCard({
super.key,
required this.errorMessage,
required this.tryAgainFunction,
});

final String errorMessage;
final void Function() tryAgainFunction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enum TextFieldTypes {

class SmoothTextFormField extends StatefulWidget {
const SmoothTextFormField({
Key? key,
super.key,
required this.type,
required this.controller,
this.enabled,
Expand All @@ -21,7 +21,7 @@ class SmoothTextFormField extends StatefulWidget {
this.textInputType,
this.onChanged,
this.autofocus,
}) : super(key: key);
});

final TextFieldTypes type;
final TextEditingController? controller;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ enum SmoothAppDataImporterStatus {
required,

/// No migration started (call [_checkStatus] to update)
notStarted,
}
notStarted;

extension SmoothAppDataImporterStatusExtension on SmoothAppDataImporterStatus {
String printableLabel(AppLocalizations appLocalizations) {
switch (this) {
case SmoothAppDataImporterStatus.alreadyDone:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
),
subtitle: Text(
appLocalizations
.dev_mode_scan_mode_subtitle(DevModeScanModeExtension.fromIndex(
.dev_mode_scan_mode_subtitle(DevModeScanMode.fromIndex(
userPreferences.getDevModeIndex(
userPreferencesEnumScanMode,
),
Expand Down Expand Up @@ -281,7 +281,7 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
if (scanMode != null) {
await userPreferences.setDevModeIndex(
userPreferencesEnumScanMode,
scanMode.index,
scanMode.idx,
);
setState(() {});
}
Expand Down Expand Up @@ -427,32 +427,24 @@ enum DevModeScanMode {
PREPROCESS_FULL_IMAGE,
PREPROCESS_HALF_IMAGE,
SCAN_FULL_IMAGE,
SCAN_HALF_IMAGE,
}

extension DevModeScanModeExtension on DevModeScanMode {
static const DevModeScanMode defaultScanMode =
DevModeScanMode.SCAN_FULL_IMAGE;

static const Map<DevModeScanMode, String> _labels = <DevModeScanMode, String>{
DevModeScanMode.CAMERA_ONLY: 'Only camera stream, no scanning',
DevModeScanMode.PREPROCESS_FULL_IMAGE:
'Camera stream and full image preprocessing, no scanning',
DevModeScanMode.PREPROCESS_HALF_IMAGE:
'Camera stream and half image preprocessing, no scanning',
DevModeScanMode.SCAN_FULL_IMAGE: 'Full image scanning',
DevModeScanMode.SCAN_HALF_IMAGE: 'Half image scanning',
};
SCAN_HALF_IMAGE;

static const Map<DevModeScanMode, int> _indices = <DevModeScanMode, int>{
DevModeScanMode.CAMERA_ONLY: 4,
DevModeScanMode.PREPROCESS_FULL_IMAGE: 3,
DevModeScanMode.PREPROCESS_HALF_IMAGE: 2,
DevModeScanMode.SCAN_FULL_IMAGE: 0,
DevModeScanMode.SCAN_HALF_IMAGE: 1,
};
static DevModeScanMode get defaultScanMode => DevModeScanMode.SCAN_FULL_IMAGE;

String get label => _labels[this]!;
String get label {
switch (this) {
case DevModeScanMode.CAMERA_ONLY:
return 'Only camera stream, no scanning';
case DevModeScanMode.PREPROCESS_FULL_IMAGE:
return 'Camera stream and full image preprocessing, no scanning';
case DevModeScanMode.PREPROCESS_HALF_IMAGE:
return 'Camera stream and half image preprocessing, no scanning';
case DevModeScanMode.SCAN_FULL_IMAGE:
return 'Full image scanning';
case DevModeScanMode.SCAN_HALF_IMAGE:
return 'Half image scanning';
}
}

String localizedLabel(AppLocalizations appLocalizations) {
switch (this) {
Expand All @@ -469,7 +461,20 @@ extension DevModeScanModeExtension on DevModeScanMode {
}
}

int get index => _indices[this]!;
int get idx {
switch (this) {
case DevModeScanMode.CAMERA_ONLY:
return 4;
case DevModeScanMode.PREPROCESS_FULL_IMAGE:
return 3;
case DevModeScanMode.PREPROCESS_HALF_IMAGE:
return 2;
case DevModeScanMode.SCAN_FULL_IMAGE:
return 0;
case DevModeScanMode.SCAN_HALF_IMAGE:
return 1;
}
}

static DevModeScanMode fromIndex(final int? index) {
if (index == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ const List<ImageField> _SORTED_IMAGE_FIELD_LIST = <ImageField>[
];

class AddNewProductPage extends StatefulWidget {
const AddNewProductPage(
this.barcode,
);
const AddNewProductPage(this.barcode);

final String barcode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import 'package:smooth_app/pages/product/common/product_refresher.dart';
/// ingredients.
class EditIngredientsPage extends StatefulWidget {
const EditIngredientsPage({
Key? key,
super.key,
required this.product,
}) : super(key: key);
});

final Product product;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import 'package:smooth_app/pages/product/nutrition_container.dart';

/// Actual nutrition page, with data already loaded.
class NutritionPageLoaded extends StatefulWidget {
const NutritionPageLoaded(this.product, this.orderedNutrients);
const NutritionPageLoaded(
this.product,
this.orderedNutrients,
);

final Product product;
final OrderedNutrients orderedNutrients;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:smooth_app/pages/product/simple_input_page_helpers.dart';

/// Simple input page: we have a list of terms, we add, we remove, we save.
class SimpleInputPage extends StatefulWidget {
const SimpleInputPage(this.helper) : super();
const SimpleInputPage(this.helper);

final AbstractSimpleInputPageHelper helper;

Expand Down
7 changes: 5 additions & 2 deletions packages/smooth_app/lib/pages/question_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,11 @@ class _QuestionPageState extends State<QuestionPage>
}

class CongratsWidget extends StatelessWidget {
const CongratsWidget(this._anonymousAnnotationList, {Key? key})
: super(key: key);
const CongratsWidget(
this._anonymousAnnotationList, {
super.key,
});

final Map<String, InsightAnnotation> _anonymousAnnotationList;

@override
Expand Down
13 changes: 4 additions & 9 deletions packages/smooth_app/lib/pages/scan/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ import 'package:smooth_app/data_models/user_preferences.dart';
class SmoothCameraController extends CameraController {
SmoothCameraController(
this.preferences,
CameraDescription description,
ResolutionPreset resolutionPreset, {
ImageFormatGroup? imageFormatGroup,
super.description,
super.resolutionPreset, {
super.imageFormatGroup,
}) : _state = _CameraState.notInitialized,
_hasAPendingResume = false,
super(
description,
resolutionPreset,
enableAudio: false,
imageFormatGroup: imageFormatGroup,
);

final UserPreferences preferences;
Expand Down Expand Up @@ -303,10 +300,8 @@ enum CameraFocusPointAlgorithm {
// Quicker algorithm, but may not work on old / Samsung devices
newAlgorithm,
// Old algorithm, which let more time between each focuses
oldAlgorithm,
}
oldAlgorithm;

extension CameraFocusPointAlgorithmExtension on CameraFocusPointAlgorithm {
FocusPointMode get mode {
switch (this) {
case CameraFocusPointAlgorithm.newAlgorithm:
Expand Down
6 changes: 3 additions & 3 deletions packages/smooth_app/lib/pages/scan/camera_image_cropper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import 'package:typed_data/typed_buffers.dart';
/// * left01: .5, top01: .5, width01: .5, height01: ..5 the bottom right rect
class CameraImageCropper extends AbstractCameraImageGetter {
CameraImageCropper(
final CameraImage cameraImage,
final CameraDescription cameraDescription, {
super.cameraImage,
super.cameraDescription, {
required this.left01,
required this.top01,
required this.width01,
required this.height01,
}) : super(cameraImage, cameraDescription) {
}) {
_computeCropParameters();
}

Expand Down
Loading

0 comments on commit ee82d91

Please sign in to comment.