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.
 
 
 
 
 
 

221 lines
6.9 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. textScaleFactor: 1.0,
  65. overflow: TextOverflow.ellipsis,
  66. style: TextStyle(
  67. color: Constants.ConfrimButtonColor, fontSize: 12.6),
  68. ),
  69. ),
  70. )
  71. : Container()
  72. ],
  73. );
  74. return Scaffold(
  75. appBar: appBar,
  76. backgroundColor: Colors.white,
  77. body: SafeArea(
  78. child: _buildBody(),
  79. ));
  80. }
  81. Widget _buildBody() {
  82. return Container(
  83. child: Column(
  84. crossAxisAlignment: CrossAxisAlignment.start,
  85. children: <Widget>[
  86. _buildGroupOwner(),
  87. _buildLine(),
  88. _buildInput(),
  89. Expanded(
  90. child: SizedBox(),
  91. ),
  92. _buildTips(),
  93. ],
  94. ),
  95. );
  96. }
  97. Widget _buildLine() {
  98. return Container(
  99. width: Screen.width,
  100. decoration:
  101. BoxDecoration(border: Border(bottom: Constants.GreyBorderSide)),
  102. margin: EdgeInsets.only(left: 20, right: 20),
  103. );
  104. }
  105. Widget _buildTips() {
  106. return isGroupOwner
  107. ? Container()
  108. : Container(
  109. width: Screen.width,
  110. margin: EdgeInsets.only(bottom: 60),
  111. child: Row(
  112. children: <Widget>[
  113. Expanded(
  114. child: Container(
  115. margin: EdgeInsets.only(left: 30, right: 10),
  116. decoration: BoxDecoration(
  117. border: Border(top: Constants.GreyBorderSide)),
  118. ),
  119. ),
  120. Text(
  121. I18n.of(context).only_host,
  122. textScaleFactor: 1.0,
  123. style: TextStyle(color: Colors.grey[350]),
  124. ),
  125. Expanded(
  126. child: Container(
  127. margin: EdgeInsets.only(right: 30, left: 10),
  128. decoration: BoxDecoration(
  129. border: Border(top: Constants.GreyBorderSide)),
  130. ),
  131. ),
  132. ],
  133. ),
  134. );
  135. }
  136. Widget _buildGroupOwner() {
  137. GroupMemberModel memberModel = widget.groupInfoModel.getHoster();
  138. var refName = Provider.of<RefNameProvider>(context)
  139. .getGroupRefName(widget.groupInfoModel.sessionId, memberModel.memberId);
  140. return Container(
  141. height: 62.5,
  142. child: Row(
  143. children: <Widget>[
  144. SizedBox(width: 20),
  145. ClipRRect(
  146. borderRadius: BorderRadius.circular(6),
  147. child: CachedNetworkImage(
  148. imageUrl: memberModel.avtar,
  149. width: 45,
  150. height: 45,
  151. )),
  152. SizedBox(width: 8),
  153. Column(
  154. crossAxisAlignment: CrossAxisAlignment.start,
  155. mainAxisAlignment: MainAxisAlignment.center,
  156. children: <Widget>[
  157. Text(
  158. refName,
  159. textScaleFactor: 1.0,
  160. style: TextStyle(fontSize: 16),
  161. ),
  162. SizedBox(height: 6.5),
  163. ],
  164. )
  165. ],
  166. ),
  167. );
  168. }
  169. Widget _buildInput() {
  170. return isGroupOwner
  171. ? Container(
  172. child: TextField(
  173. keyboardAppearance: Brightness.light,
  174. controller: _txtCtrl,
  175. style: TextStyle(
  176. fontSize: 17,
  177. color: Constants.BlackTextColor,
  178. textBaseline: TextBaseline.alphabetic),
  179. decoration: InputDecoration(
  180. contentPadding:
  181. EdgeInsets.only(right: 20, left: 20, top: 10, bottom: 10),
  182. hintText: I18n.of(context).fill_out,
  183. hintStyle: TextStyle(fontSize: 16, color: Colors.grey),
  184. border: InputBorder.none,
  185. ),
  186. autofocus: true,
  187. maxLines: 5,
  188. inputFormatters: [LengthLimitingTextInputFormatter(100)],
  189. onChanged: (str) async {},
  190. ),
  191. )
  192. : Container(
  193. //color: Colors.white,
  194. padding: EdgeInsets.only(right: 20, left: 20, top: 10, bottom: 10),
  195. child: Text(
  196. widget.groupInfoModel.describe,
  197. textScaleFactor: 1.0,
  198. ),
  199. );
  200. }
  201. @override
  202. void dispose() {
  203. super.dispose();
  204. }
  205. }