Last active
March 24, 2020 11:54
-
-
Save duytq94/3baa05ce6c7441e89faa4793d92b6df7 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
| Future uploadFile() async { | |
| String fileName = id; | |
| StorageReference reference = FirebaseStorage.instance.ref().child(fileName); | |
| StorageUploadTask uploadTask = reference.putFile(avatarImageFile); | |
| StorageTaskSnapshot storageTaskSnapshot; | |
| uploadTask.onComplete.then((value) { | |
| if (value.error == null) { | |
| storageTaskSnapshot = value; | |
| storageTaskSnapshot.ref.getDownloadURL().then((downloadUrl) { | |
| photoUrl = downloadUrl; | |
| Firestore.instance | |
| .collection('users') | |
| .document(id) | |
| .updateData({ | |
| 'nickname': nickname, | |
| 'aboutMe': aboutMe, | |
| 'photoUrl': photoUrl | |
| }).then((data) async { | |
| await prefs.setString('photoUrl', photoUrl); | |
| setState(() { | |
| isLoading = false; | |
| }); | |
| Fluttertoast.showToast(msg: "Upload success"); | |
| }).catchError((err) { | |
| setState(() { | |
| isLoading = false; | |
| }); | |
| Fluttertoast.showToast(msg: err.toString()); | |
| }); | |
| }, onError: (err) { | |
| setState(() { | |
| isLoading = false; | |
| }); | |
| Fluttertoast.showToast(msg: 'This file is not an image'); | |
| }); | |
| } else { | |
| setState(() { | |
| isLoading = false; | |
| }); | |
| Fluttertoast.showToast(msg: 'This file is not an image'); | |
| } | |
| }, onError: (err) { | |
| setState(() { | |
| isLoading = false; | |
| }); | |
| Fluttertoast.showToast(msg: err.toString()); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment