From 54e37b3e699c58853ef90376f72e19569910e475 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 20 Feb 2021 08:58:03 +0100 Subject: [PATCH] Display current build version on startup screen --- lib/helpers/version_helper.dart | 16 ++++++++++++++++ lib/main.dart | 4 ++++ lib/ui/widgets/init_widget.dart | 6 ++++++ pubspec.lock | 2 +- pubspec.yaml | 3 +++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 lib/helpers/version_helper.dart diff --git a/lib/helpers/version_helper.dart b/lib/helpers/version_helper.dart new file mode 100644 index 0000000..1b84b4f --- /dev/null +++ b/lib/helpers/version_helper.dart @@ -0,0 +1,16 @@ +import 'package:package_info/package_info.dart'; + +/// Application version helper +/// +/// @author Pierre Hubert + +class VersionHelper { + static PackageInfo _info; + + static Future ensureLoaded() async { + _info = await PackageInfo.fromPlatform(); + } + + /// Get current version information + static PackageInfo get info => _info; +} diff --git a/lib/main.dart b/lib/main.dart index dd7ba4e..7154a51 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'package:comunic/helpers/account_helper.dart'; import 'package:comunic/helpers/database/database_helper.dart'; import 'package:comunic/helpers/preferences_helper.dart'; +import 'package:comunic/helpers/version_helper.dart'; import 'package:comunic/ui/widgets/init_widget.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:flutter/material.dart'; @@ -12,6 +13,9 @@ import 'package:flutter/material.dart'; void subMain() async { WidgetsFlutterBinding.ensureInitialized(); + // Load package information + await VersionHelper.ensureLoaded(); + // Connect to database await DatabaseHelper.open(); await DatabaseHelper.cleanUpDatabase(); diff --git a/lib/ui/widgets/init_widget.dart b/lib/ui/widgets/init_widget.dart index b2e92a1..f530e17 100644 --- a/lib/ui/widgets/init_widget.dart +++ b/lib/ui/widgets/init_widget.dart @@ -1,6 +1,7 @@ import 'package:comunic/helpers/account_helper.dart'; 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/routes/login_route.dart'; import 'package:comunic/ui/routes/main_route/main_route.dart'; @@ -123,6 +124,11 @@ class _InitializeWidgetState extends SafeState { Spacer( flex: 2, ), + Text(tr("Version %version% - Build %build%", args: { + "version": VersionHelper.info.version.toString(), + "build": VersionHelper.info.buildNumber.toString() + })), + Spacer(flex: 1), ], ), ), diff --git a/pubspec.lock b/pubspec.lock index c7ff26f..163079a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -332,7 +332,7 @@ packages: source: hosted version: "0.3.0" package_info: - dependency: transitive + dependency: "direct main" description: name: package_info url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index b9b7d65..bd216ec 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -85,6 +85,9 @@ dependencies: # Pick any kind of file file_picker_cross: ^4.2.8 + # Get information about current version + package_info: ^0.4.3+4 + dev_dependencies: flutter_test: sdk: flutter