121 lines
3.9 KiB
Dart
121 lines
3.9 KiB
Dart
import 'package:dartx/dartx.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/environment.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: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),
|
|
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.printError(error)),
|
|
_ => const SliverToBoxAdapter(),
|
|
},
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class AppVersionLabel extends HookConsumerWidget {
|
|
const AppVersionLabel({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final t = ref.watch(translationsProvider);
|
|
final theme = Theme.of(context);
|
|
|
|
final appInfo = ref.watch(appInfoProvider);
|
|
final version = appInfo.version +
|
|
(appInfo.environment == Environment.prod
|
|
? ""
|
|
: " ${appInfo.environment.name}");
|
|
if (version.isBlank) return const SizedBox();
|
|
|
|
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,
|
|
textDirection: TextDirection.ltr,
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSecondaryContainer,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|