#29 - Add minimum required server version

This commit is contained in:
Sandi Milohanić
2021-10-12 18:43:45 +02:00
parent bed7da48c6
commit ee3df1bada
6 changed files with 65 additions and 2 deletions

View File

@@ -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;

View File

@@ -495,5 +495,8 @@
"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.",
"appUpdateButoon" : "Close"
}

View File

@@ -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';
@@ -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) =>

View File

@@ -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';
@@ -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,

View File

@@ -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,
),
);
}
}