Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

398 line
12 KiB

  1. import 'dart:io';
  2. import 'package:chat/data/WebData.dart';
  3. import 'package:chat/data/constants.dart';
  4. import 'package:chat/generated/i18n.dart';
  5. import 'package:chat/utils/CustomUI.dart';
  6. import 'package:chat/utils/LoadingDialog.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:image_picker/image_picker.dart';
  9. import 'package:oktoast/oktoast.dart';
  10. import 'package:video_player/video_player.dart';
  11. import '../data/UserData.dart';
  12. import '../utils/TokenMgr.dart';
  13. import "package:dio/dio.dart";
  14. import '../utils/HttpUtil.dart';
  15. import '../utils/ShadowButton.dart';
  16. var cardWidth;
  17. class VerificationCenterPage extends StatefulWidget {
  18. VerificationCenterPage({Key key}) : super(key: key);
  19. _VerificationCenterPageState createState() => _VerificationCenterPageState();
  20. }
  21. class _VerificationCenterPageState extends State<VerificationCenterPage> {
  22. String code = '';
  23. String videoUrl = '';
  24. String buttonStr = '';
  25. File videoFile;
  26. int state = 3;
  27. bool isPostVideo = false;
  28. bool isShowPlayButton = true;
  29. VideoPlayerController _controller;
  30. static const Separate_Size = 17.0;
  31. bool isLoadingFish = false;
  32. bool isLoadingVideoFinish = false;
  33. @override
  34. void initState() {
  35. super.initState();
  36. getInfo();
  37. }
  38. @override
  39. void dispose() {
  40. if (_controller != null) {
  41. _controller.dispose();
  42. }
  43. super.dispose();
  44. }
  45. getInfo() async {
  46. Map data = {
  47. "userId": UserData().basicInfo.userId,
  48. };
  49. data['sign'] = TokenMgr().getSign(data);
  50. // 0=审核中,1=申请成功,2=申请失败,3未申请
  51. Response res = await HttpUtil().post('user/female/authInfo',
  52. data: data, failback: () => Navigator.of(context).pop());
  53. Map resData = res.data;
  54. if (resData['code'] == 0) {
  55. code = resData['data']['Code'];
  56. state = resData['data']['Status'];
  57. if (state == 0 || state == 1) {
  58. isPostVideo = true;
  59. videoUrl = resData['data']['AttestationValue'];
  60. _controller = VideoPlayerController.network(videoUrl)
  61. ..initialize().then((_) {
  62. setState(() {
  63. isLoadingVideoFinish = true;
  64. });
  65. });
  66. _controller.addListener(() {
  67. if (_controller.value.position >= _controller.value.duration) {
  68. isShowPlayButton = true;
  69. setState(() {});
  70. }
  71. });
  72. buttonStr = I18n.of(context).under_review;
  73. }
  74. isLoadingFish = true;
  75. setState(() {});
  76. }
  77. }
  78. @override
  79. Widget build(BuildContext context) {
  80. Size screenSize = MediaQuery.of(context).size;
  81. cardWidth = screenSize.width;
  82. Widget content = Scaffold(
  83. appBar: AppBar(
  84. backgroundColor: AppColors.NewAppbarBgColor,
  85. title: Text(
  86. I18n.of(context).certification_center,
  87. style: TextStyle(color: AppColors.NewAppbarTextColor),
  88. ),
  89. centerTitle: true,
  90. leading: CustomUI.buildCustomLeading(context),
  91. elevation: 0,
  92. ),
  93. body: SafeArea(
  94. child: Container(
  95. padding: EdgeInsets.symmetric(horizontal: 10),
  96. color: const Color(0xFFF4F4F4),
  97. height: MediaQuery.of(context).size.height,
  98. child: SingleChildScrollView(
  99. child: _buildBody(),
  100. ))));
  101. return CustomUI.buildPageLoading(context, content, !isLoadingFish);
  102. }
  103. BoxDecoration getCardDecoration() {
  104. return new BoxDecoration(
  105. color: Colors.white,
  106. boxShadow: [
  107. BoxShadow(
  108. color: Color.fromRGBO(230, 230, 230, 1),
  109. offset: Offset(0, 10),
  110. blurRadius: 8,
  111. )
  112. ],
  113. borderRadius: BorderRadius.all(Radius.circular(10)));
  114. }
  115. Widget _buildBody() {
  116. return Column(
  117. children: <Widget>[
  118. _buildVideo(),
  119. _buildTip1(),
  120. SizedBox(height: Separate_Size),
  121. _buildTip2(),
  122. SizedBox(height: Separate_Size),
  123. _buildTip3(),
  124. SizedBox(height: Separate_Size),
  125. _buildRegisterButton(),
  126. Container(
  127. margin: EdgeInsets.only(top: 10.5, bottom: Separate_Size),
  128. child: Text(
  129. I18n.of(context).after_authentication,
  130. style: TextStyle(fontSize: 12, color: Constants.GreyTextColor),
  131. ),
  132. ),
  133. ],
  134. );
  135. }
  136. Widget _buildVideo() {
  137. Widget stack = Stack(
  138. children: <Widget>[
  139. Container(
  140. height: 230,
  141. alignment: Alignment.center,
  142. child: _controller != null && _controller.value.initialized
  143. ? AspectRatio(
  144. aspectRatio: _controller.value.aspectRatio,
  145. child: VideoPlayer(_controller),
  146. )
  147. : Container(),
  148. ),
  149. InkWell(
  150. highlightColor: Colors.transparent,
  151. radius: 0,
  152. onTap: () {
  153. setState(() {
  154. if (!_controller.value.isPlaying) {
  155. _controller.seekTo(Duration());
  156. _controller.play();
  157. isShowPlayButton = false;
  158. setState(() {});
  159. }
  160. });
  161. },
  162. child: Container(
  163. height: 230,
  164. alignment: Alignment.center,
  165. child: !isLoadingVideoFinish
  166. ? CircularProgressIndicator(
  167. valueColor: AlwaysStoppedAnimation(Colors.black38))
  168. : Container(
  169. color: Colors.black38,
  170. child: Icon(
  171. Icons.play_arrow,
  172. size:
  173. _controller != null && _controller.value.isPlaying
  174. ? 0
  175. : 50,
  176. color: Colors.white,
  177. ),
  178. )))
  179. ],
  180. );
  181. Widget img = Container(
  182. child: Image.asset(
  183. 'assets/images/login/rzzx.png',
  184. height: 230,
  185. ),
  186. );
  187. return (videoUrl == '') ? img : stack;
  188. }
  189. Widget _buildTip1() {
  190. return Container(
  191. alignment: Alignment.center,
  192. padding: EdgeInsets.only(top: 15, left: 20, right: 20, bottom: 15),
  193. width: cardWidth,
  194. child: Column(
  195. children: <Widget>[
  196. Container(
  197. padding: EdgeInsets.only(bottom: 10),
  198. alignment: Alignment.centerLeft,
  199. child: Text(
  200. I18n.of(context).certification_conditions,
  201. textScaleFactor: 1.0,
  202. style: TextStyle(
  203. fontSize: 16,
  204. fontWeight: FontWeight.w600,
  205. color: Constants.BlackTextColor),
  206. )),
  207. Container(
  208. padding: EdgeInsets.only(bottom: 5),
  209. alignment: Alignment.centerLeft,
  210. child: Text(I18n.of(context).conditions1, textScaleFactor: 1.0)),
  211. Align(
  212. alignment: Alignment.centerLeft,
  213. child: Text(I18n.of(context).conditions2, textScaleFactor: 1.0)),
  214. ],
  215. ),
  216. decoration: getCardDecoration(),
  217. );
  218. }
  219. Widget _buildTip2() {
  220. return Container(
  221. alignment: Alignment.center,
  222. padding: EdgeInsets.only(top: 15, left: 20, right: 20, bottom: 15),
  223. width: cardWidth,
  224. child: Column(
  225. children: <Widget>[
  226. Container(
  227. padding: EdgeInsets.only(bottom: 10),
  228. alignment: Alignment.centerLeft,
  229. child: Text(
  230. I18n.of(context).verification_method,
  231. textScaleFactor: 1.0,
  232. style: TextStyle(
  233. fontSize: 16,
  234. fontWeight: FontWeight.w600,
  235. color: Constants.BlackTextColor),
  236. )),
  237. Container(
  238. alignment: Alignment.centerLeft,
  239. child: Text(I18n.of(context).method3, textScaleFactor: 1.0)),
  240. Container(
  241. padding: EdgeInsets.only(bottom: 10, top: 10),
  242. alignment: Alignment.center,
  243. child: Text(
  244. code,
  245. textScaleFactor: 1.0,
  246. style: TextStyle(
  247. fontSize: 30,
  248. fontWeight: FontWeight.w600,
  249. color: const Color(0xFFFF4523)),
  250. )),
  251. Align(
  252. alignment: Alignment.centerLeft,
  253. child: Text(I18n.of(context).method4, textScaleFactor: 1.0)),
  254. ],
  255. ),
  256. decoration: getCardDecoration(),
  257. );
  258. }
  259. Widget _buildTip3() {
  260. var str = '';
  261. if (state == 0) {
  262. str = I18n.of(context).certificating;
  263. } else if (state == 2) {
  264. str = I18n.of(context).re_upload2;
  265. } else {
  266. str = I18n.of(context).not_authenticate;
  267. }
  268. return Container(
  269. alignment: Alignment.center,
  270. padding: EdgeInsets.only(top: 15, left: 20, right: 20, bottom: 15),
  271. width: cardWidth,
  272. child: Column(
  273. children: <Widget>[
  274. Container(
  275. padding: EdgeInsets.only(bottom: 10),
  276. alignment: Alignment.centerLeft,
  277. child: Text(
  278. I18n.of(context).certification_status,
  279. textScaleFactor: 1.0,
  280. style: TextStyle(
  281. fontSize: 16,
  282. fontWeight: FontWeight.w600,
  283. color: Constants.BlackTextColor),
  284. )),
  285. Container(
  286. padding: EdgeInsets.only(bottom: 5),
  287. alignment: Alignment.centerLeft,
  288. child: Text(str, textScaleFactor: 1.0)),
  289. ],
  290. ),
  291. decoration: getCardDecoration(),
  292. );
  293. }
  294. void _sendVideo() async {
  295. showDialog(
  296. context: context,
  297. barrierDismissible: false,
  298. builder: (BuildContext context) {
  299. return LoadingDialog(
  300. text: "",
  301. );
  302. });
  303. videoFile = await ImagePicker.pickVideo(source: ImageSource.camera);
  304. Navigator.of(context).pop();
  305. if (videoFile != null) {
  306. var size = await videoFile.length();
  307. if (size > 104857600) {
  308. showToast(I18n.of(context).video_more_big);
  309. videoFile = null;
  310. return;
  311. }
  312. Map data = {"type": 5, "userId": UserData().basicInfo.userId};
  313. data['sign'] = TokenMgr().getSign(data);
  314. Response res = await HttpUtil().uploadFile(
  315. videoFile, data, 'upload/file/postflie', 'video',
  316. isShowLoading: true);
  317. var resData = res.data;
  318. if (resData['code'] == 0) {
  319. showToast(I18n.of(context).success);
  320. videoUrl = resData['msg'];
  321. isPostVideo = true;
  322. _controller = VideoPlayerController.file(videoFile)
  323. ..initialize().then((_) {
  324. // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
  325. setState(() {});
  326. });
  327. _controller.addListener(() {
  328. if (_controller.value.position >= _controller.value.duration) {
  329. isShowPlayButton = true;
  330. setState(() {});
  331. }
  332. });
  333. buttonStr = I18n.of(context).submit;
  334. setState(() {});
  335. }
  336. }
  337. }
  338. void postInfo() async {
  339. Map data = {
  340. "userId": UserData().basicInfo.userId,
  341. "videoUrl": WebData().deleteDemain(videoUrl),
  342. };
  343. data['sign'] = TokenMgr().getSign(data);
  344. Response res = await HttpUtil().post('user/auth/video', data: data);
  345. Map resData = res.data;
  346. if (resData['code'] == 0) {
  347. showToast(resData['msg']);
  348. state = 0;
  349. buttonStr = I18n.of(context).under_review;
  350. setState(() {});
  351. }
  352. }
  353. //构建注册按钮
  354. Widget _buildRegisterButton() {
  355. Text text = new Text(
  356. buttonStr == '' ? I18n.of(context).upload_video : buttonStr,
  357. textScaleFactor: 1.0,
  358. style: TextStyle(fontSize: 15, color: Colors.white));
  359. LinearGradient gradientColor = new LinearGradient(colors: <Color>[
  360. Constants.ConfrimButtonColor,
  361. Constants.ConfrimButtonColor,
  362. ]);
  363. return new Container(
  364. margin: EdgeInsets.only(top: 5.5),
  365. height: 44,
  366. width: MediaQuery.of(context).size.width * 0.86,
  367. child: ShadowButton().builder(gradientColor, text,
  368. state == 0 ? () {} : (videoUrl == '' ? _sendVideo : postInfo)),
  369. );
  370. }
  371. }