diff --git a/lib/helpers/server_config_helper.dart b/lib/helpers/server_config_helper.dart index 1f3da80..0341d30 100644 --- a/lib/helpers/server_config_helper.dart +++ b/lib/helpers/server_config_helper.dart @@ -1,5 +1,6 @@ import 'package:comunic/models/api_request.dart'; import 'package:comunic/models/server_config.dart'; +import 'package:version/version.dart'; /// Server configuration helper /// @@ -20,6 +21,8 @@ class ServerConfigurationHelper { final dataConservationPolicy = response["data_conservation_policy"]; _config = ServerConfig( + minSupportedMobileVersion: + Version.parse(response["min_supported_mobile_version"]), passwordPolicy: PasswordPolicy( allowMailInPassword: passwordPolicy["allow_email_in_password"], allowNameInPassword: passwordPolicy["allow_name_in_password"], diff --git a/lib/helpers/version_helper.dart b/lib/helpers/version_helper.dart index 1b84b4f..91b0a04 100644 --- a/lib/helpers/version_helper.dart +++ b/lib/helpers/version_helper.dart @@ -1,4 +1,5 @@ import 'package:package_info/package_info.dart'; +import 'package:version/version.dart'; /// Application version helper /// @@ -13,4 +14,7 @@ class VersionHelper { /// Get current version information static PackageInfo get info => _info; + + /// Get current application version, in parsed format + static Version get version => Version.parse(info.version); } diff --git a/lib/models/server_config.dart b/lib/models/server_config.dart index bb65dd1..af39ceb 100644 --- a/lib/models/server_config.dart +++ b/lib/models/server_config.dart @@ -1,4 +1,5 @@ import 'package:flutter/widgets.dart'; +import 'package:version/version.dart'; /// Server static configuration /// @@ -57,12 +58,15 @@ class ServerDataConservationPolicy { } class ServerConfig { + final Version minSupportedMobileVersion; final PasswordPolicy passwordPolicy; final ServerDataConservationPolicy dataConservationPolicy; const ServerConfig({ + @required this.minSupportedMobileVersion, @required this.passwordPolicy, @required this.dataConservationPolicy, - }) : assert(passwordPolicy != null), + }) : assert(minSupportedMobileVersion != null), + assert(passwordPolicy != null), assert(dataConservationPolicy != null); } diff --git a/lib/ui/dialogs/deprecation_dialog.dart b/lib/ui/dialogs/deprecation_dialog.dart new file mode 100644 index 0000000..c5ec3db --- /dev/null +++ b/lib/ui/dialogs/deprecation_dialog.dart @@ -0,0 +1,28 @@ +import 'package:comunic/utils/intl_utils.dart'; +import 'package:flutter/material.dart'; + +/// Deprecation dialog +/// +/// @author Pierre Hubert + +/// Show a dialog to warn the user this version of the application is deprecated +Future showDeprecationDialog(BuildContext context) async { + await showDialog(context: context, builder: (c) => _DeprecationDialog()); +} + +class _DeprecationDialog extends StatelessWidget { + @override + Widget build(BuildContext context) { + return AlertDialog( + title: Text(tr("Deprecated application version")), + content: Text(tr( + "This version of the mobile application is deprecated. You might still be able to use it, but some features will not work. We recommend you to update to the latest version of the application.")), + actions: [ + MaterialButton( + onPressed: () => Navigator.pop(context), + child: Text(tr("OK")), + ) + ], + ); + } +} diff --git a/lib/ui/widgets/init_widget.dart b/lib/ui/widgets/init_widget.dart index f530e17..a546200 100644 --- a/lib/ui/widgets/init_widget.dart +++ b/lib/ui/widgets/init_widget.dart @@ -3,6 +3,7 @@ import 'package:comunic/helpers/events_helper.dart'; import 'package:comunic/helpers/server_config_helper.dart'; import 'package:comunic/helpers/version_helper.dart'; import 'package:comunic/helpers/websocket_helper.dart'; +import 'package:comunic/ui/dialogs/deprecation_dialog.dart'; import 'package:comunic/ui/routes/login_route.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; import 'package:comunic/ui/routes/main_route/smartphone_route.dart'; @@ -62,6 +63,9 @@ class _InitializeWidgetState extends SafeState { try { await ServerConfigurationHelper.ensureLoaded(); + if (ServerConfigurationHelper.config.minSupportedMobileVersion > VersionHelper.version) + await showDeprecationDialog(context); + if (!AccountHelper.isUserIDLoaded) { _popToMainRoute(); _openLoginPage(); diff --git a/pubspec.lock b/pubspec.lock index 163079a..338efe4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -630,6 +630,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0-nullsafety.3" + version: + dependency: "direct main" + description: + name: version + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" wakelock: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index bd216ec..92b7e03 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -88,6 +88,9 @@ dependencies: # Get information about current version package_info: ^0.4.3+4 + # Version manager + version: ^1.2.0 + dev_dependencies: flutter_test: sdk: flutter