2023-09-12 15:22:58 +03:30
|
|
|
import 'package:dartx/dartx.dart';
|
2023-07-06 17:18:41 +03:30
|
|
|
import 'package:flutter/material.dart';
|
2023-07-26 23:34:03 +03:30
|
|
|
import 'package:gap/gap.dart';
|
2023-07-06 17:18:41 +03:30
|
|
|
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';
|
2023-11-01 20:36:16 +03:30
|
|
|
import 'package:hiddify/features/common/nested_app_bar.dart';
|
|
|
|
|
import 'package:hiddify/features/common/profile_tile.dart';
|
2023-07-06 17:18:41 +03:30
|
|
|
import 'package:hiddify/features/home/widgets/widgets.dart';
|
|
|
|
|
import 'package:hiddify/utils/utils.dart';
|
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-09-07 01:56:59 +03:30
|
|
|
|
2023-07-06 17:18:41 +03:30
|
|
|
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-07-26 23:34:03 +03:30
|
|
|
title: Row(
|
|
|
|
|
children: [
|
2023-09-07 01:56:59 +03:30
|
|
|
Text(t.general.appTitle),
|
2023-07-26 23:34:03 +03:30
|
|
|
const Gap(4),
|
|
|
|
|
const AppVersionLabel(),
|
|
|
|
|
],
|
|
|
|
|
),
|
2023-07-06 17:18:41 +03:30
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed: () => const AddProfileRoute().push(context),
|
|
|
|
|
icon: const Icon(Icons.add_circle),
|
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),
|
2023-07-06 17:18:41 +03:30
|
|
|
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) =>
|
2023-10-04 18:06:48 +03:30
|
|
|
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-09-16 00:56:03 +03:30
|
|
|
final version = ref.watch(appInfoProvider).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
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|