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

218 行
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. content = UserData().basicInfo.nickName;
  69. }
  70. switch (widget.pageType) {
  71. case SendMessagePageType.AddFriends:
  72. HttpUtil().addFriends(context, widget.userId, content, () {
  73. Navigator.of(context).pop();
  74. MessageMgr().emit('post_add_friend', widget.userId);
  75. });
  76. break;
  77. case SendMessagePageType.ChangeGroupName:
  78. Navigator.of(context).pop();
  79. MsgHandler.updateGroupName(widget.userId, content);
  80. break;
  81. case SendMessagePageType.ChangeGroupNickName:
  82. Navigator.of(context).pop();
  83. MsgHandler.updateMemberRefName(widget.userId, content);
  84. break;
  85. case SendMessagePageType.Remark:
  86. Provider.of<RefNameProvider>(context)
  87. .changeRefName(widget.userId, content, () {
  88. Navigator.of(context).pop();
  89. });
  90. break;
  91. default:
  92. }
  93. },
  94. child: Container(
  95. alignment: Alignment.center,
  96. margin: EdgeInsets.only(top: 15, bottom: 15, right: 20),
  97. height: 20,
  98. padding: EdgeInsets.only(left: 18, right: 18, bottom: 1),
  99. decoration: BoxDecoration(
  100. color: Constants.ConfrimButtonColor,
  101. borderRadius: BorderRadius.circular(4.5)),
  102. child: Text(
  103. widget.pageType == SendMessagePageType.AddFriends
  104. ? I18n.of(context).send
  105. : I18n.of(context).determine,
  106. style: TextStyle(color: Colors.white, fontSize: 14),
  107. textScaleFactor: 1.0,
  108. ),
  109. ),
  110. )
  111. ],
  112. );
  113. return Scaffold(appBar: appBar, body: SafeArea(child: _buildBody()));
  114. }
  115. Widget _buildBody() {
  116. return Container(
  117. child: Column(
  118. crossAxisAlignment: CrossAxisAlignment.start,
  119. children: <Widget>[
  120. _buildTips(),
  121. _buildInput(),
  122. ],
  123. ),
  124. );
  125. }
  126. Widget _buildInput() {
  127. return Container(
  128. height: 36.5,
  129. color: Colors.white,
  130. child: TextField(
  131. keyboardAppearance: Brightness.light,
  132. controller: _txtCtrl,
  133. //autofocus: true,
  134. style: TextStyle(
  135. fontSize: 16,
  136. color: Constants.BlackTextColor,
  137. textBaseline: TextBaseline.alphabetic),
  138. decoration: InputDecoration(
  139. contentPadding:
  140. EdgeInsets.only(right: 10, left: 15, top: 10, bottom: 10),
  141. hintText: widget.pageType == SendMessagePageType.Remark
  142. ? I18n.of(context).setRemark
  143. : UserData().basicInfo.nickName,
  144. hintStyle: TextStyle(fontSize: 16, color: Colors.grey),
  145. border: InputBorder.none,
  146. suffixIcon: Padding(
  147. padding: EdgeInsetsDirectional.only(
  148. start: 2.0, end: _hasdeleteIcon ? 20.0 : 0),
  149. child: _hasdeleteIcon
  150. ? InkWell(
  151. onTap: (() {
  152. setState(() {
  153. WidgetsBinding.instance
  154. .addPostFrameCallback((_) => _txtCtrl.clear());
  155. _hasdeleteIcon = false;
  156. });
  157. }),
  158. child: Icon(
  159. Icons.cancel,
  160. size: 18.0,
  161. color: const Color(0xFFDBDBDB),
  162. ))
  163. : Text('')),
  164. ),
  165. maxLines: 1,
  166. inputFormatters: [LengthLimitingTextInputFormatter(15)],
  167. onChanged: (str) async {
  168. setState(() {
  169. if (str.isEmpty) {
  170. _hasdeleteIcon = false;
  171. } else {
  172. _hasdeleteIcon = true;
  173. }
  174. });
  175. },
  176. ),
  177. );
  178. }
  179. Widget _buildTips() {
  180. String title = '';
  181. switch (widget.pageType) {
  182. case SendMessagePageType.AddFriends:
  183. title = I18n.of(context).added_friends_tips;
  184. break;
  185. case SendMessagePageType.ChangeGroupName:
  186. title = I18n.of(context).change_group_name;
  187. break;
  188. case SendMessagePageType.ChangeGroupNickName:
  189. title = I18n.of(context).my_group_nickname_tips;
  190. break;
  191. default:
  192. }
  193. return Container(
  194. margin: EdgeInsets.only(top: 20.5, left: 15, bottom: 6),
  195. child: Text(
  196. title,
  197. textScaleFactor: 1.0,
  198. style: TextStyle(fontSize: 11),
  199. ),
  200. );
  201. }
  202. @override
  203. void dispose() {
  204. super.dispose();
  205. }
  206. }