ошибка: тип 'int' не является подтипом типа 'String' - PullRequest
0 голосов
/ 07 октября 2018

При попытке получить 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();
}
...