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.
 
 
 
 
 
 

202 lines
6.3 KiB

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