fading_bottom_bar.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. // @dart=2.9
  2. import 'dart:io';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
  6. import 'package:page_transition/page_transition.dart';
  7. import 'package:photos/core/configuration.dart';
  8. import 'package:photos/models/file.dart';
  9. import 'package:photos/models/file_type.dart';
  10. import 'package:photos/models/magic_metadata.dart';
  11. import 'package:photos/models/selected_files.dart';
  12. import 'package:photos/models/trash_file.dart';
  13. import 'package:photos/theme/colors.dart';
  14. import 'package:photos/theme/ente_theme.dart';
  15. import 'package:photos/ui/create_collection_page.dart';
  16. import 'package:photos/ui/viewer/file/file_info_widget.dart';
  17. import 'package:photos/utils/delete_file_util.dart';
  18. import 'package:photos/utils/magic_util.dart';
  19. import 'package:photos/utils/share_util.dart';
  20. class FadingBottomBar extends StatefulWidget {
  21. final File file;
  22. final Function(File) onEditRequested;
  23. final bool showOnlyInfoButton;
  24. const FadingBottomBar(
  25. this.file,
  26. this.onEditRequested,
  27. this.showOnlyInfoButton, {
  28. Key key,
  29. }) : super(key: key);
  30. @override
  31. FadingBottomBarState createState() => FadingBottomBarState();
  32. }
  33. class FadingBottomBarState extends State<FadingBottomBar> {
  34. bool _shouldHide = false;
  35. final GlobalKey shareButtonKey = GlobalKey();
  36. @override
  37. Widget build(BuildContext context) {
  38. return _getBottomBar();
  39. }
  40. void hide() {
  41. setState(() {
  42. _shouldHide = true;
  43. });
  44. }
  45. void show() {
  46. setState(() {
  47. _shouldHide = false;
  48. });
  49. }
  50. void safeRefresh() {
  51. if (mounted) {
  52. setState(() {});
  53. }
  54. }
  55. Widget _getBottomBar() {
  56. final List<Widget> children = [];
  57. children.add(
  58. Tooltip(
  59. message: "Info",
  60. child: Padding(
  61. padding: const EdgeInsets.only(top: 12, bottom: 12),
  62. child: IconButton(
  63. icon: Icon(
  64. Platform.isAndroid ? Icons.info_outline : CupertinoIcons.info,
  65. color: Colors.white,
  66. ),
  67. onPressed: () {
  68. _displayInfo(widget.file);
  69. },
  70. ),
  71. ),
  72. ),
  73. );
  74. if (widget.file is TrashFile) {
  75. _addTrashOptions(children);
  76. }
  77. if (!widget.showOnlyInfoButton && widget.file is! TrashFile) {
  78. if (widget.file.fileType == FileType.image ||
  79. widget.file.fileType == FileType.livePhoto) {
  80. children.add(
  81. Tooltip(
  82. message: "Edit",
  83. child: Padding(
  84. padding: const EdgeInsets.only(top: 12, bottom: 12),
  85. child: IconButton(
  86. icon: const Icon(
  87. Icons.tune_outlined,
  88. color: Colors.white,
  89. ),
  90. onPressed: () {
  91. widget.onEditRequested(widget.file);
  92. },
  93. ),
  94. ),
  95. ),
  96. );
  97. }
  98. if (widget.file.uploadedFileID != null &&
  99. widget.file.ownerID == Configuration.instance.getUserID()) {
  100. final bool isArchived =
  101. widget.file.magicMetadata.visibility == visibilityArchive;
  102. children.add(
  103. Tooltip(
  104. message: isArchived ? "Unhide" : "Hide",
  105. child: Padding(
  106. padding: const EdgeInsets.only(top: 12, bottom: 12),
  107. child: IconButton(
  108. icon: Icon(
  109. isArchived
  110. ? Icons.visibility_outlined
  111. : Icons.visibility_off_outlined,
  112. color: Colors.white,
  113. ),
  114. onPressed: () async {
  115. await changeVisibility(
  116. context,
  117. [widget.file],
  118. isArchived ? visibilityVisible : visibilityArchive,
  119. );
  120. safeRefresh();
  121. },
  122. ),
  123. ),
  124. ),
  125. );
  126. }
  127. children.add(
  128. Tooltip(
  129. message: "Share",
  130. child: Padding(
  131. padding: const EdgeInsets.only(top: 12, bottom: 12),
  132. child: IconButton(
  133. key: shareButtonKey,
  134. icon: Icon(
  135. Platform.isAndroid
  136. ? Icons.share_outlined
  137. : CupertinoIcons.share,
  138. color: Colors.white,
  139. ),
  140. onPressed: () {
  141. share(context, [widget.file], shareButtonKey: shareButtonKey);
  142. },
  143. ),
  144. ),
  145. ),
  146. );
  147. }
  148. final safeAreaBottomPadding = MediaQuery.of(context).padding.bottom * .5;
  149. return IgnorePointer(
  150. ignoring: _shouldHide,
  151. child: AnimatedOpacity(
  152. opacity: _shouldHide ? 0 : 1,
  153. duration: const Duration(milliseconds: 150),
  154. child: Align(
  155. alignment: Alignment.bottomCenter,
  156. child: Container(
  157. decoration: BoxDecoration(
  158. gradient: LinearGradient(
  159. begin: Alignment.topCenter,
  160. end: Alignment.bottomCenter,
  161. colors: [
  162. Colors.transparent,
  163. Colors.black.withOpacity(0.6),
  164. Colors.black.withOpacity(0.72),
  165. ],
  166. stops: const [0, 0.8, 1],
  167. ),
  168. ),
  169. child: Padding(
  170. padding: EdgeInsets.only(bottom: safeAreaBottomPadding),
  171. child: Column(
  172. mainAxisSize: MainAxisSize.min,
  173. children: [
  174. widget.file.caption.isNotEmpty
  175. ? Padding(
  176. padding: const EdgeInsets.fromLTRB(
  177. 16,
  178. 28,
  179. 16,
  180. 12,
  181. ),
  182. child: Text(
  183. widget.file.caption,
  184. style: getEnteTextTheme(context)
  185. .small
  186. .copyWith(color: textBaseDark),
  187. ),
  188. )
  189. : const SizedBox.shrink(),
  190. Row(
  191. mainAxisAlignment: MainAxisAlignment.spaceAround,
  192. children: children,
  193. ),
  194. ],
  195. ),
  196. ),
  197. ),
  198. ),
  199. ),
  200. );
  201. }
  202. void _addTrashOptions(List<Widget> children) {
  203. children.add(
  204. Tooltip(
  205. message: "Restore",
  206. child: Padding(
  207. padding: const EdgeInsets.only(top: 12, bottom: 12),
  208. child: IconButton(
  209. icon: const Icon(
  210. Icons.restore_outlined,
  211. color: Colors.white,
  212. ),
  213. onPressed: () {
  214. final selectedFiles = SelectedFiles();
  215. selectedFiles.toggleSelection(widget.file);
  216. Navigator.push(
  217. context,
  218. PageTransition(
  219. type: PageTransitionType.bottomToTop,
  220. child: CreateCollectionPage(
  221. selectedFiles,
  222. null,
  223. actionType: CollectionActionType.restoreFiles,
  224. ),
  225. ),
  226. );
  227. },
  228. ),
  229. ),
  230. ),
  231. );
  232. children.add(
  233. Tooltip(
  234. message: "Delete",
  235. child: Padding(
  236. padding: const EdgeInsets.only(top: 12, bottom: 12),
  237. child: IconButton(
  238. icon: const Icon(
  239. Icons.delete_forever_outlined,
  240. color: Colors.white,
  241. ),
  242. onPressed: () async {
  243. final trashedFile = <TrashFile>[];
  244. trashedFile.add(widget.file);
  245. if (await deleteFromTrash(context, trashedFile) == true) {
  246. Navigator.pop(context);
  247. }
  248. },
  249. ),
  250. ),
  251. ),
  252. );
  253. }
  254. Future<void> _displayInfo(File file) async {
  255. final colorScheme = getEnteColorScheme(context);
  256. return showBarModalBottomSheet(
  257. topControl: const SizedBox.shrink(),
  258. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0)),
  259. backgroundColor: colorScheme.backgroundBase,
  260. barrierColor: backdropFaintDark,
  261. context: context,
  262. builder: (BuildContext context) {
  263. return Padding(
  264. padding:
  265. EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
  266. child: FileInfoWidget(file),
  267. );
  268. },
  269. );
  270. }
  271. }