Last active
June 23, 2019 21:56
-
-
Save timbergus/fee5da581cd7a3dc25413272b6dd9c20 to your computer and use it in GitHub Desktop.
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
// 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