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'; import 'package:hiddify/features/common/active_profile/active_profile_notifier.dart'; import 'package:hiddify/features/common/active_profile/has_any_profile_notifier.dart'; import 'package:hiddify/features/common/common.dart'; import 'package:hiddify/features/home/widgets/widgets.dart'; import 'package:hiddify/utils/utils.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:recase/recase.dart'; import 'package:sliver_tools/sliver_tools.dart'; class HomePage extends HookConsumerWidget { const HomePage({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final t = ref.watch(translationsProvider); final hasAnyProfile = ref.watch(hasAnyProfileProvider); final activeProfile = ref.watch(activeProfileProvider); return Scaffold( body: Stack( alignment: Alignment.bottomCenter, children: [ CustomScrollView( slivers: [ NestedTabAppBar( title: Row( children: [ Text(t.general.appTitle.titleCase), const Gap(4), const AppVersionLabel(), ], ), actions: [ IconButton( onPressed: () => const AddProfileRoute().push(context), icon: const Icon(Icons.add_circle), tooltip: t.profile.add.buttonText, ), ], ), switch (activeProfile) { AsyncData(value: final profile?) => MultiSliver( children: [ ProfileTile(profile: profile, isMain: true), const SliverFillRemaining( hasScrollBody: false, child: Padding( padding: EdgeInsets.only( left: 8, right: 8, top: 8, bottom: 86, ), child: ConnectionButton(), ), ), ], ), AsyncData() => switch (hasAnyProfile) { AsyncData(value: true) => const EmptyActiveProfileHomeBody(), _ => const EmptyProfilesHomeBody(), }, AsyncError(:final error) => SliverErrorBodyPlaceholder(t.presentError(error)), _ => const SliverToBoxAdapter(), }, ], ), ], ), ); } } class AppVersionLabel extends HookConsumerWidget { const AppVersionLabel({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final theme = Theme.of(context); final version = ref.watch( appVersionProvider.select( (value) => switch (value) { AsyncData(:final value) => value.version, _ => "", }, ), ); 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, ), ), ); } }