diff --git a/lib/AddPage.dart b/lib/AddPage.dart index 9d21c46..353f507 100644 --- a/lib/AddPage.dart +++ b/lib/AddPage.dart @@ -30,16 +30,30 @@ class _AddScreenState extends State { _selectedIndex = widget.initialIndex; } + Future isFileSizeValid(File file, int maxSizeInMB) async { + final fileSize = await file.length(); + final maxSizeInBytes = maxSizeInMB * 1024 * 1024; + return fileSize <= maxSizeInBytes; + } Future _getImage(ImageSource source) async { final pickedFile = await ImagePicker().pickImage(source: source); if (pickedFile != null) { - setState(() { - _imageFile = File(pickedFile.path); - }); + final tempFile = File(pickedFile.path); + final bool isValid = await isFileSizeValid(tempFile, 10); + if (isValid) { + setState(() { + _imageFile = tempFile; + }); + } else { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Die Dateigröße darf maximal 10 MB betragen.')), + ); + } } } + Future addNewElementToFirestore(String title, String description, File imageFile) async { String collectionName; if (_selectedIndex == 0) { diff --git a/pubspec.lock b/pubspec.lock index 61a06b6..2eec1f5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -9,6 +9,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.1" + archive: + dependency: transitive + description: + name: archive + sha256: "0c8368c9b3f0abbc193b9d6133649a614204b528982bebc7026372d61677ce3a" + url: "https://pub.dev" + source: hosted + version: "3.3.7" async: dependency: transitive description: @@ -105,6 +113,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.17.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" cross_file: dependency: transitive description: @@ -288,6 +304,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + image: + dependency: "direct main" + description: + name: image + sha256: "73964e3609fb96e01e69b0924b939967c556e46c7ff05db2ea9e31019000f4ef" + url: "https://pub.dev" + source: hosted + version: "4.0.16" image_picker: dependency: "direct main" description: @@ -448,6 +472,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.11.1" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: "49392a45ced973e8d94a85fdb21293fbb40ba805fc49f2965101ae748a3683b4" + url: "https://pub.dev" + source: hosted + version: "5.1.0" platform: dependency: transitive description: @@ -464,6 +496,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + pointycastle: + dependency: transitive + description: + name: pointycastle + sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c" + url: "https://pub.dev" + source: hosted + version: "3.7.3" process: dependency: transitive description: @@ -597,6 +637,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + xml: + dependency: transitive + description: + name: xml + sha256: "979ee37d622dec6365e2efa4d906c37470995871fe9ae080d967e192d88286b5" + url: "https://pub.dev" + source: hosted + version: "6.2.2" sdks: dart: ">=2.19.0 <3.0.0" flutter: ">=3.3.0" diff --git a/pubspec.yaml b/pubspec.yaml index 9eda04c..a9576b0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -46,6 +46,7 @@ dependencies: cloud_firestore: ^4.5.1 change_app_package_name: ^1.1.0 cached_network_image: ^3.2.3 + image: ^4.0.16 dev_dependencies: