'Stream<DocumentSnapshot<Map<String, dynamic>>>' can't be assigned to the parameter type 'Stream<QuerySnapshot<Object?>>?'

huangapple go评论58阅读模式
英文:

'Stream<DocumentSnapshot<Map<String, dynamic>>>' can't be assigned to the parameter type 'Stream<QuerySnapshot<Object?>>?'

问题

I wanted to use DropdownMenu and display data from my 'reports' collection in it.

But I get an error "The argument type 'Stream<DocumentSnapshot<Map<String, dynamic>>' can't be assigned to the parameter type 'Stream<QuerySnapshot<Object?>>?"

My code:

StreamBuilder<QuerySnapshot>(
  stream: FirebaseFirestore.instance
      .collection('reports')
      .doc(userID)
      .snapshots(),
  builder: (context, snapshot) {
    if (!snapshot.hasData) {
      const CircularProgressIndicator();
    } else {
      final currencyItems = <DropdownMenuItem>[];
      for (var i = 0; i < snapshot.data!.docs.length; i++) {
        final DocumentSnapshot snap = snapshot.data!.docs[i];
        currencyItems.add(
          DropdownMenuItem(
            value: snap.id,
            child: Text(
              snap.id,
              style: const TextStyle(color: Color(0xff11b719)),
            ),
          ),
        );
      }
      return Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          const Icon(Icons.abc, size: 25, color: Color(0xff11b719)),
          const SizedBox(width: 50.0),
          DropdownButton(
            items: currencyItems,
            onChanged: (currencyValue) {
              setState(() {
                final selectedCurrency = currencyValue;
              });
            },
            isExpanded: false,
            hint: new Text(
              "Choose Currency Type",
              style: TextStyle(color: Color(0xff11b719)),
            ),
          ),
        ],
      );
    }
    return Container();
  },
)

My FirebaseFirestore: 'Stream<DocumentSnapshot<Map<String, dynamic>>>' can't be assigned to the parameter type 'Stream<QuerySnapshot<Object?>>?'

Does anyone have any advice? Thank you!

英文:

I wanted to use DropdownMenu and display data from my 'reports' collection in it.

But I get an error "The argument type 'Stream<DocumentSnapshot<Map<String, dynamic>>' can't be assigned to the parameter type 'Stream<QuerySnapshot<Object?>>?"

My code:

   StreamBuilder&lt;QuerySnapshot&gt;(
          stream: FirebaseFirestore.instance
              .collection(&#39;reports&#39;)
              .doc(userID)
              .snapshots(),
          builder: (context, snapshot) {
            if (!snapshot.hasData) {
              const CircularProgressIndicator();
            } else {
              final currencyItems = &lt;DropdownMenuItem&gt;[];
              for (var i = 0; i &lt; snapshot.data!.docs.length; i++) {
                final DocumentSnapshot snap = snapshot.data!.docs[i];
                currencyItems.add(
                  DropdownMenuItem(
                    value: snap.id,
                    child: Text(
                      snap.id,
                      style: const TextStyle(color: Color(0xff11b719)),
                    ),
                  ),
                );
              }
              return Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: &lt;Widget&gt;[
                  const Icon(Icons.abc, size: 25, color: Color(0xff11b719)),
                  const SizedBox(width: 50.0),
                  DropdownButton(
                    items: currencyItems,
                    onChanged: (currencyValue) {
                      setState(() {
                        final selectedCurrency = currencyValue;
                      });
                    },
                    // value: selectedCurrency,
                    isExpanded: false,
                    hint: new Text(
                      &quot;Choose Currency Type&quot;,
                      style: TextStyle(color: Color(0xff11b719)),
                    ),
                  ),
                ],
              );
            }
            return Container();
          },
        ),

My FirebaseFirestore:
'Stream<DocumentSnapshot<Map<String, dynamic>>>' can't be assigned to the parameter type 'Stream<QuerySnapshot<Object?>>?'

Does anyone have any advice ? Thank you !

答案1

得分: 1

你可以在streamBuilder上更改dateType,就像它所示的那样。

英文:

You can change the dateType on streamBuilder as it showed.

 StreamBuilder&lt;DocumentSnapshot&lt;Map&lt;String, dynamic&gt;&gt;&gt;(

huangapple
  • 本文由 发表于 2023年2月23日 22:03:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75545863.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定