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.
 
 
 
 
 
 

219 regels
7.0 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/data/constants.dart';
  3. import 'package:chat/generated/i18n.dart';
  4. import 'package:chat/models/ref_name_provider.dart';
  5. import 'package:chat/utils/CustomUI.dart';
  6. import 'package:chat/utils/HttpUtil.dart';
  7. import 'package:chat/utils/MessageMgr.dart';
  8. import 'package:chat/utils/msgHandler.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter/services.dart';
  11. import 'package:provider/provider.dart';
  12. class AddFriendPage extends StatefulWidget {
  13. final int userId;
  14. final int pageType;
  15. final String originalName;
  16. AddFriendPage(
  17. {Key key,
  18. @required this.userId,
  19. @required this.pageType,
  20. @required this.originalName})
  21. : super(key: key);
  22. @override
  23. _AddFriendPageState createState() => new _AddFriendPageState();
  24. }
  25. class _AddFriendPageState extends State<AddFriendPage> {
  26. bool _hasdeleteIcon = false;
  27. TextEditingController _txtCtrl = new TextEditingController();
  28. @override
  29. void initState() {
  30. super.initState();
  31. print('AddFriendPage init111');
  32. _txtCtrl.text = widget.originalName;
  33. _hasdeleteIcon =
  34. !(widget.originalName == null || widget.originalName == "");
  35. }
  36. @override
  37. Widget build(BuildContext context) {
  38. String title = '';
  39. switch (widget.pageType) {
  40. case SendMessagePageType.AddFriends:
  41. title = I18n.of(context).friend_verification;
  42. break;
  43. case SendMessagePageType.ChangeGroupName:
  44. title = I18n.of(context).change_group_name;
  45. break;
  46. case SendMessagePageType.ChangeGroupNickName:
  47. title = I18n.of(context).my_group_nickname;
  48. break;
  49. case SendMessagePageType.Remark:
  50. title = I18n.of(context).setRemark;
  51. break;
  52. default:
  53. }
  54. Widget appBar = new AppBar(
  55. backgroundColor: AppColors.NewAppbarBgColor,
  56. title: new Text(
  57. title,
  58. textScaleFactor: 1.0,
  59. style: TextStyle(color: AppColors.NewAppbarTextColor),
  60. ),
  61. centerTitle: true,
  62. leading: CustomUI.buildCustomLeading(context),
  63. actions: <Widget>[
  64. InkWell(
  65. onTap: () {
  66. var content = _txtCtrl.text;
  67. if (_txtCtrl.text.length == 0 &&
  68. widget.pageType != SendMessagePageType.Remark) {
  69. content = UserData().basicInfo.nickName;
  70. }
  71. switch (widget.pageType) {
  72. case SendMessagePageType.AddFriends:
  73. HttpUtil().addFriends(context, widget.userId, content, () {
  74. Navigator.of(context).pop();
  75. MessageMgr().emit('post_add_friend', widget.userId);
  76. });
  77. break;
  78. case SendMessagePageType.ChangeGroupName:
  79. Navigator.of(context).pop();
  80. MsgHandler.updateGroupName(widget.userId, content);
  81. break;
  82. case SendMessagePageType.ChangeGroupNickName:
  83. Navigator.of(context).pop();
  84. MsgHandler.updateMemberRefName(widget.userId, content);
  85. break;
  86. case SendMessagePageType.Remark:
  87. Provider.of<RefNameProvider>(context)
  88. .changeRefName(widget.userId, content, () {
  89. Navigator.of(context).pop();
  90. });
  91. break;
  92. default:
  93. }
  94. },
  95. child: Container(
  96. alignment: Alignment.center,
  97. margin: EdgeInsets.only(top: 15, bottom: 15, right: 20),
  98. height: 20,
  99. padding: EdgeInsets.only(left: 18, right: 18, bottom: 1),
  100. decoration: BoxDecoration(
  101. color: Constants.ConfrimButtonColor,
  102. borderRadius: BorderRadius.circular(4.5)),
  103. child: Text(
  104. widget.pageType == SendMessagePageType.AddFriends
  105. ? I18n.of(context).send
  106. : I18n.of(context).determine,
  107. style: TextStyle(color: Colors.white, fontSize: 14),
  108. textScaleFactor: 1.0,
  109. ),
  110. ),
  111. )
  112. ],
  113. );
  114. return Scaffold(appBar: appBar, body: SafeArea(child: _buildBody()));
  115. }
  116. Widget _buildBody() {
  117. return Container(
  118. child: Column(
  119. crossAxisAlignment: CrossAxisAlignment.start,
  120. children: <Widget>[
  121. _buildTips(),
  122. _buildInput(),
  123. ],
  124. ),
  125. );
  126. }
  127. Widget _buildInput() {
  128. return Container(
  129. height: 36.5,
  130. color: Colors.white,
  131. child: TextField(
  132. keyboardAppearance: Brightness.light,
  133. controller: _txtCtrl,
  134. //autofocus: true,
  135. style: TextStyle(
  136. fontSize: 16,
  137. color: Constants.BlackTextColor,
  138. textBaseline: TextBaseline.alphabetic),
  139. decoration: InputDecoration(
  140. contentPadding:
  141. EdgeInsets.only(right: 10, left: 15, top: 10, bottom: 10),
  142. hintText: widget.pageType == SendMessagePageType.Remark
  143. ? I18n.of(context).setRemark
  144. : UserData().basicInfo.nickName,
  145. hintStyle: TextStyle(fontSize: 16, color: Colors.grey),
  146. border: InputBorder.none,
  147. suffixIcon: Padding(
  148. padding: EdgeInsetsDirectional.only(
  149. start: 2.0, end: _hasdeleteIcon ? 20.0 : 0),
  150. child: _hasdeleteIcon
  151. ? InkWell(
  152. onTap: (() {
  153. setState(() {
  154. WidgetsBinding.instance
  155. .addPostFrameCallback((_) => _txtCtrl.clear());
  156. _hasdeleteIcon = false;
  157. });
  158. }),
  159. child: Icon(
  160. Icons.cancel,
  161. size: 18.0,
  162. color: const Color(0xFFDBDBDB),
  163. ))
  164. : Text('')),
  165. ),
  166. maxLines: 1,
  167. inputFormatters: [LengthLimitingTextInputFormatter(15)],
  168. onChanged: (str) async {
  169. setState(() {
  170. if (str.isEmpty) {
  171. _hasdeleteIcon = false;
  172. } else {
  173. _hasdeleteIcon = true;
  174. }
  175. });
  176. },
  177. ),
  178. );
  179. }
  180. Widget _buildTips() {
  181. String title = '';
  182. switch (widget.pageType) {
  183. case SendMessagePageType.AddFriends:
  184. title = I18n.of(context).added_friends_tips;
  185. break;
  186. case SendMessagePageType.ChangeGroupName:
  187. title = I18n.of(context).change_group_name;
  188. break;
  189. case SendMessagePageType.ChangeGroupNickName:
  190. title = I18n.of(context).my_group_nickname_tips;
  191. break;
  192. default:
  193. }
  194. return Container(
  195. margin: EdgeInsets.only(top: 20.5, left: 15, bottom: 6),
  196. child: Text(
  197. title,
  198. textScaleFactor: 1.0,
  199. style: TextStyle(fontSize: 11),
  200. ),
  201. );
  202. }
  203. @override
  204. void dispose() {
  205. super.dispose();
  206. }
  207. }