Skip to content

Commit

Permalink
Merge pull request #2 from levin-riegner/version-tracker
Browse files Browse the repository at this point in the history
Version Tracker migrated to null safety
  • Loading branch information
JTorrus authored Apr 9, 2021
2 parents 9f14f1f + f163de3 commit 0028dc6
Show file tree
Hide file tree
Showing 8 changed files with 483 additions and 44 deletions.
125 changes: 101 additions & 24 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,36 @@ class _HomeState extends State<Home> {

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<void> _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
Expand All @@ -67,6 +81,10 @@ class _HomeState extends State<Home> {
}
}

Future<void> _trackVersions() async {
await widget.appVersioning.tracker.track();
}

_showUpdatePopup() {
showDialog(
context: context,
Expand All @@ -75,7 +93,7 @@ class _HomeState extends State<Home> {
child: Column(
children: [
Text("Update required!"),
FlatButton(
TextButton(
onPressed: () => widget.appVersioning.launchUpdate(),
child: Text("OK"),
)
Expand All @@ -89,36 +107,95 @@ class _HomeState extends State<Home> {
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: <Widget>[
Text(
'Current Versioning Values',
style: Theme.of(context).textTheme.headline6,
),
Text(
'Current Version: ${appUpdateInfo?.currentVersion}',
Stack(
children: [
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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: <Widget>[
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>[
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),
),
Expand Down
105 changes: 105 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -158,27 +172,104 @@ 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:
name: pedantic
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:
name: plugin_platform_interface
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:
name: quiver
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
Expand Down Expand Up @@ -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"
3 changes: 3 additions & 0 deletions lib/app_versioning.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,6 +27,8 @@ export 'src/service/minimum_versioning_service.dart';
export 'src/util/version.dart';

abstract class AppVersioning {
VersionTracker get tracker;

Future<Version> getCurrentAppVersion();

Future<AppUpdateInfo> getAppUpdateInfo();
Expand Down
4 changes: 4 additions & 0 deletions lib/src/default_app_versioning.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,9 @@ class DefaultAppVersioning implements AppVersioning {
required DeviceVersioningService appUpdateService,
}) : _minimumVersioningService = minimumVersioningService,
_appUpdateService = appUpdateService;

@override
VersionTracker get tracker => VersionTracker.instance;

@override
Future<Version> getCurrentAppVersion() {
Expand Down
20 changes: 0 additions & 20 deletions lib/src/model/api_versioning.g.dart

This file was deleted.

Loading

0 comments on commit 0028dc6

Please sign in to comment.