From 31eec777a3d29ad4011e63cf518037d2c767fbb6 Mon Sep 17 00:00:00 2001 From: JTorrus Date: Thu, 1 Apr 2021 05:03:55 +0200 Subject: [PATCH 01/10] Added new dependencies and Flutter version upgrade --- example/pubspec.lock | 191 ++++++++++++++++++++++++++++++++++++++----- pubspec.lock | 189 +++++++++++++++++++++++++++++++++++++----- pubspec.yaml | 10 ++- 3 files changed, 344 insertions(+), 46 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index ab62e0f..39280a4 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -28,14 +28,14 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.2" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" build: dependency: transitive description: @@ -56,14 +56,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" + version: "1.2.0" checked_yaml: dependency: transitive description: @@ -84,14 +84,14 @@ packages: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.13" + version: "1.15.0" convert: dependency: transitive description: @@ -133,7 +133,21 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0" flutter: dependency: "direct main" description: flutter @@ -183,7 +197,7 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.2" + version: "0.6.3" json_annotation: dependency: transitive description: @@ -211,7 +225,7 @@ packages: path: ".." relative: true source: path - version: "0.0.1" + version: "0.2.0" lr_core: dependency: transitive description: @@ -227,14 +241,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.8" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" node_interop: dependency: transitive description: @@ -263,13 +277,76 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.3" + package_info_plus: + dependency: transitive + description: + name: package_info_plus + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" + package_info_plus_linux: + dependency: transitive + description: + name: package_info_plus_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.1" + package_info_plus_macos: + dependency: transitive + description: + name: package_info_plus_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" + package_info_plus_web: + dependency: transitive + description: + name: package_info_plus_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.1" + package_info_plus_windows: + dependency: transitive + description: + name: package_info_plus_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+2" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4+3" pedantic: dependency: transitive description: @@ -277,6 +354,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.9.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" platform_detect: dependency: transitive description: @@ -291,6 +375,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.1" pub_semver: dependency: transitive description: @@ -305,6 +396,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.5" + shared_preferences: + dependency: transitive + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.12" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2+4" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+11" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2+7" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2+3" sky_engine: dependency: transitive description: flutter @@ -323,49 +456,49 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.5" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.17" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" url_launcher: dependency: transitive description: @@ -407,7 +540,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0" watcher: dependency: transitive description: @@ -415,6 +548,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.9.7+15" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.4+1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2" yaml: dependency: transitive description: @@ -423,5 +570,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.9.0-14.0.dev <3.0.0" - flutter: ">=1.17.0 <2.0.0" + dart: ">=2.12.0-0.0 <3.0.0" + flutter: ">=2.0.3" diff --git a/pubspec.lock b/pubspec.lock index a36c95d..5b40801 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -28,14 +28,14 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.2" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" build: dependency: transitive description: @@ -98,14 +98,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" + version: "1.2.0" checked_yaml: dependency: transitive description: @@ -126,7 +126,7 @@ packages: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" code_builder: dependency: transitive description: @@ -140,7 +140,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.13" + version: "1.15.0" convert: dependency: transitive description: @@ -175,7 +175,21 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0" fixnum: dependency: transitive description: @@ -253,7 +267,7 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.2" + version: "0.6.3" json_annotation: dependency: transitive description: @@ -290,14 +304,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.8" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" mime: dependency: transitive description: @@ -333,13 +347,76 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.3" + package_info_plus: + dependency: "direct main" + description: + name: package_info_plus + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.4" + package_info_plus_linux: + dependency: transitive + description: + name: package_info_plus_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.1" + package_info_plus_macos: + dependency: transitive + description: + name: package_info_plus_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" + package_info_plus_web: + dependency: transitive + description: + name: package_info_plus_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.1" + package_info_plus_windows: + dependency: transitive + description: + name: package_info_plus_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+2" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4+3" pedantic: dependency: transitive description: @@ -347,6 +424,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.9.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" platform_detect: dependency: transitive description: @@ -368,6 +452,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.0" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.1" pub_semver: dependency: transitive description: @@ -389,6 +480,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.3" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "0.5.12" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2+4" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+11" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2+7" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2+3" shelf: dependency: transitive description: @@ -421,21 +554,21 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.5" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" stream_transform: dependency: transitive description: @@ -449,21 +582,21 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.17" + version: "0.2.19" timing: dependency: transitive description: @@ -477,7 +610,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" url_launcher: dependency: "direct main" description: @@ -519,7 +652,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0" watcher: dependency: transitive description: @@ -534,6 +667,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "1.7.4+1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2" yaml: dependency: transitive description: @@ -542,5 +689,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.9.0-14.0.dev <3.0.0" - flutter: ">=1.17.0 <2.0.0" + dart: ">=2.12.0-0.0 <3.0.0" + flutter: ">=2.0.3" diff --git a/pubspec.yaml b/pubspec.yaml index c2074d9..5ec3923 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: lr_app_versioning description: L+R app versioning package -version: 0.1.0 +version: 0.2.0 environment: - sdk: ">=2.7.0 <3.0.0" - flutter: ">=1.17.0 <2.0.0" + sdk: ">=2.8.0 <3.0.0" + flutter: 2.0.3 dependencies: flutter: @@ -21,8 +21,12 @@ dependencies: # App package info package_info: ^0.4.3 + package_info_plus: 0.6.4 # URL Launcher url_launcher: ^5.5.0 + # Shared preferences + shared_preferences: 0.5.12 + dev_dependencies: flutter_test: From b54e9f4bc6e535242023d2b040d8cb4d06766bda Mon Sep 17 00:00:00 2001 From: JTorrus Date: Thu, 1 Apr 2021 05:07:16 +0200 Subject: [PATCH 02/10] Add version tracker implementation without null safety --- lib/src/util/version_tracker.dart | 139 ++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 lib/src/util/version_tracker.dart diff --git a/lib/src/util/version_tracker.dart b/lib/src/util/version_tracker.dart new file mode 100644 index 0000000..f89be62 --- /dev/null +++ b/lib/src/util/version_tracker.dart @@ -0,0 +1,139 @@ +import 'package:package_info_plus/package_info_plus.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +/// Provides an easy way to track versions and builds +class VersionTracker { + final String _versionsKey = "VersionTracker.Versions"; + final String _buildsKey = "VersionTracker.Builds"; + + /// Gets a value indicating whether this is the first time this app has ever been launched on this device. + bool get isFirstLaunchEver => _isFirstLaunchEver; + bool _isFirstLaunchEver; + + /// Gets a value indicating if this is the first launch of the app for the current version number. + bool get isFirstLaunchForCurrentVersion => _isFirstLaunchForCurrentVersion; + bool _isFirstLaunchForCurrentVersion; + + /// Gets a value indicating if this is the first launch of the app for the current build number. + bool get isFirstLaunchForCurrentBuild => _isFirstLaunchForCurrentBuild; + bool _isFirstLaunchForCurrentBuild; + + /// Gets the current version number of the app. + String get currentVersion => _currentVersion; + String _currentVersion; + + /// Gets the current build of the app. + String get currentBuild => _currentBuild; + String _currentBuild; + + /// Gets the version number for the previously run version. + String get previousVersion => _previousVersion; + String _previousVersion; + + /// Gets the build number for the previously run version. + String get previousBuild => _previousBuild; + String _previousBuild; + + /// Gets the version number of the first version of the app that was installed on this device. + String get firstInstalledVersion => _firstInstalledVersion; + String _firstInstalledVersion; + + /// Gets the build number of first version of the app that was installed on this device. + String get firstInstalledBuild => _firstInstalledBuild; + String _firstInstalledBuild; + + /// Gets the collection of version numbers of the app that ran on this device. + List get versionHistory => _versionHistory; + List _versionHistory; + + /// Gets the collection of build numbers of the app that ran on this device. + List get buildHistory => _buildHistory; + List _buildHistory; + + /// Determines if this is the first launch of the app for a specified version number. + bool isFirstLaunchForVersion(String version) => + _currentVersion == version && _isFirstLaunchForCurrentVersion; + + /// Determines if this is the first launch of the app for a specified build number. + bool isFirstLaunchForBuild(String build) => + _currentBuild == build && _isFirstLaunchForCurrentBuild; + + /// Start tracking versions and builds + Future track() async { + SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + + Map> versionTrail = Map>(); + + _isFirstLaunchEver = !sharedPreferences.containsKey(_versionsKey) || + !sharedPreferences.containsKey(_buildsKey); + if (_isFirstLaunchEver) + versionTrail.addAll({_versionsKey: [], _buildsKey: []}); + else + versionTrail.addAll({ + _versionsKey: _readHistory(sharedPreferences, _versionsKey).toList(), + _buildsKey: _readHistory(sharedPreferences, _buildsKey).toList() + }); + + _currentVersion = packageInfo.version; + _currentBuild = packageInfo.buildNumber; + + _isFirstLaunchForCurrentVersion = + !versionTrail[_versionsKey].contains(_currentVersion); + if (_isFirstLaunchForCurrentVersion) + versionTrail[_versionsKey].add(_currentVersion); + + _isFirstLaunchForCurrentBuild = + !versionTrail[_buildsKey].contains(_currentBuild); + if (_isFirstLaunchForCurrentBuild) + versionTrail[_buildsKey].add(_currentBuild); + + if (_isFirstLaunchForCurrentVersion || _isFirstLaunchForCurrentBuild) { + _writeHistory( + sharedPreferences, _versionsKey, versionTrail[_versionsKey]); + _writeHistory(sharedPreferences, _buildsKey, versionTrail[_buildsKey]); + } + + _previousVersion = _getPrevious(versionTrail, _versionsKey); + _previousBuild = _getPrevious(versionTrail, _buildsKey); + _firstInstalledVersion = versionTrail[_versionsKey].first; + _firstInstalledBuild = versionTrail[_buildsKey].first; + _versionHistory = versionTrail[_versionsKey].toList(); + _buildHistory = versionTrail[_buildsKey].toList(); + } + + /// Show all the available data in a formatted string + @override + String toString() { + var sb = StringBuffer(); + sb.writeln('VersionTracker'); + sb.writeln(); + sb.writeln('IsFirstLaunchEver: $_isFirstLaunchEver'); + sb.writeln( + 'IsFirstLaunchForCurrentVersion: $_isFirstLaunchForCurrentVersion'); + sb.writeln('IsFirstLaunchForCurrentBuild: $_isFirstLaunchForCurrentBuild'); + sb.writeln(); + sb.writeln('CurrentVersion: $_currentVersion'); + sb.writeln('PreviousVersion: $_previousVersion'); + sb.writeln('FirstInstalledVersion: $_firstInstalledVersion'); + sb.writeln('VersionHistory: ${_versionHistory.join(", ")}'); + sb.writeln(); + sb.writeln('CurrentBuild: $_currentBuild'); + sb.writeln('PreviousBuild: $_previousBuild'); + sb.writeln('FirstInstalledBuild: $_firstInstalledBuild'); + sb.writeln('BuildHistory: ${_buildHistory.join(", ")}'); + return sb.toString(); + } + + List _readHistory(SharedPreferences preferences, String key) => + preferences.getString(key).split('|'); + + void _writeHistory( + SharedPreferences preferences, String key, List history) => + preferences.setString(key, history.join('|')); + + String _getPrevious(Map> versionTrail, String key) { + var trail = versionTrail[key]; + return (trail.length >= 2) ? trail[trail.length - 2] : null; + } +} \ No newline at end of file From acba75fde3b35a681644cad5fb062b5fc923b19a Mon Sep 17 00:00:00 2001 From: JTorrus Date: Thu, 1 Apr 2021 05:08:37 +0200 Subject: [PATCH 03/10] Updated example --- example/lib/main.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 18de134..00bd48e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -79,11 +79,11 @@ class _HomeState extends State { showDialog( context: context, barrierDismissible: false, - child: Container( + builder: (context) => Container( child: Column( children: [ Text("Update required!"), - FlatButton( + TextButton( onPressed: () => widget.appVersioning.launchUpdate(), child: Text("OK"), ) From b501a7b3ba066c885e36b6b404772d778c85eb76 Mon Sep 17 00:00:00 2001 From: JTorrus Date: Thu, 1 Apr 2021 05:11:13 +0200 Subject: [PATCH 04/10] Expose version tracker in app versioning --- lib/app_versioning.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/app_versioning.dart b/lib/app_versioning.dart index 278d91e..b606f27 100644 --- a/lib/app_versioning.dart +++ b/lib/app_versioning.dart @@ -10,6 +10,7 @@ export './src/defaults/mock_api_versioning_service.dart'; export './src/service/app_update_service.dart'; export './src/defaults/mock_app_update_service.dart'; export './src/util/version.dart'; +export './src/util/version_tracker.dart'; // Class imports import 'package:flutter/widgets.dart'; From 367abc2e2a8e2b3e71f57f8c0b3bd48d86b080b9 Mon Sep 17 00:00:00 2001 From: JTorrus Date: Thu, 1 Apr 2021 05:19:44 +0200 Subject: [PATCH 05/10] Switched version tracker instance to singleton --- lib/src/util/version_tracker.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/src/util/version_tracker.dart b/lib/src/util/version_tracker.dart index f89be62..d7a8650 100644 --- a/lib/src/util/version_tracker.dart +++ b/lib/src/util/version_tracker.dart @@ -3,6 +3,11 @@ import 'package:shared_preferences/shared_preferences.dart'; /// Provides an easy way to track versions and builds class VersionTracker { + VersionTracker._internal(); + + static final VersionTracker _instance = VersionTracker._internal(); + static VersionTracker get instance => _instance; + final String _versionsKey = "VersionTracker.Versions"; final String _buildsKey = "VersionTracker.Builds"; From d9360e12dfeb415661a61c93af56d0ac522fa8e8 Mon Sep 17 00:00:00 2001 From: JTorrus Date: Thu, 1 Apr 2021 05:28:18 +0200 Subject: [PATCH 06/10] Upgraded url launcher --- example/pubspec.lock | 19 +++++++++++++------ pubspec.lock | 19 +++++++++++++------ pubspec.yaml | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 39280a4..e6c0e9b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -505,35 +505,42 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "5.5.2" + version: "6.0.3" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+1" + version: "2.0.0" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+7" + version: "2.0.0" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.8" + version: "2.0.1" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.3+1" + version: "2.0.0" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" vector_math: dependency: transitive description: @@ -570,5 +577,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.12.0-0.0 <3.0.0" + dart: ">=2.12.0-259.9.beta <3.0.0" flutter: ">=2.0.3" diff --git a/pubspec.lock b/pubspec.lock index 5b40801..a238ca6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -617,35 +617,42 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "5.5.2" + version: "6.0.3" url_launcher_linux: dependency: transitive description: name: url_launcher_linux url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+1" + version: "2.0.0" url_launcher_macos: dependency: transitive description: name: url_launcher_macos url: "https://pub.dartlang.org" source: hosted - version: "0.0.1+7" + version: "2.0.0" url_launcher_platform_interface: dependency: transitive description: name: url_launcher_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.8" + version: "2.0.1" url_launcher_web: dependency: transitive description: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.3+1" + version: "2.0.0" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" vector_math: dependency: transitive description: @@ -689,5 +696,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.12.0-0.0 <3.0.0" + dart: ">=2.12.0-259.9.beta <3.0.0" flutter: ">=2.0.3" diff --git a/pubspec.yaml b/pubspec.yaml index 5ec3923..818e86e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: package_info: ^0.4.3 package_info_plus: 0.6.4 # URL Launcher - url_launcher: ^5.5.0 + url_launcher: ^6.0.3 # Shared preferences shared_preferences: 0.5.12 From 7205d528ed109d6eefa6f4aa5a513ee22cb78341 Mon Sep 17 00:00:00 2001 From: JTorrus Date: Thu, 8 Apr 2021 21:52:22 +0200 Subject: [PATCH 07/10] Version tracker migrated to null safety --- example/pubspec.lock | 105 ++++++++++++++++++++++++ lib/src/util/version_tracker.dart | 129 +++++++++++++++++------------- pubspec.lock | 105 ++++++++++++++++++++++++ pubspec.yaml | 2 + 4 files changed, 286 insertions(+), 55 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index c312c78..e06bbbe 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -50,6 +50,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0" firebase_core: dependency: transitive description: @@ -158,6 +172,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" pedantic: dependency: transitive description: @@ -165,6 +200,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.11.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" plugin_platform_interface: dependency: transitive description: @@ -172,6 +214,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.3" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.1" quiver: dependency: transitive description: @@ -179,6 +228,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.5" + shared_preferences: + dependency: transitive + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" sky_engine: dependency: transitive description: flutter @@ -282,6 +373,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" sdks: dart: ">=2.12.0 <3.0.0" flutter: ">=1.22.0" diff --git a/lib/src/util/version_tracker.dart b/lib/src/util/version_tracker.dart index d7a8650..cd02c08 100644 --- a/lib/src/util/version_tracker.dart +++ b/lib/src/util/version_tracker.dart @@ -1,4 +1,4 @@ -import 'package:package_info_plus/package_info_plus.dart'; +import 'package:package_info/package_info.dart'; import 'package:shared_preferences/shared_preferences.dart'; /// Provides an easy way to track versions and builds @@ -12,99 +12,118 @@ class VersionTracker { final String _buildsKey = "VersionTracker.Builds"; /// Gets a value indicating whether this is the first time this app has ever been launched on this device. - bool get isFirstLaunchEver => _isFirstLaunchEver; - bool _isFirstLaunchEver; + bool? get isFirstLaunchEver => _isFirstLaunchEver; + bool? _isFirstLaunchEver; /// Gets a value indicating if this is the first launch of the app for the current version number. - bool get isFirstLaunchForCurrentVersion => _isFirstLaunchForCurrentVersion; - bool _isFirstLaunchForCurrentVersion; + bool? get isFirstLaunchForCurrentVersion => _isFirstLaunchForCurrentVersion; + bool? _isFirstLaunchForCurrentVersion; /// Gets a value indicating if this is the first launch of the app for the current build number. - bool get isFirstLaunchForCurrentBuild => _isFirstLaunchForCurrentBuild; - bool _isFirstLaunchForCurrentBuild; + bool? get isFirstLaunchForCurrentBuild => _isFirstLaunchForCurrentBuild; + bool? _isFirstLaunchForCurrentBuild; /// Gets the current version number of the app. - String get currentVersion => _currentVersion; - String _currentVersion; + String? get currentVersion => _currentVersion; + String? _currentVersion; /// Gets the current build of the app. - String get currentBuild => _currentBuild; - String _currentBuild; + String? get currentBuild => _currentBuild; + String? _currentBuild; /// Gets the version number for the previously run version. - String get previousVersion => _previousVersion; - String _previousVersion; + String? get previousVersion => _previousVersion; + String? _previousVersion; /// Gets the build number for the previously run version. - String get previousBuild => _previousBuild; - String _previousBuild; + String? get previousBuild => _previousBuild; + String? _previousBuild; /// Gets the version number of the first version of the app that was installed on this device. - String get firstInstalledVersion => _firstInstalledVersion; - String _firstInstalledVersion; + String? get firstInstalledVersion => _firstInstalledVersion; + String? _firstInstalledVersion; /// Gets the build number of first version of the app that was installed on this device. - String get firstInstalledBuild => _firstInstalledBuild; - String _firstInstalledBuild; + String? get firstInstalledBuild => _firstInstalledBuild; + String? _firstInstalledBuild; /// Gets the collection of version numbers of the app that ran on this device. - List get versionHistory => _versionHistory; - List _versionHistory; + List? get versionHistory => _versionHistory; + List? _versionHistory; /// Gets the collection of build numbers of the app that ran on this device. - List get buildHistory => _buildHistory; - List _buildHistory; + List? get buildHistory => _buildHistory; + List? _buildHistory; /// Determines if this is the first launch of the app for a specified version number. bool isFirstLaunchForVersion(String version) => - _currentVersion == version && _isFirstLaunchForCurrentVersion; + _currentVersion == version && _isFirstLaunchForCurrentVersion!; /// Determines if this is the first launch of the app for a specified build number. bool isFirstLaunchForBuild(String build) => - _currentBuild == build && _isFirstLaunchForCurrentBuild; + _currentBuild == build && _isFirstLaunchForCurrentBuild!; /// Start tracking versions and builds - Future track() async { + Future track( + {int? versionHistoryMaxLength, int? buildHistoryMaxLength}) async { SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); PackageInfo packageInfo = await PackageInfo.fromPlatform(); - Map> versionTrail = Map>(); + Map> historyTrail = Map>(); _isFirstLaunchEver = !sharedPreferences.containsKey(_versionsKey) || !sharedPreferences.containsKey(_buildsKey); - if (_isFirstLaunchEver) - versionTrail.addAll({_versionsKey: [], _buildsKey: []}); + if (_isFirstLaunchEver!) + historyTrail.addAll({_versionsKey: [], _buildsKey: []}); else - versionTrail.addAll({ + historyTrail.addAll({ _versionsKey: _readHistory(sharedPreferences, _versionsKey).toList(), _buildsKey: _readHistory(sharedPreferences, _buildsKey).toList() }); + // Handle versions _currentVersion = packageInfo.version; - _currentBuild = packageInfo.buildNumber; _isFirstLaunchForCurrentVersion = - !versionTrail[_versionsKey].contains(_currentVersion); - if (_isFirstLaunchForCurrentVersion) - versionTrail[_versionsKey].add(_currentVersion); + !historyTrail[_versionsKey]!.contains(_currentVersion); + if (_isFirstLaunchForCurrentVersion!) + historyTrail[_versionsKey]!.add(_currentVersion); + + if (versionHistoryMaxLength != null && versionHistoryMaxLength > 0) { + var versionsToRemove = + historyTrail[_versionsKey]!.length - versionHistoryMaxLength; + if (versionsToRemove > 0) + historyTrail[_versionsKey]!.removeRange(1, versionsToRemove + 1); + } + + _previousVersion = _getPrevious(historyTrail, _versionsKey); + _firstInstalledVersion = historyTrail[_versionsKey]!.first; + _versionHistory = historyTrail[_versionsKey]!.toList(); + + // Handle builds + _currentBuild = packageInfo.buildNumber; _isFirstLaunchForCurrentBuild = - !versionTrail[_buildsKey].contains(_currentBuild); - if (_isFirstLaunchForCurrentBuild) - versionTrail[_buildsKey].add(_currentBuild); + !historyTrail[_buildsKey]!.contains(_currentBuild); + if (_isFirstLaunchForCurrentBuild!) + historyTrail[_buildsKey]!.add(_currentBuild); + + if (buildHistoryMaxLength != null && buildHistoryMaxLength > 0) { + var buildsToRemove = + historyTrail[_buildsKey]!.length - buildHistoryMaxLength; + if (buildsToRemove > 0) + historyTrail[_buildsKey]!.removeRange(1, buildsToRemove + 1); + } - if (_isFirstLaunchForCurrentVersion || _isFirstLaunchForCurrentBuild) { + if (_isFirstLaunchForCurrentVersion! || _isFirstLaunchForCurrentBuild!) { _writeHistory( - sharedPreferences, _versionsKey, versionTrail[_versionsKey]); - _writeHistory(sharedPreferences, _buildsKey, versionTrail[_buildsKey]); + sharedPreferences, _versionsKey, historyTrail[_versionsKey]!); + _writeHistory(sharedPreferences, _buildsKey, historyTrail[_buildsKey]!); } - _previousVersion = _getPrevious(versionTrail, _versionsKey); - _previousBuild = _getPrevious(versionTrail, _buildsKey); - _firstInstalledVersion = versionTrail[_versionsKey].first; - _firstInstalledBuild = versionTrail[_buildsKey].first; - _versionHistory = versionTrail[_versionsKey].toList(); - _buildHistory = versionTrail[_buildsKey].toList(); + _previousBuild = _getPrevious(historyTrail, _buildsKey); + _firstInstalledBuild = historyTrail[_buildsKey]!.first; + _buildHistory = historyTrail[_buildsKey]!.toList(); } /// Show all the available data in a formatted string @@ -121,24 +140,24 @@ class VersionTracker { sb.writeln('CurrentVersion: $_currentVersion'); sb.writeln('PreviousVersion: $_previousVersion'); sb.writeln('FirstInstalledVersion: $_firstInstalledVersion'); - sb.writeln('VersionHistory: ${_versionHistory.join(", ")}'); + sb.writeln('VersionHistory: ${_versionHistory!.join(", ")}'); sb.writeln(); sb.writeln('CurrentBuild: $_currentBuild'); sb.writeln('PreviousBuild: $_previousBuild'); sb.writeln('FirstInstalledBuild: $_firstInstalledBuild'); - sb.writeln('BuildHistory: ${_buildHistory.join(", ")}'); + sb.writeln('BuildHistory: ${_buildHistory!.join(", ")}'); return sb.toString(); } - List _readHistory(SharedPreferences preferences, String key) => - preferences.getString(key).split('|'); + List _readHistory(SharedPreferences preferences, String key) => + preferences.getString(key)!.split('|'); - void _writeHistory( - SharedPreferences preferences, String key, List history) => - preferences.setString(key, history.join('|')); + void _writeHistory(SharedPreferences preferences, String key, + List historyTrail) => + preferences.setString(key, historyTrail.join('|')); - String _getPrevious(Map> versionTrail, String key) { - var trail = versionTrail[key]; + String? _getPrevious(Map> historyTrail, String key) { + var trail = historyTrail[key]!; return (trail.length >= 2) ? trail[trail.length - 2] : null; } } \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 9c3e5dd..e6a98db 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -50,6 +50,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.0" firebase_core: dependency: transitive description: @@ -151,6 +165,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" pedantic: dependency: transitive description: @@ -158,6 +193,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.11.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" plugin_platform_interface: dependency: transitive description: @@ -165,6 +207,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.3" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.1" quiver: dependency: transitive description: @@ -172,6 +221,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.5" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" sky_engine: dependency: transitive description: flutter @@ -275,6 +366,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" sdks: dart: ">=2.12.0 <3.0.0" flutter: ">=1.22.0" diff --git a/pubspec.yaml b/pubspec.yaml index 477cb93..90af75d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,6 +20,8 @@ dependencies: package_info: 2.0.0 # URL Launcher url_launcher: 6.0.3 + # Shared Preferences + shared_preferences: 2.0.5 # Firebase Remote Config firebase_remote_config: 0.4.3 From f1ebc41c06bc7ba1eafdd9da8ed6318c34caad9b Mon Sep 17 00:00:00 2001 From: JTorrus Date: Thu, 8 Apr 2021 22:16:23 +0200 Subject: [PATCH 08/10] Expose version tracker --- lib/app_versioning.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/app_versioning.dart b/lib/app_versioning.dart index cfadd44..c12346f 100644 --- a/lib/app_versioning.dart +++ b/lib/app_versioning.dart @@ -24,6 +24,7 @@ export 'src/model/minimum_versions.dart'; export 'src/service/device_versioning_service.dart'; export 'src/service/minimum_versioning_service.dart'; export 'src/util/version.dart'; +export 'src/util/version_tracker.dart'; abstract class AppVersioning { Future getCurrentAppVersion(); From 19a9db43c7cfc8f812e861d0b90ba2a145bcf820 Mon Sep 17 00:00:00 2001 From: JTorrus Date: Fri, 9 Apr 2021 14:35:06 +0200 Subject: [PATCH 09/10] Version tracker exposed as a class getter instead of a library --- lib/app_versioning.dart | 4 +++- lib/src/default_app_versioning.dart | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/app_versioning.dart b/lib/app_versioning.dart index c12346f..44db9fc 100644 --- a/lib/app_versioning.dart +++ b/lib/app_versioning.dart @@ -13,6 +13,7 @@ import 'package:lr_app_versioning/src/model/app_update_info.dart'; import 'package:lr_app_versioning/src/service/device_versioning_service.dart'; import 'package:lr_app_versioning/src/service/minimum_versioning_service.dart'; import 'package:lr_app_versioning/src/util/version.dart'; +import 'package:lr_app_versioning/src/util/version_tracker.dart'; // Library Export Classes export 'src/api/exports.dart'; @@ -24,9 +25,10 @@ export 'src/model/minimum_versions.dart'; export 'src/service/device_versioning_service.dart'; export 'src/service/minimum_versioning_service.dart'; export 'src/util/version.dart'; -export 'src/util/version_tracker.dart'; abstract class AppVersioning { + VersionTracker get tracker; + Future getCurrentAppVersion(); Future getAppUpdateInfo(); diff --git a/lib/src/default_app_versioning.dart b/lib/src/default_app_versioning.dart index e9337f0..74359bb 100644 --- a/lib/src/default_app_versioning.dart +++ b/lib/src/default_app_versioning.dart @@ -5,6 +5,7 @@ import 'package:lr_app_versioning/src/model/app_update_info.dart'; import 'package:lr_app_versioning/src/service/device_versioning_service.dart'; import 'package:lr_app_versioning/src/service/minimum_versioning_service.dart'; import 'package:lr_app_versioning/src/util/version.dart'; +import 'package:lr_app_versioning/src/util/version_tracker.dart'; class DefaultAppVersioning implements AppVersioning { final MinimumVersioningService _minimumVersioningService; @@ -15,6 +16,9 @@ class DefaultAppVersioning implements AppVersioning { required DeviceVersioningService appUpdateService, }) : _minimumVersioningService = minimumVersioningService, _appUpdateService = appUpdateService; + + @override + VersionTracker get tracker => VersionTracker.instance; @override Future getCurrentAppVersion() { From f163de3ca4465cb26722b181e981cd6b13b0e2a6 Mon Sep 17 00:00:00 2001 From: JTorrus Date: Fri, 9 Apr 2021 15:52:20 +0200 Subject: [PATCH 10/10] Added version tracker to example --- example/lib/main.dart | 123 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 100 insertions(+), 23 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index bca347b..b22cb42 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -41,22 +41,36 @@ class _HomeState extends State { bool isLoading = false; + int _currentIndex = 0; + @override void initState() { super.initState(); - _getAppVersioning(); + _startVersioningServices(); } - void _getAppVersioning() async { + void _startVersioningServices() async { setState(() { isLoading = true; }); + await Future.wait( + [ + _getAppVersioning(), + _trackVersions(), + ], + ); + + setState(() { + isLoading = false; + }); + } + + Future _getAppVersioning() async { // Get Api Versioning (just to show on screen) final appUpdateInfo = await widget.appVersioning.getAppUpdateInfo(); setState(() { this.appUpdateInfo = appUpdateInfo; - this.isLoading = false; }); // Check Update Required @@ -67,6 +81,10 @@ class _HomeState extends State { } } + Future _trackVersions() async { + await widget.appVersioning.tracker.track(); + } + _showUpdatePopup() { showDialog( context: context, @@ -89,36 +107,95 @@ class _HomeState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('App Versioning Example')), - body: Stack( + body: IndexedStack( + index: _currentIndex, children: [ - Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'Current Versioning Values', - style: Theme.of(context).textTheme.headline6, - ), - Text( - 'Current Version: ${appUpdateInfo?.currentVersion}', + Stack( + children: [ + Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Current Versioning Values', + style: Theme.of(context).textTheme.headline6, + ), + Text( + 'Current Version: ${appUpdateInfo?.currentVersion}', + ), + Text( + 'Minimum Version: ${appUpdateInfo?.minimumVersion}', + ), + Text( + 'Update Available: ${appUpdateInfo?.isUpdateAvailable}', + ), + Text( + 'Update Type: ${appUpdateInfo?.updateType}', + ), + ], ), - Text( - 'Minimum Version: ${appUpdateInfo?.minimumVersion}', + ), + if (isLoading) + Center( + child: CircularProgressIndicator(), ), - Text( - 'Update Available: ${appUpdateInfo?.isUpdateAvailable}', + ], + ), + Stack( + children: [ + Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Version Tracking Status', + style: Theme.of(context).textTheme.headline6, + ), + Text( + 'Is first launch ever: ${widget.appVersioning.tracker.isFirstLaunchEver}', + ), + Text( + 'Is first launch for current version: ${widget.appVersioning.tracker.isFirstLaunchForCurrentVersion}', + ), + Text( + 'Is first launch for current build: ${widget.appVersioning.tracker.isFirstLaunchForCurrentBuild}', + ), + Text( + 'Version history: ${widget.appVersioning.tracker.versionHistory}', + ), + ], ), - Text( - 'Update Type: ${appUpdateInfo?.updateType}', + ), + if (isLoading) + Center( + child: CircularProgressIndicator(), ), - ], + ], + ) + ], + ), + bottomNavigationBar: BottomNavigationBar( + currentIndex: _currentIndex, + onTap: (index) => setState( + () { + _currentIndex = index; + }, + ), + items: [ + BottomNavigationBarItem( + icon: Icon( + Icons.analytics, ), + label: "App versioning", + ), + BottomNavigationBarItem( + icon: Icon(Icons.history), + label: "Version tracker", ), - if (isLoading) Center(child: CircularProgressIndicator()), ], ), floatingActionButton: FloatingActionButton( - onPressed: () => _getAppVersioning(), + onPressed: _startVersioningServices, tooltip: 'Refresh', child: Icon(Icons.refresh), ),