fading_bottom_bar.dart 7.1 KB

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