Skip to content

Commit

Permalink
fixes review/4
Browse files Browse the repository at this point in the history
  • Loading branch information
D3bi7 committed Jul 8, 2024
1 parent d38f6a6 commit e8c80bb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
26 changes: 26 additions & 0 deletions lib/barcode_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:barcode_widget/barcode_widget.dart';

enum BarcodeType {
ean13,
ean8,
}

extension BarcodeTypeExtension on BarcodeType {
String get name {
switch (this) {
case BarcodeType.ean13:
return 'EAN13';
case BarcodeType.ean8:
return 'EAN8';
}
}

Barcode get barcode {
switch (this) {
case BarcodeType.ean13:
return Barcode.ean13();
case BarcodeType.ean8:
return Barcode.ean8();
}
}
}
31 changes: 11 additions & 20 deletions lib/barcodes_panel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:barcode_widget/barcode_widget.dart';
import 'barcode_type.dart' as custom;

class BarcodesPanel extends StatefulWidget {
const BarcodesPanel({
Expand All @@ -16,7 +17,7 @@ class BarcodesPanel extends StatefulWidget {
class BarcodesPanelState extends State<BarcodesPanel> {
final TextEditingController _descriptionController = TextEditingController();
final TextEditingController _dataController = TextEditingController();
String _selectedBarcodeType = 'EAN13';
custom.BarcodeType _selectedBarcodeType = custom.BarcodeType.ean13;

@override
void dispose() {
Expand All @@ -28,13 +29,7 @@ class BarcodesPanelState extends State<BarcodesPanel> {
void _handleAddBarcode() {
final description = _descriptionController.text;
final data = _dataController.text;

Barcode barcodeType;
if (_selectedBarcodeType == 'EAN13') {
barcodeType = Barcode.ean13();
} else {
barcodeType = Barcode.ean8();
}
final barcodeType = _selectedBarcodeType.barcode;

if (description.isNotEmpty && data.isNotEmpty) {
widget.onAddBarcode(description, data, barcodeType);
Expand All @@ -56,22 +51,18 @@ class BarcodesPanelState extends State<BarcodesPanel> {

Widget _dropdownField() {
return Expanded(
child: DropdownButtonFormField<String>(
child: DropdownButtonFormField<custom.BarcodeType>(
value: _selectedBarcodeType,
decoration: const InputDecoration(
labelText: "Typ kodu",
),
items: const [
DropdownMenuItem(
value: 'EAN13',
child: Text("EAN13"),
),
DropdownMenuItem(
value: 'EAN8',
child: Text("EAN8"),
),
],
onChanged: (String? newValue) {
items: custom.BarcodeType.values.map((custom.BarcodeType type) {
return DropdownMenuItem<custom.BarcodeType>(
value: type,
child: Text(type.name),
);
}).toList(),
onChanged: (custom.BarcodeType? newValue) {
setState(() {
if (newValue != null) {
_selectedBarcodeType = newValue;
Expand Down

0 comments on commit e8c80bb

Please sign in to comment.