0

await キーワードの下に緑色の渦巻き状の線が表示されます。

緑の渦巻き線の上にマウスを置くと、 と表示されます'await' applied to 'Query', which is not a 'Future'

await キーワードをどのステートメントに適用する必要があるのか​​ わかりません。

メソッドに await/async および Future を適用しないと、呼び出し元のメソッドはこのメソッドが完了するまで待機せず、残りのコードの実行を続行するため、null 値が返されます。

問題のコードを以下に示します。

Future<List<ContData>> readCC(String tID) async {
    List<ContData> conList = [];
    try {
      final conCollection = await FirebaseFirestore.instance
          .collection('CC')
          .where('conID', isEqualTo: tID);

      await conCollection.snapshots().listen((snapshot) {
        var tc = snapshot.docs[0].data()['con'];
        ContData con;
        for (var t in tc) {
          con = ContData.fromMap(data: t);
          print(con);
          final conType = con.conType;
          final conText = con.conText;
          final conCodeCaption = con.conCodeCaption;
          final conCodeText = con.conCodeText;
          final conCodeOutput = con.conCodeOutput;
          final conImageFilename = con.conImageFilename;
          final conImageCaption = con.conImageCaption;
          final conImageCredit = con.conImageCredit;
          final conImageCreditLink = con.conImageCreditLink;
          final conAnchorText = con.conAnchorText;
          final conAnchorLink = con.conAnchorLink;
          final ContData = ContData(
              conType: conType,
              conText: conText,
              conCodeCaption: conCodeCaption,
              conCodeText: conCodeText,
              conCodeOutput: conCodeOutput,
              conImageFilename: conImageFilename,
              conImageCaption: conImageCaption,
              conImageCredit: conImageCredit,
              conImageCreditLink: conImageCreditLink,
              conAnchorText: conAnchorText,
              conAnchorLink: conAnchorLink);
        }
      });
    } catch (e) {
      print(e.toString());
    }
    return conList;
  }

貴重な時間を割いていただき、事前にご協力いただき、誠にありがとうございました。

4

1 に答える 1