fading_bottom_bar.dart 7.0 KB

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