Widget _buildList() {
return RefreshIndicator(
onRefresh: _loadFavorites,
child: ListView.builder(
padding: EdgeInsets.all(16),
itemCount: _favorites.length,
itemBuilder: (ctx, index) {
final favorite = _favorites[index];
return Card(
margin: EdgeInsets.only(bottom: 12),
child: ListTile(
leading: CircleAvatar(
backgroundColor: Theme.of(context).primaryColor,
child: Icon(Icons.favorite, color: Colors.white),
),
title: Text(
favorite.label,
style: TextStyle(fontWeight: FontWeight.bold),
),
subtitle: Text('${favorite.from} → ${favorite.to}'),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
favorite.defaultTime,
style: TextStyle(color: Colors.grey),
),
IconButton(
icon: Icon(Icons.delete_outline, color: Colors.red),
onPressed: () => _deleteFavorite(favorite),
),
],
),
onTap: () {
// Navigate to route search with pre-filled from/to
Navigator.pushNamed(
context,
'/route-search',
arguments: {
'from': favorite.from,
'to': favorite.to,
},
);
},
),
);
},
),
);
}