near_detail.dart 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/internal/bbs/page/chat_room.dart';
  3. import 'package:liftmanager/internal/bbs/page/jubao_page.dart';
  4. import 'package:liftmanager/net/api_service.dart';
  5. import 'package:liftmanager/res/iconfont.dart';
  6. import 'package:liftmanager/utils/toast.dart';
  7. import 'package:liftmanager/widgets/app_bar.dart';
  8. import 'package:liftmanager/routers/fluro_navigator.dart';
  9. import 'package:liftmanager/widgets/load_image.dart';
  10. import 'package:liftmanager/internal/friends/model/near_model.dart';
  11. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  12. import '../friends_router.dart';
  13. import 'package:liftmanager/internal/friends/model/friend_model.dart';
  14. class NearDetail extends StatefulWidget {
  15. final NearModel model;
  16. final Records friendModel;
  17. const NearDetail({Key key, this.model, this.friendModel}) : super(key: key);
  18. @override
  19. State<StatefulWidget> createState() {
  20. return NearDetailState();
  21. }
  22. }
  23. class NearDetailState extends State<NearDetail> {
  24. ScrollController _scrollController = new ScrollController();
  25. String targetUserId;
  26. int distance;
  27. String avatarUrl;
  28. String name;
  29. void initState() {
  30. super.initState();
  31. targetUserId = widget.model != null
  32. ? widget.model.userId.toString()
  33. : widget.friendModel.targetUserId;
  34. distance = widget.model != null ? widget.model.distance : null;
  35. avatarUrl = widget.model != null
  36. ? widget.model.avatarUrl
  37. : widget.friendModel.avatarUrl;
  38. name = widget.model != null
  39. ? widget.model.remarks ?? widget.model.name
  40. : widget.friendModel.remarks ?? widget.friendModel.userName;
  41. }
  42. Future createPrivateChatRoom(id) async {
  43. await NewApiService().createPrivateChatRoom(id.toString(),
  44. onSuccess: (res) async {
  45. print(res["room"]);
  46. String roomId = res["room"];
  47. await Navigator.push(
  48. context,
  49. MaterialPageRoute(
  50. builder: (_) => ChatDetailPage(
  51. id: roomId,
  52. type: 'nearToOne',
  53. toUserId: id,
  54. title: name,
  55. jubaoToUserId: widget.friendModel?.targetUserId,
  56. ),
  57. ),
  58. );
  59. }, onError: (code, msg) {
  60. toasts(msg);
  61. });
  62. }
  63. @override
  64. void dispose() {
  65. _scrollController.dispose();
  66. super.dispose();
  67. }
  68. @override
  69. Widget build(BuildContext context) {
  70. double width = MediaQuery.of(context).size.width;
  71. return Scaffold(
  72. appBar: MyAppBar(
  73. centerTitle: widget.model != null ? "附近的人" : '圈子',
  74. ),
  75. body: Container(
  76. child: Column(children: <Widget>[
  77. SizedBox(
  78. height: 10,
  79. ),
  80. Row(
  81. crossAxisAlignment: CrossAxisAlignment.start,
  82. children: <Widget>[
  83. SizedBox(width: 10),
  84. ClipRRect(
  85. borderRadius: BorderRadius.all(Radius.circular(29)),
  86. child: LoadNetworkImage(
  87. avatarUrl,
  88. width: 57,
  89. height: 57,
  90. // alignment: Alignment.centerLeft,
  91. ),
  92. ),
  93. SizedBox(width: 10),
  94. Expanded(
  95. child: Column(
  96. crossAxisAlignment: CrossAxisAlignment.start,
  97. children: <Widget>[
  98. Text(
  99. name ?? "",
  100. style: TextStyle(
  101. fontSize: 16,
  102. color: Colors.black,
  103. ),
  104. textAlign: TextAlign.start,
  105. ),
  106. if (distance != null)
  107. Text(
  108. '距离: $distance 米以内',
  109. style:
  110. TextStyle(color: Color(0xff666666), fontSize: 13),
  111. textAlign: TextAlign.start,
  112. ),
  113. ],
  114. ),
  115. ),
  116. ],
  117. ),
  118. SizedBox(
  119. height: 20,
  120. ),
  121. Divider(
  122. height: 0.5,
  123. thickness: 0.5,
  124. color: Color(0xffF8F8F8),
  125. ),
  126. GestureDetector(
  127. onTap: () async {
  128. if (widget.model != null) {
  129. NavigatorUtils.pushResult(context,
  130. "${FriendsRouter.remarks}?id=${targetUserId}&remarks=${Uri.encodeComponent(widget.model.remarks ?? '')}",
  131. (res) {
  132. setState(() {
  133. widget.model.remarks = res;
  134. name = res;
  135. });
  136. });
  137. } else {
  138. NavigatorUtils.pushResult(context,
  139. "${FriendsRouter.remarks}?id=${targetUserId}&remarks=${Uri.encodeComponent(widget.friendModel.remarks ?? '')}",
  140. (res) {
  141. setState(() {
  142. widget.friendModel.remarks = res;
  143. name = res;
  144. });
  145. });
  146. }
  147. },
  148. child: Container(
  149. color: Colors.white,
  150. height: 50,
  151. child: Row(
  152. children: [
  153. SizedBox(
  154. width: 10,
  155. ),
  156. Text(
  157. '备注名',
  158. style: TextStyle(
  159. color: Color(0xff333333),
  160. fontSize: 14,
  161. ),
  162. ),
  163. Spacer(),
  164. Icon(
  165. Iconfont.gengduo,
  166. color: Color(0xffcccccc),
  167. size: 14,
  168. ),
  169. SizedBox(
  170. width: 10,
  171. ),
  172. ],
  173. ),
  174. ),
  175. ),
  176. GestureDetector(
  177. onTap: () async {
  178. Navigator.of(context).push(MaterialPageRoute(
  179. builder: (context) => JuBaoPage(
  180. toUserId: widget.friendModel.targetUserId,
  181. )));
  182. },
  183. child: Container(
  184. color: Colors.white,
  185. height: 50,
  186. child: Row(
  187. children: [
  188. SizedBox(
  189. width: 10,
  190. ),
  191. Text(
  192. '举报',
  193. style: TextStyle(
  194. color: Color(0xff333333),
  195. fontSize: 14,
  196. ),
  197. ),
  198. Spacer(),
  199. Icon(
  200. Iconfont.gengduo,
  201. color: Color(0xffcccccc),
  202. size: 14,
  203. ),
  204. SizedBox(
  205. width: 10,
  206. ),
  207. ],
  208. ),
  209. ),
  210. ),
  211. Divider(
  212. height: 5,
  213. thickness: 5,
  214. color: Color(0xffF8F8F8),
  215. ),
  216. FlatButton(
  217. height: 50,
  218. child: Text(widget.model != null ? "打招呼" : "发消息"),
  219. textColor: Color(0xff5589FF),
  220. onPressed: () async {
  221. if (widget.model != null) {
  222. createPrivateChatRoom(targetUserId);
  223. } else {
  224. if (widget.friendModel.dataTable == 3) {
  225. await Navigator.push(
  226. context,
  227. MaterialPageRoute(
  228. builder: (_) => ChatDetailPage(
  229. id: widget.friendModel.sessionid,
  230. type: 'nearToOne',
  231. toUserId: widget.friendModel.userId,
  232. jubaoToUserId: widget.friendModel.targetUserId,
  233. title: widget.friendModel.remarks ??
  234. widget.friendModel.userName),
  235. ),
  236. );
  237. }
  238. }
  239. },
  240. ),
  241. Expanded(
  242. child: Container(
  243. color: Color(0xfff8f8f8),
  244. ),
  245. )
  246. ]),
  247. ),
  248. );
  249. }
  250. }