Folks, I get the String' is not a subtype of type 'Widget error in the below code. Mind you that I have a list with a named route inside and goes like this:
List tasks = [
{
'taskName': 'Delivery',
'onPressed': () {
Navigator.pushNamed(context, '/deliveryScreen');
}
},
];
The rest is a listview.builder:
Container(
height: 70,
width: double.infinity,
margin: EdgeInsets.all(5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.white,
border: Border.all(
width: 1.5,
color: selectedTask == index ? Colors.green : Colors.red,
),
),
child: Align(
alignment: Alignment.center,
child: ListTile(
onTap: tasks[index]['onPressed'],
title: tasks[index]['taskName'],
trailing: Icon(
Ionicons.chevron_forward_outline,
color: selectedTask == index ? Colors.green : Colors.red,
),
),
),
),
),
),
How do I get rid of that error?
CodePudding user response:
Replace this:
title: tasks[index]['taskName'],
With this:
title: Text(tasks[index]['taskName']),
CodePudding user response:
Try to Put your title proper way, refer ListTile
ListTile(
onTap: tasks[index]['onPressed'],
title: Text(tasks[index]['taskName'],),
trailing: Icon(
Ionicons.chevron_forward_outline,
color: selectedTask == index ? Colors.green : Colors.red,
),
),