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.
 
 
 
 
 
 

232 lines
8.2 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/models/group_info_model.dart';
  3. import 'package:chat/models/money_change.dart';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:oktoast/oktoast.dart';
  7. import 'package:provider/provider.dart';
  8. import '../../data/constants.dart';
  9. import '../../generated/i18n.dart';
  10. import '../../r.dart';
  11. import '../../utils/CustomUI.dart';
  12. import 'package:chat/utils/PopUpMenu.dart' as myPop;
  13. class TranslationButlerPage extends StatefulWidget {
  14. final GroupInfoModel groupInfoModel;
  15. TranslationButlerPage({Key key, this.groupInfoModel}) : super(key: key);
  16. @override
  17. State<StatefulWidget> createState() {
  18. return TranslationButlerPageState();
  19. }
  20. }
  21. class TranslationButlerPageState extends State<TranslationButlerPage> {
  22. int curToLang = 1;
  23. int curSourceLang = UserData().language;
  24. List langList;
  25. @override
  26. void initState() {
  27. super.initState();
  28. }
  29. @override
  30. void didChangeDependencies() {
  31. super.didChangeDependencies();
  32. langList = [
  33. I18n.of(context).english,
  34. I18n.of(context).Vietnamese,
  35. I18n.of(context).traditional_Chinese,
  36. I18n.of(context).Simplified_Chinese,
  37. I18n.of(context).Korean,
  38. I18n.of(context).Japanese,
  39. ];
  40. }
  41. @override
  42. void dispose() {
  43. // MessageMgr().off('Update Group Info', updateGroupInfo);
  44. super.dispose();
  45. }
  46. _langPopMenu(bool isSource) {
  47. var curIndex = isSource ? curSourceLang : curToLang;
  48. return myPop.PopupMenuButton(
  49. child: Container(
  50. constraints: BoxConstraints(
  51. minHeight: 41,
  52. minWidth: 115,
  53. maxWidth: 165),
  54. decoration: BoxDecoration(color: Color(0xffD3E7FF),borderRadius:BorderRadius.circular(10) ),
  55. child: Row(
  56. children: <Widget>[
  57. Expanded(child: Text(langList[curIndex],textAlign: TextAlign.center,textScaleFactor: 1.0,style: TextStyle(color: Colors.black, fontSize: 16),)),
  58. Icon(IconData(0xe63b, fontFamily: Constants.IconFontFamily),
  59. color: Colors.grey)
  60. ],
  61. ),
  62. ),
  63. offset: Offset(0, 100),
  64. onSelected: (int index) {
  65. if (curIndex != index) {
  66. if (isSource) {
  67. curSourceLang = index;
  68. } else {
  69. curToLang = index;
  70. }
  71. print('更换翻译语言');
  72. setState(() {});
  73. }
  74. },
  75. itemBuilder: (BuildContext context) {
  76. return List<myPop.PopupMenuItem<int>>.generate(langList.length,
  77. (int i) {
  78. return myPop.PopupMenuItem(
  79. child: Container(
  80. alignment: Alignment.center,
  81. color: Colors.white,
  82. padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
  83. child: Text(langList[i],
  84. textScaleFactor: 1.0,
  85. maxLines: 1,
  86. style: TextStyle(
  87. color: i == curIndex
  88. ? Colors.blueAccent
  89. : Color(AppColors.AppBarColor),
  90. fontSize: 14)),
  91. ),
  92. value: i,
  93. );
  94. });
  95. });
  96. }
  97. @override
  98. Widget build(BuildContext context) {
  99. Widget appBar = AppBar(
  100. backgroundColor: AppColors.NewAppbarBgColor,
  101. title: Text(
  102. I18n.of(context).translation_butler,
  103. textScaleFactor: 1.0,
  104. style: TextStyle(color: AppColors.NewAppbarTextColor),
  105. ),
  106. // leading: CustomUI.buildCustomLeading(context),
  107. centerTitle: true,
  108. actions: <Widget>[ Container(child: CustomUI.buildImageLabel(
  109. R.assetsImagesCoin, Provider.of<MoneyChangeProvider>(context).money,
  110. isLeft: true),decoration: BoxDecoration(borderRadius:BorderRadius.circular(10)),),SizedBox(width: 10,)],
  111. );
  112. return Scaffold(
  113. appBar: appBar,
  114. body: SafeArea(
  115. child: Container(
  116. color: Color(0xffE8EAF0),
  117. child: ListView(
  118. children: <Widget>[
  119. Padding(
  120. padding: EdgeInsets.only(left: 10, right: 10, top: 15),
  121. child: Text(
  122. I18n.of(context).translation_butler_tips,
  123. textScaleFactor: 1.0,
  124. style: TextStyle(color: Color(0xffABABAB), fontSize: 13),
  125. ),
  126. ),
  127. Container(
  128. margin: EdgeInsets.all(10),
  129. child: Card(
  130. elevation: 5, // 阴影
  131. shape: RoundedRectangleBorder(
  132. borderRadius: BorderRadius.circular(10),
  133. // side: BorderSide(color: Colors.green,width: 25),
  134. ),
  135. child: Container(
  136. padding: EdgeInsets.all(10),
  137. child: Column(
  138. crossAxisAlignment: CrossAxisAlignment.start,
  139. children: <Widget>[
  140. Text(
  141. I18n.of(context).choose_language,
  142. textScaleFactor: 1.0,
  143. textAlign: TextAlign.left,
  144. style: TextStyle(color: AppColors.NewAppbarTextColor,fontSize: 17),
  145. ),
  146. Row(
  147. children: <Widget>[
  148. Image.asset(
  149. R.assetsImagesImgTranslationIcon,
  150. width: 195,
  151. height: 175,
  152. ),
  153. Column(
  154. mainAxisSize: MainAxisSize.min,
  155. children: <Widget>[
  156. _langPopMenu(true),
  157. SizedBox(width: 10),
  158. InkWell(
  159. onTap: () {
  160. var temp = curSourceLang;
  161. curSourceLang = curToLang;
  162. curToLang = temp;
  163. setState(() {});
  164. },
  165. child: Container(
  166. child: Icon(
  167. IconData(
  168. 0xe669,
  169. fontFamily: Constants.IconFontFamily,
  170. ),
  171. size: 12,
  172. ),
  173. padding: EdgeInsets.symmetric(
  174. vertical: 5, horizontal: 5),
  175. ),
  176. ),
  177. SizedBox(width: 20),
  178. _langPopMenu(false),
  179. ],
  180. ),
  181. ],
  182. ),
  183. Padding(
  184. padding: EdgeInsets.only(left: 10, right: 10, top: 15),
  185. child: Text(
  186. I18n.of(context).translation_butler_rules,
  187. textScaleFactor: 1.0,
  188. style: TextStyle(color: Color(0xffABABAB), fontSize: 13),
  189. ),
  190. ),
  191. ],
  192. ),
  193. ),
  194. ),
  195. ),
  196. Container(
  197. margin: EdgeInsets.only(left: 70, right: 70,top: 50),
  198. height: 47,
  199. child: RaisedButton(
  200. color: Color(0xff3875E9),
  201. shape:RoundedRectangleBorder(
  202. borderRadius: BorderRadius.all(Radius.circular(10))
  203. ),
  204. child: Text(I18n.of(context).translation_butler_call+' (50h)',textScaleFactor: 1.0,style: TextStyle(color: Colors.white,fontSize: 19),),
  205. onPressed: () {
  206. showToast(
  207. '呼叫管家${I18n.of(context).translation_butler_call}');
  208. }),
  209. )
  210. ],
  211. ),
  212. ),
  213. ),
  214. );
  215. }
  216. }