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.
 
 
 
 
 
 

681 lines
23 KiB

  1. import 'dart:async';
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:chat/chat/ChatPage.dart';
  4. import 'package:chat/data/UserData.dart';
  5. import 'package:chat/data/chat_data_mgr.dart';
  6. import 'package:chat/data/group_data_mgr.dart';
  7. import 'package:chat/home/add_friend.dart';
  8. import 'package:chat/home/group_announcement.dart';
  9. import 'package:chat/home/group_manage_page.dart';
  10. import 'package:chat/models/group_info_model.dart';
  11. import 'package:chat/models/money_change.dart';
  12. import 'package:chat/models/ref_name_provider.dart';
  13. import 'package:chat/utils/MessageMgr.dart';
  14. import 'package:chat/utils/group_member_model.dart';
  15. import 'package:chat/utils/msgHandler.dart';
  16. import 'package:chat/utils/screen.dart';
  17. import 'package:chat/utils/sp_utils.dart';
  18. import 'package:flutter/cupertino.dart';
  19. import 'package:flutter/material.dart';
  20. import 'package:flutter/services.dart';
  21. import 'package:oktoast/oktoast.dart';
  22. import 'package:provider/provider.dart';
  23. import '../../data/constants.dart';
  24. import '../../generated/i18n.dart';
  25. import '../../r.dart';
  26. import '../../utils/CustomUI.dart';
  27. import '../../utils/FullWithButton.dart';
  28. import '../../utils/app_navigator.dart';
  29. import '../create_group_view.dart';
  30. import 'package:chat/utils/PopUpMenu.dart' as myPop;
  31. class TranslationButlerPage extends StatefulWidget {
  32. final GroupInfoModel groupInfoModel;
  33. TranslationButlerPage({Key key, this.groupInfoModel}) : super(key: key);
  34. @override
  35. State<StatefulWidget> createState() {
  36. return TranslationButlerPageState();
  37. }
  38. }
  39. class TranslationButlerPageState extends State<TranslationButlerPage> {
  40. int curToLang = 1;
  41. int curSourceLang = UserData().language;
  42. int curScenes = 0;
  43. List langList;
  44. List scenesList;
  45. String extraMsg;
  46. @override
  47. void initState() {
  48. super.initState();
  49. initData();
  50. WidgetsBinding.instance.addPostFrameCallback((_) {
  51. Future.delayed(Duration(seconds: 2), () {
  52. // CustomUI.buildTranslationHelperOrderDialog(context);
  53. Navigator.of(context).push(
  54. new MaterialPageRoute(
  55. builder: (context) {
  56. return ChatPage(
  57. key: Key('Chat'),
  58. friendId: 100006,
  59. isTranslateButler: true,
  60. );
  61. },
  62. ),
  63. );
  64. });
  65. });
  66. }
  67. initData() async {
  68. String time = (await SPUtils.get(Constants.TranslationHelper));
  69. if (time != null) {
  70. print('time:$time');
  71. int second = int.parse(time) ~/ 1000;
  72. // if(DateTime.now().millisecondsSinceEpoch~/1000-second>5*3600){ ///超过5小时清除缓存记录
  73. // SPUtils.save(Constants.TranslationHelper,null);
  74. // return;
  75. // }
  76. secondsPassed =
  77. ((DateTime.now().millisecondsSinceEpoch ~/ 1000 - second));
  78. apply();
  79. } else {
  80. print('time: null');
  81. }
  82. }
  83. apply() {
  84. isApply = false;
  85. timer = Timer.periodic(Duration(seconds: 1), (Timer t) {
  86. handleTick();
  87. });
  88. setState(() {});
  89. }
  90. @override
  91. void didChangeDependencies() {
  92. super.didChangeDependencies();
  93. langList = [
  94. I18n.of(context).english,
  95. I18n.of(context).Vietnamese,
  96. I18n.of(context).traditional_Chinese,
  97. I18n.of(context).Simplified_Chinese,
  98. I18n.of(context).Korean,
  99. I18n.of(context).Japanese,
  100. ];
  101. scenesList = [
  102. I18n.of(context).translation_scenes_1,
  103. I18n.of(context).translation_scenes_2,
  104. I18n.of(context).translation_scenes_3,
  105. I18n.of(context).translation_scenes_4,
  106. ];
  107. }
  108. @override
  109. void dispose() {
  110. // MessageMgr().off('Update Group Info', updateGroupInfo);
  111. timer?.cancel();
  112. if (!isApply && timeStamp != null) {
  113. print('保存时间戳$timeStamp');
  114. SPUtils.save(Constants.TranslationHelper, timeStamp.toString());
  115. }
  116. super.dispose();
  117. }
  118. _langPopMenu(bool isSource) {
  119. var curIndex = isSource ? curSourceLang : curToLang;
  120. return myPop.PopupMenuButton(
  121. child: Container(
  122. height: 40,
  123. width: double.maxFinite,
  124. decoration: BoxDecoration(
  125. color: Color(0xffD3E7FF),
  126. borderRadius: BorderRadius.circular(10)),
  127. child: Row(
  128. mainAxisAlignment: MainAxisAlignment.start,
  129. children: <Widget>[
  130. Expanded(
  131. child: Text(
  132. langList[curIndex],
  133. textAlign: TextAlign.center,
  134. overflow: TextOverflow.ellipsis,
  135. textScaleFactor: 1.0,
  136. style: TextStyle(color: Color(0xff4A5E76), fontSize: 14),
  137. )),
  138. Icon(IconData(0xe63b, fontFamily: Constants.IconFontFamily),
  139. size: 30, color: Color(0xff4A5E76))
  140. ],
  141. ),
  142. ),
  143. offset: Offset(0, 100),
  144. onSelected: (int index) {
  145. if (curIndex != index) {
  146. if (isSource) {
  147. curSourceLang = index;
  148. } else {
  149. curToLang = index;
  150. }
  151. print('更换翻译语言');
  152. setState(() {});
  153. }
  154. },
  155. itemBuilder: (BuildContext context) {
  156. return List<myPop.PopupMenuItem<int>>.generate(langList.length,
  157. (int i) {
  158. return myPop.PopupMenuItem(
  159. child: Container(
  160. alignment: Alignment.center,
  161. color: Colors.white,
  162. padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
  163. child: Text(langList[i],
  164. textScaleFactor: 1.0,
  165. maxLines: 1,
  166. style: TextStyle(
  167. color: i == curIndex
  168. ? Colors.blueAccent
  169. : Color(AppColors.AppBarColor),
  170. fontSize: 14)),
  171. ),
  172. value: i,
  173. );
  174. });
  175. });
  176. }
  177. _scenesPopMenu() {
  178. var curIndex = curScenes;
  179. return myPop.PopupMenuButton(
  180. child: Container(
  181. height: 40,
  182. width: double.maxFinite,
  183. child: Card(
  184. elevation: 2, // 阴影
  185. shape: RoundedRectangleBorder(
  186. borderRadius: BorderRadius.circular(10),
  187. // side: BorderSide(color: Colors.green,width: 25),
  188. ),
  189. child: Row(
  190. mainAxisAlignment: MainAxisAlignment.start,
  191. children: <Widget>[
  192. Expanded(
  193. child: Text(
  194. scenesList[curIndex],
  195. textAlign: TextAlign.center,
  196. overflow: TextOverflow.ellipsis,
  197. textScaleFactor: 1.0,
  198. style: TextStyle(color: Color(0xff3875E9), fontSize: 14),
  199. )),
  200. Icon(IconData(0xe63b, fontFamily: Constants.IconFontFamily),
  201. size: 30, color: Color(0xff4A5E76))
  202. ],
  203. ),
  204. ),
  205. ),
  206. offset: Offset(0, 100),
  207. onSelected: (int index) {
  208. if (curIndex != index) {
  209. curScenes = index;
  210. print('更换场景');
  211. setState(() {});
  212. }
  213. },
  214. itemBuilder: (BuildContext context) {
  215. return List<myPop.PopupMenuItem<int>>.generate(scenesList.length,
  216. (int i) {
  217. return myPop.PopupMenuItem(
  218. child: Container(
  219. width: Screen.width / 2 - 40,
  220. alignment: Alignment.center,
  221. color: Colors.white,
  222. padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
  223. child: Text(scenesList[i],
  224. textScaleFactor: 1.0,
  225. maxLines: 1,
  226. style: TextStyle(
  227. color: i == curIndex
  228. ? Colors.blueAccent
  229. : Color(AppColors.AppBarColor),
  230. fontSize: 14)),
  231. ),
  232. value: i,
  233. );
  234. });
  235. });
  236. }
  237. @override
  238. Widget build(BuildContext context) {
  239. Widget appBar = AppBar(
  240. backgroundColor: AppColors.NewAppbarBgColor,
  241. title: Text(
  242. I18n.of(context).translation_butler,
  243. textScaleFactor: 1.0,
  244. style: TextStyle(color: AppColors.NewAppbarTextColor),
  245. ),
  246. // leading: CustomUI.buildCustomLeading(context),
  247. centerTitle: true,
  248. actions: <Widget>[
  249. Container(
  250. child: CustomUI.buildImageLabel(R.assetsImagesCoin,
  251. Provider.of<MoneyChangeProvider>(context).money,
  252. isLeft: true),
  253. decoration: BoxDecoration(borderRadius: BorderRadius.circular(15)),
  254. ),
  255. SizedBox(
  256. width: 10,
  257. )
  258. ],
  259. );
  260. return Scaffold(
  261. appBar: appBar,
  262. body: SafeArea(
  263. child: Container(
  264. color: Color(0xffE8EAF0),
  265. child: isApply ? applyPage() : waitPage(),
  266. ),
  267. ),
  268. );
  269. }
  270. Widget applyPage() {
  271. return ListView(
  272. children: <Widget>[
  273. Padding(
  274. padding: EdgeInsets.only(left: 20, right: 10, top: 15),
  275. child: Text(
  276. I18n.of(context).translation_butler_tips,
  277. textScaleFactor: 1.0,
  278. style: TextStyle(color: Color(0xffABABAB), fontSize: 13),
  279. ),
  280. ),
  281. Container(
  282. margin: EdgeInsets.all(10),
  283. child: Card(
  284. elevation: 2, // 阴影
  285. shape: RoundedRectangleBorder(
  286. borderRadius: BorderRadius.circular(10),
  287. // side: BorderSide(color: Colors.green,width: 25),
  288. ),
  289. child: Container(
  290. padding: EdgeInsets.all(10),
  291. child: Column(
  292. crossAxisAlignment: CrossAxisAlignment.start,
  293. children: <Widget>[
  294. Padding(
  295. padding: EdgeInsets.only(bottom: 12),
  296. child: Text(
  297. I18n.of(context).choose_language,
  298. textScaleFactor: 1.0,
  299. textAlign: TextAlign.left,
  300. style: TextStyle(
  301. color: AppColors.NewAppbarTextColor, fontSize: 17),
  302. ),
  303. ),
  304. Row(
  305. children: <Widget>[
  306. Expanded(
  307. child: _langPopMenu(true),
  308. flex: 5,
  309. ),
  310. Expanded(
  311. child: InkWell(
  312. onTap: () {
  313. var temp = curSourceLang;
  314. curSourceLang = curToLang;
  315. curToLang = temp;
  316. setState(() {});
  317. },
  318. child: Container(
  319. child: Icon(
  320. IconData(
  321. 0xe669,
  322. fontFamily: Constants.IconFontFamily,
  323. ),
  324. size: 24,
  325. color: Color(0xff4A5E76),
  326. ),
  327. padding: EdgeInsets.symmetric(
  328. vertical: 5, horizontal: 5),
  329. ),
  330. ),
  331. flex: 2,
  332. ),
  333. Expanded(
  334. child: _langPopMenu(false),
  335. flex: 5,
  336. ),
  337. ],
  338. ),
  339. Row(
  340. children: <Widget>[
  341. Expanded(
  342. child: Image.asset(
  343. R.assetsImagesImgTranslationIcon,
  344. width: 195,
  345. height: 175,
  346. ),
  347. flex: 1,
  348. ),
  349. Expanded(
  350. child: Column(
  351. children: <Widget>[
  352. Text(
  353. I18n.of(context).translation_butler_scenes,
  354. textScaleFactor: 1.0,
  355. textAlign: TextAlign.left,
  356. style: TextStyle(
  357. color: AppColors.NewAppbarTextColor,
  358. fontSize: 15),
  359. ),
  360. _scenesPopMenu(),
  361. ],
  362. ),
  363. flex: 1,
  364. )
  365. ],
  366. ),
  367. Container(
  368. alignment: Alignment.topLeft,
  369. height: 100.5,
  370. width: Screen.width-50,
  371. padding: EdgeInsets.only(left: 17),
  372. // constraints: BoxConstraints(
  373. // minHeight: 82,
  374. // ),
  375. decoration: BoxDecoration(
  376. color: Color(0xFFE9EEF4),
  377. borderRadius: BorderRadius.all(Radius.circular(10))),
  378. child: TextField(
  379. keyboardAppearance: Brightness.light,
  380. decoration: new InputDecoration(
  381. hintText: I18n.of(context).set_password2,
  382. hintStyle: TextStyle(fontSize: 14),
  383. border: InputBorder.none,
  384. ),
  385. // maxLines: 1,
  386. inputFormatters: [LengthLimitingTextInputFormatter(160)],
  387. // obscureText: true,
  388. style: TextStyle(textBaseline: TextBaseline.alphabetic),
  389. onChanged: (str) {
  390. extraMsg = str;
  391. setState(() {});
  392. },
  393. ),
  394. ),
  395. Text(
  396. I18n.of(context).translation_butler_scenes_tips,
  397. textScaleFactor: 1.0,
  398. style: TextStyle(color: Color(0xFFFA7B3D), fontSize: 12),
  399. ),
  400. ],
  401. ),
  402. ),
  403. ),
  404. ),
  405. Container(
  406. margin: EdgeInsets.only(left: 70, right: 70, top: 50),
  407. height: 47,
  408. child: RaisedButton(
  409. color: Color(0xff3875E9),
  410. shape: RoundedRectangleBorder(
  411. borderRadius: BorderRadius.all(Radius.circular(10))),
  412. child: Text(
  413. I18n.of(context).translation_butler_call + ' (50h)',
  414. textScaleFactor: 1.0,
  415. style: TextStyle(color: Colors.white, fontSize: 19),
  416. ),
  417. onPressed: () {
  418. timeStamp = DateTime.now().millisecondsSinceEpoch;
  419. apply();
  420. }),
  421. ),
  422. Container(
  423. width: double.maxFinite,
  424. alignment: Alignment.center,
  425. padding: EdgeInsets.only(left: 10, right: 10, top: 15,bottom: 20),
  426. child: Text(
  427. I18n.of(context).translation_butler_rules,
  428. textScaleFactor: 1.0,
  429. style: TextStyle(color: Color(0xffABABAB), fontSize: 13),
  430. ),
  431. ),
  432. ],
  433. );
  434. }
  435. Widget waitPage() {
  436. // ~/ 取整操作
  437. int seconds = secondsPassed % 60;
  438. int minutes = secondsPassed ~/ 60;
  439. return ListView(
  440. children: <Widget>[
  441. ///当前排队人数过多。。。
  442. Container(
  443. margin: EdgeInsets.all(10),
  444. child: Card(
  445. elevation: 2, // 阴影
  446. shape: RoundedRectangleBorder(
  447. borderRadius: BorderRadius.circular(10),
  448. // side: BorderSide(color: Colors.green,width: 25),
  449. ),
  450. child: Container(
  451. // width: double.maxFinite,
  452. // color: Colors.blue,
  453. padding: EdgeInsets.fromLTRB(14, 14, 14, 22),
  454. child: Column(
  455. children: <Widget>[
  456. Padding(
  457. padding: EdgeInsets.only(bottom: 20, top: 10),
  458. child: Text(
  459. I18n.of(context).translation_butler_tips2,
  460. textScaleFactor: 1.0,
  461. textAlign: TextAlign.left,
  462. style: TextStyle(color: Color(0xff797979), fontSize: 13),
  463. ),
  464. ),
  465. Container(
  466. width: double.maxFinite,
  467. child: Row(
  468. mainAxisSize: MainAxisSize.max,
  469. mainAxisAlignment: MainAxisAlignment.spaceAround,
  470. children: <Widget>[
  471. Column(
  472. mainAxisAlignment: MainAxisAlignment.center,
  473. children: <Widget>[
  474. fixedText(
  475. I18n.of(context).translation_butler_wait_people,
  476. fontSize: 16,
  477. color: Colors.black),
  478. SizedBox(
  479. height: 10,
  480. ),
  481. RichText(
  482. maxLines: 3,
  483. textAlign: TextAlign.center,
  484. text: TextSpan(children: [
  485. TextSpan(
  486. text: '333',
  487. style: TextStyle(
  488. color: Color(0xffFF1010),
  489. fontSize: 27)),
  490. TextSpan(
  491. text: ' ' +
  492. I18n.of(context)
  493. .translation_butler_wait_people_unit,
  494. style: TextStyle(
  495. color: Colors.black, fontSize: 17)),
  496. ]))
  497. ],
  498. ),
  499. Container(
  500. width: 1,
  501. height: 65,
  502. color: Color(0xffD8D8D8),
  503. ),
  504. Column(
  505. mainAxisAlignment: MainAxisAlignment.center,
  506. children: <Widget>[
  507. fixedText(
  508. I18n.of(context).translation_butler_wait_time,
  509. fontSize: 16,
  510. color: Colors.black),
  511. SizedBox(
  512. height: 10,
  513. ),
  514. RichText(
  515. maxLines: 3,
  516. textAlign: TextAlign.center,
  517. text: TextSpan(children: [
  518. TextSpan(
  519. text: '666',
  520. style: TextStyle(
  521. color: Color(0xff3875E9),
  522. fontSize: 27)),
  523. TextSpan(
  524. text: ' ' + I18n.of(context).minute,
  525. style: TextStyle(
  526. color: Colors.black, fontSize: 17)),
  527. ]))
  528. ],
  529. ),
  530. ],
  531. ),
  532. )
  533. ],
  534. ),
  535. ),
  536. ),
  537. ),
  538. Padding(
  539. padding: EdgeInsets.only(left: 20, right: 10, top: 5, bottom: 10),
  540. child: Text(
  541. I18n.of(context).translation_butler_tips3,
  542. textScaleFactor: 1.0,
  543. style: TextStyle(color: Colors.black, fontSize: 18),
  544. ),
  545. ),
  546. Stack(
  547. alignment: Alignment.center,
  548. children: <Widget>[
  549. UnconstrainedBox(
  550. child: Container(
  551. //限制进度条的高度
  552. height: 190.0,
  553. //限制进度条的宽度
  554. width: 190.0,
  555. child: CircularProgressIndicator(
  556. //0~1的浮点数,用来表示进度多少;如果 value 为 null 或空,则显示一个动画,否则显示一个定值
  557. value: null,
  558. strokeWidth: 5,
  559. //背景颜色
  560. backgroundColor: Color(0xffB2B2B2),
  561. //进度颜色
  562. valueColor:
  563. AlwaysStoppedAnimation<Color>(Color(0xff3875E9))),
  564. ),
  565. ),
  566. Column(
  567. children: <Widget>[
  568. Text(
  569. I18n.of(context).translation_butler_already_wait,
  570. textScaleFactor: 1.0,
  571. style: TextStyle(color: Colors.black, fontSize: 19),
  572. ),
  573. SizedBox(
  574. height: 10,
  575. ),
  576. Text(
  577. getFull(minutes) + ' : ' + getFull(seconds),
  578. textScaleFactor: 1.0,
  579. style: TextStyle(color: Color(0xffFF1010), fontSize: 35),
  580. )
  581. ],
  582. )
  583. ],
  584. ),
  585. Container(
  586. margin: EdgeInsets.only(left: 70, right: 70, top: 50),
  587. height: 47,
  588. child: RaisedButton(
  589. color: Color(0xff3875E9),
  590. shape: RoundedRectangleBorder(
  591. borderRadius: BorderRadius.all(Radius.circular(10))),
  592. child: Text(
  593. I18n.of(context).translation_butler_cancel,
  594. textScaleFactor: 1.0,
  595. style: TextStyle(color: Colors.white, fontSize: 19),
  596. ),
  597. onPressed: () async {
  598. await SPUtils.save(Constants.TranslationHelper, null);
  599. setState(() {
  600. isApply = true;
  601. timer?.cancel();
  602. secondsPassed = 0;
  603. });
  604. }),
  605. ),
  606. Container(
  607. margin: EdgeInsets.only(left: 70, right: 70, top: 25),
  608. height: 47,
  609. child: RaisedButton(
  610. color: Color(0xffB3B3B3),
  611. shape: RoundedRectangleBorder(
  612. borderRadius: BorderRadius.all(Radius.circular(10))),
  613. child: Text(
  614. I18n.of(context).translation_butler_wait_service,
  615. textScaleFactor: 1.0,
  616. style: TextStyle(color: Colors.white, fontSize: 19),
  617. ),
  618. onPressed: () {}),
  619. )
  620. ],
  621. );
  622. }
  623. bool isApply = true;
  624. int secondsPassed = 1;
  625. int timeStamp;
  626. Timer timer;
  627. void handleTick() {
  628. // if (isActive) {
  629. setState(() {
  630. secondsPassed = secondsPassed + 1; //需要更新UI
  631. });
  632. // }
  633. }
  634. getFull(int sec) {
  635. return sec < 10 ? '0$sec' : '$sec';
  636. }
  637. }