下载URL Firebase存储Flutter

时间:2020-08-30 08:12:34

标签: firebase flutter firebase-storage

嘿,有谁知道如何获取url变量:Image.network(url) 功能?但是,当我这样做时,其下划线为红色。当该网址位于Image.network函数中时,即使有人重新启动该应用程序,该图片仍会显示。如果有人知道如何处理,请在评论中告诉我。

Future uploadPic(BuildContext context)async{
    String fileName=basename(_image.path);
    StorageReference firebaseStorageRef=FirebaseStorage.instance.ref().child(fileName);
    StorageUploadTask uploadTask=firebaseStorageRef.putFile(_image);
    StorageTaskSnapshot taskSnapshot= await uploadTask.onComplete;
    var downUrl = await (await uploadTask.onComplete).ref.getDownloadURL();
    var url = downUrl.toString();

    setState(() {
      print('Profile Picture uploaded');
      Scaffold.of(context).showSnackBar(SnackBar(content: Text('Profile Picture Uploaded')));
    });
   }


  @override
  Widget build(BuildContext context) {

    Future<DocumentSnapshot> getUserInfo()async{
      var firebaseUser = await FirebaseAuth.instance.currentUser;
      return await Firestore.instance.collection("SerX").doc(firebaseUser.uid).get();
    }


    final _kTabPages = <Widget>[

      Center(child: Icon(Icons.new_releases, size: 64.0, color: Colors.white)),

      Center(child: Icon(Icons.local_grocery_store, size: 64.0, color: Colors.white)),

      Center(child: Icon(Icons.chat, size: 64.0, color: Colors.white)),


      ListView(
        children: <Widget> [
          Center(
            child: FutureBuilder(
              future: getUserInfo(),
              builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
                if (snapshot.connectionState == ConnectionState.done) {
                  return ListView.builder(
                      shrinkWrap: true,
                      itemCount: 1,
                      itemBuilder: (BuildContext context, int index) {
                        return ListTile(
                          subtitle: Text(snapshot.data.data()["Email"], style: TextStyle(
                            color: Colors.white,
                            fontFamily: 'Orbitron',
                            fontSize: 15.0,
                            fontWeight: FontWeight.bold,),textAlign: TextAlign.right,
                          ),
                          title: Text(snapshot.data.data()["Username"], style: TextStyle(
                              color: Colors.white,
                              fontFamily: 'Orbitron',
                              fontSize: 35.0,
                              fontWeight: FontWeight.bold),textAlign: TextAlign.right,),
                        );});
                } else if (snapshot.connectionState == ConnectionState.none) {
                  return Text("No data");}
                return Center(
                  child: SpinKitFadingCircle(color: Colors.white, size: 20.0),heightFactor: 29,
                );
              },
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children:<Widget> [
              Container(
                padding:  EdgeInsets.only(left: 20),
                child: CircleAvatar(
                  radius: 50.0,
                  backgroundColor: Colors.white,
                  child: ClipOval(
                    child: SizedBox(
                      width: 95.0,
                      height: 95.0,
                      child:(_image!=null)?Image.file(_image,fit:BoxFit.fill)
                          :Image.network(".....", fit: BoxFit.fill,),
                    ),
                  ),
                ),
              ),

0 个答案:

没有答案