',firebase,flutter,dart"/>

首页 > 解决方案 > 参数类型 'Set' 不能分配给参数类型 'Map'

问题描述

我的产品.DART 页面

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:uuid/uuid.dart';

class ProductService{
  FirebaseFirestore _firestore = FirebaseFirestore.instance;
  String ref = "products";

  void uploadProduct({String productName, String brand, String category, int quantity, List sizes, List images, double price}){
    var id = Uuid();
    String productId = id.v1();

_firestore.collection(ref).doc(productId).set({
  "name" = productName,
  "brand" = brand,
  "id" = productId,
  "category" = category,
});


 }
}

我的问题是:我不能将这些变量包含在 data() 方法中

错误:

error: The argument type 'Set<String>' can't be assigned to the parameter type 'Map<String, dynamic>'. (argument_type_not_assignable at [ecommerceadmin_app] lib\db\product.dart:12)

标签: firebaseflutterdart

解决方案


将 = 替换为 : 如下:

_firestore.collection(ref).doc(productId).set({
  "name": productName,
  "brand": brand,
  "id": productId,
  "category": category,
});

推荐阅读