home_page_app_bar.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import 'package:auto_route/auto_route.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:hooks_riverpod/hooks_riverpod.dart';
  4. import 'package:immich_mobile/shared/models/store.dart';
  5. import 'package:immich_mobile/shared/ui/user_circle_avatar.dart';
  6. import 'package:immich_mobile/modules/login/models/authentication_state.model.dart';
  7. import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
  8. import 'package:immich_mobile/routing/router.dart';
  9. import 'package:immich_mobile/modules/backup/models/backup_state.model.dart';
  10. import 'package:immich_mobile/shared/models/server_info_state.model.dart';
  11. import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
  12. import 'package:immich_mobile/shared/providers/server_info.provider.dart';
  13. class HomePageAppBar extends ConsumerWidget implements PreferredSizeWidget {
  14. @override
  15. Size get preferredSize => const Size.fromHeight(kToolbarHeight);
  16. const HomePageAppBar({
  17. super.key,
  18. this.onPopBack,
  19. });
  20. final Function? onPopBack;
  21. @override
  22. Widget build(BuildContext context, WidgetRef ref) {
  23. final BackUpState backupState = ref.watch(backupProvider);
  24. final bool isEnableAutoBackup =
  25. backupState.backgroundBackup || backupState.autoBackup;
  26. final ServerInfoState serverInfoState = ref.watch(serverInfoProvider);
  27. AuthenticationState authState = ref.watch(authenticationProvider);
  28. final user = Store.tryGet(StoreKey.currentUser);
  29. buildProfilePhoto() {
  30. if (authState.profileImagePath.isEmpty || user == null) {
  31. return IconButton(
  32. splashRadius: 25,
  33. icon: const Icon(
  34. Icons.face_outlined,
  35. size: 30,
  36. ),
  37. onPressed: () {
  38. Scaffold.of(context).openDrawer();
  39. },
  40. );
  41. } else {
  42. return InkWell(
  43. onTap: () {
  44. Scaffold.of(context).openDrawer();
  45. },
  46. child: UserCircleAvatar(
  47. radius: 18,
  48. size: 33,
  49. user: user,
  50. ),
  51. );
  52. }
  53. }
  54. return AppBar(
  55. backgroundColor: Theme.of(context).appBarTheme.backgroundColor,
  56. shape: const RoundedRectangleBorder(
  57. borderRadius: BorderRadius.all(
  58. Radius.circular(5),
  59. ),
  60. ),
  61. leading: Builder(
  62. builder: (BuildContext context) {
  63. return Stack(
  64. children: [
  65. Center(
  66. child: buildProfilePhoto(),
  67. ),
  68. if (serverInfoState.isVersionMismatch)
  69. Positioned(
  70. bottom: 4,
  71. right: 6,
  72. child: GestureDetector(
  73. onTap: () => Scaffold.of(context).openDrawer(),
  74. child: Material(
  75. // color: Colors.grey[200],
  76. elevation: 1,
  77. shape: RoundedRectangleBorder(
  78. borderRadius: BorderRadius.circular(50.0),
  79. ),
  80. child: const Padding(
  81. padding: EdgeInsets.all(2.0),
  82. child: Icon(
  83. Icons.info,
  84. color: Color.fromARGB(255, 243, 188, 106),
  85. size: 15,
  86. ),
  87. ),
  88. ),
  89. ),
  90. ),
  91. ],
  92. );
  93. },
  94. ),
  95. title: const Text(
  96. 'IMMICH',
  97. style: TextStyle(
  98. fontFamily: 'SnowburstOne',
  99. fontWeight: FontWeight.bold,
  100. fontSize: 22,
  101. ),
  102. ),
  103. actions: [
  104. Stack(
  105. alignment: AlignmentDirectional.center,
  106. children: [
  107. if (backupState.backupProgress == BackUpProgressEnum.inProgress)
  108. Positioned(
  109. top: 10,
  110. right: 12,
  111. child: SizedBox(
  112. height: 8,
  113. width: 8,
  114. child: CircularProgressIndicator(
  115. strokeWidth: 1,
  116. valueColor: AlwaysStoppedAnimation<Color>(
  117. Theme.of(context).primaryColor,
  118. ),
  119. ),
  120. ),
  121. ),
  122. IconButton(
  123. splashRadius: 25,
  124. iconSize: 30,
  125. icon: isEnableAutoBackup
  126. ? const Icon(
  127. Icons.backup_rounded,
  128. )
  129. : Badge(
  130. padding: const EdgeInsets.all(4),
  131. backgroundColor: Colors.white,
  132. label: const Icon(
  133. Icons.cloud_off_rounded,
  134. size: 8,
  135. color: Colors.indigo,
  136. ),
  137. child: Icon(
  138. Icons.backup_rounded,
  139. color: Theme.of(context).primaryColor,
  140. ),
  141. ),
  142. onPressed: () async {
  143. var onPop = await AutoRouter.of(context)
  144. .push(const BackupControllerRoute());
  145. if (onPop != null && onPop == true) {
  146. onPopBack!();
  147. }
  148. },
  149. ),
  150. if (backupState.backupProgress == BackUpProgressEnum.inProgress)
  151. Positioned(
  152. bottom: 5,
  153. child: Text(
  154. '${backupState.allUniqueAssets.length - backupState.selectedAlbumsBackupAssetsIds.length}',
  155. style:
  156. const TextStyle(fontSize: 9, fontWeight: FontWeight.bold),
  157. ),
  158. ),
  159. ],
  160. ),
  161. ],
  162. );
  163. }
  164. }