message_detail_page.dart 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_easyrefresh/easy_refresh.dart';
  5. import 'package:sport/bean/comment.dart';
  6. import 'package:sport/bean/notice.dart';
  7. import 'package:sport/bean/post.dart';
  8. import 'package:sport/bean/post_user.dart';
  9. import 'package:sport/provider/lib/provider_widget.dart';
  10. import 'package:sport/provider/lib/view_state_lifecycle.dart';
  11. import 'package:sport/provider/message_detail_model.dart';
  12. import 'package:sport/router/navigator_util.dart';
  13. import 'package:sport/services/api/resp.dart';
  14. import 'package:sport/utils/DateFormat.dart';
  15. import 'package:sport/utils/toast.dart';
  16. import 'package:sport/widgets/appbar.dart';
  17. import 'package:sport/widgets/dialog/comment_dialog.dart';
  18. import 'package:sport/widgets/dialog/request_dialog.dart';
  19. import 'package:sport/widgets/error.dart';
  20. import 'package:sport/widgets/image.dart';
  21. import 'package:sport/widgets/loading.dart';
  22. import 'package:sport/widgets/misc.dart';
  23. import 'package:sport/widgets/space.dart';
  24. class MessageDetailPage extends StatefulWidget {
  25. final String type;
  26. MessageDetailPage(this.type);
  27. @override
  28. State<StatefulWidget> createState() => _PageState();
  29. }
  30. class _PageState extends ViewStateLifecycle<MessageDetailPage, MessageDetailModel> {
  31. String _title;
  32. @override
  33. MessageDetailModel createModel() => MessageDetailModel(widget.type);
  34. @override
  35. void initState() {
  36. super.initState();
  37. if (widget.type == "comment") {
  38. _title = "回复我的";
  39. } else if (widget.type == "like") {
  40. _title = "点赞我的";
  41. }
  42. }
  43. @override
  44. void dispose() {
  45. super.dispose();
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. return Scaffold(
  50. backgroundColor: Colors.white,
  51. body: ProviderWidget<MessageDetailModel>(
  52. model: model,
  53. onModelReady: (model) => model.initData(),
  54. builder: (_, model, __) {
  55. return EasyRefresh.custom(
  56. controller: model.refreshController,
  57. enableControlFinishRefresh: true,
  58. enableControlFinishLoad: true,
  59. onRefresh: () => model.refresh(),
  60. onLoad: model.isIdle ? () => model.loadMore() : null,
  61. header: buildClassicalHeader(
  62. extent: 100.0 + MediaQuery.of(context).padding.top,
  63. triggerDistance: 120.0 + MediaQuery.of(context).padding.top,
  64. ),
  65. footer: buildClassicalFooter(),
  66. slivers: <Widget>[
  67. buildSliverAppBar(context, _title),
  68. if (model.isBusy)
  69. SliverToBoxAdapter(
  70. child: RequestLoadingWidget(),
  71. ),
  72. if (model.isIdle)
  73. SliverList(
  74. delegate: SliverChildBuilderDelegate(
  75. (context, index) {
  76. if (index.isOdd) {
  77. return Divider();
  78. }
  79. return _buildDetailWidget(context, model.list[index ~/ 2]);
  80. },
  81. childCount: model.list.length * 2 - 1,
  82. ),
  83. ),
  84. if (model.isEmpty)
  85. SliverFillRemaining(
  86. child: Center(
  87. child: RequestErrorWidget(
  88. // ()=>model.readAll(),
  89. // action: widget.type == "comment" ? "查看所有回复" : "查看所有点赞",
  90. null,
  91. msg: widget.type == "comment" ? "暂无回复~" : "暂无点赞~",
  92. assets: RequestErrorWidget.ASSETS_NO_COMMENT,
  93. ),
  94. ),
  95. )
  96. ],
  97. );
  98. },
  99. ));
  100. }
  101. Widget _buildDetailWidget(BuildContext context, Notice item) {
  102. return Padding(
  103. padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 6.0),
  104. child: Column(
  105. crossAxisAlignment: CrossAxisAlignment.start,
  106. children: <Widget>[
  107. if (item.fromUserInfo != null)
  108. GestureDetector(
  109. onTap: () => NavigatorUtil.goSocialUserDetail(context, item.fromUserInfo),
  110. child: Row(
  111. children: <Widget>[
  112. CircleAvatar(backgroundImage: userAvatarProvider(item.fromUserInfo.avatar), radius: 18),
  113. Space(
  114. width: 8,
  115. ),
  116. Column(
  117. crossAxisAlignment: CrossAxisAlignment.start,
  118. children: <Widget>[
  119. Text(
  120. item.fromUserInfo.name,
  121. style: Theme.of(context).textTheme.subtitle1.copyWith(fontWeight: FontWeight.w600),
  122. ),Space(
  123. height: 4,
  124. ),
  125. Text(DateFormat.formatTime(item.createTime), style: Theme.of(context).textTheme.bodyText1)
  126. ],
  127. )
  128. ],
  129. ),
  130. ),
  131. Padding(
  132. padding: const EdgeInsets.symmetric(vertical: 12.0),
  133. child: widget.type == "like"
  134. ? Row(
  135. children: <Widget>[
  136. Image.asset("lib/assets/img/bbs_icon_like_complete.png"),
  137. SizedBox(
  138. width: 8,
  139. ),
  140. Text(
  141. "赞了我的${item.commentDetail == null ? '帖子' : '评论'}",
  142. style: Theme.of(context).textTheme.subtitle1.copyWith(fontSize: 16),
  143. )
  144. ],
  145. )
  146. : RichText(
  147. maxLines: 3,
  148. text: TextSpan(children: <InlineSpan>[
  149. TextSpan(text: '回复:', style: TextStyle(color: Theme.of(context).accentColor, fontSize: 16)),
  150. TextSpan(text: item.content, style: Theme.of(context).textTheme.subtitle1.copyWith(fontSize: 16)),
  151. ]),
  152. ),
  153. ),
  154. item.subjectDetail == null
  155. ? Container()
  156. : item.commentDetail == null ? _buildPostWidget(item.subjectDetail) : _buildCommentWidget(item.commentDetail, item.subjectDetail)
  157. ],
  158. ),
  159. );
  160. }
  161. Widget _buildCommentWidget(Comment item, Post post) {
  162. return GestureDetector(
  163. behavior: HitTestBehavior.opaque,
  164. onTap: () {
  165. Comment current = Comment.fromJson(item.toJson());
  166. current.socialInfo = PostUser(id: item.userId, name: item.userName, avatar: item.userAvatar);
  167. showCommentList(context, current);
  168. },
  169. child: Container(
  170. padding: EdgeInsets.all(12.0),
  171. decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(10)), color: Color(0xfff1f1f1)),
  172. child: Column(
  173. crossAxisAlignment: CrossAxisAlignment.start,
  174. children: <Widget>[
  175. RichText(
  176. maxLines: 3,
  177. text: TextSpan(children: <InlineSpan>[
  178. TextSpan(text: '我的评论:', style: TextStyle(color: Theme.of(context).accentColor)),
  179. if (item.toUserName != null && item.toUserName.isNotEmpty)
  180. TextSpan(
  181. text: '@${item.toUserName} ',
  182. style: Theme.of(context).textTheme.subtitle1.copyWith(fontSize: 16, color: Theme.of(context).accentColor),
  183. ),
  184. TextSpan(text: item.content, style: TextStyle(color: Color(0xff666666))),
  185. ]),
  186. ),
  187. if (post != null)
  188. Container(
  189. margin: EdgeInsets.symmetric(vertical: 12),
  190. padding: const EdgeInsets.symmetric(vertical: 7.0, horizontal: 8.0),
  191. decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(10)), color: Colors.white),
  192. child: _postWidget(post)),
  193. ],
  194. ),
  195. ),
  196. );
  197. }
  198. Widget _buildPostWidget(Post post) {
  199. return Container(
  200. padding: const EdgeInsets.symmetric(vertical: 7.0, horizontal: 8.0),
  201. decoration: new BoxDecoration(
  202. color: Color(0xfff1f1f1), // 底色
  203. borderRadius: new BorderRadius.all(Radius.circular(10.0)),
  204. ),
  205. child: _postWidget(post));
  206. }
  207. _postWidget(Post post) {
  208. return GestureDetector(
  209. behavior: HitTestBehavior.opaque,
  210. onTap: () async {
  211. Post netPost = await request(context, () async {
  212. RespData<Post> data = await model.api.getPostDetail(post.id).catchError((onError) {});
  213. if(data.code ==0){
  214. return data.data;
  215. }else {
  216. ToastUtil.show(data.msg);
  217. return null;
  218. }
  219. });
  220. if (netPost != null) NavigatorUtil.goSocialPostDetail(context, netPost);
  221. },
  222. child: Row(
  223. children: <Widget>[
  224. if (post.images != null && post.images.isNotEmpty)
  225. ClipRRect(
  226. child: CachedNetworkImage(
  227. imageUrl: post.images[0].src,
  228. fit: BoxFit.cover,
  229. width: 50,
  230. height: 50,
  231. ),
  232. // 也可控件一边圆角大小
  233. borderRadius: new BorderRadius.all(Radius.circular(6.0)),
  234. ),
  235. Expanded(
  236. child: Container(
  237. margin: const EdgeInsets.all(5.0),
  238. child: Text(post.content, maxLines: 1, overflow: TextOverflow.ellipsis, style: Theme.of(context).textTheme.subtitle1),
  239. ),
  240. )
  241. ],
  242. ));
  243. }
  244. }