Skip to content

Commit

Permalink
fixes review/2
Browse files Browse the repository at this point in the history
  • Loading branch information
D3bi7 committed Jul 5, 2024
1 parent 5e2ab7f commit 0de0b10
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 46 deletions.
17 changes: 2 additions & 15 deletions lib/barcodes_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ class BarcodesPage extends StatefulWidget {
}

class BarcodesPageState extends State<BarcodesPage> {
final TextEditingController _descriptionController = TextEditingController();
final TextEditingController _dataController = TextEditingController();

void _addBarcode() {
final description = _descriptionController.text;
final data = _dataController.text;

void _addBarcode(String description, String data) {
if (description.isNotEmpty && data.isNotEmpty) {
setState(() {
widget.barcodes.add(
Expand All @@ -34,9 +28,6 @@ class BarcodesPageState extends State<BarcodesPage> {
),
);
});

_descriptionController.clear();
_dataController.clear();
}
}

Expand All @@ -54,11 +45,7 @@ class BarcodesPageState extends State<BarcodesPage> {
child: BarcodesListView(barcodes: widget.barcodes),
),
const SizedBox(height: 8.0),
BarcodesPanel(
descriptionController: _descriptionController,
dataController: _dataController,
onAddBarcode: _addBarcode,
),
BarcodesPanel(onAddBarcode: _addBarcode),
],
),
),
Expand Down
87 changes: 56 additions & 31 deletions lib/barcodes_panel.dart
Original file line number Diff line number Diff line change
@@ -1,47 +1,72 @@
import 'package:flutter/material.dart';

class BarcodesPanel extends StatelessWidget {
class BarcodesPanel extends StatefulWidget {
const BarcodesPanel({
super.key,
required this.descriptionController,
required this.dataController,
required this.onAddBarcode,
});

final TextEditingController descriptionController;
final TextEditingController dataController;
final VoidCallback onAddBarcode;
final void Function(String description, String data) onAddBarcode;

@override
_BarcodesPanelState createState() => _BarcodesPanelState();
}

class _BarcodesPanelState extends State<BarcodesPanel> {
final TextEditingController _descriptionController = TextEditingController();
final TextEditingController _dataController = TextEditingController();

@override
void dispose() {
_descriptionController.dispose();
_dataController.dispose();
super.dispose();
}

void _handleAddBarcode() {
final description = _descriptionController.text;
final data = _dataController.text;

widget.onAddBarcode(description, data);

_descriptionController.clear();
_dataController.clear();
}

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: TextField(
controller: descriptionController,
decoration: const InputDecoration(
labelText: 'Opis',
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: TextField(
controller: _descriptionController,
decoration: const InputDecoration(
labelText: 'Opis',
),
),
),
),
),
const SizedBox(width: 10),
Expanded(
child: TextField(
controller: dataController,
decoration: const InputDecoration(
labelText: 'Kod kreskowy',
const SizedBox(width: 10),
Expanded(
child: TextField(
controller: _dataController,
decoration: const InputDecoration(
labelText: 'Kod kreskowy',
),
),
),
),
),
const SizedBox(width: 10),
ElevatedButton(
onPressed: onAddBarcode,
child: const Text('Dodaj kod kreskowy'),
const SizedBox(width: 10),
ElevatedButton(
onPressed: _handleAddBarcode,
child: const Text('Dodaj kod kreskowy'),
),
],
),
],
),
),
],
);
}
}

0 comments on commit 0de0b10

Please sign in to comment.