Hibok
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

215 行
6.7 KiB

  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:chat/data/UserData.dart';
  3. import 'package:chat/data/constants.dart';
  4. import 'package:chat/generated/i18n.dart';
  5. import 'package:chat/models/group_info_model.dart';
  6. import 'package:chat/models/ref_name_provider.dart';
  7. import 'package:chat/utils/CustomUI.dart';
  8. import 'package:chat/utils/group_member_model.dart';
  9. import 'package:chat/utils/msgHandler.dart';
  10. import 'package:chat/utils/screen.dart';
  11. import 'package:flutter/material.dart';
  12. import 'package:flutter/services.dart';
  13. import 'package:provider/provider.dart';
  14. class GroupAnnouncementPage extends StatefulWidget {
  15. final GroupInfoModel groupInfoModel;
  16. GroupAnnouncementPage({Key key, @required this.groupInfoModel})
  17. : super(key: key);
  18. @override
  19. _GroupAnnouncementPageState createState() =>
  20. new _GroupAnnouncementPageState();
  21. }
  22. class _GroupAnnouncementPageState extends State<GroupAnnouncementPage> {
  23. TextEditingController _txtCtrl = new TextEditingController();
  24. bool isGroupOwner = false;
  25. @override
  26. void initState() {
  27. super.initState();
  28. print('GroupAnnouncementPage initState');
  29. _txtCtrl.text = widget.groupInfoModel.describe;
  30. isGroupOwner =
  31. widget.groupInfoModel.hosterId == UserData().basicInfo.userId;
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. Widget appBar = new AppBar(
  36. backgroundColor: AppColors.NewAppbarBgColor,
  37. title: new Text(
  38. I18n.of(context).group_announcement,
  39. style: TextStyle(color: AppColors.NewAppbarTextColor),
  40. textScaleFactor: 1.0,
  41. ),
  42. centerTitle: true,
  43. leading: CustomUI.buildCustomLeading(context),
  44. actions: <Widget>[
  45. isGroupOwner
  46. ? InkWell(
  47. onTap: () {
  48. var content = _txtCtrl.text;
  49. MsgHandler.updateGroupNotice(
  50. widget.groupInfoModel.sessionId, content);
  51. Navigator.of(context).pop();
  52. },
  53. child: Container(
  54. alignment: Alignment.center,
  55. margin: EdgeInsets.only(top: 15, bottom: 15, right: 20),
  56. height: 20,
  57. width: 60,
  58. padding: EdgeInsets.symmetric(horizontal: 5),
  59. decoration: BoxDecoration(
  60. color: Colors.white,
  61. borderRadius: BorderRadius.circular(4.5)),
  62. child: Text(
  63. I18n.of(context).determine,
  64. overflow: TextOverflow.ellipsis,
  65. style: TextStyle(
  66. color: Constants.ConfrimButtonColor, fontSize: 12.6),
  67. ),
  68. ),
  69. )
  70. : Container()
  71. ],
  72. );
  73. return Scaffold(
  74. appBar: appBar,
  75. backgroundColor: Colors.white,
  76. body: SafeArea(
  77. child: _buildBody(),
  78. ));
  79. }
  80. Widget _buildBody() {
  81. return Container(
  82. child: Column(
  83. crossAxisAlignment: CrossAxisAlignment.start,
  84. children: <Widget>[
  85. _buildGroupOwner(),
  86. _buildLine(),
  87. _buildInput(),
  88. Expanded(
  89. child: SizedBox(),
  90. ),
  91. _buildTips(),
  92. ],
  93. ),
  94. );
  95. }
  96. Widget _buildLine() {
  97. return Container(
  98. width: Screen.width,
  99. decoration:
  100. BoxDecoration(border: Border(bottom: Constants.GreyBorderSide)),
  101. margin: EdgeInsets.only(left: 20, right: 20),
  102. );
  103. }
  104. Widget _buildTips() {
  105. return isGroupOwner
  106. ? Container()
  107. : Container(
  108. width: Screen.width,
  109. margin: EdgeInsets.only(bottom: 60),
  110. child: Row(
  111. children: <Widget>[
  112. Expanded(
  113. child: Container(
  114. margin: EdgeInsets.only(left: 30, right: 10),
  115. decoration: BoxDecoration(
  116. border: Border(top: Constants.GreyBorderSide)),
  117. ),
  118. ),
  119. Text(
  120. I18n.of(context).only_host,
  121. style: TextStyle(color: Colors.grey[350]),
  122. ),
  123. Expanded(
  124. child: Container(
  125. margin: EdgeInsets.only(right: 30, left: 10),
  126. decoration: BoxDecoration(
  127. border: Border(top: Constants.GreyBorderSide)),
  128. ),
  129. ),
  130. ],
  131. ),
  132. );
  133. }
  134. Widget _buildGroupOwner() {
  135. GroupMemberModel memberModel = widget.groupInfoModel.getHoster();
  136. var refName = Provider.of<RefNameProvider>(context)
  137. .getGroupRefName(widget.groupInfoModel.sessionId, memberModel.memberId);
  138. return Container(
  139. height: 62.5,
  140. child: Row(
  141. children: <Widget>[
  142. SizedBox(width: 20),
  143. ClipRRect(
  144. borderRadius: BorderRadius.circular(6),
  145. child: CachedNetworkImage(
  146. imageUrl: memberModel.avtar,
  147. width: 45,
  148. height: 45,
  149. )),
  150. SizedBox(width: 8),
  151. Column(
  152. crossAxisAlignment: CrossAxisAlignment.start,
  153. mainAxisAlignment: MainAxisAlignment.center,
  154. children: <Widget>[
  155. Text(
  156. refName,
  157. style: TextStyle(fontSize: 16),
  158. ),
  159. SizedBox(height: 6.5),
  160. ],
  161. )
  162. ],
  163. ),
  164. );
  165. }
  166. Widget _buildInput() {
  167. return isGroupOwner
  168. ? Container(
  169. child: TextField(
  170. keyboardAppearance: Brightness.light,
  171. controller: _txtCtrl,
  172. style: TextStyle(
  173. fontSize: 17,
  174. color: Constants.BlackTextColor,
  175. textBaseline: TextBaseline.alphabetic),
  176. decoration: InputDecoration(
  177. contentPadding:
  178. EdgeInsets.only(right: 20, left: 20, top: 10, bottom: 10),
  179. hintText: I18n.of(context).fill_out,
  180. hintStyle: TextStyle(fontSize: 16, color: Colors.grey),
  181. border: InputBorder.none,
  182. ),
  183. autofocus: true,
  184. maxLines: 5,
  185. inputFormatters: [LengthLimitingTextInputFormatter(100)],
  186. onChanged: (str) async {},
  187. ),
  188. )
  189. : Container(
  190. //color: Colors.white,
  191. padding: EdgeInsets.only(right: 20, left: 20, top: 10, bottom: 10),
  192. child: Text(widget.groupInfoModel.describe),
  193. );
  194. }
  195. @override
  196. void dispose() {
  197. super.dispose();
  198. }
  199. }