diff --git a/lib/screens/missing_event.dart b/lib/screens/missing_event.dart index ce25d15..363a16b 100644 --- a/lib/screens/missing_event.dart +++ b/lib/screens/missing_event.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:Emma_home/screens/details_db.dart'; import 'package:Emma_home/utils/data.dart'; @@ -8,8 +10,16 @@ import 'package:supabase_flutter/supabase_flutter.dart'; import 'package:Emma_home/main.dart'; import 'package:Emma_home/utils/data.dart'; import 'dart:math'; +import 'package:image_picker/image_picker.dart'; +import 'package:intl/intl.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -class MissingEvent extends StatelessWidget { +class MissingEvent extends StatefulWidget { + @override + _MissingEvent createState() => _MissingEvent(); +} + +class _MissingEvent extends State { @override Widget build(BuildContext context) { var size = MediaQuery.of(context).size; @@ -47,6 +57,85 @@ class MissingEvent extends StatelessWidget { final double itemWidth = (size.width - 40) / 2; MediaQueryData queryData; queryData = MediaQuery.of(context); + late File imageFile = File(""); + bool isloaded = false; + final ImagePicker _picker = ImagePicker(); + + Future pickImage() async { + final XFile? image = await _picker.pickImage( + source: ImageSource.gallery, + // Add any desired options, such as image quality + //imageQuality: 100, + //maxWidth: 800, + //maxHeight: 600, + ); + + if (image != null) { + setState(() { + imageFile = File(image.path); + isloaded = true; + setState(() {}); + }); + // Use the image file + final String imagePath = image.path; + try { + final fileBytes = await image.readAsBytes(); + DateTime now = DateTime.now(); + // Datums- und Zeitformat definieren + DateFormat formatter = DateFormat( + 'yyyyMMddHHmmss'); // Beachte das große 'HH' für 24-Stunden-Format + + // Datum und Uhrzeit als String formatieren + String formattedDateTime = formatter.format(now); + final fileName = '${formattedDateTime}_${image.name}'; + await supabase.storage.from('event_upload').uploadBinary( + fileName, + fileBytes, + ); + setState(() {}); + } catch (e) { + print(e); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('Error uploading file: ${e.toString()}'), + ), + ); + } + print('Image path: $imagePath'); + } else { + print('No image selected.'); + } + } + + Future captureImage() async { + final XFile? image = await _picker.pickImage( + source: ImageSource.camera, + //imageQuality: 100, + ); + + if (image != null) { + final String imagePath = image.path; + try { + final fileBytes = await image.readAsBytes(); + final fileName = '${TimeOfDay.now()}_${image.name}'; + await supabase.storage.from('event_upload').uploadBinary( + fileName, + fileBytes, + ); + setState(() {}); + } catch (e) { + print(e); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('Error uploading file: ${e.toString()}'), + ), + ); + } + print('Image path: $imagePath'); + } else { + print('No image captured.'); + } + } var appBar = AppBar( leading: SizedBox( @@ -139,12 +228,12 @@ class MissingEvent extends StatelessWidget { Align( alignment: Alignment.centerLeft, child: SizedBox( - width: 329, + width: double.infinity, height: 144, child: RichText( text: TextSpan( text: - 'Du hast unterwegs ein Event gesehen, \nwelches noch nicht bei uns in der Liste \nsteht? Schicke uns das Foto von dem Event\nzu. Wir werden diese, wenn nicht schon \ngeschehen den Events hinzufügen. \nDanke für deine Unterstützung!', + 'Du hast unterwegs ein Event gesehen, welches noch nicht bei uns in der Liste steht? Schicke uns das Foto von dem Event zu. Wir werden diese, wenn nicht schon geschehen den Events hinzufügen. Danke für deine Unterstützung!', style: TextStyle( color: Colors.black, fontSize: 16, @@ -158,9 +247,9 @@ class MissingEvent extends StatelessWidget { ), const SizedBox(height: 10), Container( - width: 329, - height: 155, - padding: const EdgeInsets.symmetric(horizontal: 95, vertical: 35), + width: 300, + height: 200, + padding: const EdgeInsets.symmetric(horizontal: 70, vertical: 85), decoration: ShapeDecoration( color: Color(0xFFEDEDED), shape: RoundedRectangleBorder( @@ -171,41 +260,42 @@ class MissingEvent extends StatelessWidget { borderRadius: BorderRadius.circular(10), ), ), - child: Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Container( - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - /* Container( - width: 36, - height: 36, - clipBehavior: Clip.antiAlias, - decoration: BoxDecoration(), - child: FlutterLogo(), - ), */ - const SizedBox(height: 10), - Text( - 'Bild hochladen', - style: TextStyle( - color: Colors.black, - fontSize: 18, - fontFamily: 'Inter', - fontWeight: FontWeight.w500, - height: 0, - ), - ), - ], + child: SizedBox( + width: 200, // Breite des Buttons + height: 50, + child: OutlinedButton.icon( + icon: const Icon( + Icons.image, + size: 10, + ), + onPressed: () { + pickImage(); + }, + style: ButtonStyle( + side: WidgetStateProperty.all( + const BorderSide( + color: Colors.red, + width: 1, + ), ), ), - ], + label: const Text( + 'Bild hochladen', + ), + ), ), ), + + /* Padding( + padding: const EdgeInsets.all(8.0), + child: !isloaded + ? Image.network( + "https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/No_image_available.svg/2048px-No_image_available.svg.png", + width: 100, // Maximalbreite des Bildes + height: 100, // Maximalhöhe des Bildes + fit: BoxFit.contain, + ) + : Image.file(imageFile)), */ const SizedBox(height: 10), Row( mainAxisSize: MainAxisSize.min, @@ -247,7 +337,17 @@ class MissingEvent extends StatelessWidget { Container( width: 23, height: 20.70, - child: Stack(), + child: IconButton( + icon: FaIcon(FontAwesomeIcons.camera, size: 20), + onPressed: () { + // Füge hier die YouTube-Aktion hinzu + captureImage(); + }, + padding: EdgeInsets + .zero, // Entfernt das Padding des IconButton + constraints: + BoxConstraints(), // Entfernt die Standardbeschränkungen + ), ), ], ), @@ -318,7 +418,7 @@ class MissingEvent extends StatelessWidget { ), ], ), - const SizedBox(height: 10), +/* const SizedBox(height: 10), Text( 'Bock dein Event bei uns zu \npräsentieren? ', style: TextStyle( @@ -360,7 +460,7 @@ class MissingEvent extends StatelessWidget { ], ), ), - ), + ), */ ], ), );