Skip to content

Commit

Permalink
Feature/13 slang (#15)
Browse files Browse the repository at this point in the history
* integration of the slang library and transfer of strings to the translation file

# Conflicts:
#	lib/barcodes_panel.dart

* add slang to barcode panel

* review fixes/13

* fixes review/13

* fixes review/13

* fixes review/13

* fixes review/13

* fixes review/13

* fixes review/13

* fixes review/13
  • Loading branch information
karolgeneral authored Jul 18, 2024
1 parent 092c8be commit af04f85
Show file tree
Hide file tree
Showing 11 changed files with 507 additions and 55 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ linter:

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

81 changes: 45 additions & 36 deletions lib/barcode_item.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:barcode_widget/barcode_widget.dart';
import 'i18n/strings.g.dart';

class BarcodeItem {
final String description;
Expand All @@ -11,40 +12,48 @@ class BarcodeItem {
required this.type,
});

static final List<BarcodeItem> barcodes = [
BarcodeItem(
description: "Firma nie zweryfikowana",
data: "5905499300707",
type: Barcode.ean13()),
BarcodeItem(
description: "Firma zweryfikowana z pełną punktacją",
data: "5907632637572",
type: Barcode.ean13()),
BarcodeItem(
description: "Firma zweryfikowana z niepełną punktacją",
data: "5900497025454",
type: Barcode.ean13()),
BarcodeItem(
description: "Kod wewnętrzny", data: "00000000", type: Barcode.ean8()),
BarcodeItem(
description: "Firma zarejestrowana poza Polską",
data: "8680861069075",
type: Barcode.ean13()),
BarcodeItem(
description: "Firma zarejerstrowana w ...",
data: "5090000000006",
type: Barcode.ean13()),
BarcodeItem(
description: "Marka własna Lidla",
data: "20982515",
type: Barcode.ean8()),
BarcodeItem(
description: "Przyjaciel Poli",
data: "5906395053018",
type: Barcode.ean13()),
BarcodeItem(
description: "Rozszerzony opis firmy",
data: "9771644705002",
type: Barcode.ean13()),
];
static List<BarcodeItem> barcodes(Translations translations) {
return [
BarcodeItem(
description: translations.barcodesDescription.companyNotVerified,
data: "5905499300707",
type: Barcode.ean13()),
BarcodeItem(
description:
translations.barcodesDescription.companyVerifiedWithFullScores,
data: "5907632637572",
type: Barcode.ean13()),
BarcodeItem(
description: translations
.barcodesDescription.companyVerifiedWithIncompleteScores,
data: "5900497025454",
type: Barcode.ean13()),
BarcodeItem(
description: translations.barcodesDescription.internalCode,
data: "00000000",
type: Barcode.ean8()),
BarcodeItem(
description:
translations.barcodesDescription.companyRegisteredOutsidePoland,
data: "8680861069075",
type: Barcode.ean13()),
BarcodeItem(
description: translations.barcodesDescription.companyRegisteredIn,
data: "5090000000006",
type: Barcode.ean13()),
BarcodeItem(
description: translations.barcodesDescription.lidlOwnBrand,
data: "20982515",
type: Barcode.ean8()),
BarcodeItem(
description: translations.barcodesDescription.polaFriend,
data: "5906395053018",
type: Barcode.ean13()),
BarcodeItem(
description:
translations.barcodesDescription.extendedCompanyDescription,
data: "9771644705002",
type: Barcode.ean13()),
];
}
}
5 changes: 3 additions & 2 deletions lib/barcodes_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'barcode_item.dart';
import 'barcodes_list_view.dart';
import 'barcodes_panel.dart';
import 'i18n/strings.g.dart';

class BarcodesPage extends StatefulWidget {
const BarcodesPage({
Expand Down Expand Up @@ -32,10 +33,10 @@ class BarcodesPageState extends State<BarcodesPage> {
}

@override
Widget build(BuildContext context) {
Widget build(context) {
return Scaffold(
appBar: AppBar(
title: const Text('Lista Kodów Kreskowych'),
title: Text(Translations.of(context).barcodeList)
),
body: Padding(
padding: const EdgeInsets.all(8.0),
Expand Down
32 changes: 19 additions & 13 deletions lib/barcodes_panel.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:barcode_widget/barcode_widget.dart';
import 'barcode_type.dart' as custom;
import 'i18n/strings.g.dart';

class BarcodesPanel extends StatefulWidget {
const BarcodesPanel({
Expand Down Expand Up @@ -35,18 +36,21 @@ class BarcodesPanelState extends State<BarcodesPanel> {
final data = _dataController.text;
final barcodeType = _selectedBarcodeType;

setState(() {
_descriptionError =
description.isEmpty ? "Opis nie może być pusty" : null;
_dataError = data.isEmpty ? "Kod kreskowy nie może być pusty" : null;
setState(() {
final translations = Translations.of(context);
_descriptionError = description.isEmpty
? translations.error.emptyDescription
: null;
_dataError =
data.isEmpty ? translations.error.emptyCode : null;

if (_descriptionError == null && _dataError == null) {
if (barcodeType.barcode.isValid(data)) {
widget.onAddBarcode(description, data, barcodeType.barcode);
_descriptionController.clear();
_dataController.clear();
} else {
_dataError = "Nieprawidłowy kod kreskowy";
_dataError = translations.error.invalidCode;
}
}
});
Expand Down Expand Up @@ -79,15 +83,15 @@ class BarcodesPanelState extends State<BarcodesPanel> {
);
}

Widget _dropdownField() {
Widget _dropdownField(BuildContext context) {
return Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DropdownButtonFormField<custom.BarcodeType>(
value: _selectedBarcodeType,
decoration: const InputDecoration(
labelText: "Typ kodu",
decoration: InputDecoration(
labelText: Translations.of(context).codeType,
),
items: custom.BarcodeType.values.map((custom.BarcodeType type) {
return DropdownMenuItem<custom.BarcodeType>(
Expand All @@ -103,7 +107,7 @@ class BarcodesPanelState extends State<BarcodesPanel> {
});
},
),
const SizedBox(height: Constants.errorHeight)
const SizedBox(height: Constants.errorHeight),
],
),
);
Expand All @@ -118,17 +122,19 @@ class BarcodesPanelState extends State<BarcodesPanel> {
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_textField(_descriptionController, "Opis", _descriptionError),
_textField(_descriptionController,
Translations.of(context).description, _descriptionError),
const SizedBox(width: Constants.fieldSpacing),
_textField(_dataController, "Kod kreskowy", _dataError),
_textField(
_dataController, Translations.of(context).code, _dataError),
const SizedBox(width: Constants.fieldSpacing),
_dropdownField(),
_dropdownField(context),
const SizedBox(width: Constants.fieldSpacing),
Padding(
padding: const EdgeInsets.only(top: Constants.errorHeight),
child: ElevatedButton(
onPressed: _handleAddBarcode,
child: const Text('Dodaj kod kreskowy'),
child: Text(Translations.of(context).addCode),
),
),
],
Expand Down
24 changes: 24 additions & 0 deletions lib/i18n/strings-en.i18n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"appTitle": "Pola test codes",
"barcodeList": "Barcode List",
"description": "Description",
"code": "Barcode",
"addCode": "Add Barcode",
"error": {
"emptyDescription": "Description cannot be empty",
"emptyCode": "Barcode cannot be empty",
"invalidCode": "Invalid barcode"
},
"codeType": "Code type",
"barcodesDescription": {
"companyNotVerified": "Company not verified",
"companyVerifiedWithFullScores": "Company verified with full scores",
"companyVerifiedWithIncompleteScores": "Company verified with incomplete scores",
"internalCode": "Internal Code",
"companyRegisteredOutsidePoland": "Company registered outside Poland",
"companyRegisteredIn": "Company registered in...",
"lidlOwnBrand": "Lidl's own brand",
"polaFriend": "Pola's Friend",
"extendedCompanyDescription": "Extended company description"
}
}
24 changes: 24 additions & 0 deletions lib/i18n/strings-pl.i18n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"appTitle": "Kody testowe poli",
"barcodeList": "Lista Kodów Kreskowych",
"description": "Opis",
"code": "Kod kreskowy",
"addCode": "Dodaj kod kreskowy",
"error": {
"emptyDescription": "Opis nie może być pusty",
"emptyCode": "Kod kreskowy nie może być pusty",
"invalidCode": "Nieprawidłowy kod kreskowy"
},
"codeType": "Typ kodu",
"barcodesDescription": {
"companyNotVerified": "Firma nie zweryfikowana",
"companyVerifiedWithFullScores": "Firma zweryfikowana z pełną punktacją",
"companyVerifiedWithIncompleteScores": "Firma zweryfikowana z niepełną punktacją",
"internalCode": "Kod wewnętrzny",
"companyRegisteredOutsidePoland": "Firma zarejestrowana poza Polską",
"companyRegisteredIn": "Firma zarejerstrowana w ...",
"lidlOwnBrand": "Marka własna Lidla",
"polaFriend": "Przyjaciel Poli",
"extendedCompanyDescription": "Rozszerzony opis firmy"
}
}
Loading

0 comments on commit af04f85

Please sign in to comment.