Doppelter upload fix
This commit is contained in:
+10
-1
@@ -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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user