面临的错误:类型'int'不是类型'String'的子类型

时间:2018-10-07 10:58:26

标签: flutter firebase-storage flutter-dependencies

当我尝试从云存储中获取URL时遇到错误……我在以前的项目中使用了此代码,但工作正常,但是现在当我尝试在新项目中使用此代码时,它向我显示错误“类型'int'不是类型'String'的子类型。“ ...任何人都可以在这方面帮助我...........

void compressImage() async {
    print('startin');
    final tempDir = await getTemporaryDirectory();
    final path = tempDir.path;
    int rand = new Math.Random().nextInt(99999999);

    Im.Image image = Im.decodeImage(file.readAsBytesSync());
    Im.copyResize(image, 500);

//    image.format = Im.Image.RGBA;
//    Im.Image newim = Im.remapColors(image, alpha: Im.LUMINANCE);

    var newim2 = new File('$path/img_$rand.jpg')
      ..writeAsBytesSync(Im.encodeJpg(image, quality: 85));

    setState(() {
      file = newim2;
    });
    print('done');
  }

  void clearImage() {
    setState(() {
      file = null;
    });
  }

  void postImage(String currentusername, String currentuseremail,
      String currentuserimage, String currentuserid) {
    setState(() {
      uploading = true;
    });
    compressImage();
    Future<String> upload = uploadImage(file).then((String data) {
      Firestore.instance.collection("Advertice").document().setData({
        "Content": discription,
        "title": title.toUpperCase(),
        "url": data,
        "username": currentusername,
        "userEmail": currentuseremail,
        "userimage": currentuserimage,
        "userid": currentuserid,
        "type": "Advertice",
        "Seenstatus": {},
        "likes": {},
        "status": "Approved",
        "timestamp": new DateTime.now().toString(),
      });
    }).then((_) {
      setState(() {
        file = null;
        uploading = false;
      });
    });
  }
}


Future<String> uploadImage(var imageFile) async {
  var uuid = new Uuid().v1();
  StorageReference ref = FirebaseStorage.instance.ref().child("post_$uuid.jpg");
  StorageUploadTask uploadTask = ref.put(imageFile);
  Uri downloadUrl = (await uploadTask.future).downloadUrl;
  return downloadUrl.toString();
}

0 个答案:

没有答案