From aba4bf9c0bd8b09a67e0f104145fa81e08d86e1a Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Wed, 9 Jul 2025 17:30:28 +0200 Subject: [PATCH] Implemented VersionService --- lib/main.dart | 2 + lib/presentation/views/settings_view.dart | 64 ++++------------------- lib/services/version_service.dart | 32 ++++++++++++ pubspec.yaml | 2 +- 4 files changed, 44 insertions(+), 56 deletions(-) create mode 100644 lib/services/version_service.dart diff --git a/lib/main.dart b/lib/main.dart index 06e2d2b..b826072 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,7 @@ import 'package:cabo_counter/l10n/app_localizations.dart'; import 'package:cabo_counter/presentation/views/tab_view.dart'; import 'package:cabo_counter/services/config_service.dart'; import 'package:cabo_counter/services/local_storage_service.dart'; +import 'package:cabo_counter/services/version_service.dart'; import 'package:cabo_counter/utility/custom_theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; @@ -13,6 +14,7 @@ Future main() async { await ConfigService.initConfig(); ConfigService.pointLimit = await ConfigService.getPointLimit(); ConfigService.caboPenalty = await ConfigService.getCaboPenalty(); + await VersionService.init(); runApp(const App()); } diff --git a/lib/presentation/views/settings_view.dart b/lib/presentation/views/settings_view.dart index 34540a4..2ed422f 100644 --- a/lib/presentation/views/settings_view.dart +++ b/lib/presentation/views/settings_view.dart @@ -3,11 +3,10 @@ import 'package:cabo_counter/presentation/widgets/custom_form_row.dart'; import 'package:cabo_counter/presentation/widgets/stepper.dart'; import 'package:cabo_counter/services/config_service.dart'; import 'package:cabo_counter/services/local_storage_service.dart'; +import 'package:cabo_counter/services/version_service.dart'; import 'package:cabo_counter/utility/custom_theme.dart'; -import 'package:cabo_counter/utility/globals.dart'; import 'package:flutter/cupertino.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:package_info_plus/package_info_plus.dart'; import 'package:url_launcher/url_launcher.dart'; class SettingsView extends StatefulWidget { @@ -149,59 +148,18 @@ class _SettingsViewState extends State { prefixText: 'App-Version', prefixIcon: CupertinoIcons.info, onPressed: null, - suffixWidget: FutureBuilder( - future: _getPackageInfo(), - builder: (context, snapshot) { - if (snapshot.hasData) { - return Text( - '${Globals.appDevPhase} ${snapshot.data!.version} ', - style: TextStyle( - color: CustomTheme.primaryColor, - ), - ); - } else if (snapshot.hasError) { - return Text( - '${AppLocalizations.of(context).app_version} -.-.-', - style: TextStyle( - color: CustomTheme.primaryColor, - ), - ); - } - return Text( - AppLocalizations.of(context).loading, - style: TextStyle( - color: CustomTheme.primaryColor, - ), - ); - }, - )), + suffixWidget: Text(VersionService.getVersion(), + style: TextStyle( + color: CustomTheme.primaryColor, + ))), CustomFormRow( prefixText: 'Build-Nr.', prefixIcon: CupertinoIcons.info, onPressed: null, - suffixWidget: FutureBuilder( - future: _getPackageInfo(), - builder: (context, snapshot) { - if (snapshot.hasData) { - return Text( - snapshot.data!.buildNumber, - style: TextStyle( - color: CustomTheme.primaryColor, - ), - ); - } else if (snapshot.hasError) { - return Text( - '-', - style: TextStyle( - color: CustomTheme.primaryColor, - ), - ); - } - return Text( - AppLocalizations.of(context).loading, - ); - }, - )), + suffixWidget: Text(VersionService.getBuildNumber(), + style: TextStyle( + color: CustomTheme.primaryColor, + ))), ])), ], ), @@ -210,10 +168,6 @@ class _SettingsViewState extends State { ); } - Future _getPackageInfo() async { - return await PackageInfo.fromPlatform(); - } - void showFeedbackDialog(ImportStatus status) { if (status == ImportStatus.canceled) return; final (title, message) = _getDialogContent(status); diff --git a/lib/services/version_service.dart b/lib/services/version_service.dart new file mode 100644 index 0000000..c23d187 --- /dev/null +++ b/lib/services/version_service.dart @@ -0,0 +1,32 @@ +import 'package:cabo_counter/utility/globals.dart'; +import 'package:package_info_plus/package_info_plus.dart'; + +class VersionService { + static String _version = '-.-.-'; + static String _buildNumber = '-'; + + static Future init() async { + var packageInfo = await PackageInfo.fromPlatform(); + _version = packageInfo.version; + _buildNumber = packageInfo.buildNumber; + } + + static String getVersionNumber() { + return _version; + } + + static String getVersion() { + if (_version == '-.-.-') { + return getVersionNumber(); + } + return '${Globals.appDevPhase} $_version'; + } + + static String getBuildNumber() { + return _buildNumber; + } + + static String getVersionWithBuild() { + return '$_version ($_buildNumber)'; + } +} diff --git a/pubspec.yaml b/pubspec.yaml index fdf9916..414389d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: cabo_counter description: "Mobile app for the card game Cabo" publish_to: 'none' -version: 0.4.0+371 +version: 0.4.0+376 environment: sdk: ^3.5.4