near_detail.dart 6.8 KB

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