title: Cant store firebase storage image url to firestore
body: <p>I'm writing a code to save data in firestore, but it saves other data without image url. </p>
  
  <p>Here is my code: </p>
  
  <pre><code>    import 'package:flutter/material.dart';
      import 'package:flutter_learning_app/Models/notice.dart';
      import 'package:flutter_learning_app/Services/crud.dart';
      import 'package:uuid/uuid.dart';
  
      class NoticeProvider with ChangeNotifier {
      final firestoreService=FirestoreService();
       String _userName;
       String _userPost;
       String _date; 
       String _photoUrl;
  
       var uuid=Uuid();
  
      //setters
  
       changeUserName(String value){
       _userName=value;
       notifyListeners();
      }
       changeUserPost(String value){
       _userPost=value;
       notifyListeners();
      }
       changeDate(String value){
       _date=value;
       notifyListeners();
      }
       changePhotoUrl(value){
       _photoUrl=value;
       print('$photoUrl');
       notifyListeners();
         }
  
        //getters
  
       String get userName =&gt; _userName;
       String get userPost =&gt; _userPost;
       String get date =&gt; _date;
       String get photoUrl =&gt; _photoUrl;
  
  
       saveNotice(){
  
       print('$photoUrl');
       print('$userName');
        var newNotice=Notice(userName:userName,userPost:userPost,
       date:date,photoUrl:photoUrl , noticeId: uuid.v4());
         firestoreService.saveNotice(newNotice);
  
       }
  
  
  
        }
  </code></pre>
  
  <p>I think <code>saveNotice()</code> function is executing before <code>changePhotoUrl(value)</code> function, it print value to <code>username</code> but it prints <code>photourl</code>null, after that it prints url. I think it is the result of the print statement which is in <code>changePhotoUrl(value)</code>.</p>
  
  <p>This is the place where  I get download photo url:</p>
  
  <pre><code>      File noticepic;
        Future getNotice()async{
        var tempImage = await ImagePicker.pickImage(source: ImageSource.gallery);
         setState(() {
           noticepic=tempImage ;
           });
          }
          uploadNotice()async{
         String fileName=basename(noticepic.path);
           final StorageReference firebaseStorageRef=FirebaseStorage().ref().child
        ('cisnotices/$fileName');
          final StorageUploadTask task = firebaseStorageRef.putFile(noticepic);
           await task.onComplete;
           await firebaseStorageRef.getDownloadURL().then((url) {
  
             noticeProvider.changePhotoUrl(url.toString());
           });
        }
       NoticeProvider noticeProvider=NoticeProvider();
  </code></pre>
  
  <p>This is the place where I call getimage and upload image functions, then I called <code>saveNotice()</code> function:</p>
  
  <pre><code>
           Padding( padding: const EdgeInsets.only(left: 280),
               child: Container(
               child: IconButton(
  
               icon:Icon(
               Icons.add_photo_alternate
               ),
  
         color: Colors.grey[700],
  
          iconSize: 40,
  
          onPressed:(){
  
          getNotice().then((f) async =&gt; await uploadNotice());
  
  
           }
  
               ),
                      ),
                           ),
           SizedBox(height:10.0),
  
                    Container(
                      height: 30.0,
                      width: 100.0,
                      child: RaisedButton(
  
                        onPressed: (){
                          noticeProvider.saveNotice();
  
                        },
  
                        child: Text('Upload'),
                        color: Colors.green[400],
                      ),
                    )
  
  </code></pre>
  
  <p>This is the output: </p>
  
  <pre><code>I/flutter (19698): null
  I/flutter (19698): aja yogan
  I/System.out(19698): (HTTPLog)-Static: isSBSettingEnabled false
  I/System.out(19698): (HTTPLog)-Static: isSBSettingEnabled false
  D/NetworkManagementSocketTagger(19698): tagSocket(116) with statsTag=0xffffffff, statsUid=-1
  I/System.out(19698): (HTTPLog)-Static: isSBSettingEnabled false
  I/System.out(19698): (HTTPLog)-Static: isSBSettingEnabled false
  I/flutter (19698): https://firebasestorage.googleapis.com/v0/b/learningapp-313e5.appspot.com/o/cisnotices%2Fimage_picker5085188822864985108.jpg?alt=media&amp;token=8eccc3c7-14b5-4820-916e-5f1e4a67954e
  </code></pre>