簡體   English   中英

未處理的異常:鍵入&#39;Future <void> &#39;不是&#39;Future類型的子類型 <Photography> 在Firestore上

[英]Unhandled Exception: type 'Future<void>' is not a subtype of type 'Future<Photography>' on Firestore

我需要從Firestore數據庫中獲取所有數據。 我遵循這種方式, https://stackoverflow.com/a/55865045/9139407

 Future<Photography> getPhotography() {
  Future<Photography> data =  await db
    .collection('photography')
    .document('0yUc5QBGHNNq6WK9CyyF')
    .setData(jsonDecode(jsonEncode(Photography(
  [AllImages(["list"])],
  "image_url",
  "Shanika",
  "image_url",
  "lovely couple",
  "Bhanuka"
))));

return data;
}

錯誤消息是:

未處理的異常:類型'Future <void>'不是類型'Future <攝影>'的子類型

攝影模特班

import 'package:json_annotation/json_annotation.dart';
part 'Model.g.dart';

@JsonSerializable()
class Photography{
   List<AllImages> all_images;
   String couplePhoto;
   String female;
   String image_url;
   String info;
   String male;

  Photography();

  factory Photography.fromJson(Map<String, dynamic> json) => _$PhotographyFromJson(json);
   Map<String,dynamic> toJson() => _$PhotographyToJson(this);
}

@JsonSerializable()
class AllImages {
  final List<String> imageUrl;

  AllImages(this.imageUrl);

  factory AllImages.fromJson(Map<String, dynamic> json) => _$AllImagesFromJson(json);
  Map<String,dynamic> toJson() => _$AllImagesToJson(this);
}

接下來的問題是,如何在集團接收器上添加這些數據?

  Sink<Photography> get inFirestore => _firestoreController.sink;

這樣的東西? 但是錯誤是,不能將參數類型“ Future”分配給參數類型“ Photography”

final result = db.getPhotography();
inFirestore.add(result);

Document.setData()返回Future<void> -表示將來完成時不會返回任何數據。 當然,對於二傳手來說這是合理的。 這就是為什么您不能將其變成任何東西的原因。 目前尚不清楚您打算從何處獲取data 您從一個空的(?) Photography ,對其進行編碼,解碼並存儲,然后期望返回一些東西。 什么? 原來的空物體? (您可以退還-但我認為那不是您想要的。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM