top_control_app_bar.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/asset.dart';
  5. class TopControlAppBar extends HookConsumerWidget {
  6. const TopControlAppBar({
  7. Key? key,
  8. required this.asset,
  9. required this.onMoreInfoPressed,
  10. required this.onDownloadPressed,
  11. required this.onAddToAlbumPressed,
  12. required this.onToggleMotionVideo,
  13. required this.isPlayingMotionVideo,
  14. required this.onFavorite,
  15. required this.onUploadPressed,
  16. required this.isFavorite,
  17. }) : super(key: key);
  18. final Asset asset;
  19. final Function onMoreInfoPressed;
  20. final VoidCallback? onUploadPressed;
  21. final VoidCallback? onDownloadPressed;
  22. final VoidCallback onToggleMotionVideo;
  23. final VoidCallback onAddToAlbumPressed;
  24. final VoidCallback? onFavorite;
  25. final bool isPlayingMotionVideo;
  26. final bool isFavorite;
  27. @override
  28. Widget build(BuildContext context, WidgetRef ref) {
  29. const double iconSize = 22.0;
  30. Widget buildFavoriteButton() {
  31. return IconButton(
  32. onPressed: onFavorite,
  33. icon: Icon(
  34. isFavorite ? Icons.favorite : Icons.favorite_border,
  35. color: Colors.grey[200],
  36. ),
  37. );
  38. }
  39. Widget buildLivePhotoButton() {
  40. return IconButton(
  41. onPressed: () {
  42. onToggleMotionVideo();
  43. },
  44. icon: isPlayingMotionVideo
  45. ? Icon(
  46. Icons.motion_photos_pause_outlined,
  47. color: Colors.grey[200],
  48. )
  49. : Icon(
  50. Icons.play_circle_outline_rounded,
  51. color: Colors.grey[200],
  52. ),
  53. );
  54. }
  55. Widget buildMoreInfoButton() {
  56. return IconButton(
  57. onPressed: () {
  58. onMoreInfoPressed();
  59. },
  60. icon: Icon(
  61. Icons.info_outline_rounded,
  62. color: Colors.grey[200],
  63. ),
  64. );
  65. }
  66. Widget buildDownloadButton() {
  67. return IconButton(
  68. onPressed: onDownloadPressed,
  69. icon: Icon(
  70. Icons.cloud_download_outlined,
  71. color: Colors.grey[200],
  72. ),
  73. );
  74. }
  75. Widget buildAddToAlbumButtom() {
  76. return IconButton(
  77. onPressed: () {
  78. onAddToAlbumPressed();
  79. },
  80. icon: Icon(
  81. Icons.add,
  82. color: Colors.grey[200],
  83. ),
  84. );
  85. }
  86. Widget buildUploadButton() {
  87. return IconButton(
  88. onPressed: onUploadPressed,
  89. icon: Icon(
  90. Icons.backup_outlined,
  91. color: Colors.grey[200],
  92. ),
  93. );
  94. }
  95. Widget buildBackButton() {
  96. return IconButton(
  97. onPressed: () {
  98. AutoRouter.of(context).pop();
  99. },
  100. icon: Icon(
  101. Icons.arrow_back_ios_new_rounded,
  102. size: 20.0,
  103. color: Colors.grey[200],
  104. ),
  105. );
  106. }
  107. return AppBar(
  108. foregroundColor: Colors.grey[100],
  109. backgroundColor: Colors.transparent,
  110. leading: buildBackButton(),
  111. actionsIconTheme: const IconThemeData(
  112. size: iconSize,
  113. ),
  114. actions: [
  115. if (asset.isRemote) buildFavoriteButton(),
  116. if (asset.livePhotoVideoId != null) buildLivePhotoButton(),
  117. if (asset.isLocal && !asset.isRemote) buildUploadButton(),
  118. if (asset.isRemote && !asset.isLocal) buildDownloadButton(),
  119. if (asset.isRemote) buildAddToAlbumButtom(),
  120. buildMoreInfoButton(),
  121. ],
  122. );
  123. }
  124. }