Skip to content

Instantly share code, notes, and snippets.

@valterh4ck3r
Last active December 13, 2023 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valterh4ck3r/17234008b36a45beb84f28489daca6ec to your computer and use it in GitHub Desktop.
Save valterh4ck3r/17234008b36a45beb84f28489daca6ec to your computer and use it in GitHub Desktop.
Flutter - Upload Image with ImagePicker Web and Firebase Storate
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