chat_room.dart 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/widgets/app_bar.dart';
  3. import '../provide/websocket.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import '../common/style/style.dart';
  6. import './chat_detail/chat_content_view.dart';
  7. import '../model/conversation.dart';
  8. import 'package:provider/provider.dart';
  9. import 'package:liftmanager/widgets/load_image.dart';
  10. import 'package:liftmanager/internal/bbs/model/talk_model.dart';
  11. import 'package:liftmanager/utils/url.dart';
  12. import 'package:liftmanager/utils/log_util.dart';
  13. import 'dart:convert';
  14. import 'package:dart_notification_center/dart_notification_center.dart';
  15. import 'package:liftmanager/utils/fast_notification.dart';
  16. import 'package:liftmanager/routers/fluro_navigator.dart';
  17. import 'package:liftmanager/internal/friends/friends_router.dart';
  18. import 'package:liftmanager/routers/routers.dart';
  19. import 'package:liftmanager/common/common.dart';
  20. import 'package:flustars/flustars.dart' as flustars;
  21. import 'package:shared_preferences/shared_preferences.dart';
  22. import 'package:liftmanager/utils/toast.dart';
  23. import 'package:image_picker/image_picker.dart';
  24. import 'package:liftmanager/net/api_service.dart';
  25. import 'package:liftmanager/utils/theme_utils.dart';
  26. import 'package:liftmanager/widgets/chat_list_view.dart';
  27. class ChatDetailPage extends StatefulWidget {
  28. ChatDetailPage(this.id, this.type,this.toUserId);
  29. final String id;
  30. final String type;
  31. final String toUserId;
  32. @override
  33. _ChatDetailPageState createState() => _ChatDetailPageState();
  34. // _ChatDetailPageState createState() => _ChatDetailPageState(type,index);
  35. }
  36. class _ChatDetailPageState extends State<ChatDetailPage> {
  37. bool hasText = false;
  38. // String type0;
  39. // String index0;
  40. int type = 0;
  41. int index = 1;
  42. List<dynamic> msgList = [];
  43. List<dynamic> msgListBack = [];
  44. List<dynamic> assList = [];
  45. bool showEmoji = false;
  46. bool hasMore = true;
  47. int _page = 0;
  48. int pageSize = 10;
  49. // int index = int.parse("3");
  50. Conversation data;
  51. // _ChatDetailPageState(this.type0,this.index0);
  52. WebSocketProvide provider = WebSocketProvide();
  53. ScrollController _scrollController;
  54. List<dynamic> userList;
  55. List<dynamic> storyList = [];
  56. List<dynamic> storyListUserOnline = [];
  57. //避免从附近的人打招呼重复的initRoom
  58. bool isTrim = false;
  59. int dataTable;
  60. final controller = TextEditingController();
  61. void _handleSubmitted(context, String text) {
  62. FocusScope.of(context).requestFocus(FocusNode());
  63. if (controller.text.length > 0) {
  64. FocusScope.of(context).requestFocus(FocusNode());
  65. print('发送${text}');
  66. print(type);
  67. // if(type == 1){
  68. print(666);
  69. Provider.of<WebSocketProvide>(context, listen: false)
  70. .sendMessage(context, text, widget.id,1,dataTable,widget.toUserId);
  71. showEmoji = false;
  72. hasMore = true;
  73. _page = 0;
  74. // }
  75. // new Future.delayed(Duration(milliseconds: 1000),(){
  76. // setState(() {
  77. // hasText = false;
  78. // // messageList.add({'type':1,'text':text,});
  79. // msgList = Provider.of<WebSocketProvide>(context,listen: false).historyMessageqqq;
  80. // });
  81. // });
  82. controller.clear(); //清空输入框
  83. FocusScope.of(context).requestFocus(FocusNode());
  84. // _jumpBottom();
  85. } else {
  86. toasts("请输入");
  87. }
  88. }
  89. void _jumpBottom() {
  90. //滚动到底部
  91. _scrollController.animateTo(999999999,
  92. curve: Curves.easeOut, duration: Duration(milliseconds: 200));
  93. }
  94. String emoji = "😀,😁,😂,😃,😄,😅,😆,😉,😊,😋,😎,😍,😘,😗,😙,😚,😇,😐,😑,😶,😏,😣,😥,😮,😯,😪,😫,😴,😌,😛,😜,😝,😒,😓,😔,😕,😲,😷,😖,😞,😟,😤,😢,😭,😦,😧,😨,😬,😰,😱,😳,😵,😡,😠";
  95. List<String>emojiList = [];
  96. void setWebSocket() async {
  97. SharedPreferences prefs = await SharedPreferences.getInstance();
  98. new Future.delayed(Duration(milliseconds: 500), () {
  99. Provider.of<WebSocketProvide>(context, listen: false)
  100. .incomeRoom(widget.id);
  101. getStringEvent(widget.id);
  102. });
  103. }
  104. void initJump() async {
  105. new Future.delayed(Duration(milliseconds: 500), () {
  106. FocusScope.of(context).requestFocus(FocusNode());
  107. _jumpBottom();
  108. });
  109. }
  110. void disposeJump() async {
  111. new Future.delayed(Duration(milliseconds: 500), () {
  112. Provider.of<WebSocketProvide>(context, listen: false).closeWebSocket();
  113. });
  114. }
  115. void getMsgList() async {
  116. new Future.delayed(Duration(milliseconds: 2000), () {
  117. setState(() {
  118. // msgList = storyList;
  119. msgList = Provider.of<WebSocketProvide>(context, listen: false)
  120. .historyMessageqqq;
  121. print(JsonEncoder().convert(msgList));
  122. print(444443);
  123. _jumpBottom();
  124. });
  125. // LogUtil.d(msgList);
  126. // print(44444484444);
  127. });
  128. }
  129. @override
  130. void initState() {
  131. emojiList = emoji.split(',');
  132. // print(emojiList);
  133. assList = [];
  134. if(widget.type == "nearToOne"){
  135. dataTable = 3;
  136. }else {
  137. dataTable = null;
  138. }
  139. print(JsonEncoder().convert(emojiList));
  140. print(widget.id);
  141. print(66669999);
  142. // DartNotificationCenter.registerChannel(channel: 'socket_event');
  143. // DartNotificationCenter.post(
  144. // channel: "socket_event",
  145. // options: 'with options!!',
  146. // );
  147. FastNotification.addListener("chat_room", (historyMessageqqq) {
  148. if (mounted) {
  149. setState(() {
  150. msgList = historyMessageqqq;
  151. print(JsonEncoder().convert(msgList));
  152. print(4444499);
  153. });
  154. _jumpBottom();
  155. }
  156. });
  157. FastNotification.addListener("chat_room_chat", (historyMessageqqq) {
  158. if (mounted) {
  159. setState(() {
  160. msgList = historyMessageqqq;
  161. print(JsonEncoder().convert(msgList));
  162. print(444449911111111);
  163. });
  164. _jumpBottom();
  165. }
  166. });
  167. FastNotification.addListener("set_user", (setUserList) {
  168. if (mounted) {
  169. new Future.delayed(Duration(milliseconds: 1000), () {
  170. // setState(() {
  171. // userList = setUserList;
  172. // });
  173. });
  174. }
  175. });
  176. FastNotification.addListener("initSocket", (initThisSocket) {
  177. if (mounted) {
  178. isTrim = true;
  179. setWebSocket();
  180. _jumpBottom();
  181. FocusScope.of(context).requestFocus(FocusNode());
  182. toasts("聊天室已重连!");
  183. }
  184. });
  185. print("开启123");
  186. super.initState();
  187. _scrollController = new ScrollController();
  188. setWebSocket();
  189. // getStringEvent(widget.id);
  190. // initJump();
  191. }
  192. @override
  193. void didChangeDependencies() {
  194. super.didChangeDependencies();
  195. }
  196. void getStringEvent(roomId) async {
  197. SharedPreferences prefs = await SharedPreferences.getInstance();
  198. List<dynamic> storyList = [];
  199. List<dynamic> storyListUserOnline = [];
  200. if (prefs.getStringList(roomId) != null) {
  201. List<String> hisString = prefs.getStringList(roomId);
  202. storyList = hisString.map((item) => jsonDecode(item)).toList();
  203. // new Future.delayed(Duration(milliseconds: 1000),(){
  204. // setState(() {
  205. // msgList = storyList;
  206. // userList = storyListUserOnline;
  207. // print(JsonEncoder().convert(msgList));
  208. // print(444447);
  209. // _jumpBottom();
  210. // });
  211. // // LogUtil.d(msgList);
  212. // // print(44444484444);
  213. // });
  214. } else {
  215. prefs.setStringList(roomId, []);
  216. }
  217. // if (flustars.SpUtil.getString(roomId + "userOnline") != null &&
  218. // flustars.SpUtil.getString(roomId + "userOnline") != "") {
  219. // // if(prefs.getString(roomId+"userOnline")!=null){
  220. // // String hisStringUserOnline = prefs.getString(roomId+"userOnline");
  221. // // flustars.SpUtil.putString(roomId+"userOnline", res.token);
  222. // String hisStringUserOnline =
  223. // flustars.SpUtil.getString(roomId + "userOnline");
  224. // for (var value in JsonDecoder().convert(hisStringUserOnline)) {
  225. // print(value);
  226. // storyListUserOnline.add(value);
  227. // }
  228. // ;
  229. // // storyListUserOnline = JsonDecoder().convert(hisStringUserOnline);
  230. // // storyListUserOnline = hisStringUserOnline.map((item)=>jsonDecode(item)).toList();
  231. // } else {
  232. // // prefs.setString(roomId+"userOnline",'');
  233. // }
  234. // print(JsonEncoder().convert(storyList));
  235. // print(JsonEncoder().convert(storyListUserOnline));
  236. new Future.delayed(Duration(milliseconds: 1000), () {
  237. setState(() {
  238. if (storyList.length > 0) {
  239. msgList = storyList;
  240. // _onRefresh();
  241. }
  242. if (storyListUserOnline.length > 0) {
  243. userList = storyListUserOnline;
  244. }
  245. print(JsonEncoder().convert(msgList));
  246. print(444447);
  247. _jumpBottom();
  248. });
  249. // LogUtil.d(msgList);
  250. // print(44444484444);
  251. });
  252. }
  253. // @override
  254. // void didChangeDependencies() {
  255. // // Provider.of<WebSocketProvide>(context).closeWebSocket();
  256. // Provider.of<WebSocketProvide>(context,listen: false).closeWebSocket();
  257. // super.didChangeDependencies();
  258. // }
  259. FocusNode blankNode = FocusNode();
  260. ///选择图片
  261. void selectPicker() {
  262. showDialog(
  263. context: context,
  264. builder: (BuildContext context) {
  265. return SimpleDialog(
  266. title: Text("选择方式"),
  267. children: ["拍照", '从手机相册选择'].map((String value) {
  268. print("$value");
  269. return SimpleDialogOption(
  270. child: Text(
  271. "${value}",
  272. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  273. ),
  274. onPressed: () {
  275. _getImage(value == '拍照' ? 1 : 0);
  276. Navigator.of(context).pop();
  277. },
  278. );
  279. }).toList());
  280. });
  281. }
  282. List<String>imagesList = [];
  283. List<String>imagesListLast = [];
  284. void _getImage(int key) async {
  285. try {
  286. var _imageFile = await ImagePicker.pickImage(
  287. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  288. maxWidth: 800,
  289. imageQuality: 95);
  290. print(_imageFile);
  291. print(3333);
  292. if (_imageFile != null) {
  293. // images.add(_imageFile);
  294. upLoadFileOnce(_imageFile.path);
  295. // setState(() {});
  296. }
  297. } catch (e) {
  298. toasts("没有权限,无法打开相册!");
  299. }
  300. }
  301. upLoadFileOnce(path) {
  302. showLoading(context, "正在发送...");
  303. NewApiService().upload(path, onSuccess: (res) {
  304. // imagesUrl.add(res.path);
  305. dismissLoading(context);
  306. String imagesUrl;
  307. imagesUrl = (res.pathUrl);
  308. Provider.of<WebSocketProvide>(context, listen: false)
  309. .sendMessage(context, imagesUrl, widget.id,2,dataTable,widget.toUserId);
  310. }, onError: (code, msg) {
  311. dismissLoading(context);
  312. toasts(msg);
  313. });
  314. }
  315. @override
  316. Widget build(BuildContext context) {
  317. double width = MediaQuery.of(context).size.width;
  318. double height = MediaQuery.of(context).size.height;
  319. // print(JsonEncoder().convert(msgList));
  320. imagesList = [];
  321. msgListBack = [];
  322. msgList.forEach((element) {
  323. msgListBack.insert(0, element);
  324. });
  325. print(JsonEncoder().convert(msgListBack));
  326. print("/**/*/**///---------------------");
  327. if(msgList.length > 0){
  328. msgList.forEach((element) {
  329. if(element["type"]==2){
  330. imagesList.add(element["msg"]);
  331. }
  332. });
  333. }
  334. // print(1234567980);
  335. return ChangeNotifierProvider<WebSocketProvide>(
  336. create: (_) => provider,
  337. child: Scaffold(
  338. appBar: MyAppBar(
  339. centerTitle: "聊天室",
  340. // onPressed:(){
  341. // NavigatorUtils.push(context, FriendsRouter.friendsList);
  342. // }
  343. isFun: true,
  344. fun: () {
  345. // Provider.of<WebSocketProvide>(context,listen: false).closeWebSocket();
  346. // NavigatorUtils.push(context, FriendsRouter.friendsList);
  347. Navigator.popUntil(context, ModalRoute.withName('/home'));
  348. // NavigatorUtils.push(context, FriendsRouter.friendsList, clearStack: true);
  349. // NavigatorUtils.push(context, Routers.home, clearStack: true);
  350. },
  351. ),
  352. body: GestureDetector(
  353. onTap: () {
  354. // 点击空白页面关闭键盘
  355. FocusScope.of(context).requestFocus(blankNode);
  356. },
  357. child: Stack(
  358. children: <Widget>[
  359. GestureDetector(
  360. onTap: (){
  361. setState(() {
  362. showEmoji = false;
  363. });
  364. },
  365. child: Container(
  366. padding: widget.type == "someToOne"
  367. ? EdgeInsets.only(top: ScreenUtil().setWidth(10))
  368. : EdgeInsets.only(top: ScreenUtil().setWidth(10)),
  369. // color: Colors.red,
  370. color: ThemeUtils.getTabsBg(context),
  371. child: Column(
  372. // crossAxisAlignment: CrossAxisAlignment.end,
  373. // mainAxisAlignment: MainAxisAlignment.end,
  374. children: <Widget>[
  375. !hasMore?Container(
  376. padding: EdgeInsets.only(bottom:5),
  377. child: Text(
  378. "无更多历史记录~",
  379. style: TextStyle(
  380. color: Color(0xff999999),
  381. fontSize: ScreenUtil().setSp(14)),
  382. textAlign: TextAlign.center,
  383. ),
  384. ):Container(child: null,),
  385. Expanded(
  386. child: ChatListView(
  387. key: Key('chat_list'),
  388. scrollController: _scrollController,
  389. onRefresh:_loadMore,
  390. pageSize: 10,
  391. itemCount: msgList.length,
  392. hasMore: hasMore,
  393. itemBuilder: (_, index) {
  394. int typeUser;
  395. // print(msgList[index]["fromUser"]);
  396. // print(msgList[index]["msg"]);
  397. // print(jsonDecode(msgList[index])["fromUser"]);
  398. // print(1234567890);
  399. if (msgList[index]["fromUser"] ==
  400. flustars.SpUtil.getString(Constant.userId)) {
  401. typeUser = 1;
  402. } else {
  403. typeUser = 0;
  404. }
  405. // if(msgList[index]["type"]==2){
  406. // imagesList.add(msgList[index]["msg"]);
  407. // print(msgList[index]["msg"]);
  408. // }
  409. // print("///////////////////////////////////////////");
  410. // LogUtil.d(imagesList);
  411. // print("///////////////////////////////////////////");
  412. return ChatContentView(
  413. contentIndex:index,
  414. urlList:imagesList,
  415. type: typeUser,
  416. text: msgList[index]["msg"],
  417. msgType: msgList[index]["type"],
  418. avatar: msgList[index]["avatarUrl"],
  419. username: msgList[index]["name"],
  420. isNetwork: msgList[index]["avatarUrl"] != null
  421. ? true
  422. : false);
  423. },
  424. )
  425. ),
  426. // Consumer<WebSocketProvide>(builder: (context, child, val) {
  427. // return
  428. // Expanded(
  429. // child: ChatListView(
  430. // key: Key('chat_list'),
  431. // scrollController: _scrollController,
  432. // onRefresh:_loadMore,
  433. // pageSize: 10,
  434. // itemCount: msgList.length,
  435. // loadMore: _loadMore,
  436. // hasMore: hasMore,
  437. // itemBuilder: (_, index) {
  438. // int typeUser;
  439. // // print(msgList[index]["fromUser"]);
  440. // // print(msgList[index]["msg"]);
  441. // // print(jsonDecode(msgList[index])["fromUser"]);
  442. // // print(1234567890);
  443. // if (msgList[index]["fromUser"] ==
  444. // flustars.SpUtil.getString(Constant.userId)) {
  445. // typeUser = 1;
  446. // } else {
  447. // typeUser = 0;
  448. // }
  449. // // if(msgList[index]["type"]==2){
  450. // // imagesList.add(msgList[index]["msg"]);
  451. // // print(msgList[index]["msg"]);
  452. // // }
  453. // print("///////////////////////////////////////////");
  454. // LogUtil.d(imagesList);
  455. // print("///////////////////////////////////////////");
  456. // return ChatContentView(
  457. // contentIndex:index,
  458. // urlList:imagesList,
  459. // type: typeUser,
  460. // text: msgList[index]["msg"],
  461. // msgType: msgList[index]["type"],
  462. // avatar: msgList[index]["avatarUrl"],
  463. // username: msgList[index]["name"],
  464. // isNetwork: msgList[index]["avatarUrl"] != null
  465. // ? true
  466. // : false);
  467. // },
  468. // )
  469. // // ListView.builder(
  470. // // controller: _scrollController,
  471. // // physics: ClampingScrollPhysics(),
  472. // // itemBuilder: (BuildContext context, int index) {
  473. // // int typeUser;
  474. // // // print(msgList[index]["fromUser"]);
  475. // // // print(msgList[index]["msg"]);
  476. // // // print(jsonDecode(msgList[index])["fromUser"]);
  477. // // // print(1234567890);
  478. // // if (msgList[index]["fromUser"] ==
  479. // // flustars.SpUtil.getString(Constant.userId)) {
  480. // // typeUser = 1;
  481. // // } else {
  482. // // typeUser = 0;
  483. // // }
  484. // // // if(msgList[index]["type"]==2){
  485. // // // imagesList.add(msgList[index]["msg"]);
  486. // // // print(msgList[index]["msg"]);
  487. // // // }
  488. // // // print("///////////////////////////////////////////");
  489. // // // LogUtil.d(imagesList);
  490. // // // print("///////////////////////////////////////////");
  491. // // return ChatContentView(
  492. // // contentIndex:index,
  493. // // urlList:imagesList,
  494. // // type: typeUser,
  495. // // text: msgList[index]["msg"],
  496. // // msgType: msgList[index]["type"],
  497. // // avatar: msgList[index]["avatarUrl"],
  498. // // username: msgList[index]["name"],
  499. // // isNetwork: msgList[index]["avatarUrl"] != null
  500. // // ? true
  501. // // : false);
  502. // // // return ChatContentView(type:typeUser,text:msgList[index]["msg"],avatar:imgFontUrl+msgList[index]["avatarUrl"],username:msgList[index]["name"],isNetwork:msgList[index]["avatarUrl"]!=null?true:false);
  503. // // },
  504. // // itemCount: msgList.length,
  505. // // // itemCount:type == 1 ? list.length : messageList.length ,
  506. // // )
  507. // );
  508. // }),
  509. showEmoji?Container(
  510. padding: EdgeInsets.only(left:ScreenUtil().setWidth(6),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(10),right: ScreenUtil().setWidth(6)),
  511. color: Colors.white,
  512. height: ScreenUtil().setWidth(200),
  513. child: GridView.extent(
  514. //横轴的最大长度
  515. maxCrossAxisExtent: 35,
  516. //内边距
  517. padding: EdgeInsets.all(4.0),
  518. //垂直方向的间距
  519. mainAxisSpacing: 4.0,
  520. //水平方向的间距
  521. crossAxisSpacing: 4.0,
  522. children: emojiList.map((element) {
  523. return GestureDetector(
  524. onTap: (){
  525. controller.text += element;
  526. },
  527. child: Text(
  528. element,
  529. style: TextStyle(
  530. color: Color(0xff000000),
  531. fontSize: ScreenUtil().setSp(22)),
  532. textAlign: TextAlign.center,
  533. ),
  534. );
  535. }).toList(),
  536. )
  537. ):Container(child: null,),
  538. Container(
  539. padding: EdgeInsets.only(
  540. top: ScreenUtil().setHeight(2.0),
  541. bottom: ScreenUtil().setHeight(2.0),
  542. left: 0,
  543. right: 0),
  544. color: ThemeUtils.getDialogTextFieldColor(context),
  545. child: Row(
  546. children: <Widget>[
  547. Container(
  548. width: ScreenUtil().setWidth(30.0),
  549. margin: EdgeInsets.only(
  550. right: ScreenUtil().setWidth(10.0)),
  551. child: IconButton(
  552. icon: Icon(ICons.ADD),
  553. onPressed: () {
  554. selectPicker();
  555. FocusScope.of(context).requestFocus(FocusNode());
  556. }),
  557. ),
  558. Expanded(
  559. child: Container(
  560. // padding: EdgeInsets.only(top: ScreenUtil().setHeight(8.0), bottom: ScreenUtil().setHeight(8.0)),
  561. height: ScreenUtil().setHeight(30.0),
  562. decoration: BoxDecoration(
  563. borderRadius:
  564. BorderRadius.all(Radius.circular(5.0)),
  565. color: Colors.white),
  566. child: TextField(
  567. controller: controller,
  568. // decoration: InputDecoration.collapsed(hintText: null),
  569. decoration: InputDecoration(
  570. border: InputBorder.none,
  571. ),
  572. maxLines: 1,
  573. autocorrect: true,
  574. autofocus: false,
  575. textAlign: TextAlign.start,
  576. style: TextStyle(color: Colors.black),
  577. cursorColor: Colors.green,
  578. onChanged: (text) {
  579. setState(() {
  580. hasText = text.length > 0 ? true : false;
  581. });
  582. // print('change=================== $text');
  583. },
  584. // onSubmitted:_handleSubmitted,
  585. enabled: true, //bu禁用
  586. ),
  587. )),
  588. Container(
  589. width: ScreenUtil().setWidth(30.0),
  590. child: IconButton(
  591. icon: Icon(ICons.FACES), //发送按钮图标
  592. onPressed: () {
  593. print('打开表情面板');
  594. setState(() {
  595. showEmoji = !showEmoji;
  596. });
  597. }),
  598. ),
  599. Container(
  600. width: ScreenUtil().setWidth(30.0),
  601. margin: EdgeInsets.only(
  602. right: ScreenUtil().setWidth(10.0)),
  603. child: IconButton(
  604. //发送按钮或者+按钮
  605. icon: Icon(Icons.send),
  606. onPressed: () {
  607. if (controller.text == null || controller.text == '') {
  608. toasts("请输入内容");
  609. } else {
  610. _handleSubmitted(context, controller.text);
  611. }
  612. }),
  613. )
  614. ],
  615. ),
  616. )
  617. ],
  618. ),
  619. ),
  620. ),
  621. // widget.type == "someToOne"
  622. // ? Positioned(
  623. // top: 0,
  624. // left: 0,
  625. // child: userList != null && userList != []
  626. // ? Container(
  627. // width: width,
  628. // height: ScreenUtil().setWidth(100),
  629. // padding: EdgeInsets.only(
  630. // top: ScreenUtil().setWidth(15),
  631. // bottom: ScreenUtil().setWidth(10)),
  632. // color: Colors.white,
  633. // child: ListView(
  634. // scrollDirection: Axis.horizontal,
  635. // children: userList.asMap().keys.map((i) {
  636. // if (i == 0) {
  637. // return userList[i]["flag"]
  638. // ? Container(
  639. // padding: EdgeInsets.only(
  640. // right:
  641. // ScreenUtil().setWidth(15),
  642. // left: ScreenUtil()
  643. // .setWidth(15)),
  644. // child: Column(children: <Widget>[
  645. // ClipRRect(
  646. // borderRadius:
  647. // BorderRadius.all(
  648. // Radius.circular(
  649. // 22)),
  650. // child: LoadNetworkImage(
  651. // userList[i]["avatarUrl"],
  652. // width: ScreenUtil()
  653. // .setWidth(43),
  654. // height: ScreenUtil()
  655. // .setWidth(43),
  656. // )
  657. // // userList[i]["avatarUrl"]!=null&&userList[i]["avatarUrl"]!=null ?
  658. // // FadeInImage.assetNetwork(
  659. // // placeholder: 'assets/images/temporary/avator2.png',
  660. // // //预览图
  661. // // fit: BoxFit.fitWidth,
  662. // // image: imgFontUrl+userList[i]["avatarUrl"],
  663. // // width: ScreenUtil().setWidth(43),
  664. // // height:ScreenUtil().setWidth(43),
  665. // // )
  666. // // :Image.asset(
  667. // // 'assets/images/temporary/avator2.png',
  668. // // fit: BoxFit.cover,
  669. // // width: ScreenUtil().setWidth(43),
  670. // // height:ScreenUtil().setWidth(43),
  671. // // ),
  672. // ),
  673. // Container(
  674. // height: 5, child: null),
  675. // Text(
  676. // userList[i]["name"],
  677. // style: TextStyle(
  678. // color: Color(0xff000000),
  679. // fontSize: ScreenUtil()
  680. // .setSp(14)),
  681. // textAlign: TextAlign.start,
  682. // ),
  683. // ]),
  684. // )
  685. // : Container(child: null);
  686. // } else {
  687. // return userList[i]["flag"]
  688. // ? Container(
  689. // padding: EdgeInsets.only(
  690. // right: ScreenUtil()
  691. // .setWidth(15)),
  692. // child: Column(children: <Widget>[
  693. // ClipRRect(
  694. // borderRadius:
  695. // BorderRadius.all(
  696. // Radius.circular(22)),
  697. // child: LoadNetworkImage(
  698. // userList[i]["avatarUrl"],
  699. // width: ScreenUtil()
  700. // .setWidth(43),
  701. // height: ScreenUtil()
  702. // .setWidth(43),
  703. // ),
  704. // // userList[i]["avatarUrl"]!=null&&userList[i]["avatarUrl"]!=null ?
  705. // // FadeInImage.assetNetwork(
  706. // // placeholder: 'assets/images/temporary/avator2.png',
  707. // // //预览图
  708. // // fit: BoxFit.fitWidth,
  709. // // image: imgFontUrl+userList[i]["avatarUrl"],
  710. // // width: ScreenUtil().setWidth(43),
  711. // // height:ScreenUtil().setWidth(43),
  712. // // )
  713. // // :Image.asset(
  714. // // 'assets/images/temporary/avator2.png',
  715. // // fit: BoxFit.cover,
  716. // // width: ScreenUtil().setWidth(43),
  717. // // height:ScreenUtil().setWidth(43),
  718. // // ),
  719. // ),
  720. // Container(
  721. // height: 5, child: null),
  722. // Text(
  723. // userList[i]["name"],
  724. // style: TextStyle(
  725. // color: Color(0xff000000),
  726. // fontSize: ScreenUtil()
  727. // .setSp(14)),
  728. // textAlign: TextAlign.start,
  729. // ),
  730. // ]),
  731. // )
  732. // : Container(child: null);
  733. // }
  734. // }).toList()))
  735. // : Container(
  736. // child: null,
  737. // ))
  738. // : Container(child: null)
  739. ],
  740. ),
  741. ),
  742. ),
  743. );
  744. }
  745. // @override
  746. // void dispose() {
  747. // Provider.of<WebSocketProvide>(context,listen: false).closeWebSocket();
  748. // // disposeJump();
  749. // super.dispose();
  750. // }
  751. Future _onRefresh() async {
  752. _page = 1;
  753. await NewApiService().getMsgHistoryList(
  754. {
  755. "pageNum":_page,
  756. "pageSize":pageSize,
  757. "sessionid":widget.id,
  758. },
  759. onSuccess: (res) {
  760. print("初始化数据");
  761. print(JsonEncoder().convert(res));
  762. List<dynamic> ass = [];
  763. if(res != null && res.length > 0){
  764. ass.addAll(res);
  765. }
  766. ass.addAll(msgList);
  767. setState(() {
  768. msgList = ass;
  769. _jumpBottom();
  770. });
  771. print("初始化数据");
  772. }, onError: (code, msg) {
  773. toasts(msg);
  774. });
  775. }
  776. Future _loadMore() async {
  777. if(hasMore){
  778. _page++;
  779. await NewApiService().getMsgHistoryList(
  780. {
  781. "pageNum":_page,
  782. "pageSize":10,
  783. // "pageSize":pageSize,
  784. "sessionid":widget.id,
  785. },
  786. onSuccess: (res) {
  787. print(JsonEncoder().convert(res));
  788. print(123456111);
  789. if (res != null && res.length > 0) {
  790. print("初始化数据");
  791. print(JsonEncoder().convert(res));
  792. List<dynamic> ass = [];
  793. ass.addAll(res);
  794. if(assList.length == 0){
  795. ass.addAll(msgList);
  796. }else {
  797. ass.addAll(assList);
  798. }
  799. assList = ass;
  800. setState(() {
  801. msgList = ass;
  802. hasMore = true;
  803. // _jumpBottom();
  804. });
  805. print("初始化数据");
  806. }else {
  807. setState(() {
  808. hasMore = false;
  809. });
  810. }
  811. }, onError: (code, msg) {
  812. toasts(msg);
  813. });
  814. }else {
  815. print("无更多历史记录!");
  816. }
  817. print("加载更多了");
  818. }
  819. }