Doppelter upload fix

This commit is contained in:
2023-04-13 21:35:50 +02:00
parent aeef64a109
commit 6f22b24596
+10 -1
View File
@@ -16,6 +16,7 @@ class _AddScreenState extends State<AddScreen> {
final _titleController = TextEditingController(); final _titleController = TextEditingController();
final _descriptionController = TextEditingController(); final _descriptionController = TextEditingController();
File? _imageFile; File? _imageFile;
bool _uploading = false;
Future<void> _getImage(ImageSource source) async { Future<void> _getImage(ImageSource source) async {
final pickedFile = await ImagePicker().getImage(source: source); final pickedFile = await ImagePicker().getImage(source: source);
@@ -68,16 +69,24 @@ class _AddScreenState extends State<AddScreen> {
child: IconButton( child: IconButton(
icon: Icon(Icons.check), icon: Icon(Icons.check),
onPressed: () async { onPressed: () async {
if (_formKey.currentState!.validate() && _imageFile != null) { if (_formKey.currentState!.validate() && _imageFile != null && !_uploading) {
setState(() {
_uploading = true;
});
try { try {
await addNewElementToFirestore(_titleController.text, _descriptionController.text, _imageFile!); await addNewElementToFirestore(_titleController.text, _descriptionController.text, _imageFile!);
Navigator.pop(context); Navigator.pop(context);
} catch (e) { } catch (e) {
print(e); print(e);
// Fehlerbehandlung hier // Fehlerbehandlung hier
} finally {
setState(() {
_uploading = false;
});
} }
} }
}, },
), ),
), ),
], ],