Skip to content

Commit 176436b

Browse files
committed
feat: create country item widget
- Displays country flag and name - Handles flag loading errors - Placeholder for no flag image - Shows snackbar on tap
1 parent 935eb1a commit 176436b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:ht_shared/ht_shared.dart'; // Import Country model
3+
4+
/// A simple widget to display a Country search result.
5+
class CountryItemWidget extends StatelessWidget {
6+
const CountryItemWidget({required this.country, super.key});
7+
8+
final Country country;
9+
10+
@override
11+
Widget build(BuildContext context) {
12+
return ListTile(
13+
leading: CircleAvatar(
14+
backgroundImage: NetworkImage(country.flagUrl),
15+
onBackgroundImageError: (exception, stackTrace) {
16+
debugPrint('Error loading country flag: $exception');
17+
},
18+
child: country.flagUrl.isEmpty
19+
? const Icon(Icons.public_off_outlined) // Placeholder if no flag
20+
: null,
21+
),
22+
title: Text(country.name),
23+
// TODO(you): Implement onTap navigation if needed for countries
24+
onTap: () {
25+
// Example: Navigate to a page showing headlines from this country
26+
// context.goNamed('someCountryFeedRoute', params: {'isoCode': country.isoCode});
27+
ScaffoldMessenger.of(context).showSnackBar(
28+
SnackBar(content: Text('Tapped on country: ${country.name}')),
29+
);
30+
},
31+
);
32+
}
33+
}

0 commit comments

Comments
 (0)