Skip to content

Commit

Permalink
fix(android): not showing version in settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
Merrit committed Feb 18, 2024
1 parent 0de8e4d commit d849048
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
13 changes: 7 additions & 6 deletions lib/src/settings/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ class SettingsPage extends StatelessWidget {
'${translations.settings.currentVersion}: ${state.runningVersion}',
),
),
ListTile(
title: Text(
(state.updateAvailable)
? '${translations.settings.updateAvailable}: ${state.updateVersion}'
: translations.settings.upToDate,
if (state.updateVersion != null)
ListTile(
title: Text(
(state.updateAvailable)
? '${translations.settings.updateAvailable}: ${state.updateVersion}'
: translations.settings.upToDate,
),
),
),
ListTile(
title: const Text('About'),
onTap: () => showAboutDialog(
Expand Down
21 changes: 17 additions & 4 deletions lib/src/updates/update_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:package_info_plus/package_info_plus.dart';
import 'package:pub_semver/pub_semver.dart';
Expand Down Expand Up @@ -43,14 +44,26 @@ class UpdateService {

/// Gets the latest version of the app.
Future<Version?> _getLatestVersion() async {
// We don't request network access on Android.
if (defaultTargetPlatform == TargetPlatform.android) {
return null;
}

final uri = Uri.parse(
'https://api.github.com/repos/merrit/feeling_finder/releases',
);

final response = await http.get(
uri,
headers: {'Accept': 'application/vnd.github.v3+json'},
);
final http.Response response;

try {
response = await http.get(
uri,
headers: {'Accept': 'application/vnd.github.v3+json'},
);
} on Exception catch (e) {
log.e('Issue getting latest version info from GitHub: $e');
return null;
}

if (response.statusCode == 200) {
final json = jsonDecode(response.body) as List;
Expand Down

0 comments on commit d849048

Please sign in to comment.