简体   繁体   中英

Missing selector such as '.identifier' or '[0]'

Good day,

So I'm struggling with http.post. I get the error on 'name' and 'description' due to the missing selector.

Where should i add the selector.

Any advice?

void addService(Service service){
const url =  'https://protion-app-default-rtdb.firebaseio.com/service.json';
http.post(Uri.parse(url), body: json.encode({
  'name' = service.name,
  'description' = service.description,
},),);
final newService = Service(
  id: DateTime.now().toString(),
  name: service.name,
  description: service.description,
  aboutUs: service.aboutUs,
  streetNumber: service.streetNumber,
  streetName: service.streetName,
  suburb: service.suburb,
  city: service.city,
  province: service.province,
  zipCode: service.zipCode,
  contactNum: service.contactNum,
  email: service.email,
  logoUrl: service.logoUrl,
  imageUrl: service.imageUrl,
);
_items.add(newService);
///_items.insert(0, newService); ///ad to top of list
notifyListeners();

}

To json.encode, you need to pass a Map<String, dynamic> and delimit your properties using a colon as opposed to "=", as in:

json.encode({
  'name' : service.name,
  'description' : service.description,
})

since it's a Map<String, dynamic>, with key-value pairs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM