小编bib*_*101的帖子

如何在 Flutter 中从 Firestore 存储和检索颜色

我想在 Firestore 中将颜色存储为“颜色”并检索它以添加我的卡片的颜色;

但是当我添加新数据时,它不会被添加。也许我将颜色值存储为字符串,而颜色不支持字符串。那么我该如何解决这个问题呢?

代码如下 -


这是我调用 Firestore 并添加文档的地方(有一个名为“color”的文档)

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

class FirestoreServices {
  final _fireStore = Firestore.instance;

  void addNewMatch(int rScore, int bScore) async {
    if (_fireStore.collection('matches').snapshots() != null) {
      if (rScore > bScore)
        await _fireStore.collection('matches').add({
          'WinnerText': 'Rikesh Wins',
          'RS': rScore,
          'BS': bScore,
          'Score': ('${rScore.toInt()} - ${bScore.toInt()}'),
          'id':
              _fireStore.collection('matches').document().documentID.toString(),
          'date': DateFormat.yMMMd().format(DateTime.now()),
          'color' : Colors.red
        });
      if (bScore > rScore)
        await _fireStore.collection('matches').add({
          'WinnerText': 'Bibin Wins',
          'RS': rScore,
          'BS': bScore,
          'Score': ('${bScore.toInt()} - ${rScore.toInt()}'),
          'id':
              _fireStore.collection('matches').document().documentID.toString(),
          'date': DateFormat.yMMMd().format(DateTime.now()), …
Run Code Online (Sandbox Code Playgroud)

firebase flutter google-cloud-firestore

4
推荐指数
2
解决办法
2351
查看次数

标签 统计

firebase ×1

flutter ×1

google-cloud-firestore ×1