I want to fetch status from database and show in listview as text but status which i store in database is number, how can i set those status as text?
0 = start
2 = pending approval
3 = Approved
return ListView.builder(
itemCount: problemlist.length,
itemBuilder: ((context, index) {
problemModel problem = problemlist[index];
return Card(
margin: EdgeInsets.all(10),
child: ListTile(
leading: CircleAvatar(
backgroundImage: NetworkImage(
'http://192.168.1.5/skc/Problem_image/${problem.image}',
),
),
title: Text(
problem.name_surname,
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 19),
),
subtitle: Text(
problem.status,
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 17),
),
),
);
}));
2
Answers
The straigthforward method is to create an helper function to change the type of your value.
Or later on if you have more complex object that not only has a status and manage directly custom types in your app
create a status enum
which can be accessed through
where ‘i’ is status code