129 lines
4.0 KiB
Dart
129 lines
4.0 KiB
Dart
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/clash/clash_controller.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);
|
|
|
|
ref.listen(
|
|
clashControllerProvider,
|
|
(_, next) {
|
|
if (next case AsyncError(:final error)) {
|
|
CustomToast.error(
|
|
t.presentError(error),
|
|
duration: const Duration(seconds: 10),
|
|
).show(context);
|
|
}
|
|
},
|
|
);
|
|
|
|
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),
|
|
),
|
|
],
|
|
),
|
|
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.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,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|