File tree Expand file tree Collapse file tree 2 files changed +45
-19
lines changed Expand file tree Collapse file tree 2 files changed +45
-19
lines changed Original file line number Diff line number Diff line change @@ -124,12 +124,18 @@ class ChatScreenState extends State<ChatScreen> {
124
124
StorageReference reference = FirebaseStorage .instance.ref ().child (fileName);
125
125
StorageUploadTask uploadTask = reference.putFile (imageFile);
126
126
StorageTaskSnapshot storageTaskSnapshot = await uploadTask.onComplete;
127
- imageUrl = await storageTaskSnapshot.ref.getDownloadURL ();
128
- setState (() {
129
- isLoading = false ;
127
+ storageTaskSnapshot.ref.getDownloadURL ().then ((downloadUrl) {
128
+ imageUrl = downloadUrl;
129
+ setState (() {
130
+ isLoading = false ;
131
+ onSendMessage (imageUrl, 1 );
132
+ });
133
+ }, onError: (err) {
134
+ setState (() {
135
+ isLoading = false ;
136
+ });
137
+ Fluttertoast .showToast (msg: 'This file is not an image' );
130
138
});
131
-
132
- onSendMessage (imageUrl, 1 );
133
139
}
134
140
135
141
void onSendMessage (String content, int type) {
Original file line number Diff line number Diff line change @@ -84,23 +84,43 @@ class SettingsScreenState extends State<SettingsScreen> {
84
84
String fileName = id;
85
85
StorageReference reference = FirebaseStorage .instance.ref ().child (fileName);
86
86
StorageUploadTask uploadTask = reference.putFile (avatarImageFile);
87
- StorageTaskSnapshot storageTaskSnapshot = await uploadTask.onComplete;
88
- photoUrl = await storageTaskSnapshot.ref.getDownloadURL ();
89
- Firestore .instance
90
- .collection ('users' )
91
- .document (id)
92
- .updateData ({'nickname' : nickname, 'aboutMe' : aboutMe, 'photoUrl' : photoUrl}).then ((data) async {
93
- await prefs.setString ('photoUrl' , photoUrl);
87
+ StorageTaskSnapshot storageTaskSnapshot;
88
+ uploadTask.onComplete.then ((value) {
89
+ if (value.error == null ) {
90
+ storageTaskSnapshot = value;
91
+ storageTaskSnapshot.ref.getDownloadURL ().then ((downloadUrl) {
92
+ photoUrl = downloadUrl;
93
+ Firestore .instance
94
+ .collection ('users' )
95
+ .document (id)
96
+ .updateData ({'nickname' : nickname, 'aboutMe' : aboutMe, 'photoUrl' : photoUrl}).then ((data) async {
97
+ await prefs.setString ('photoUrl' , photoUrl);
98
+ setState (() {
99
+ isLoading = false ;
100
+ });
101
+ Fluttertoast .showToast (msg: "Upload success" );
102
+ }).catchError ((err) {
103
+ setState (() {
104
+ isLoading = false ;
105
+ });
106
+ Fluttertoast .showToast (msg: err.toString ());
107
+ });
108
+ }, onError: (err) {
109
+ setState (() {
110
+ isLoading = false ;
111
+ });
112
+ Fluttertoast .showToast (msg: 'This file is not an image' );
113
+ });
114
+ } else {
115
+ setState (() {
116
+ isLoading = false ;
117
+ });
118
+ Fluttertoast .showToast (msg: 'This file is not an image' );
119
+ }
120
+ }, onError: (err) {
94
121
setState (() {
95
122
isLoading = false ;
96
123
});
97
-
98
- Fluttertoast .showToast (msg: "Upload success" );
99
- }).catchError ((err) {
100
- setState (() {
101
- isLoading = false ;
102
- });
103
-
104
124
Fluttertoast .showToast (msg: err.toString ());
105
125
});
106
126
}
You can’t perform that action at this time.
0 commit comments