-
Notifications
You must be signed in to change notification settings - Fork 7
/
media_preview.dart
169 lines (161 loc) · 5.43 KB
/
media_preview.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import 'package:flutter/material.dart';
import 'package:gallery_service/gallery_service.dart';
import 'package:layout_service/layout_service.dart';
import 'package:routers_service/routers_service.dart';
const kIconSizeSelected = 0.4;
const kIconSizeUnselected = 0.25;
class MediaPreviewWidget extends StatefulWidget {
MediaPreviewWidget({
required this.index,
required this.gridView,
required this.isVideoType,
required this.isSelected,
required this.media,
required this.containerHeight,
required this.selectionAnimationDuration,
required this.selectionAnimationCurve,
required this.onUnselectedTapped,
});
final int index;
final bool gridView;
final bool isVideoType;
final bool isSelected;
final Media media;
final double containerHeight;
final Duration selectionAnimationDuration;
final Curve selectionAnimationCurve;
final VoidCallback onUnselectedTapped;
@override
_MediaPreviewWidgetState createState() => _MediaPreviewWidgetState();
}
class _MediaPreviewWidgetState extends State<MediaPreviewWidget> {
bool _onHover = false;
@override
Widget build(BuildContext context) {
final playIconSize = widget.isSelected
? widget.containerHeight * kIconSizeSelected
: widget.containerHeight * kIconSizeUnselected;
final stackedWidget = [
Positioned.fill(
child: Opacity(
opacity: 0.3,
child: Container(
color: Colors.black,
),
),
),
TweenAnimationBuilder<double>(
tween: Tween<double>(
begin: playIconSize,
end: playIconSize,
),
duration: widget.selectionAnimationDuration,
curve: widget.selectionAnimationCurve,
builder: (context, size, child) {
return Icon(
Icons.play_circle_outline,
color: Colors.white,
size: size,
);
},
),
];
return Center(
child: Card(
elevation: 10.0,
clipBehavior: Clip.antiAliasWithSaveLayer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
child: InkWell(
onTap: () {
if (widget.isSelected || widget.gridView) {
final browserState =
GalleryRouterStateScope.of(context)!.browserState!;
final newState = browserState
.rebuild((b) => b..media = widget.media.toBuilder());
final newPath = MediaFullscreenPath(
browserState.galleriesHistory.last, widget.media.path);
GalleryRouterStateScope.of(context)!
..routePath = newPath
..browserState = newState;
} else {
widget.onUnselectedTapped();
}
},
child: Hero(
tag: widget.media.path,
child: AnimatedContainer(
duration: widget.selectionAnimationDuration,
curve: widget.selectionAnimationCurve,
height: widget.containerHeight,
child: Stack(
alignment: Alignment.center,
fit: StackFit.passthrough,
children: [
Image.network(
widget.media.thumbnail,
fit: BoxFit.fitHeight,
frameBuilder:
(context, child, frame, wasSynchronouslyLoaded) {
if (wasSynchronouslyLoaded) {
return child;
}
return AnimatedOpacity(
child: child,
opacity: frame == null ? 0 : 1,
duration: const Duration(seconds: 1),
curve: Curves.easeOut,
);
},
),
if (widget.isVideoType)
for (Widget widget in stackedWidget) widget,
if (isDesktop())
Positioned.fill(
child: AnimatedOpacity(
opacity: widget.gridView
? 1.0
: widget.isSelected
? 0.0
: 1.0,
duration: widget.selectionAnimationDuration,
curve: widget.selectionAnimationCurve,
child: AnimatedOpacity(
opacity: _onHover ||
(widget.isSelected && !widget.gridView)
? 0.0
: 1.0,
duration: const Duration(milliseconds: 250),
child: MouseRegion(
onEnter: _onMouseEnter,
onExit: _onMouseExit,
child: Opacity(
opacity: 0.4,
child: Container(
color: Colors.black,
),
),
),
),
),
),
],
),
),
),
),
),
);
}
void _onMouseEnter(PointerEvent details) {
setState(() {
_onHover = true;
});
}
void _onMouseExit(PointerEvent details) {
setState(() {
_onHover = false;
});
}
}