Skip to content

Commit

Permalink
Added try/catch to avoid messing retro if github or the device doesnt…
Browse files Browse the repository at this point in the history
… have internet
  • Loading branch information
KiritoDv committed Jun 3, 2024
1 parent 90d8b10 commit 146b944
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/features/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ class _HomeScreenState extends State<HomeScreen> {
Future<void> getRetroVersion() async {
const url = 'https://raw.githubusercontent.com/HarbourMasters/retro/main/release.json';

final response = await http.get(
Uri.parse(url),
headers: {
'Content-Type': 'application/json',
}
);
try {
final response = await http.get(
Uri.parse(url),
headers: {
'Content-Type': 'application/json',
}
);

if (response.statusCode == 200) {
final data = json.decode(response.body);
setState(() {
versionCode = data['version'] as int;
});
} else {
throw Exception('Failed to load data');
if (response.statusCode == 200) {
final data = json.decode(response.body);
setState(() {
versionCode = data['version'] as int;
});
}
} catch (e) {
print('Error fetching version code: $e');
}
}

Expand Down

0 comments on commit 146b944

Please sign in to comment.