map_page_app_bar.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import 'dart:io';
  2. import 'package:auto_route/auto_route.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_hooks/flutter_hooks.dart';
  5. import 'package:immich_mobile/modules/home/ui/asset_grid/disable_multi_select_button.dart';
  6. import 'package:immich_mobile/modules/map/ui/map_settings_dialog.dart';
  7. class MapAppBar extends HookWidget implements PreferredSizeWidget {
  8. final ValueNotifier<bool> selectionEnabled;
  9. final int selectedAssetsLength;
  10. final bool isDarkTheme;
  11. final void Function() onShare;
  12. final void Function() onFavorite;
  13. final void Function() onArchive;
  14. const MapAppBar({
  15. super.key,
  16. required this.selectionEnabled,
  17. required this.selectedAssetsLength,
  18. required this.onShare,
  19. required this.onArchive,
  20. required this.onFavorite,
  21. this.isDarkTheme = false,
  22. });
  23. List<Widget> buildNonSelectionWidgets(BuildContext context) {
  24. return [
  25. Padding(
  26. padding: const EdgeInsets.only(left: 15, top: 15),
  27. child: ElevatedButton(
  28. onPressed: () => AutoRouter.of(context).pop(),
  29. style: ElevatedButton.styleFrom(
  30. shape: const CircleBorder(),
  31. padding: const EdgeInsets.all(12),
  32. ),
  33. child: const Icon(Icons.arrow_back_ios_new_rounded, size: 22),
  34. ),
  35. ),
  36. Padding(
  37. padding: const EdgeInsets.only(right: 15, top: 15),
  38. child: ElevatedButton(
  39. onPressed: () => showDialog(
  40. context: context,
  41. builder: (BuildContext _) {
  42. return const MapSettingsDialog();
  43. },
  44. ),
  45. style: ElevatedButton.styleFrom(
  46. shape: const CircleBorder(),
  47. padding: const EdgeInsets.all(12),
  48. ),
  49. child: const Icon(Icons.more_vert_rounded, size: 22),
  50. ),
  51. ),
  52. ];
  53. }
  54. List<Widget> buildSelectionWidgets() {
  55. return [
  56. DisableMultiSelectButton(
  57. onPressed: () {
  58. selectionEnabled.value = false;
  59. },
  60. selectedItemCount: selectedAssetsLength,
  61. ),
  62. Row(
  63. children: [
  64. // Share button
  65. Padding(
  66. padding: const EdgeInsets.only(top: 15),
  67. child: ElevatedButton(
  68. onPressed: onShare,
  69. style: ElevatedButton.styleFrom(
  70. shape: const CircleBorder(),
  71. padding: const EdgeInsets.all(12),
  72. ),
  73. child: Icon(
  74. Platform.isAndroid
  75. ? Icons.share_rounded
  76. : Icons.ios_share_rounded,
  77. size: 22,
  78. ),
  79. ),
  80. ),
  81. // Favorite button
  82. Padding(
  83. padding: const EdgeInsets.only(top: 15),
  84. child: ElevatedButton(
  85. onPressed: onFavorite,
  86. style: ElevatedButton.styleFrom(
  87. shape: const CircleBorder(),
  88. padding: const EdgeInsets.all(12),
  89. ),
  90. child: const Icon(
  91. Icons.favorite,
  92. size: 22,
  93. ),
  94. ),
  95. ),
  96. // Archive Button
  97. Padding(
  98. padding: const EdgeInsets.only(right: 10, top: 15),
  99. child: ElevatedButton(
  100. onPressed: onArchive,
  101. style: ElevatedButton.styleFrom(
  102. shape: const CircleBorder(),
  103. padding: const EdgeInsets.all(12),
  104. ),
  105. child: const Icon(
  106. Icons.archive,
  107. size: 22,
  108. ),
  109. ),
  110. ),
  111. ],
  112. ),
  113. ];
  114. }
  115. @override
  116. Widget build(BuildContext context) {
  117. return Padding(
  118. padding: const EdgeInsets.only(top: 30),
  119. child: Row(
  120. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  121. children: [
  122. if (!selectionEnabled.value) ...buildNonSelectionWidgets(context),
  123. if (selectionEnabled.value) ...buildSelectionWidgets(),
  124. ],
  125. ),
  126. );
  127. }
  128. @override
  129. Size get preferredSize => const Size.fromHeight(100);
  130. }