Last active
December 13, 2023 21:17
-
-
Save valterh4ck3r/17234008b36a45beb84f28489daca6ec to your computer and use it in GitHub Desktop.
Flutter - Upload Image with ImagePicker Web and Firebase Storate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:html' as html; | |
import 'package:uuid/uuid.dart'; | |
import 'package:image_picker_web/image_picker_web.dart'; | |
Future uploadImage() async { | |
var image = await ImagePicker().pickImage(source: ImageSource.gallery); | |
if (image != null) { | |
final metadata = SettableMetadata( | |
contentType: 'image/png', | |
); | |
var uploadTask = FirebaseStorage.instance | |
.ref("/noticias/$uuid/thumbnail-$uuid.png") | |
.putData(await image.readAsBytes(), metadata) | |
.snapshotEvents; | |
uploadTask.listen((event) async { | |
if (event.state == TaskState.success) { | |
String fotoURL = await event.ref.getDownloadURL(); | |
setState(() { | |
thumbnailUrl = fotoURL; | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment