mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
#29 - Add minimum required server version
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
@@ -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,
|
||||
|
||||
36
lib/screens/update_app_screen.dart
Normal file
36
lib/screens/update_app_screen.dart
Normal 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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user