advanced_settings.dart 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import 'package:easy_localization/easy_localization.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_hooks/flutter_hooks.dart';
  4. import 'package:hooks_riverpod/hooks_riverpod.dart';
  5. import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
  6. import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
  7. import 'package:immich_mobile/modules/settings/ui/settings_switch_list_tile.dart';
  8. import 'package:immich_mobile/shared/services/immich_logger.service.dart';
  9. import 'package:logging/logging.dart';
  10. class AdvancedSettings extends HookConsumerWidget {
  11. const AdvancedSettings({super.key});
  12. @override
  13. Widget build(BuildContext context, WidgetRef ref) {
  14. final appSettingService = ref.watch(appSettingsServiceProvider);
  15. final isEnabled =
  16. useState(AppSettingsEnum.advancedTroubleshooting.defaultValue);
  17. final levelId = useState(AppSettingsEnum.logLevel.defaultValue);
  18. useEffect(
  19. () {
  20. isEnabled.value = appSettingService.getSetting<bool>(
  21. AppSettingsEnum.advancedTroubleshooting,
  22. );
  23. levelId.value = appSettingService.getSetting(AppSettingsEnum.logLevel);
  24. return null;
  25. },
  26. [],
  27. );
  28. final logLevel = Level.LEVELS[levelId.value].name;
  29. return ExpansionTile(
  30. textColor: Theme.of(context).primaryColor,
  31. title: const Text(
  32. "advanced_settings_tile_title",
  33. style: TextStyle(
  34. fontWeight: FontWeight.bold,
  35. ),
  36. ).tr(),
  37. subtitle: const Text(
  38. "advanced_settings_tile_subtitle",
  39. style: TextStyle(
  40. fontSize: 13,
  41. ),
  42. ).tr(),
  43. children: [
  44. SettingsSwitchListTile(
  45. enabled: true,
  46. appSettingService: appSettingService,
  47. valueNotifier: isEnabled,
  48. settingsEnum: AppSettingsEnum.advancedTroubleshooting,
  49. title: "advanced_settings_troubleshooting_title".tr(),
  50. subtitle: "advanced_settings_troubleshooting_subtitle".tr(),
  51. ),
  52. ListTile(
  53. dense: true,
  54. title: Text(
  55. // Not translated because the levels are only English
  56. "Log level: $logLevel",
  57. style: const TextStyle(fontWeight: FontWeight.bold),
  58. ),
  59. subtitle: Slider(
  60. value: levelId.value.toDouble(),
  61. onChanged: (double v) => levelId.value = v.toInt(),
  62. onChangeEnd: (double v) {
  63. appSettingService.setSetting(
  64. AppSettingsEnum.logLevel,
  65. v.toInt(),
  66. );
  67. ImmichLogger().level = Level.LEVELS[v.toInt()];
  68. },
  69. max: 8,
  70. min: 1.0,
  71. divisions: 7,
  72. label: logLevel,
  73. activeColor: Theme.of(context).primaryColor,
  74. ),
  75. ),
  76. ],
  77. );
  78. }
  79. }