Flutter web - Upload Image File to Firebase Storage

前端 未结 4 1305
轮回少年
轮回少年 2020-12-16 19:34

On flutter web, I pick an image file from the computer and get a File image object. Then I want to upload it to Firebase Storage. For Android and iOS versions of the app I w

4条回答
  •  情话喂你
    2020-12-16 20:14

    Related Addendum: How to download: Why this was such a hidden secret, I have no idea. Thanks to Learn Flutter Code for this nice little tutorial.

    Don't make Firebase Storage a dependency, just Firebase with:

    import 'package:firebase/firebase.dart' as fb;
    

    Then create a method:

            Future myDownloadURL() async {return await fb.storage().refFromURL('gs://').child('$id.jpg').getDownloadURL();}
    

    Call it from a FutureBuilder like so:

            FutureBuilder(
            future: myDownloadURL(),
            builder: (context, AsyncSnapshot snapshot) {
              if (snapshot.connectionState == ConnectionState.waiting) {
                return ;
              }
              return CircleAvatar(
                radius: backgroundRadius * 2,
                child: Image.network(snapshot.data.toString()),
              );
            },
          )
    

提交回复
热议问题