implemented max size for uploading images

This commit is contained in:
2023-05-03 18:45:01 +02:00
parent 0a10bf256c
commit f470e92aab
3 changed files with 66 additions and 3 deletions
+15 -1
View File
@@ -30,16 +30,30 @@ class _AddScreenState extends State<AddScreen> {
_selectedIndex = widget.initialIndex;
}
Future<bool> isFileSizeValid(File file, int maxSizeInMB) async {
final fileSize = await file.length();
final maxSizeInBytes = maxSizeInMB * 1024 * 1024;
return fileSize <= maxSizeInBytes;
}
Future<void> _getImage(ImageSource source) async {
final pickedFile = await ImagePicker().pickImage(source: source);
if (pickedFile != null) {
final tempFile = File(pickedFile.path);
final bool isValid = await isFileSizeValid(tempFile, 10);
if (isValid) {
setState(() {
_imageFile = File(pickedFile.path);
_imageFile = tempFile;
});
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Die Dateigröße darf maximal 10 MB betragen.')),
);
}
}
}
Future<void> addNewElementToFirestore(String title, String description, File imageFile) async {
String collectionName;
if (_selectedIndex == 0) {
+48
View File
@@ -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"
+1
View File
@@ -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: