Implemented VersionService
This commit is contained in:
@@ -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/presentation/views/tab_view.dart';
|
||||||
import 'package:cabo_counter/services/config_service.dart';
|
import 'package:cabo_counter/services/config_service.dart';
|
||||||
import 'package:cabo_counter/services/local_storage_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/custom_theme.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -13,6 +14,7 @@ Future<void> main() async {
|
|||||||
await ConfigService.initConfig();
|
await ConfigService.initConfig();
|
||||||
ConfigService.pointLimit = await ConfigService.getPointLimit();
|
ConfigService.pointLimit = await ConfigService.getPointLimit();
|
||||||
ConfigService.caboPenalty = await ConfigService.getCaboPenalty();
|
ConfigService.caboPenalty = await ConfigService.getCaboPenalty();
|
||||||
|
await VersionService.init();
|
||||||
runApp(const App());
|
runApp(const App());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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/presentation/widgets/stepper.dart';
|
||||||
import 'package:cabo_counter/services/config_service.dart';
|
import 'package:cabo_counter/services/config_service.dart';
|
||||||
import 'package:cabo_counter/services/local_storage_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/custom_theme.dart';
|
||||||
import 'package:cabo_counter/utility/globals.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.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';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class SettingsView extends StatefulWidget {
|
class SettingsView extends StatefulWidget {
|
||||||
@@ -149,59 +148,18 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
prefixText: 'App-Version',
|
prefixText: 'App-Version',
|
||||||
prefixIcon: CupertinoIcons.info,
|
prefixIcon: CupertinoIcons.info,
|
||||||
onPressed: null,
|
onPressed: null,
|
||||||
suffixWidget: FutureBuilder<PackageInfo>(
|
suffixWidget: Text(VersionService.getVersion(),
|
||||||
future: _getPackageInfo(),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (snapshot.hasData) {
|
|
||||||
return Text(
|
|
||||||
'${Globals.appDevPhase} ${snapshot.data!.version} ',
|
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: CustomTheme.primaryColor,
|
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,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
CustomFormRow(
|
CustomFormRow(
|
||||||
prefixText: 'Build-Nr.',
|
prefixText: 'Build-Nr.',
|
||||||
prefixIcon: CupertinoIcons.info,
|
prefixIcon: CupertinoIcons.info,
|
||||||
onPressed: null,
|
onPressed: null,
|
||||||
suffixWidget: FutureBuilder<PackageInfo>(
|
suffixWidget: Text(VersionService.getBuildNumber(),
|
||||||
future: _getPackageInfo(),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (snapshot.hasData) {
|
|
||||||
return Text(
|
|
||||||
snapshot.data!.buildNumber,
|
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: CustomTheme.primaryColor,
|
color: CustomTheme.primaryColor,
|
||||||
),
|
))),
|
||||||
);
|
|
||||||
} else if (snapshot.hasError) {
|
|
||||||
return Text(
|
|
||||||
'-',
|
|
||||||
style: TextStyle(
|
|
||||||
color: CustomTheme.primaryColor,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return Text(
|
|
||||||
AppLocalizations.of(context).loading,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)),
|
|
||||||
])),
|
])),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -210,10 +168,6 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<PackageInfo> _getPackageInfo() async {
|
|
||||||
return await PackageInfo.fromPlatform();
|
|
||||||
}
|
|
||||||
|
|
||||||
void showFeedbackDialog(ImportStatus status) {
|
void showFeedbackDialog(ImportStatus status) {
|
||||||
if (status == ImportStatus.canceled) return;
|
if (status == ImportStatus.canceled) return;
|
||||||
final (title, message) = _getDialogContent(status);
|
final (title, message) = _getDialogContent(status);
|
||||||
|
|||||||
32
lib/services/version_service.dart
Normal file
32
lib/services/version_service.dart
Normal file
@@ -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<void> 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)';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ name: cabo_counter
|
|||||||
description: "Mobile app for the card game Cabo"
|
description: "Mobile app for the card game Cabo"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 0.4.0+371
|
version: 0.4.0+376
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.4
|
sdk: ^3.5.4
|
||||||
|
|||||||
Reference in New Issue
Block a user