Hibok
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

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