2023-09-12 15:22:58 +03:30
|
|
|
import 'package:dartx/dartx.dart';
|
2024-02-15 15:23:02 +03:30
|
|
|
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
|
2023-07-06 17:18:41 +03:30
|
|
|
import 'package:flutter/material.dart';
|
2023-12-01 12:56:24 +03:30
|
|
|
import 'package:hiddify/core/app_info/app_info_provider.dart';
|
|
|
|
|
import 'package:hiddify/core/localization/translations.dart';
|
|
|
|
|
import 'package:hiddify/core/model/failures.dart';
|
2023-07-06 17:18:41 +03:30
|
|
|
import 'package:hiddify/core/router/router.dart';
|
2023-11-01 20:36:16 +03:30
|
|
|
import 'package:hiddify/features/common/nested_app_bar.dart';
|
2023-12-01 12:56:24 +03:30
|
|
|
import 'package:hiddify/features/home/widget/connection_button.dart';
|
|
|
|
|
import 'package:hiddify/features/home/widget/empty_profiles_home_body.dart';
|
2023-11-26 21:20:58 +03:30
|
|
|
import 'package:hiddify/features/profile/notifier/active_profile_notifier.dart';
|
|
|
|
|
import 'package:hiddify/features/profile/widget/profile_tile.dart';
|
2024-02-10 13:55:31 +03:30
|
|
|
import 'package:hiddify/features/proxy/active/active_proxy_delay_indicator.dart';
|
2024-02-09 12:02:52 +03:30
|
|
|
import 'package:hiddify/features/proxy/active/active_proxy_footer.dart';
|
2024-08-04 16:46:51 +02:00
|
|
|
import 'package:hiddify/features/proxy/active/active_proxy_notifier.dart';
|
2023-07-06 17:18:41 +03:30
|
|
|
import 'package:hiddify/utils/utils.dart';
|
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.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: [
|
2023-11-01 20:36:16 +03:30
|
|
|
NestedAppBar(
|
2023-11-10 15:35:44 +03:30
|
|
|
title: Text.rich(
|
|
|
|
|
TextSpan(
|
|
|
|
|
children: [
|
2025-12-26 18:41:25 +03:00
|
|
|
const TextSpan(text: "Umbrix"),
|
2023-11-10 15:35:44 +03:30
|
|
|
const TextSpan(text: " "),
|
|
|
|
|
const WidgetSpan(
|
|
|
|
|
child: AppVersionLabel(),
|
|
|
|
|
alignment: PlaceholderAlignment.middle,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2023-07-26 23:34:03 +03:30
|
|
|
),
|
2023-07-06 17:18:41 +03:30
|
|
|
actions: [
|
2024-03-07 17:04:32 +03:30
|
|
|
IconButton(
|
|
|
|
|
onPressed: () => const QuickSettingsRoute().push(context),
|
|
|
|
|
icon: const Icon(FluentIcons.options_24_filled),
|
2024-03-08 17:24:43 +03:30
|
|
|
tooltip: t.config.quickSettings,
|
2024-03-07 17:04:32 +03:30
|
|
|
),
|
2023-07-06 17:18:41 +03:30
|
|
|
IconButton(
|
|
|
|
|
onPressed: () => const AddProfileRoute().push(context),
|
2024-02-15 15:23:02 +03:30
|
|
|
icon: const Icon(FluentIcons.add_circle_24_filled),
|
2023-08-24 22:19:36 +03:30
|
|
|
tooltip: t.profile.add.buttonText,
|
2023-07-06 17:18:41 +03:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
switch (activeProfile) {
|
|
|
|
|
AsyncData(value: final profile?) => MultiSliver(
|
|
|
|
|
children: [
|
2023-07-24 19:45:58 +03:30
|
|
|
ProfileTile(profile: profile, isMain: true),
|
2024-02-09 12:02:52 +03:30
|
|
|
SliverFillRemaining(
|
2023-07-06 17:18:41 +03:30
|
|
|
hasScrollBody: false,
|
2024-02-09 12:02:52 +03:30
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
2024-02-10 17:32:45 +03:30
|
|
|
const Expanded(
|
2025-12-26 02:39:35 +03:00
|
|
|
child: Padding(
|
|
|
|
|
padding: EdgeInsets.only(top: 160),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
ConnectionButton(),
|
|
|
|
|
ActiveProxyDelayIndicator(),
|
|
|
|
|
],
|
|
|
|
|
),
|
2024-02-10 13:55:31 +03:30
|
|
|
),
|
|
|
|
|
),
|
2024-08-04 16:46:51 +02:00
|
|
|
if (MediaQuery.sizeOf(context).width < 840) const ActiveProxyFooter(),
|
2024-02-09 12:02:52 +03:30
|
|
|
],
|
2023-07-06 17:18:41 +03:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
AsyncData() => switch (hasAnyProfile) {
|
2024-08-04 16:46:51 +02:00
|
|
|
AsyncData(value: true) => const EmptyActiveProfileHomeBody(),
|
2023-07-06 17:18:41 +03:30
|
|
|
_ => const EmptyProfilesHomeBody(),
|
|
|
|
|
},
|
2024-08-04 16:46:51 +02:00
|
|
|
AsyncError(:final error) => SliverErrorBodyPlaceholder(t.presentShortError(error)),
|
2023-07-06 17:18:41 +03:30
|
|
|
_ => const SliverToBoxAdapter(),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-26 23:34:03 +03:30
|
|
|
|
|
|
|
|
class AppVersionLabel extends HookConsumerWidget {
|
|
|
|
|
const AppVersionLabel({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-09-12 00:05:44 +03:30
|
|
|
final t = ref.watch(translationsProvider);
|
2023-07-26 23:34:03 +03:30
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
2023-12-01 12:56:24 +03:30
|
|
|
final version = ref.watch(appInfoProvider).requireValue.presentVersion;
|
2023-09-12 15:22:58 +03:30
|
|
|
if (version.isBlank) return const SizedBox();
|
2023-07-26 23:34:03 +03:30
|
|
|
|
2023-09-12 00:05:44 +03:30
|
|
|
return Semantics(
|
|
|
|
|
label: t.about.version,
|
|
|
|
|
button: false,
|
|
|
|
|
child: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: theme.colorScheme.secondaryContainer,
|
|
|
|
|
borderRadius: BorderRadius.circular(4),
|
|
|
|
|
),
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 4,
|
|
|
|
|
vertical: 1,
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
version,
|
2023-09-12 15:22:58 +03:30
|
|
|
textDirection: TextDirection.ltr,
|
2023-09-12 00:05:44 +03:30
|
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
|
|
|
color: theme.colorScheme.onSecondaryContainer,
|
|
|
|
|
),
|
2023-07-26 23:34:03 +03:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|