map_settings_dialog.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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/map/providers/map_state.provider.dart';
  6. class MapSettingsDialog extends HookConsumerWidget {
  7. const MapSettingsDialog({super.key});
  8. @override
  9. Widget build(BuildContext context, WidgetRef ref) {
  10. final mapSettingsNotifier = ref.read(mapStateNotifier.notifier);
  11. final mapSettings = ref.read(mapStateNotifier);
  12. final isDarkMode = useState(mapSettings.isDarkTheme);
  13. final showFavoriteOnly = useState(mapSettings.showFavoriteOnly);
  14. final showRelativeDate = useState(mapSettings.relativeTime);
  15. final ThemeData theme = Theme.of(context);
  16. Widget buildMapThemeSetting() {
  17. return SwitchListTile.adaptive(
  18. value: isDarkMode.value,
  19. onChanged: (value) {
  20. isDarkMode.value = value;
  21. },
  22. activeColor: theme.primaryColor,
  23. dense: true,
  24. title: Text(
  25. "map_settings_dark_mode".tr(),
  26. style:
  27. theme.textTheme.labelLarge?.copyWith(fontWeight: FontWeight.bold),
  28. ),
  29. );
  30. }
  31. Widget buildFavoriteOnlySetting() {
  32. return SwitchListTile.adaptive(
  33. value: showFavoriteOnly.value,
  34. onChanged: (value) {
  35. showFavoriteOnly.value = value;
  36. },
  37. activeColor: theme.primaryColor,
  38. dense: true,
  39. title: Text(
  40. "map_settings_only_show_favorites".tr(),
  41. style:
  42. theme.textTheme.labelLarge?.copyWith(fontWeight: FontWeight.bold),
  43. ),
  44. );
  45. }
  46. Widget buildDateRangeSetting() {
  47. final now = DateTime.now();
  48. return DropdownMenu(
  49. enableSearch: false,
  50. enableFilter: false,
  51. initialSelection: showRelativeDate.value,
  52. onSelected: (value) {
  53. showRelativeDate.value = value!;
  54. },
  55. dropdownMenuEntries: [
  56. const DropdownMenuEntry(value: 0, label: "All"),
  57. const DropdownMenuEntry(
  58. value: 1,
  59. label: "Past 24 hours",
  60. ),
  61. const DropdownMenuEntry(
  62. value: 7,
  63. label: "Past 7 days",
  64. ),
  65. const DropdownMenuEntry(
  66. value: 30,
  67. label: "Past 30 days",
  68. ),
  69. DropdownMenuEntry(
  70. value: now
  71. .difference(
  72. DateTime(
  73. now.year - 1,
  74. now.month,
  75. now.day,
  76. now.hour,
  77. now.minute,
  78. now.second,
  79. ),
  80. )
  81. .inDays,
  82. label: "Past year",
  83. ),
  84. DropdownMenuEntry(
  85. value: now
  86. .difference(
  87. DateTime(
  88. now.year - 3,
  89. now.month,
  90. now.day,
  91. now.hour,
  92. now.minute,
  93. now.second,
  94. ),
  95. )
  96. .inDays,
  97. label: "Past 3 years",
  98. ),
  99. ],
  100. );
  101. }
  102. List<Widget> getDialogActions() {
  103. return <Widget>[
  104. TextButton(
  105. onPressed: () => Navigator.of(context).pop(),
  106. style: TextButton.styleFrom(
  107. backgroundColor:
  108. mapSettings.isDarkTheme ? Colors.grey[100] : Colors.grey[700],
  109. ),
  110. child: Text(
  111. "map_settings_dialog_cancel".tr(),
  112. style: theme.textTheme.labelSmall?.copyWith(
  113. fontWeight: FontWeight.bold,
  114. color:
  115. mapSettings.isDarkTheme ? Colors.grey[900] : Colors.grey[100],
  116. ),
  117. ),
  118. ),
  119. TextButton(
  120. onPressed: () {
  121. mapSettingsNotifier.switchTheme(isDarkMode.value);
  122. mapSettingsNotifier.switchFavoriteOnly(showFavoriteOnly.value);
  123. mapSettingsNotifier.setRelativeTime(showRelativeDate.value);
  124. Navigator.of(context).pop();
  125. },
  126. style: TextButton.styleFrom(
  127. backgroundColor: theme.primaryColor,
  128. ),
  129. child: Text(
  130. "map_settings_dialog_save".tr(),
  131. style: theme.textTheme.labelSmall?.copyWith(
  132. fontWeight: FontWeight.bold,
  133. color: theme.primaryTextTheme.labelLarge?.color,
  134. ),
  135. ),
  136. ),
  137. ];
  138. }
  139. return AlertDialog(
  140. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
  141. title: Center(
  142. child: Text(
  143. "map_settings_dialog_title".tr(),
  144. style: TextStyle(
  145. color: theme.primaryColor,
  146. fontWeight: FontWeight.bold,
  147. fontSize: 18,
  148. ),
  149. ),
  150. ),
  151. content: SizedBox(
  152. width: double.maxFinite,
  153. child: ConstrainedBox(
  154. constraints: BoxConstraints(
  155. maxHeight: MediaQuery.of(context).size.height * 0.6,
  156. ),
  157. child: ListView(
  158. shrinkWrap: true,
  159. children: [
  160. buildMapThemeSetting(),
  161. buildFavoriteOnlySetting(),
  162. const SizedBox(
  163. height: 10,
  164. ),
  165. Padding(
  166. padding: const EdgeInsets.only(left: 20),
  167. child: Column(
  168. crossAxisAlignment: CrossAxisAlignment.start,
  169. children: [
  170. Text(
  171. "map_settings_only_relative_range".tr(),
  172. style: const TextStyle(fontWeight: FontWeight.bold),
  173. ),
  174. buildDateRangeSetting(),
  175. ],
  176. ),
  177. ),
  178. ].toList(),
  179. ),
  180. ),
  181. ),
  182. actions: getDialogActions(),
  183. actionsAlignment: MainAxisAlignment.spaceEvenly,
  184. );
  185. }
  186. }