firebase issue list working :O
This commit is contained in:
+29
-4
@@ -1,7 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
|
||||
class AddScreen extends StatefulWidget {
|
||||
@override
|
||||
@@ -24,6 +27,23 @@ class _AddScreenState extends State<AddScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> addNewElementToFirestore(String title, String description, File imageFile) async {
|
||||
// Zunächst das Bild in Firebase Storage speichern
|
||||
Reference ref = FirebaseStorage.instance.ref().child("images/${DateTime.now().toString()}");
|
||||
UploadTask uploadTask = ref.putFile(imageFile);
|
||||
String imageUrl = await (await uploadTask).ref.getDownloadURL();
|
||||
|
||||
// Das neue Element in der Firestore-Sammlung "Issues" speichern
|
||||
await FirebaseFirestore.instance.collection("Issues").add({
|
||||
"title": title,
|
||||
"description": description,
|
||||
"imageUrl": imageUrl,
|
||||
"createdDate": DateTime.now(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -47,10 +67,15 @@ class _AddScreenState extends State<AddScreen> {
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.check),
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// Hier wird die Logik zum Hinzufügen des neuen Elements ausgeführt
|
||||
Navigator.pop(context);
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate() && _imageFile != null) {
|
||||
try {
|
||||
await addNewElementToFirestore(_titleController.text, _descriptionController.text, _imageFile!);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
// Fehlerbehandlung hier
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user