Skip to content

Commit

Permalink
Improve error handling and added message if upload photo was successful.
Browse files Browse the repository at this point in the history
Signed-off-by: Dmytro Turskyi <[email protected]>
  • Loading branch information
Turskyi committed Feb 14, 2024
1 parent a5a4d5e commit 98aa449
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 94 deletions.
10 changes: 8 additions & 2 deletions components/interface_adapters/assets/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"title": "Ethical Scanner",
"app_feedback": "App Feedback",
"copied_to_clipboard": "Copied to clipboard",
"menu": {
"home": "Home",
"scan": "Scan",
Expand All @@ -27,13 +28,18 @@
"ingredients_colon": "Ingredients: ",
"website_colon": "Website: ",
"country_ai_colon": "AI-Generated Country Information: ",
"error_colon": "Error: "
"error_colon": "Error: ",
"click": "Click ",
"here": "here",
"or": " or ",
"to_know_more": " to know more."
},
"scan": {
"scan_screen": "Scan screen",
"scanning": "Scanning..."
},
"photo": {
"capture_ingredients": "Make a photo of the ingredients."
"capture_ingredients": "Make a photo of the ingredients.",
"image_upload_successful": "Image upload successful!"
}
}
10 changes: 8 additions & 2 deletions components/interface_adapters/assets/i18n/uk.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"title": "Ethical Scanner",
"app_feedback": "Відгук про додаток",
"copied_to_clipboard": "Скопійовано в буфер обміну.",
"menu": {
"home": "Домашня сторінка",
"scan": "Сканер",
Expand All @@ -27,13 +28,18 @@
"ingredients_colon": "Інгредієнти: ",
"website_colon": "Веб-сайт: ",
"country_ai_colon": "Інформація про країну, згенерована ШІ: ",
"error_colon": "Помилка: "
"error_colon": "Помилка: ",
"click": "Натисніть ",
"here": "тут",
"or": " або ",
"to_know_more": " щоб дізнатися більше."
},
"scan": {
"scan_screen": "Вікно сканування",
"scanning": "Сканування..."
},
"photo": {
"capture_ingredients": "Сфотографуйте\nінгредієнти."
"capture_ingredients": "Сфотографуйте\nінгредієнти.",
"image_upload_successful": "Завантаження зображення успішне!"
}
}
1 change: 1 addition & 0 deletions components/interface_adapters/lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const String scanSoundAsset =
'components/interface_adapters/assets/audio/store_scanner_beep.mp3';
const String mailToScheme = 'mailto';
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ class HomePresenter extends Bloc<HomeEvent, HomeViewModel> {
modifiableProductInfo[ProductInfoType.companyTerrorismSponsor] =
productInfo.isCompanyTerrorismSponsor
? (state.language.isEnglish
? 'Probably yes'
: 'Напевно так')
? 'Probably yes. '
: 'Напевно так. ')
: 'No';
if (state is LoadingProductInfoState) {
LoadingProductInfoState loadingState =
Expand Down Expand Up @@ -193,6 +193,7 @@ class HomePresenter extends Bloc<HomeEvent, HomeViewModel> {
);
}
}

if (productInfo.vegan != Vegan.unknown) {
modifiableProductInfo[ProductInfoType.isVegan] =
productInfo.vegan == Vegan.positive ? 'Yes' : 'No';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import 'package:package_info_plus/package_info_plus.dart';
import 'package:path_provider/path_provider.dart';

class ProductInfoBody extends StatelessWidget {
const ProductInfoBody({
super.key,
});
const ProductInfoBody({super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -40,12 +38,12 @@ class ProductInfoBody extends StatelessWidget {
builder: (_, HomeViewModel viewModel) {
if (viewModel is ProductInfoState) {
return RefreshIndicator(
onRefresh: () =>
PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
return BetterFeedback.of(context).show((UserFeedback feedback) {
return _sendFeedback(feedback, packageInfo);
});
}),
onRefresh: () => PackageInfo.fromPlatform().then(
(PackageInfo packageInfo) => BetterFeedback.of(context).show(
(UserFeedback feedback) =>
_sendFeedback(feedback, packageInfo),
),
),
child: ListView.builder(
padding: EdgeInsets.only(
top: dimens.productInfoListTopPadding,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:entities/entities.dart';
import 'package:flutter/gestures.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/ui/modules/home/home_event.dart';
import 'package:interface_adapters/src/ui/modules/home/home_presenter.dart';
import 'package:interface_adapters/src/ui/res/color/material_colors.dart';
import 'package:interface_adapters/src/ui/res/resources.dart';
import 'package:url_launcher/url_launcher.dart';

class ProductInfoTile extends StatelessWidget {
const ProductInfoTile({
Expand Down Expand Up @@ -45,8 +47,8 @@ class ProductInfoTile extends StatelessWidget {
} else {
return Icons.star;
}
// Call the function immediately and use the returned value as the
// icon parameter.
// Call the function immediately `()` and use the returned value as
// the `icon` parameter.
}(),
),
onPressed: isIngredientsMissing
Expand All @@ -62,45 +64,100 @@ class ProductInfoTile extends StatelessWidget {
fontSize: textTheme.titleLarge?.fontSize,
),
),
subtitle: Text(
value +
(type.isWebsite ||
type.isCompanyWarSponsor ||
type.isTerrorismSponsor
? translate('product_info.click_to_know')
: isIngredientsMissing
? translate('product_info.ingredients_missing')
: isIngredientsImageAdded
? translate('product_info.ingredients_image_added')
: ''),
style: TextStyle(
fontStyle: FontStyle.italic,
fontSize: textTheme.bodyLarge?.fontSize,
decoration: type.isWebsite ||
type.isCompanyWarSponsor ||
type.isTerrorismSponsor
? TextDecoration.underline
: null,
),
),
onTap:
type.isWebsite || type.isCompanyWarSponsor || type.isTerrorismSponsor
? () => context.read<HomePresenter>().add(
LaunchUrlEvent(
uri: type.isCompanyWarSponsor
? resources.strings.warSponsorSource
: type.isTerrorismSponsor
? resources.strings.russiaTerrorismSponsorSource
: value,
language: Language.fromIsoLanguageCode(
LocalizedApp.of(context)
.delegate
.currentLocale
.languageCode,
),
subtitle: type.isCompanyWarSponsor
? RichText(
text: TextSpan(
text: value + translate('product_info.click'),
style: TextStyle(
fontStyle: FontStyle.italic,
fontSize: textTheme.bodyLarge?.fontSize,
),
children: <TextSpan>[
TextSpan(
text: translate('product_info.here'),
style: TextStyle(
color: Colors.lightBlueAccent,
decoration: TextDecoration.underline,
fontStyle: FontStyle.italic,
fontSize: textTheme.bodyLarge?.fontSize,
),
recognizer: TapGestureRecognizer()
..onTap = () {
final Uri link = Uri.parse(
resources.strings.warSponsorsSource,
);
launchUrl(link);
},
),
TextSpan(
text: translate('product_info.or'),
style: TextStyle(
fontStyle: FontStyle.italic,
fontSize: textTheme.bodyLarge?.fontSize,
),
),
TextSpan(
text: translate('product_info.here'),
style: TextStyle(
color: Colors.lightBlueAccent,
decoration: TextDecoration.underline,
fontStyle: FontStyle.italic,
fontSize: textTheme.bodyLarge?.fontSize,
),
recognizer: TapGestureRecognizer()
..onTap = () {
final Uri link = Uri.parse(
resources.strings.russiaSponsorsSource,
);
launchUrl(link);
},
),
TextSpan(
text: translate('product_info.to_know_more'),
style: TextStyle(
fontStyle: FontStyle.italic,
fontSize: textTheme.bodyLarge?.fontSize,
),
)
: null,
),
],
),
)
: Text(
value +
(type.isWebsite || type.isTerrorismSponsor
? translate('product_info.click_to_know')
: isIngredientsMissing
? translate('product_info.ingredients_missing')
: isIngredientsImageAdded
? translate(
'product_info.ingredients_image_added',
)
: ''),
style: TextStyle(
fontStyle: FontStyle.italic,
fontSize: textTheme.bodyLarge?.fontSize,
decoration: type.isWebsite ||
type.isCompanyWarSponsor ||
type.isTerrorismSponsor
? TextDecoration.underline
: null,
),
),
onTap: type.isWebsite || type.isTerrorismSponsor
? () => context.read<HomePresenter>().add(
LaunchUrlEvent(
uri: type.isTerrorismSponsor
? resources.strings.russiaTerrorismSponsorSource
: value,
language: Language.fromIsoLanguageCode(
LocalizedApp.of(context)
.delegate
.currentLocale
.languageCode,
),
),
)
: null,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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';
Expand Down Expand Up @@ -218,9 +219,9 @@ class _CameraScreenState extends State<PhotoView> {
ClipboardData(text: viewModel.errorMessage),
);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
SnackBar(
content: Text(
'Copied to clipboard',
translate('copied_to_clipboard'),
textAlign: TextAlign.right,
),
),
Expand Down Expand Up @@ -251,15 +252,13 @@ class _CameraScreenState extends State<PhotoView> {
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
ElevatedButton(
onPressed: () {
_adjustZoomLevel(-_zoomStep); // Decrease zoom
},
// Decrease zoom
onPressed: () => _adjustZoomLevel(-_zoomStep),
child: const Icon(Icons.remove),
),
ElevatedButton(
onPressed: () {
_adjustZoomLevel(_zoomStep); // Increase zoom
},
// Increase zoom
onPressed: () => _adjustZoomLevel(_zoomStep),
child: const Icon(Icons.add),
),
],
Expand Down Expand Up @@ -367,7 +366,7 @@ class _CameraScreenState extends State<PhotoView> {
);
}

final String email = match.group(0)!;
final String? email = match.group(0);
spans.add(
TextSpan(
text: email,
Expand All @@ -380,7 +379,7 @@ class _CameraScreenState extends State<PhotoView> {
recognizer: TapGestureRecognizer()
..onTap = () async {
final Uri emailLaunchUri = Uri(
scheme: 'mailto',
scheme: constants.mailToScheme,
path: email,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class Strings {
const Strings();

final String warSponsorSource = 'https://sanctions.nazk.gov.ua/en/boycott/';
final String warSponsorsSource = 'https://sanctions.nazk.gov.ua/en/boycott/';
final String russiaSponsorsSource =
'https://www.yalerussianbusinessretreat.com';
final String russiaTerrorismSponsorSource =
'https://www.europarl.europa.eu/delegations/en/recognising-the-russian-federation-as-a-/product-details/20221124DPU34521';
}
7 changes: 4 additions & 3 deletions components/interface_adapters/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: interface_adapters
description: The software in the interface adapters layer is a set of adapters that convert data
from the format most convenient for the use cases and entities to the format most convenient for
some external agency such as the database or the web.
some external agency such as the database or the web services.
The presenters, views, and controllers all belong in the interface adapters layer.
No code inward of this circle should know anything at all about the database.
version: 0.0.1
# This prevents the package from being accidentally published to pub.dev using pub publish. This is
# preferred for private packages.
publish_to: none
homepage: https://ethical-scanner.turskyi.com
repository: https://github.com/Turskyi/ethical_scanner/tree/master/components/interface_adapters

environment:
sdk: '>=3.2.3 <4.0.0'
Expand All @@ -17,7 +18,7 @@ environment:
dependencies:
audiofileplayer: ^2.1.1
# state management package that helps implement the Business Logic Component design pattern.
bloc: ^8.1.2
bloc: ^8.1.3

camera: ^0.10.5+9
entities:
Expand All @@ -29,7 +30,7 @@ dependencies:
sdk: flutter

# Built to be used with the `bloc` state management package
flutter_bloc: ^8.1.3
flutter_bloc: ^8.1.4

# localization / internationalization (i18n) library
flutter_email_sender: ^6.0.2
Expand Down
Loading

0 comments on commit 98aa449

Please sign in to comment.