11import 'dart:typed_data' ;
22
33import 'package:blurhash_dart/blurhash_dart.dart' ;
4+ import 'package:clipboard/utils/clipboard_actions.dart' ;
45import 'package:copycat_base/constants/strings/asset_constants.dart' ;
56import 'package:copycat_base/constants/widget_styles.dart' ;
67import 'package:copycat_base/db/clipboard_item/clipboard_item.dart' ;
8+ import 'package:copycat_base/l10n/l10n.dart' ;
79import 'package:flutter/material.dart' ;
810import 'package:flutter_svg_provider/flutter_svg_provider.dart' ;
911import 'package:image/image.dart' as img;
@@ -18,7 +20,7 @@ class MediaClipPreviewCard extends StatelessWidget {
1820 required this .isMobile,
1921 });
2022
21- ImageProvider getPreview () {
23+ ImageProvider ? getPreview () {
2224 if (item.localPath != null ) {
2325 if (item.fileMimeType! .contains ("svg" )) {
2426 return Svg (
@@ -40,35 +42,55 @@ class MediaClipPreviewCard extends StatelessWidget {
4042 }
4143 }
4244
43- Icon getIcon () {
45+ void open () async {
46+ openFile (item);
47+ }
48+
49+ Widget ? getPrimaryView (BuildContext context) {
4450 if (item.fileMimeType != null ) {
4551 if (item.fileMimeType! .startsWith ("image" )) {
46- return const Icon (
47- Icons .image,
48- color: Colors .white,
52+ return const Align (
53+ alignment: Alignment (- .98 , - .98 ),
54+ child: Icon (
55+ Icons .image,
56+ color: Colors .white,
57+ ),
4958 );
5059 }
5160 if (item.fileMimeType! .startsWith ("video" )) {
52- return const Icon (
53- Icons .ondemand_video_rounded,
54- color: Colors .white,
61+ if (item.inCache) {
62+ return Center (
63+ child: ElevatedButton .icon (
64+ icon: const Icon (Icons .play_arrow_rounded),
65+ onPressed: open,
66+ label: Text (context.locale.open),
67+ ),
68+ );
69+ }
70+ return const Align (
71+ alignment: Alignment (- .98 , - .98 ),
72+ child: Icon (
73+ Icons .video_file,
74+ color: Colors .white,
75+ ),
5576 );
5677 }
5778 if (item.fileMimeType! .startsWith ("audio" )) {
58- return const Icon (
59- Icons .audiotrack,
60- color: Colors .white,
79+ return const Align (
80+ alignment: Alignment (- .98 , - .98 ),
81+ child: Icon (
82+ Icons .audiotrack,
83+ color: Colors .white,
84+ ),
6185 );
6286 }
6387 }
64- return const Icon (
65- Icons .image,
66- color: Colors .white,
67- );
88+ return null ;
6889 }
6990
7091 @override
7192 Widget build (BuildContext context) {
93+ final preview = getPreview ();
7294 return Card .filled (
7395 margin: isMobile
7496 ? const EdgeInsets .only (
@@ -86,20 +108,19 @@ class MediaClipPreviewCard extends StatelessWidget {
86108 ),
87109 child: DecoratedBox (
88110 decoration: BoxDecoration (
89- image: DecorationImage (
90- image: getPreview (),
91- fit: BoxFit .contain,
92- ),
111+ image: preview != null
112+ ? DecorationImage (
113+ image: preview,
114+ fit: BoxFit .contain,
115+ )
116+ : null ,
93117 borderRadius: isMobile
94118 ? radius12
95119 : const BorderRadius .horizontal (
96120 left: Radius .circular (12 ),
97121 ),
98122 ),
99- child: Align (
100- alignment: const Alignment (0.95 , 0.95 ),
101- child: getIcon (),
102- ),
123+ child: getPrimaryView (context),
103124 ),
104125 );
105126 }
0 commit comments