-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} |