Home > Back-end >  Missing selector such as '.identifier' or '[0]'
Missing selector such as '.identifier' or '[0]'

Time:03-02

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();

}

CodePudding user response:

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.

  • Related