This commit is contained in:
problematicconsumer
2023-07-06 17:18:41 +03:30
commit b617c95f62
352 changed files with 21017 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
import 'package:flutter/material.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: Text(t.general.appTitle.titleCase),
actions: [
IconButton(
onPressed: () => const AddProfileRoute().push(context),
icon: const Icon(Icons.add_circle),
),
],
),
switch (activeProfile) {
AsyncData(value: final profile?) => MultiSliver(
children: [
ActiveProfileCard(profile),
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(),
},
],
),
],
),
);
}
}

View File

@@ -0,0 +1 @@
export 'home_page.dart';

View File

@@ -0,0 +1,171 @@
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/domain/profiles/profiles.dart';
import 'package:hiddify/features/common/active_profile/active_profile_notifier.dart';
import 'package:hiddify/features/common/common.dart';
import 'package:hiddify/utils/utils.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:recase/recase.dart';
// TODO: rewrite
class ActiveProfileCard extends HookConsumerWidget {
const ActiveProfileCard(this.profile, {super.key});
final Profile profile;
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
return Card(
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Material(
borderRadius: BorderRadius.circular(16),
color: Colors.transparent,
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () async {
await const ProfilesRoute().push(context);
},
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
child: Row(
children: [
Expanded(
child: Text(
profile.name,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.titleMedium,
),
),
const Gap(4),
const Icon(Icons.arrow_drop_down),
],
),
),
),
),
),
TextButton.icon(
onPressed: () async {
const AddProfileRoute().push(context);
},
label: Text(t.profile.add.buttonText.titleCase),
icon: const Icon(Icons.add),
),
],
),
if (profile.hasSubscriptionInfo) ...[
const Divider(thickness: 0.5),
SubscriptionInfoTile(profile.subInfo!),
],
],
),
),
);
}
}
class SubscriptionInfoTile extends HookConsumerWidget {
const SubscriptionInfoTile(this.subInfo, {super.key});
final SubscriptionInfo subInfo;
@override
Widget build(BuildContext context, WidgetRef ref) {
if (!subInfo.isValid) return const SizedBox.shrink();
final t = ref.watch(translationsProvider);
final themeData = Theme.of(context);
final updateProfileMutation = useMutation(
initialOnFailure: (err) {
CustomToast.error(t.presentError(err)).show(context);
},
initialOnSuccess: () =>
CustomToast.success(t.profile.update.successMsg).show(context),
);
return Row(
children: [
Flexible(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text(
formatTrafficByteSize(
subInfo.consumption,
subInfo.total!,
),
style: themeData.textTheme.titleSmall,
),
),
Text(
t.profile.subscription.traffic,
style: themeData.textTheme.bodySmall,
),
],
),
const SizedBox(height: 2),
RemainingTrafficIndicator(subInfo.ratio),
],
),
),
const Gap(8),
IconButton(
onPressed: () async {
if (updateProfileMutation.state.isInProgress) return;
updateProfileMutation.setFuture(
ref.read(activeProfileProvider.notifier).updateProfile(),
);
},
icon: const Icon(Icons.refresh, size: 44),
),
const Gap(8),
if (subInfo.isExpired)
Text(
t.profile.subscription.expired,
style: themeData.textTheme.titleSmall
?.copyWith(color: themeData.colorScheme.error),
)
else if (subInfo.ratio >= 1)
Text(
t.profile.subscription.noTraffic,
style: themeData.textTheme.titleSmall
?.copyWith(color: themeData.colorScheme.error),
)
else
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
formatExpireDuration(subInfo.remaining),
style: themeData.textTheme.titleSmall,
),
Text(
t.profile.subscription.remaining,
style: themeData.textTheme.bodySmall,
),
],
),
],
);
}
}

View File

@@ -0,0 +1,70 @@
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:gap/gap.dart';
import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/core/theme/theme.dart';
import 'package:hiddify/features/common/connectivity/connectivity_controller.dart';
import 'package:hiddify/gen/assets.gen.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
// TODO: rewrite
class ConnectionButton extends HookConsumerWidget {
const ConnectionButton({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
final connectionStatus = ref.watch(connectivityControllerProvider);
final Color connectionLogoColor = connectionStatus.isConnected
? ConnectionButtonColor.connected
: ConnectionButtonColor.disconnected;
final bool intractable = !connectionStatus.isSwitching;
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
blurRadius: 16,
color: connectionLogoColor.withOpacity(0.5),
),
],
),
width: 148,
height: 148,
child: Material(
shape: const CircleBorder(),
color: Colors.white,
child: InkWell(
onTap: () async {
await ref
.read(connectivityControllerProvider.notifier)
.toggleConnection();
},
child: Padding(
padding: const EdgeInsets.all(36),
child: Assets.images.logo.svg(
colorFilter: ColorFilter.mode(
connectionLogoColor,
BlendMode.srcIn,
),
),
),
),
).animate(target: intractable ? 0 : 1).blurXY(end: 1),
).animate(target: intractable ? 0 : 1).scaleXY(end: .88),
const Gap(16),
Text(
connectionStatus.present(t),
style: Theme.of(context).textTheme.bodyLarge,
),
],
);
}
}

View File

@@ -0,0 +1,55 @@
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:hooks_riverpod/hooks_riverpod.dart';
import 'package:recase/recase.dart';
class EmptyProfilesHomeBody extends HookConsumerWidget {
const EmptyProfilesHomeBody({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
return SliverFillRemaining(
hasScrollBody: false,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(t.home.emptyProfilesMsg.sentenceCase),
const Gap(16),
OutlinedButton.icon(
onPressed: () => const AddProfileRoute().push(context),
icon: const Icon(Icons.add),
label: Text(t.profile.add.buttonText.titleCase),
)
],
),
);
}
}
class EmptyActiveProfileHomeBody extends HookConsumerWidget {
const EmptyActiveProfileHomeBody({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
return SliverFillRemaining(
hasScrollBody: false,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(t.home.noActiveProfileMsg.sentenceCase),
const Gap(16),
OutlinedButton(
onPressed: () => const ProfilesRoute().push(context),
child: Text(t.profile.overviewPageTitle.titleCase),
)
],
),
);
}
}

View File

@@ -0,0 +1,3 @@
export 'active_profile_card.dart';
export 'connection_button.dart';
export 'empty_profiles_home_body.dart';