immich_app_bar.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import 'package:flutter/material.dart';
  2. import 'package:hooks_riverpod/hooks_riverpod.dart';
  3. import 'package:immich_mobile/extensions/build_context_extensions.dart';
  4. import 'package:immich_mobile/shared/models/store.dart';
  5. import 'package:immich_mobile/shared/ui/app_bar_dialog/app_bar_dialog.dart';
  6. import 'package:immich_mobile/shared/ui/user_circle_avatar.dart';
  7. import 'package:immich_mobile/routing/router.dart';
  8. import 'package:immich_mobile/modules/backup/models/backup_state.model.dart';
  9. import 'package:immich_mobile/shared/models/server_info/server_info.model.dart';
  10. import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
  11. import 'package:immich_mobile/shared/providers/server_info.provider.dart';
  12. class ImmichAppBar extends ConsumerWidget implements PreferredSizeWidget {
  13. @override
  14. Size get preferredSize => const Size.fromHeight(kToolbarHeight);
  15. final Widget? action;
  16. const ImmichAppBar({super.key, this.action});
  17. @override
  18. Widget build(BuildContext context, WidgetRef ref) {
  19. final BackUpState backupState = ref.watch(backupProvider);
  20. final bool isEnableAutoBackup =
  21. backupState.backgroundBackup || backupState.autoBackup;
  22. final ServerInfo serverInfoState = ref.watch(serverInfoProvider);
  23. final user = Store.tryGet(StoreKey.currentUser);
  24. final isDarkTheme = context.isDarkTheme;
  25. const widgetSize = 30.0;
  26. buildProfileIndicator() {
  27. return InkWell(
  28. onTap: () => showDialog(
  29. context: context,
  30. useRootNavigator: false,
  31. builder: (ctx) => const ImmichAppBarDialog(),
  32. ),
  33. borderRadius: BorderRadius.circular(12),
  34. child: Badge(
  35. label: Container(
  36. decoration: BoxDecoration(
  37. color: Colors.black,
  38. borderRadius: BorderRadius.circular(widgetSize / 2),
  39. ),
  40. child: const Icon(
  41. Icons.info,
  42. color: Color.fromARGB(255, 243, 188, 106),
  43. size: widgetSize / 2,
  44. ),
  45. ),
  46. backgroundColor: Colors.transparent,
  47. alignment: Alignment.bottomRight,
  48. isLabelVisible: serverInfoState.isVersionMismatch,
  49. offset: const Offset(2, 2),
  50. child: user == null
  51. ? const Icon(
  52. Icons.face_outlined,
  53. size: widgetSize,
  54. )
  55. : UserCircleAvatar(
  56. radius: 15,
  57. size: 27,
  58. user: user,
  59. ),
  60. ),
  61. );
  62. }
  63. getBackupBadgeIcon() {
  64. final iconColor = isDarkTheme ? Colors.white : Colors.black;
  65. if (isEnableAutoBackup) {
  66. if (backupState.backupProgress == BackUpProgressEnum.inProgress) {
  67. return Container(
  68. padding: const EdgeInsets.all(3.5),
  69. child: CircularProgressIndicator(
  70. strokeWidth: 2,
  71. strokeCap: StrokeCap.round,
  72. valueColor: AlwaysStoppedAnimation<Color>(iconColor),
  73. ),
  74. );
  75. } else if (backupState.backupProgress !=
  76. BackUpProgressEnum.inBackground &&
  77. backupState.backupProgress != BackUpProgressEnum.manualInProgress) {
  78. return Icon(
  79. Icons.check_outlined,
  80. size: 9,
  81. color: iconColor,
  82. );
  83. }
  84. }
  85. if (!isEnableAutoBackup) {
  86. return Icon(
  87. Icons.cloud_off_rounded,
  88. size: 9,
  89. color: iconColor,
  90. );
  91. }
  92. }
  93. buildBackupIndicator() {
  94. final indicatorIcon = getBackupBadgeIcon();
  95. final badgeBackground = isDarkTheme ? Colors.blueGrey[800] : Colors.white;
  96. return InkWell(
  97. onTap: () => context.autoPush(const BackupControllerRoute()),
  98. borderRadius: BorderRadius.circular(12),
  99. child: Badge(
  100. label: Container(
  101. width: widgetSize / 2,
  102. height: widgetSize / 2,
  103. decoration: BoxDecoration(
  104. color: badgeBackground,
  105. border: Border.all(
  106. color: isDarkTheme ? Colors.black : Colors.grey,
  107. ),
  108. borderRadius: BorderRadius.circular(widgetSize / 2),
  109. ),
  110. child: indicatorIcon,
  111. ),
  112. backgroundColor: Colors.transparent,
  113. alignment: Alignment.bottomRight,
  114. isLabelVisible: indicatorIcon != null,
  115. offset: const Offset(2, 2),
  116. child: Icon(
  117. Icons.backup_rounded,
  118. size: widgetSize,
  119. color: context.primaryColor,
  120. ),
  121. ),
  122. );
  123. }
  124. return AppBar(
  125. backgroundColor: context.themeData.appBarTheme.backgroundColor,
  126. shape: const RoundedRectangleBorder(
  127. borderRadius: BorderRadius.all(
  128. Radius.circular(5),
  129. ),
  130. ),
  131. automaticallyImplyLeading: false,
  132. centerTitle: false,
  133. title: Builder(
  134. builder: (BuildContext context) {
  135. return Row(
  136. children: [
  137. Container(
  138. padding: const EdgeInsets.only(top: 3),
  139. width: 28,
  140. height: 28,
  141. child: Image.asset(
  142. 'assets/immich-logo.png',
  143. ),
  144. ),
  145. Container(
  146. margin: const EdgeInsets.only(left: 10),
  147. child: const Text(
  148. 'IMMICH',
  149. style: TextStyle(
  150. fontFamily: 'SnowburstOne',
  151. fontWeight: FontWeight.bold,
  152. fontSize: 24,
  153. ),
  154. ),
  155. ),
  156. ],
  157. );
  158. },
  159. ),
  160. actions: [
  161. if (action != null)
  162. Padding(padding: const EdgeInsets.only(right: 20), child: action!),
  163. Padding(
  164. padding: const EdgeInsets.only(right: 20),
  165. child: buildBackupIndicator(),
  166. ),
  167. Padding(
  168. padding: const EdgeInsets.only(right: 20),
  169. child: buildProfileIndicator(),
  170. ),
  171. ],
  172. );
  173. }
  174. }