firebase - 圆形进度条 flutter

标签 firebase flutter dart google-cloud-firestore

Future uploadImage(BuildContext context) async {
  final picker = ImagePicker();
  final pickedFile = await picker.getImage(source: ImageSource.gallery);
  setState(() {
    _image = File(pickedFile.path);
  });
  StorageReference firebaseStorageRef = FirebaseStorage.instance
      .ref()
      .child('event_profile/${Path.basename(_image.path)}}');
  StorageUploadTask uploadTask = firebaseStorageRef.putFile(_image);
  var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();
  setState(() {
    _imageURL = dowurl.toString();
  });
  showAlertDialog(context);
  print(_imageURL);
 }
这是我用于将图像上传到Firebase存储的代码。
如何使用圆形进度条向用户指示图像仍在上传。
谢谢 !

最佳答案

您可以创建一个 bool(boolean) 实例变量isLoading并相应地对其进行更新。例:

bool isLoading = false;


Future uploadImage(BuildContext context) async {
  final picker = ImagePicker();
  final pickedFile = await picker.getImage(source: ImageSource.gallery);
  setState(() {
    _image = File(pickedFile.path);
    isLoading = true; //add this line
  });
  StorageReference firebaseStorageRef = FirebaseStorage.instance
      .ref()
      .child('event_profile/${Path.basename(_image.path)}}');
  StorageUploadTask uploadTask = firebaseStorageRef.putFile(_image);
  var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();
  setState(() {
    _imageURL = dowurl.toString();
    isLoading = false;
  });
  showAlertDialog(context);
  print(_imageURL);
 }
然后在build方法中,您可以具有以下内容:
            isLoading
                ? CircularProgressIndicator()
                : Visibility(visible: false, child: Text("test")),
因此,以这种方式,当isLoading等于false时,就不会出现CircularProgressIndicator(),当它更改为true时,setState()将调用build()方法,并且CircularProgressIndicator()将出现。

关于firebase - 圆形进度条 flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62619782/

相关文章:

javascript - 如何在 React Native 中更新配置文件(displayName)firebase?

ios - 如何匿名化来自 Firebase 的 Analytics 中的 IP?

angularFire 2 的 Firebase Firestore 集合计数

dart - 使 BoxDecoration 图像褪色/透明

flutter - 在 Flutter 中使用 contacts_service 更改联系人的电话号码

dart web toolkit 自定义打开和关闭图像

firebase - 云功能安全规则

flutter - 在 Flutter 中重播相同的 Flare 动画

android - flutter 简单文本示例

Flutter RootRestorationScope 不恢复最后一个根