Change experimental feature notice

This commit is contained in:
problematicconsumer
2024-03-08 17:15:17 +03:30
parent 13c4fcce1c
commit 7f0397a97f
5 changed files with 68 additions and 68 deletions

View File

@@ -1,29 +1,20 @@
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:gap/gap.dart';
import 'package:hiddify/core/localization/translations.dart';
import 'package:hiddify/core/preferences/preferences_provider.dart';
import 'package:hiddify/core/router/routes.dart';
import 'package:hiddify/core/utils/preferences_utils.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'experimental_feature_notice.g.dart';
bool _testExperimentalNotice = false;
@riverpod
class DisableExperimentalFeatureNotice
extends _$DisableExperimentalFeatureNotice {
static const _key = "disable_experimental_feature_notice";
@override
bool build() {
return ref.read(sharedPreferencesProvider).requireValue.getBool(_key) ??
false;
}
Future<void> change(bool pref) async {
state = pref;
await ref.read(sharedPreferencesProvider).requireValue.setBool(_key, pref);
}
}
final disableExperimentalFeatureNoticeProvider =
PreferencesNotifier.createAutoDispose(
"disable_experimental_feature_notice",
false,
overrideValue: _testExperimentalNotice && kDebugMode ? false : null,
);
class ExperimentalFeatureNoticeDialog extends HookConsumerWidget {
const ExperimentalFeatureNoticeDialog({super.key});
@@ -38,48 +29,56 @@ class ExperimentalFeatureNoticeDialog extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final t = ref.watch(translationsProvider);
final shouldDisable =
useState(ref.read(disableExperimentalFeatureNoticeProvider));
final disableNotice = ref.watch(disableExperimentalFeatureNoticeProvider);
return PopScope(
onPopInvoked: (didPop) async {
await ref
.read(disableExperimentalFeatureNoticeProvider.notifier)
.change(shouldDisable.value);
},
child: AlertDialog(
title: Text(t.home.connection.experimentalNotice),
content: SingleChildScrollView(
child: SizedBox(
width: 468,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(t.home.connection.experimentalNoticeMsg),
CheckboxListTile(
value: shouldDisable.value,
title: Text(t.home.connection.disableExperimentalNotice),
onChanged: (value) => shouldDisable.value = value ?? false,
),
],
),
return AlertDialog(
title: Text(t.home.connection.experimentalNotice),
content: SingleChildScrollView(
child: SizedBox(
width: 468,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(t.home.connection.experimentalNoticeMsg),
const Gap(8),
CheckboxListTile(
value: disableNotice,
title: Text(t.home.connection.disableExperimentalNotice),
secondary: const Icon(FluentIcons.eye_off_24_regular),
onChanged: (value) async => ref
.read(disableExperimentalFeatureNoticeProvider.notifier)
.update(value ?? false),
dense: true,
),
ListTile(
title: Text(t.settings.config.pageTitle),
leading: const Icon(FluentIcons.box_edit_24_regular),
trailing: const Icon(FluentIcons.chevron_right_20_regular),
onTap: () async {
await Navigator.of(context).maybePop(false);
if (context.mounted) {
const ConfigOptionsRoute().push(context);
}
},
dense: true,
),
],
),
),
actions: [
TextButton(
onPressed: () async {
await Navigator.of(context).maybePop(false);
if (context.mounted) const ConfigOptionsRoute().push(context);
},
child: Text(t.settings.config.pageTitle),
),
TextButton(
onPressed: () => Navigator.of(context).maybePop(true),
child: Text(MaterialLocalizations.of(context).okButtonLabel),
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).maybePop(false),
child: Text(
MaterialLocalizations.of(context).cancelButtonLabel.toUpperCase(),
),
),
TextButton(
onPressed: () => Navigator.of(context).maybePop(true),
child: Text(t.home.connection.connectAnyWay.toUpperCase()),
),
],
);
}
}