Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/helpers/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ const ENERGY_CARBOHYDRATES = 4;

/// kcal per gram of fat (approx)
const ENERGY_FAT = 9;

/// Flag to check for updates to the new version.
const ENABLED_UPDATE = false;
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -495,5 +495,7 @@
"dataCopied": "Data copied to new entry",
"@dataCopied": {
"description": "Snackbar message to show on copying data to a new log entry"
}
},
"appUpdateTitle" : "App Update Available",
"appUpdateContent" : "The newer version of the app is availibale. Please update your application."
}
9 changes: 8 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import 'package:wger/screens/nutritional_diary_screen.dart';
import 'package:wger/screens/nutritional_plan_screen.dart';
import 'package:wger/screens/nutritional_plans_screen.dart';
import 'package:wger/screens/splash_screen.dart';
import 'package:wger/screens/update_app_screen.dart';
import 'package:wger/screens/weight_screen.dart';
import 'package:wger/screens/workout_plan_screen.dart';
import 'package:wger/screens/workout_plans_screen.dart';
Expand Down Expand Up @@ -103,7 +104,13 @@ class MyApp extends StatelessWidget {
title: 'wger',
theme: wgerTheme,
home: auth.isAuth
? HomeTabsScreen()
? FutureBuilder(
future: auth.neededApplicationUpdate(),
builder: (ctx, snapshot) =>
snapshot.connectionState == ConnectionState.done && snapshot.data == true
? UpdateAppScreen()
: HomeTabsScreen(),
)
: FutureBuilder(
future: auth.tryAutoLogin(),
builder: (ctx, authResultSnapshot) =>
Expand Down
13 changes: 13 additions & 0 deletions lib/providers/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;
import 'package:package_info/package_info.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:version/version.dart';
import 'package:wger/exceptions/http_exception.dart';
import 'package:wger/helpers/consts.dart';

Expand Down Expand Up @@ -76,6 +77,18 @@ class AuthProvider with ChangeNotifier {
applicationVersion = packageInfo;
}

/// Checking if there is a new version of the application.
Future<bool> neededApplicationUpdate() async {
if (!ENABLED_UPDATE) {
return false;
}
final response = await http.get(makeUri(serverUrl!, 'min-app-version'));
final applicationLatestVersion = json.decode(response.body);
final currentVersion = Version.parse(applicationVersion!.version);
final latestAppVersion = Version.parse(applicationLatestVersion);
return latestAppVersion > currentVersion;
}

/// Registers a new user
Future<void> register({
required String username,
Expand Down
36 changes: 36 additions & 0 deletions lib/screens/update_app_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (C) 2020, 2021 wger Team
*
* wger Workout Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class UpdateAppScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: AlertDialog(
title: Text(
AppLocalizations.of(context).appUpdateTitle,
style: TextStyle(fontSize: 24),
),
content: Text(AppLocalizations.of(context).appUpdateContent),
actions: null,
),
);
}
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies:
image_picker: ^0.8.4
intl: ^0.17.0
json_annotation: ^4.0.1
version: ^2.0.0
package_info: ^2.0.2
provider: ^5.0.0
shared_preferences: ^2.0.7
Expand Down