From c4c75242d6a5b9c41ad539976aa3e2bb6cec31ce Mon Sep 17 00:00:00 2001 From: Maximilian Mitchell Date: Fri, 7 May 2021 17:39:41 +0100 Subject: [PATCH] Change version string to include build --- lib/screens/settings.dart | 15 ++++++++------- lib/utils/utils.dart | 6 ------ lib/ws.dart | 4 +++- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 28674eb0..ea74ad95 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -16,6 +16,7 @@ import 'package:notifi/utils/icons.dart'; import 'package:notifi/utils/pallete.dart'; import 'package:notifi/utils/utils.dart'; import 'package:notifi/utils/version.dart'; +import 'package:package_info/package_info.dart'; import 'package:provider/provider.dart'; import 'package:share/share.dart'; import 'package:toast/toast.dart'; @@ -29,19 +30,19 @@ class SettingsScreen extends StatefulWidget { } class SettingsScreenState extends State { - ValueNotifier _version; + ValueNotifier _versionString; ValueNotifier _hasUpgrade; @override void initState() { - _version = ValueNotifier(''); + _versionString = ValueNotifier(''); _hasUpgrade = ValueNotifier(false); super.initState(); } @override void dispose() { - _version.dispose(); + _versionString.dispose(); _hasUpgrade.dispose(); super.dispose(); } @@ -51,9 +52,9 @@ class SettingsScreenState extends State { const double leadingWidth = 60.0; if (!isTest()) { - getVersion().then((String version) { - _version.value = version; - hasUpgrade(version).then((bool hasUpgrade) { + PackageInfo.fromPlatform().then((PackageInfo package) { + _versionString.value = '${package.version} (${package.buildNumber})'; + hasUpgrade(package.version).then((bool hasUpgrade) { _hasUpgrade.value = hasUpgrade; }); }); @@ -200,7 +201,7 @@ class SettingsScreenState extends State { ), if (!isTest()) ValueListenableBuilder( - valueListenable: _version, + valueListenable: _versionString, // ignore: always_specify_types builder: (BuildContext context, String version, Widget child) { return Container( diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index f76db4c0..4269f286 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -6,7 +6,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart' as dot_env; -import 'package:package_info/package_info.dart'; import 'package:toast/toast.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -52,11 +51,6 @@ class MenuBarIcon { } } -Future getVersion() async { - final PackageInfo packageInfo = await PackageInfo.fromPlatform(); - return packageInfo.buildNumber; -} - Future loadDotEnv() async { await dot_env.load(); } diff --git a/lib/ws.dart b/lib/ws.dart index 2eb7e471..24bb55a0 100644 --- a/lib/ws.dart +++ b/lib/ws.dart @@ -4,18 +4,20 @@ import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:notifi/user.dart'; import 'package:notifi/utils/utils.dart'; +import 'package:package_info/package_info.dart'; import 'package:web_socket_channel/io.dart'; Future connectToWS( UserStruct user, Future> Function(String) onMessage, Function(bool) setErr) async { + final PackageInfo package = await PackageInfo.fromPlatform(); final Map headers = { 'Sec-Key': env['SERVER_KEY'], 'Uuid': user.uuid, 'Credentials': user.credentials, 'Key': user.credentialKey, - 'Version': await getVersion(), + 'Version': package.version, }; if (shouldUseFirebase) {