tiktok_video.dart
3.91 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
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:Parlando/tiktok/style/style.dart';
import 'package:Parlando/tiktok/widgets/tiktok_video_gesture.dart';
import 'package:Parlando/extension/int_extension.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? leftPoemArea;
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,
this.leftPoemArea,
}) : super(key: key);
@override
Widget build(BuildContext context) {
// 右边的按钮列表
Widget rightButtons = rightButtonColumn ?? Container();
Widget leftPoem = leftPoemArea ?? Container();
// 视频加载的动画 // TODO 不要删除,后续添加加载逻辑
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,
),
),
// videoLoading, // TODO 加载动画需要修补
hidePauseIcon
? Container()
: Container(
height: double.infinity,
width: double.infinity,
alignment: Alignment.center,
child: Icon(
Icons.play_circle_outline,
size: 120.px,
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.bottomCenter,
child: leftPoem,
),
Container(
height: double.infinity,
width: double.infinity,
alignment: Alignment.bottomRight,
child: rightButtons,
),
],
);
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 SizedBox(
height: 64.px,
width: 64.px,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SpinKitWave(
size: 36,
color: Colors.white.withOpacity(0.3),
),
Container(
padding: EdgeInsets.all(50.px),
child: Text(
tag,
style: StandardTextStyle.normalWithOpacity,
),
),
],
),
);
}
}