Skip to content

Commit

Permalink
Fix errors. (#12)
Browse files Browse the repository at this point in the history
* Increment version number to 0.0.9.

Signed-off-by: Dmytro Turskyi <[email protected]>

* Remove unused parameters in onError

Signed-off-by: Dmytro Turskyi <[email protected]>

* Fix "Don't use 'BuildContext's across async gaps, guarded by an unrelated 'mounted' check • "

Signed-off-by: Dmytro Turskyi <[email protected]>

* Adding animation and duration enum constants.

Signed-off-by: Dmytro Turskyi <[email protected]>

---------

Signed-off-by: Dmytro Turskyi <[email protected]>
  • Loading branch information
Turskyi authored Feb 18, 2024
1 parent e0287cb commit b2aa77c
Show file tree
Hide file tree
Showing 28 changed files with 176 additions and 131 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

# Ethical Scanner

Ethical Scanner is a Flutter project for Android and iOS mobile app that scans the barcode
**Ethical Scanner** is a Flutter project for building Android and iOS mobile apps that scans the
barcode
of a product and tells you if the product meets your ethical standards.

The app allows you to customize your preferences based on
Expand Down Expand Up @@ -41,7 +42,8 @@ For more information, please visit the project website at https://ethical-scanne

• CI/CD: [GitHub Actions](https://docs.github.com/en/actions) is used to deliver new Android
Package (APK) to [Firebase App Distribution](https://firebase.google.com/docs/app-distribution)
after every push to the **dev** branch, [Codemagic](https://codemagic.io/start/) is used to deliver
after every push to any other than the **main** branch, [Codemagic](https://codemagic.io/start/) is
used to deliver
new release app bundle to **Google Play** after every merge (push) to **master** branch;

• State management approach: [BLoC](https://bloclibrary.dev);
Expand Down
6 changes: 4 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//noinspection GrUnresolvedAccess
plugins {
id "com.android.application"
id "kotlin-android"
Expand All @@ -10,6 +11,7 @@ def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
//noinspection GroovyAssignabilityCheck
localProperties.load(reader)
}
}
Expand Down Expand Up @@ -116,6 +118,6 @@ flutter {
}

dependencies {
implementation 'com.google.firebase:firebase-crashlytics:18.6.1'
implementation 'com.google.firebase:firebase-analytics:21.5.0'
implementation 'com.google.firebase:firebase-crashlytics:18.6.2'
implementation 'com.google.firebase:firebase-analytics:21.5.1'
}
4 changes: 2 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.turskyi.ethical_scanner"
android:versionCode="8"
android:versionName="0.0.8">
android:versionCode="9"
android:versionName="0.0.9">

<queries>
<intent>
Expand Down
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//noinspection GrUnresolvedAccess
buildscript {
ext {
kotlin_version = '1.9.0'
Expand Down
2 changes: 2 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//noinspection GrUnresolvedAccess
pluginManagement {
//noinspection GroovyAssignabilityCheck
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
Expand Down
1 change: 1 addition & 0 deletions components/core/entities/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#file: noinspection GrazieInspection
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
Expand Down
1 change: 1 addition & 0 deletions components/core/use_cases/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#file: noinspection GrazieInspection
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
Expand Down
2 changes: 1 addition & 1 deletion components/interface_adapters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ flutter pub run build_runner build --delete-conflicting-outputs
## Usage

The low-level details of the `construct_pm_interface_adapters` are relegated to plugin modules that
can be deployed and developed independently from the modules that contain high-level policies.
can be deployed and developed independently of the modules that contain high-level policies.
`ui` could be replaced with any other kind of interface—and the business rules would not care.
If the `ui` plugs in to the business rules, then changes in the `ui` cannot affect those business
rules.
Expand Down
2 changes: 2 additions & 0 deletions components/interface_adapters/lib/interface_adapters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ export 'src/ui/modules/photo/view/photo_view.dart';
export 'src/ui/modules/scan/scan_event.dart';
export 'src/ui/modules/scan/scan_presenter.dart';
export 'src/ui/modules/scan/view/scan_view.dart';
export 'src/ui/res/enums/animation_constants.dart';
export 'src/ui/res/enums/duration_seconds.dart';
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:interface_adapters/interface_adapters.dart';

class DelayedAnimation extends StatefulWidget {
const DelayedAnimation({
Expand Down Expand Up @@ -33,7 +34,7 @@ class _DelayedAnimationState extends State<DelayedAnimation>
curve: Curves.easeOutQuint,
);
_animOffset = Tween<Offset>(
begin: const Offset(0.0, 0.35),
begin: Offset(AnimationConstants.transparentOpacityAnimation.value, 0.35),
end: Offset.zero,
).animate(curve);
if (widget.delay == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class _FabState extends State<Fab> with TickerProviderStateMixin {
builder: (_, HomeViewModel viewModel) {
return AnimatedPadding(
padding: EdgeInsets.only(bottom: _bottomPadding),
duration: const Duration(seconds: 1),
duration: Duration(seconds: DurationSeconds.short.time),
child: Stack(
alignment: AlignmentDirectional.center,
children: <Widget>[
Expand Down Expand Up @@ -142,7 +142,7 @@ class _FabState extends State<Fab> with TickerProviderStateMixin {
valueListenable: _isExpandedNotifier,
builder: (_, bool isExpanded, __) => AnimatedPositioned(
bottom: isExpanded ? 0 : 2,
duration: const Duration(seconds: 1),
duration: Duration(seconds: DurationSeconds.short.time),
child: ValueListenableBuilder<bool>(
valueListenable: _isEnabledNotifier,
builder:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_translate/flutter_translate.dart';
import 'package:interface_adapters/src/constants.dart' as constants;
import 'package:interface_adapters/src/ui/modules/photo/photo_event.dart';
import 'package:interface_adapters/src/ui/modules/photo/photo_presenter.dart';
import 'package:interface_adapters/src/ui/res/resources.dart';
import 'package:interface_adapters/src/ui/res/values/constants.dart'
as constants;
import 'package:interface_adapters/src/ui/res/values/dimens.dart';
import 'package:url_launcher/url_launcher.dart';

Expand Down Expand Up @@ -298,10 +299,12 @@ class _CameraScreenState extends State<PhotoView> {
XFile picture =
await _controller.takePicture();

if (mounted) {
if (context.mounted) {
context
.read<PhotoPresenter>()
.add(TakenPhotoEvent(picture.path));
} else {
//TODO: add error event
}
} catch (e) {
debugPrint('Error taking picture: $e');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:interface_adapters/interface_adapters.dart';
import 'package:interface_adapters/src/ui/modules/scan/view/scan_painter.dart';

class ScanAnimation extends StatefulWidget {
Expand All @@ -10,8 +11,7 @@ class ScanAnimation extends StatefulWidget {

class _ScanAnimationState extends State<ScanAnimation>
with SingleTickerProviderStateMixin {
// Define meaningful names for durations and sizes
final Duration _animationDuration = const Duration(seconds: 2);
// Define meaningful names for durations and sizes.
final double _paintSize = 300.0;
final double _transparentOpacityAnimation = 0.0;
final double _opaqueOpacityAnimation = 1.0;
Expand All @@ -24,7 +24,7 @@ class _ScanAnimationState extends State<ScanAnimation>
super.initState();
_controller = AnimationController(
vsync: this,
duration: _animationDuration,
duration: Duration(seconds: DurationSeconds.long.time),
);
_animation = Tween<double>(
begin: _transparentOpacityAnimation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import 'package:audiofileplayer/audiofileplayer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_translate/flutter_translate.dart';
import 'package:interface_adapters/src/constants.dart' as constants;
import 'package:interface_adapters/src/ui/modules/home/view/widgets/scanner_error_widget.dart';
import 'package:interface_adapters/src/ui/modules/scan/scan_event.dart';
import 'package:interface_adapters/src/ui/modules/scan/scan_presenter.dart';
import 'package:interface_adapters/src/ui/modules/scan/view/scan_placeholder_widget.dart';
import 'package:interface_adapters/src/ui/modules/scan/view/scanner_overlay.dart';
import 'package:interface_adapters/src/ui/res/resources.dart';
import 'package:interface_adapters/src/ui/res/values/constants.dart'
as constants;
import 'package:interface_adapters/src/ui/res/values/dimens.dart';
import 'package:mobile_scanner/mobile_scanner.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enum AnimationConstants {
transparentOpacityAnimation(0.0),
maxTranslationOffset(100.0);

const AnimationConstants(this.value);

final double value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enum DurationSeconds {
long(2),
short(1);

const DurationSeconds(this.time);

final int time;
}
6 changes: 2 additions & 4 deletions lib/data/data_sources/remote/remote_data_source_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'dart:io';
import 'package:collection/collection.dart';
import 'package:dart_openai/dart_openai.dart';
import 'package:entities/entities.dart';
import 'package:ethical_scanner/constants.dart' as constants;
import 'package:ethical_scanner/data/data_mappers/product_data_mapper.dart';
import 'package:ethical_scanner/data/data_mappers/product_result_data_mapper.dart';
import 'package:ethical_scanner/res/values/constants.dart' as constants;
import 'package:interface_adapters/interface_adapters.dart';
import 'package:openfoodfacts/openfoodfacts.dart';

Expand Down Expand Up @@ -89,9 +89,7 @@ class RemoteDataSourceImpl implements RemoteDataSource {
.choices.firstOrNull?.message.content?.firstOrNull?.text
?.trim();
return country ?? '';
}).onError((Object? error, StackTrace stacktrace) {
return '';
});
}).onError((_, __) => '');

@override
Future<void> addProduct(ProductInfo product) async {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:dio/dio.dart' hide Headers;
import 'package:entities/entities.dart';
import 'package:ethical_scanner/constants.dart' as constants;
import 'package:ethical_scanner/data/data_sources/remote/models/russia_sponsors_response/russia_sponsor_response.dart';
import 'package:ethical_scanner/res/values/constants.dart' as constants;
import 'package:retrofit/retrofit.dart';

part 'retrofit_client.g.dart';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/di/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import 'package:camera/camera.dart';
import 'package:dart_openai/dart_openai.dart';
import 'package:entities/entities.dart';
import 'package:ethical_scanner/camera_descriptions.dart' as cameras;
import 'package:ethical_scanner/constants.dart' as constants;
import 'package:ethical_scanner/di/dependencies.dart';
import 'package:ethical_scanner/res/values/constants.dart' as constants;
import 'package:flutter/widgets.dart';
import 'package:interface_adapters/interface_adapters.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:package_info_plus/package_info_plus.dart';

Future<Dependencies> injectAndGetDependencies() async {
/// Filter the `OpenFoodFactsLanguage` values based on the `Language` enum.
// Filter the `OpenFoodFactsLanguage` values based on the `Language` enum.
OpenFoodAPIConfiguration.globalLanguages = OpenFoodFactsLanguage.values
.where(
// Compare the code of the OpenFoodFactsLanguage value with the
Expand All @@ -34,8 +34,8 @@ Future<Dependencies> injectAndGetDependencies() async {
comment: constants.openFoodUserComment,
);

/// Needed for `Dependencies`, `PackageInfo.fromPlatform()` and
/// `availableCameras`.
// Needed for `Dependencies`, `PackageInfo.fromPlatform()` and
// `availableCameras`.
WidgetsFlutterBinding.ensureInitialized();

PackageInfo packageInfo = await PackageInfo.fromPlatform();
Expand Down
8 changes: 4 additions & 4 deletions lib/localization_delelegate_getter.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import 'package:entities/entities.dart';
import 'package:ethical_scanner/constants.dart' as constants;
import 'package:ethical_scanner/res/values/constants.dart' as constants;
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_translate/flutter_translate.dart';

Future<LocalizationDelegate> getLocalizationDelegate() async {
/// Get the singleton instance of the `PlatformDispatcher`.
// Get the singleton instance of the `PlatformDispatcher`.
PlatformDispatcher platformDispatcher = PlatformDispatcher.instance;

/// Get the current locale from the `PlatformDispatcher`.
// Get the current locale from the `PlatformDispatcher`.
Locale deviceLocale = platformDispatcher.locale;

/// Get the language code from the `Locale`.
// Get the language code from the `Locale`.
String deviceIsoLanguageCode = deviceLocale.languageCode;

LocalizationDelegate localizationDelegate = await LocalizationDelegate.create(
Expand Down
15 changes: 10 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ import 'package:interface_adapters/interface_adapters.dart';
/// The [main] is the ultimate detail — the lowest-level policy.
/// It is the initial entry point of the system.
/// Nothing, other than the operating system, depends on it.
/// Think of [main] as a plugin to the [App]. Its job is to create all the
/// factories, strategies, and other global facilities, and then hand control
/// over to the high-level policy of the [App].
/// It is in this [main] component that [Dependencies] should be injected.
/// The [main] is a dirty low-level module in the outermost circle of the clean
/// architecture.
/// Think of [main] as a plugin to the [App] — a plugin that sets up the
/// initial conditions and configurations, gathers all the outside resources,
/// and then hands control over to the high-level policy of the [App].
/// When [main] is released, it has utterly no effect on any of the other
/// components in the system. They don’t know about [main], and they don’t care
/// when it changes.
void main() async {
/// Get the singleton instance of the `PlatformDispatcher`.
LocalizationDelegate localizationDelegate = await getLocalizationDelegate();

/// Filter the `OpenFoodFactsLanguage` values based on the `Language` enum.
// Filter the `OpenFoodFactsLanguage` values based on the `Language` enum.
Dependencies dependencies = await injectAndGetDependencies();

runApp(
Expand Down
File renamed without changes.
Loading

0 comments on commit b2aa77c

Please sign in to comment.