Created
June 26, 2019 14:50
-
-
Save timbergus/6350a78d5c09f8b926ffd5992c1dda06 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
// This is the variable that stores the image URL. | |
String imageUrl = ''; | |
// This is the variable that stores the image extension. | |
String ext = ''; | |
// This is the function to fetch the image from the storage. | |
Future fetchImage() async { | |
var ref = _storage.ref().child('user.avatar${this.ext}'); | |
if (ref != null) { | |
String url = await ref.getDownloadURL(); | |
setState(() { | |
imageUrl = url; | |
}); | |
} | |
} | |
// And this is the button that request the avatar of the user. | |
RaisedButton( | |
child: Text('Show Avatar'), | |
color: Colors.orangeAccent, | |
onPressed: fetchImage, | |
) | |
// After fetching the avatar, we will show it with this widget. | |
isLogged && this.imageUrl != '' | |
? Container( | |
width: 200, | |
height: 200, | |
child: Image.network( | |
this.imageUrl, | |
fit: BoxFit.fitWidth, | |
), | |
) | |
: Container(), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment