feat: add version label in settings
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../models/settings.dart';
|
||||
@@ -15,6 +16,9 @@ class SettingsScreenView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
String _appVersion = '';
|
||||
int _versionTaps = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -22,6 +26,32 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.read<SettingsViewModel>().ensureLoaded();
|
||||
context.read<PinLockViewModel>().ensureLoaded();
|
||||
_loadVersion();
|
||||
});
|
||||
}
|
||||
|
||||
Future<String> currentVersion() async {
|
||||
final info = await PackageInfo.fromPlatform();
|
||||
debugPrint("Current app version: ${info.version}");
|
||||
return info.version;
|
||||
}
|
||||
|
||||
void _onVersionTap() {
|
||||
_versionTaps++;
|
||||
|
||||
if (_versionTaps >= 7) {
|
||||
_versionTaps = 0;
|
||||
context.push('/dev');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadVersion() async {
|
||||
final version = await currentVersion();
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
setState(() {
|
||||
_appVersion = version;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -229,6 +259,25 @@ class _SettingsScreenViewState extends State<SettingsScreenView> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
GestureDetector(
|
||||
onTap: _onVersionTap,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Version $_appVersion',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall
|
||||
?.copyWith(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user