top_control_app_bar.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.isFavorite,
  16. }) : super(key: key);
  17. final Asset asset;
  18. final Function onMoreInfoPressed;
  19. final VoidCallback? onDownloadPressed;
  20. final VoidCallback onToggleMotionVideo;
  21. final VoidCallback onAddToAlbumPressed;
  22. final VoidCallback? onFavorite;
  23. final bool isPlayingMotionVideo;
  24. final bool isFavorite;
  25. @override
  26. Widget build(BuildContext context, WidgetRef ref) {
  27. const double iconSize = 22.0;
  28. Widget buildFavoriteButton() {
  29. return IconButton(
  30. onPressed: onFavorite,
  31. icon: Icon(
  32. isFavorite ? Icons.favorite : Icons.favorite_border,
  33. color: Colors.grey[200],
  34. ),
  35. );
  36. }
  37. return AppBar(
  38. foregroundColor: Colors.grey[100],
  39. backgroundColor: Colors.transparent,
  40. leading: IconButton(
  41. onPressed: () {
  42. AutoRouter.of(context).pop();
  43. },
  44. icon: Icon(
  45. Icons.arrow_back_ios_new_rounded,
  46. size: 20.0,
  47. color: Colors.grey[200],
  48. ),
  49. ),
  50. actionsIconTheme: const IconThemeData(
  51. size: iconSize,
  52. ),
  53. actions: [
  54. if (asset.isRemote) buildFavoriteButton(),
  55. if (asset.livePhotoVideoId != null)
  56. IconButton(
  57. onPressed: () {
  58. onToggleMotionVideo();
  59. },
  60. icon: isPlayingMotionVideo
  61. ? Icon(
  62. Icons.motion_photos_pause_outlined,
  63. color: Colors.grey[200],
  64. )
  65. : Icon(
  66. Icons.play_circle_outline_rounded,
  67. color: Colors.grey[200],
  68. ),
  69. ),
  70. if (!asset.isLocal)
  71. IconButton(
  72. onPressed: onDownloadPressed,
  73. icon: Icon(
  74. Icons.cloud_download_outlined,
  75. color: Colors.grey[200],
  76. ),
  77. ),
  78. if (asset.storage == AssetState.merged)
  79. IconButton(
  80. onPressed: onDownloadPressed,
  81. icon: Icon(
  82. Icons.cloud_download_outlined,
  83. color: Colors.grey[200],
  84. ),
  85. ),
  86. if (asset.isRemote)
  87. IconButton(
  88. onPressed: () {
  89. onAddToAlbumPressed();
  90. },
  91. icon: Icon(
  92. Icons.add,
  93. color: Colors.grey[200],
  94. ),
  95. ),
  96. IconButton(
  97. onPressed: () {
  98. onMoreInfoPressed();
  99. },
  100. icon: Icon(
  101. Icons.info_outline_rounded,
  102. color: Colors.grey[200],
  103. ),
  104. ),
  105. ],
  106. );
  107. }
  108. }