Hibok
您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 
 
 
 

536 行
18 KiB

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