I’m a newbie Flutter programmer.
Im trying to make a generic grid widget that let me pass an object and create columns and rows dynamically.
I’ve made it work with an specific object but what i need is to read the names of attributes of an object to dynamically create grid column names and values so i can use the same grid for client or articles or everything.
For example i have a class for clients
class Client {
int id;
String name;
String mail;
Client({required this.id, required this.name, required this.mail});
}
then in my code retrieve a list of clients and pass that to the grid widget as List.
I just need to know how to loop the object recieved to:
- get the list of fields names (id, name, mail)
- then get its value for example something like
var field_name = element;
obj.field_name.value;
Hope you can understand what im trying to do.
Thank you in advance.
2
Answers
you can try this code
let me know if this is working for you.
Say you are getting List of Client Object and Class looks like this
Now if your question is how can i differentiate some Client from the list and have a separate Grid widget for them?
If yes, lets take example with above given class
We have Client with category, Design, Development etc.
We can simply have a another variable in class such as
and