Files
umbrix/lib/features/about/view/about_page.dart

141 lines
5.0 KiB
Dart
Raw Normal View History

2023-07-22 16:02:06 +03:30
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:hiddify/core/core_providers.dart';
import 'package:hiddify/domain/constants.dart';
2023-07-27 18:03:41 +03:30
import 'package:hiddify/domain/failures.dart';
import 'package:hiddify/features/common/new_version_dialog.dart';
2023-07-22 16:02:06 +03:30
import 'package:hiddify/features/common/runtime_details.dart';
import 'package:hiddify/gen/assets.gen.dart';
2023-09-01 15:00:41 +03:30
import 'package:hiddify/services/service_providers.dart';
2023-08-25 17:58:04 +03:30
import 'package:hiddify/utils/utils.dart';
2023-07-22 16:02:06 +03:30
import 'package:hooks_riverpod/hooks_riverpod.dart';
class AboutPage extends HookConsumerWidget {
const AboutPage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
2023-07-27 18:03:41 +03:30
final appVersion = ref.watch(appVersionProvider);
final isCheckingForUpdate = ref.watch(
runtimeDetailsNotifierProvider.select(
(value) => value.maybeWhen(
data: (data) => data.latestVersion.isLoading,
orElse: () => false,
),
),
);
ref.listen(
runtimeDetailsNotifierProvider,
(_, next) async {
if (next case AsyncData(:final value)) {
switch (value.latestVersion) {
case AsyncError(:final error):
2023-08-26 17:01:51 +03:30
CustomToast.error(t.printError(error)).show(context);
2023-07-27 18:03:41 +03:30
default:
if (value.newVersionAvailable) {
await NewVersionDialog(
value.appVersion,
value.latestVersion.value!,
canIgnore: false,
).show(context);
}
}
}
},
);
2023-07-22 16:02:06 +03:30
return Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
2023-09-07 01:56:59 +03:30
title: Text(t.about.pageTitle),
2023-07-22 16:02:06 +03:30
),
2023-07-27 18:03:41 +03:30
...switch (appVersion) {
2023-07-22 16:02:06 +03:30
AsyncData(:final value) => [
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Assets.images.logo.svg(width: 64, height: 64),
const Gap(16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
2023-09-07 01:56:59 +03:30
t.general.appTitle,
2023-07-22 16:02:06 +03:30
style: Theme.of(context).textTheme.titleLarge,
),
const Gap(4),
Text(
"${t.about.version} ${value.version} ${value.buildNumber}",
),
],
2023-08-25 17:58:04 +03:30
),
2023-07-22 16:02:06 +03:30
],
),
),
),
SliverList(
delegate: SliverChildListDelegate(
[
ListTile(
2023-09-07 01:56:59 +03:30
title: Text(t.about.sourceCode),
2023-07-22 16:02:06 +03:30
trailing: const Icon(Icons.open_in_new),
onTap: () async {
2023-08-25 17:58:04 +03:30
await UriUtils.tryLaunch(
2023-07-22 16:02:06 +03:30
Uri.parse(Constants.githubUrl),
);
},
),
ListTile(
2023-09-07 01:56:59 +03:30
title: Text(t.about.telegramChannel),
2023-07-22 16:02:06 +03:30
trailing: const Icon(Icons.open_in_new),
onTap: () async {
2023-08-25 17:58:04 +03:30
await UriUtils.tryLaunch(
2023-07-22 16:02:06 +03:30
Uri.parse(Constants.telegramChannelUrl),
);
},
),
ListTile(
2023-09-07 01:56:59 +03:30
title: Text(t.about.checkForUpdate),
2023-07-27 18:03:41 +03:30
trailing: isCheckingForUpdate
? const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(),
)
: const Icon(Icons.update),
onTap: () async {
await ref
.read(runtimeDetailsNotifierProvider.notifier)
.checkForUpdates();
},
2023-07-22 16:02:06 +03:30
),
2023-09-01 15:00:41 +03:30
ListTile(
title: Text(t.settings.general.openWorkingDir),
trailing: const Icon(Icons.arrow_outward_outlined),
onTap: () async {
final path = ref
.read(filesEditorServiceProvider)
.workingDir
.uri;
await UriUtils.tryLaunch(path);
},
),
2023-07-22 16:02:06 +03:30
],
),
),
],
_ => [],
2023-08-25 17:58:04 +03:30
},
2023-07-22 16:02:06 +03:30
],
),
);
}
}