Hibok
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

215 wiersze
6.8 KiB

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