I have created a map, but I want some of the keys (locations & jobs) to have multiple values. Is it best practice to create a new "Client" for each new kay value, or can I make the locations & jobs maps? I have this:
class Client {
String? name;
String? status;
String? location;
String? job;
String? notes;
String? priority;
String? estimate;
String? doe;
int? time;
Client.fromJson(Map<String, dynamic> json) {
name = json['name'];
status = json['status'];
location = json['location']; // multiple locations per client (name)
job = json['job']; // multiple jobs per client & location combo
notes = json['notes'];
priority = json['priority'];
estimate = json['estimate'];
doe = json['doe'];
time = json['time'];
}
final map = {
"name": nameController.text,
"location": locationController.text,
"job": jobController.text,
"notes": notesController.text,
"priority": priority,
"status": status,
"time": DateTime.now().millisecondsSinceEpoch,
};
I essentially want this output, but I'm not sure which path to take:
name1, location1, jobA
name1, location1, jobB
name1, location2, jobC
name2, location2, jobD
I haven't tried anything yet. I am very new to coding and don't know what would be best for the database functionality.
You have a good approach with the
Clientclass, you may continue using the same approach with location and job, if they are complex objects.And then use them in the
ClientIf you don't have a complex objects, then just use a
List<Object>(Replace object with the proper type).p.s. You mentioned database, so You can implement
toJsonmethod, which serialize all your objects back to aMap, so you can easily store them inside a db.