tiktok_video.dart
5.23 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:one_poem/tiktok/style/style.dart';
import 'package:one_poem/tiktok/widgets/tiktok_video_gesture.dart';
///
/// TikTok风格的一个视频页组件,覆盖在video上,提供以下功能:
/// 播放按钮的遮罩
/// 单击事件
/// 点赞事件回调(每次)
/// 长宽比控制
/// 底部padding(用于适配有沉浸式底部状态栏时)
///
class TikTokVideoPage extends StatelessWidget {
final Widget? video;
final double aspectRatio;
final String? tag;
final double bottomPadding;
final Widget? rightButtonColumn;
final Widget? topInfo;
final Widget? userInfoWidget;
final bool hidePauseIcon;
final Function? onAddFavorite;
final Function? onSingleTap;
const TikTokVideoPage({
Key? key,
this.bottomPadding = 16,
this.tag,
this.rightButtonColumn,
this.topInfo,
this.userInfoWidget,
this.onAddFavorite,
this.onSingleTap,
this.video,
this.aspectRatio = 9 / 16.0,
this.hidePauseIcon = false,
}) : super(key: key);
@override
Widget build(BuildContext context) {
// 右边的按钮列表
Widget rightButtons = rightButtonColumn ?? Container();
// 用户信息
Widget userInfo = userInfoWidget ??
VideoUserInfo(
bottomPadding: bottomPadding,
);
// 视频加载的动画
// Widget videoLoading = VideoLoadingPlaceHolder(tag: tag);
// 视频播放页
Widget videoContainer = Stack(
children: <Widget>[
Container(
height: double.infinity,
width: double.infinity,
color: Colors.black,
alignment: Alignment.center,
child: AspectRatio(
aspectRatio: aspectRatio,
child: video,
),
),
TikTokVideoGesture(
onAddFavorite: onAddFavorite,
onSingleTap: onSingleTap,
child: Container(
color: ColorPlate.clear,
height: double.infinity,
width: double.infinity,
),
),
hidePauseIcon
? Container()
: Container(
height: double.infinity,
width: double.infinity,
alignment: Alignment.center,
child: Icon(
Icons.play_circle_outline,
size: 120,
color: Colors.white.withOpacity(0.4),
),
),
],
);
Widget body = Stack(
children: <Widget>[
videoContainer,
Container(
height: double.infinity,
width: double.infinity,
alignment: Alignment.topCenter,
child: topInfo,
),
Container(
height: double.infinity,
width: double.infinity,
alignment: Alignment.bottomRight,
child: rightButtons,
),
Container(
height: double.infinity,
width: double.infinity,
alignment: Alignment.bottomLeft,
child: userInfo,
),
],
);
return body;
}
}
class VideoLoadingPlaceHolder extends StatelessWidget {
const VideoLoadingPlaceHolder({
Key? key,
required this.tag,
}) : super(key: key);
final String tag;
@override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
colors: <Color>[
Colors.blue,
Colors.green,
],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SpinKitWave(
size: 36,
color: Colors.white.withOpacity(0.3),
),
Container(
padding: const EdgeInsets.all(50),
child: Text(
tag,
style: StandardTextStyle.normalWithOpacity,
),
),
],
),
);
}
}
class VideoUserInfo extends StatelessWidget {
final String? desc;
// final Function onGoodGift;
const VideoUserInfo({
Key? key,
required this.bottomPadding,
// @required this.onGoodGift,
this.desc,
}) : super(key: key);
final double bottomPadding;
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(
left: 12,
bottom: bottomPadding,
),
margin: const EdgeInsets.only(right: 80),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text(
'每日一言',
style: StandardTextStyle.big,
),
Container(height: 6),
Text(
desc ?? '#一言 临境',
style: StandardTextStyle.normal,
),
Container(height: 6),
Row(
children: const <Widget>[
// Icon(Icons.music_note, size: 14),
Expanded(
child: Text(
'宜 · 安静/看书/喝茶',
maxLines: 9,
style: StandardTextStyle.normal,
),
)
],
)
],
),
);
}
}