Skip to content

Instantly share code, notes, and snippets.

@timbergus
Last active June 23, 2019 21:56
Show Gist options
  • Save timbergus/fee5da581cd7a3dc25413272b6dd9c20 to your computer and use it in GitHub Desktop.
Save timbergus/fee5da581cd7a3dc25413272b6dd9c20 to your computer and use it in GitHub Desktop.
// Here we get an instance to Firebase Storage.
FirebaseStorage _storage = FirebaseStorage.instance;
// This async function gets the image from the gallery
// and upload it to Firebase Storage.
Future uploadImage() async {
var image = await ImagePicker.pickImage(
source: ImageSource.gallery,
);
if (image != null) {
var ref = _storage.ref().child('user.avatar${extension(image.path)}');
ref.putFile(image);
ext = extension(image.path);
} else {
print('No image was selected!');
}
}
// This button launches the process.
RaisedButton(
child: Text('Choose Avatar'),
color: Colors.greenAccent,
onPressed: uploadImage,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment