Add version number to appbar

This commit is contained in:
problematicconsumer
2023-07-26 23:34:03 +03:30
parent b66a3364e1
commit f34407fc67
4 changed files with 50 additions and 1 deletions

View File

@@ -2,3 +2,4 @@ export 'confirmation_dialogs.dart';
export 'custom_app_bar.dart';
export 'profile_tile.dart';
export 'qr_code_scanner_screen.dart';
export 'runtime_details.dart';

View File

@@ -32,6 +32,8 @@ class RuntimeDetails with _$RuntimeDetails {
required String clashVersion,
}) = _RuntimeDetails;
String get fullVersion => version + buildNumber;
factory RuntimeDetails.fromJson(Map<String, dynamic> json) =>
_$RuntimeDetailsFromJson(json);
}

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/core/router/router.dart';
import 'package:hiddify/domain/failures.dart';
@@ -40,7 +41,13 @@ class HomePage extends HookConsumerWidget {
CustomScrollView(
slivers: [
NestedTabAppBar(
title: Text(t.general.appTitle.titleCase),
title: Row(
children: [
Text(t.general.appTitle.titleCase),
const Gap(4),
const AppVersionLabel(),
],
),
actions: [
IconButton(
onPressed: () => const AddProfileRoute().push(context),
@@ -82,3 +89,40 @@ class HomePage extends HookConsumerWidget {
);
}
}
class AppVersionLabel extends HookConsumerWidget {
const AppVersionLabel({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final version = ref.watch(
runtimeDetailsNotifierProvider.select(
(value) => switch (value) {
AsyncData(:final value) => value.fullVersion,
_ => "",
},
),
);
if (version.isEmpty) return const SizedBox();
return Container(
decoration: BoxDecoration(
color: theme.colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(4),
),
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 1,
),
child: Text(
version,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSecondaryContainer,
),
),
);
}
}