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
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'DetailPage.dart';
|
||||
|
||||
|
||||
|
||||
class UserDefinedItem extends StatelessWidget {
|
||||
final String title;
|
||||
final String description;
|
||||
final Image? image;
|
||||
|
||||
|
||||
const UserDefinedItem({super.key,
|
||||
required this.title,
|
||||
required this.description,
|
||||
this.image,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String shortDescription = "${description.substring(0, 30)}...";
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
// File generated by FlutterFire CLI.
|
||||
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
|
||||
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
|
||||
import 'package:flutter/foundation.dart'
|
||||
show defaultTargetPlatform, kIsWeb, TargetPlatform;
|
||||
|
||||
/// Default [FirebaseOptions] for use with your Firebase apps.
|
||||
///
|
||||
/// Example:
|
||||
/// ```dart
|
||||
/// import 'firebase_options.dart';
|
||||
/// // ...
|
||||
/// await Firebase.initializeApp(
|
||||
/// options: DefaultFirebaseOptions.currentPlatform,
|
||||
/// );
|
||||
/// ```
|
||||
class DefaultFirebaseOptions {
|
||||
static FirebaseOptions get currentPlatform {
|
||||
if (kIsWeb) {
|
||||
return web;
|
||||
}
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.android:
|
||||
return android;
|
||||
case TargetPlatform.iOS:
|
||||
return ios;
|
||||
case TargetPlatform.macOS:
|
||||
throw UnsupportedError(
|
||||
'DefaultFirebaseOptions have not been configured for macos - '
|
||||
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||
);
|
||||
case TargetPlatform.windows:
|
||||
throw UnsupportedError(
|
||||
'DefaultFirebaseOptions have not been configured for windows - '
|
||||
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||
);
|
||||
case TargetPlatform.linux:
|
||||
throw UnsupportedError(
|
||||
'DefaultFirebaseOptions have not been configured for linux - '
|
||||
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||
);
|
||||
default:
|
||||
throw UnsupportedError(
|
||||
'DefaultFirebaseOptions are not supported for this platform.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static const FirebaseOptions web = FirebaseOptions(
|
||||
apiKey: 'AIzaSyBmdRrWkqosCAtlOeqs-G-4oWAvwLt3KnQ',
|
||||
appId: '1:576683162451:web:71c67b5ef44ab7c1083fa6',
|
||||
messagingSenderId: '576683162451',
|
||||
projectId: 'gemeinde-trommler',
|
||||
authDomain: 'gemeinde-trommler.firebaseapp.com',
|
||||
storageBucket: 'gemeinde-trommler.appspot.com',
|
||||
measurementId: 'G-ZH37BQ8679',
|
||||
);
|
||||
|
||||
static const FirebaseOptions android = FirebaseOptions(
|
||||
apiKey: 'AIzaSyAWjSjX1f2rGUGHLbXQS873DYY_oXqcHhs',
|
||||
appId: '1:576683162451:android:b792a81fceafa932083fa6',
|
||||
messagingSenderId: '576683162451',
|
||||
projectId: 'gemeinde-trommler',
|
||||
storageBucket: 'gemeinde-trommler.appspot.com',
|
||||
);
|
||||
|
||||
static const FirebaseOptions ios = FirebaseOptions(
|
||||
apiKey: 'AIzaSyDV441PhkPEC7igZmYMpJ_axLMc2bKQ5fY',
|
||||
appId: '1:576683162451:ios:2fd841a4b4ca70d5083fa6',
|
||||
messagingSenderId: '576683162451',
|
||||
projectId: 'gemeinde-trommler',
|
||||
storageBucket: 'gemeinde-trommler.appspot.com',
|
||||
iosClientId: '576683162451-vf1g0qoge66lb3bmpsg4neckv4opovub.apps.googleusercontent.com',
|
||||
iosBundleId: 'com.example.demoapp',
|
||||
);
|
||||
}
|
||||
+11
-1
@@ -2,9 +2,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'home.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'firebase_options.dart';
|
||||
|
||||
void main() {
|
||||
// ...
|
||||
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
);
|
||||
runApp(const MyApp());
|
||||
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user