Files
umbrix/lib/features/app_update/widget/new_version_dialog.dart

102 lines
3.0 KiB
Dart
Raw Normal View History

2023-07-27 18:03:41 +03:30
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
2023-12-01 12:56:24 +03:30
import 'package:hiddify/core/localization/translations.dart';
import 'package:hiddify/features/app_update/model/remote_version_entity.dart';
import 'package:hiddify/features/app_update/notifier/app_update_notifier.dart';
2023-08-25 17:58:04 +03:30
import 'package:hiddify/utils/utils.dart';
2023-07-27 18:03:41 +03:30
import 'package:hooks_riverpod/hooks_riverpod.dart';
2023-10-04 18:06:48 +03:30
class NewVersionDialog extends HookConsumerWidget with PresLogger {
NewVersionDialog(
2023-07-27 18:03:41 +03:30
this.currentVersion,
this.newVersion, {
this.canIgnore = true,
2023-10-04 18:06:48 +03:30
}) : super(key: _dialogKey);
2023-07-27 18:03:41 +03:30
2023-09-12 15:22:58 +03:30
final String currentVersion;
2023-12-01 12:56:24 +03:30
final RemoteVersionEntity newVersion;
2023-07-27 18:03:41 +03:30
final bool canIgnore;
2023-10-04 18:06:48 +03:30
static final _dialogKey = GlobalKey(debugLabel: 'new version dialog');
Future<void> show(BuildContext context) async {
if (_dialogKey.currentContext == null) {
return showDialog(
context: context,
builder: (context) => this,
);
} else {
loggy.warning("new version dialog is already open");
}
2023-07-27 18:03:41 +03:30
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
final theme = Theme.of(context);
return AlertDialog(
2023-09-07 01:56:59 +03:30
title: Text(t.appUpdate.dialogTitle),
2023-07-27 18:03:41 +03:30
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(t.appUpdate.updateMsg),
const Gap(8),
Text.rich(
TextSpan(
children: [
TextSpan(
text: "${t.appUpdate.currentVersionLbl}: ",
style: theme.textTheme.bodySmall,
),
TextSpan(
2023-09-12 15:22:58 +03:30
text: currentVersion,
2023-07-27 18:03:41 +03:30
style: theme.textTheme.labelMedium,
),
],
),
),
Text.rich(
TextSpan(
children: [
TextSpan(
text: "${t.appUpdate.newVersionLbl}: ",
style: theme.textTheme.bodySmall,
),
TextSpan(
2023-09-16 00:56:03 +03:30
text: newVersion.presentVersion,
2023-07-27 18:03:41 +03:30
style: theme.textTheme.labelMedium,
),
],
),
),
],
),
actions: [
if (canIgnore)
TextButton(
2023-10-05 21:49:36 +03:30
onPressed: () async {
await ref
.read(appUpdateNotifierProvider.notifier)
.ignoreRelease(newVersion);
if (context.mounted) context.pop();
2023-07-27 18:03:41 +03:30
},
2023-09-07 01:56:59 +03:30
child: Text(t.appUpdate.ignoreBtnTxt),
2023-07-27 18:03:41 +03:30
),
TextButton(
onPressed: context.pop,
2023-09-07 01:56:59 +03:30
child: Text(t.appUpdate.laterBtnTxt),
2023-07-27 18:03:41 +03:30
),
TextButton(
onPressed: () async {
2023-09-16 13:14:52 +03:30
await UriUtils.tryLaunch(Uri.parse(newVersion.url));
2023-07-27 18:03:41 +03:30
},
2023-09-07 01:56:59 +03:30
child: Text(t.appUpdate.updateNowBtnTxt),
2023-07-27 18:03:41 +03:30
),
],
);
}
}