2023-12-14 14:50:10 +03:30
|
|
|
import 'dart:io';
|
|
|
|
|
|
2023-07-08 23:16:22 +03:30
|
|
|
import 'package:flutter/material.dart';
|
2023-12-01 12:56:24 +03:30
|
|
|
import 'package:hiddify/core/localization/translations.dart';
|
|
|
|
|
import 'package:hiddify/core/preferences/general_preferences.dart';
|
|
|
|
|
import 'package:hiddify/core/theme/app_theme_mode.dart';
|
|
|
|
|
import 'package:hiddify/core/theme/theme_preferences.dart';
|
2023-12-28 23:16:56 +03:30
|
|
|
import 'package:hiddify/features/auto_start/notifier/auto_start_notifier.dart';
|
2023-11-09 15:23:48 +03:30
|
|
|
import 'package:hiddify/features/common/general_pref_tiles.dart';
|
2023-08-25 17:58:04 +03:30
|
|
|
import 'package:hiddify/utils/utils.dart';
|
2023-07-08 23:16:22 +03:30
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
|
|
2023-09-01 15:00:41 +03:30
|
|
|
class GeneralSettingTiles extends HookConsumerWidget {
|
|
|
|
|
const GeneralSettingTiles({super.key});
|
2023-07-08 23:16:22 +03:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final t = ref.watch(translationsProvider);
|
|
|
|
|
|
2023-12-01 12:56:24 +03:30
|
|
|
final themeMode = ref.watch(themePreferencesProvider);
|
2023-07-08 23:16:22 +03:30
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
2023-09-17 00:23:31 +03:30
|
|
|
const LocalePrefTile(),
|
2023-07-08 23:16:22 +03:30
|
|
|
ListTile(
|
2023-09-01 15:00:41 +03:30
|
|
|
title: Text(t.settings.general.themeMode),
|
2023-12-01 12:56:24 +03:30
|
|
|
subtitle: Text(themeMode.present(t)),
|
2023-09-01 15:00:41 +03:30
|
|
|
leading: const Icon(Icons.light_mode),
|
2023-07-08 23:16:22 +03:30
|
|
|
onTap: () async {
|
2023-10-24 11:26:57 +02:00
|
|
|
final selectedThemeMode = await showDialog<AppThemeMode>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return SimpleDialog(
|
|
|
|
|
title: Text(t.settings.general.themeMode),
|
|
|
|
|
children: AppThemeMode.values
|
|
|
|
|
.map(
|
|
|
|
|
(e) => RadioListTile(
|
|
|
|
|
title: Text(e.present(t)),
|
|
|
|
|
value: e,
|
2023-12-01 12:56:24 +03:30
|
|
|
groupValue: themeMode,
|
2023-12-28 10:43:57 +03:30
|
|
|
onChanged: Navigator.of(context).maybePop,
|
2023-10-24 11:26:57 +02:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.toList(),
|
2023-09-06 12:56:30 +03:30
|
|
|
);
|
2023-10-24 11:26:57 +02:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
if (selectedThemeMode != null) {
|
|
|
|
|
await ref
|
2023-12-01 12:56:24 +03:30
|
|
|
.read(themePreferencesProvider.notifier)
|
|
|
|
|
.changeThemeMode(selectedThemeMode);
|
2023-10-24 11:26:57 +02:00
|
|
|
}
|
2023-07-08 23:16:22 +03:30
|
|
|
},
|
|
|
|
|
),
|
2024-01-13 16:16:49 +03:30
|
|
|
const EnableAnalyticsPrefTile(),
|
2023-12-14 14:50:10 +03:30
|
|
|
if (Platform.isAndroid)
|
|
|
|
|
SwitchListTile(
|
|
|
|
|
title: Text(t.settings.general.dynamicNotification),
|
|
|
|
|
secondary: const Icon(Icons.speed),
|
|
|
|
|
value: ref.watch(dynamicNotificationProvider),
|
|
|
|
|
onChanged: (value) async {
|
|
|
|
|
await ref
|
|
|
|
|
.read(dynamicNotificationProvider.notifier)
|
|
|
|
|
.update(value);
|
|
|
|
|
},
|
|
|
|
|
),
|
2023-08-24 00:58:58 +03:30
|
|
|
if (PlatformUtils.isDesktop) ...[
|
2023-09-09 16:47:11 +03:30
|
|
|
SwitchListTile(
|
|
|
|
|
title: Text(t.settings.general.autoStart),
|
2023-12-28 23:16:56 +03:30
|
|
|
value: ref.watch(autoStartNotifierProvider).asData!.value,
|
2023-09-09 16:47:11 +03:30
|
|
|
onChanged: (value) async {
|
|
|
|
|
if (value) {
|
2023-12-28 23:16:56 +03:30
|
|
|
await ref.read(autoStartNotifierProvider.notifier).enable();
|
2023-09-09 16:47:11 +03:30
|
|
|
} else {
|
2023-12-28 23:16:56 +03:30
|
|
|
await ref.read(autoStartNotifierProvider.notifier).disable();
|
2023-09-09 16:47:11 +03:30
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
2023-07-15 18:00:44 +03:30
|
|
|
SwitchListTile(
|
2023-09-01 15:00:41 +03:30
|
|
|
title: Text(t.settings.general.silentStart),
|
2023-09-07 13:43:46 +03:30
|
|
|
value: ref.watch(silentStartNotifierProvider),
|
2023-08-26 16:18:38 +03:30
|
|
|
onChanged: (value) async {
|
2023-09-07 13:43:46 +03:30
|
|
|
await ref
|
|
|
|
|
.read(silentStartNotifierProvider.notifier)
|
|
|
|
|
.update(value);
|
2023-07-15 18:00:44 +03:30
|
|
|
},
|
|
|
|
|
),
|
2023-08-24 00:58:58 +03:30
|
|
|
],
|
2023-07-08 23:16:22 +03:30
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|