Jelajahi Sumber

聊天室修改

jyj 4 tahun lalu
induk
melakukan
5552eca566

+ 146 - 146
lib/internal/bbs/page/brand_page.dart

@@ -96,158 +96,158 @@ class BrandPageState extends State<BrandPage> {
       body:changeList!=null?Container(
         child: Stack(
           children: <Widget>[
-            Positioned(
-                  left: 0,
-                  top: 0,
-                  child:  FlatButton(
-                    padding: EdgeInsets.symmetric(horizontal: 0),
-                    child: Container(
-                      width: width,
-                      height: ScreenUtil().setWidth(48),
-                      padding: EdgeInsets.only(top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(10),left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15)),
-                      // color: Color(0xFFF1F4FC),
-                      color: ThemeUtils.getDialogTextFieldColor(context),
-                      child:Row(
-                        children: <Widget>[
-                          Container(
-                            padding: EdgeInsets.only(right:ScreenUtil().setWidth(10)),
-                            child: Icon(
-                              IconData(
-                                0xe6dd,
-                                fontFamily:"myfont"
-                              ),
-                              size: 24.0,
-                              color:Color(0xffcccccc),
-                            ),
-                          ),
-                        Text(
-                          "自定义品牌",
-                          style: TextStyle(
-                            fontSize:ScreenUtil().setSp(16)
-                          ),
-                          textAlign:TextAlign.start,
-                        ),
-                        ],
-                      )
-                    ),
-                    onPressed: (){
-                      showDialog(
-                        context: context,
-                        barrierDismissible: true,  // 是否可以点击底部遮罩层取消dialog
-                        // child: Text('data')
-                        builder: (context) {
-                          return Container(
-                            child: AlertDialog(
-                              backgroundColor:ThemeUtils.getDialogTextFieldColor(context),
-                              title: Text('品牌名称:'),
-                              titlePadding: EdgeInsets.fromLTRB(24.0, 24.0, 0.0, 0.0),
-                              titleTextStyle: TextStyle( fontSize: ScreenUtil().setSp(16)),
-                              content: Container(
-                                height: ScreenUtil().setWidth(30),
-                                child: TextField(
-                                /*
-                                *  _textEditingController.text是当前文本
-                                *  initialValue + onChanged 也可以实现获取当前文本
-                                * 
-                                *  onChanged是专门用于监听文本变化
-                                *  而controller 除了能监听文本变化外,它还可以设置默认值、选择文本
-                                */
-                                controller: _textEditingController,
-                                // textInputAction: TextInputAction.go, // 输入框的确定按钮
-                                focusNode: _focusNode1,
-                                decoration: InputDecoration(
-                                  contentPadding: EdgeInsets.only(left:ScreenUtil().setWidth(10),right:ScreenUtil().setWidth(5),),
-                                  border: OutlineInputBorder(
-                                      borderRadius: BorderRadius.circular(2.0),
-                        //            borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
-                                  ),
-                                  // labelText: 'TextField', // 上标
-                                  // icon: Icon(Icons.ac_unit), // Field外部
-                                  hintText: '请输入', // hint 暗示
-                                  // helperText: '左下角', // helper 帮手
-                                  hasFloatingPlaceholder: false, // labelText是否漂浮
-                                  // errorText: '错误文本',
-                                  errorBorder: InputBorder.none, // 当error时的border
-                                  // prefixIcon: Icon(Icons.phone_iphone), // Field前边
-                                  // 后缀和前缀在focus时显示
-                                  // prefixText: '前缀',  // 前缀
-                                  // prefix: Text('prefix'),
-                                  // suffixText: '后缀', // 后缀
-                                  // counterText: '右下角', // 计数器
-                                  filled: false, // 背景色
-                                  // fillColor: Colors.cyan.withAlpha(35),
-                                  focusedBorder: OutlineInputBorder(), // 当focus时的border
-                                  // semanticCounterText: '222'
-                                ),
-                                // keyboardType: TextInputType.numberWithOptions(),
-                                cursorColor: Color(0xFF999999),
-                                obscureText: false, // 输入变成**
-                                onChanged: (val) {
-                                  // xxx
-                                },
-                              ),
-                              ),
-                              contentPadding: EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
-                              contentTextStyle: TextStyle(fontSize: ScreenUtil().setSp(14)),
-                              actions: <Widget>[
-                                Container(
-                                  height:36,
-                                  decoration: BoxDecoration(
-                                    gradient: const LinearGradient(
-                                        colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
-                                  ),
-                                  child: FlatButton(
-                                    child: Text('确认',style: TextStyle(color:Colors.white),),
-                                    onPressed: (){
-                                      print(_textEditingController.text);
-                                      if(_textEditingController.text.trim()== null){
-                                        toasts("请输入");
-                                        return;
-                                      }
-                                      if(!isChinese(_textEditingController.text)){
-                                        toasts("请输入中文");
-                                        return;
-                                      }
-                                      NewApiService().addBrand(_textEditingController.text, onSuccess: (res) {
-                                        toasts("自定义品牌成功");
-                                        getBrandList();
-                                        setState(() {});
-                                        _textEditingController.text = "";
-                                        Navigator.maybePop(context);
-                                      }, onError: (code, msg) {
-                                        toasts(msg);
-                                        _textEditingController.text = "";
-                                        Navigator.maybePop(context);
-                                      });
+            // Positioned(
+            //       left: 0,
+            //       top: 0,
+            //       child:  FlatButton(
+            //         padding: EdgeInsets.symmetric(horizontal: 0),
+            //         child: Container(
+            //           width: width,
+            //           height: ScreenUtil().setWidth(48),
+            //           padding: EdgeInsets.only(top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(10),left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15)),
+            //           // color: Color(0xFFF1F4FC),
+            //           color: ThemeUtils.getDialogTextFieldColor(context),
+            //           child:Row(
+            //             children: <Widget>[
+            //               Container(
+            //                 padding: EdgeInsets.only(right:ScreenUtil().setWidth(10)),
+            //                 child: Icon(
+            //                   IconData(
+            //                     0xe6dd,
+            //                     fontFamily:"myfont"
+            //                   ),
+            //                   size: 24.0,
+            //                   color:Color(0xffcccccc),
+            //                 ),
+            //               ),
+            //             Text(
+            //               "自定义品牌",
+            //               style: TextStyle(
+            //                 fontSize:ScreenUtil().setSp(16)
+            //               ),
+            //               textAlign:TextAlign.start,
+            //             ),
+            //             ],
+            //           )
+            //         ),
+            //         onPressed: (){
+            //           showDialog(
+            //             context: context,
+            //             barrierDismissible: true,  // 是否可以点击底部遮罩层取消dialog
+            //             // child: Text('data')
+            //             builder: (context) {
+            //               return Container(
+            //                 child: AlertDialog(
+            //                   backgroundColor:ThemeUtils.getDialogTextFieldColor(context),
+            //                   title: Text('品牌名称:'),
+            //                   titlePadding: EdgeInsets.fromLTRB(24.0, 24.0, 0.0, 0.0),
+            //                   titleTextStyle: TextStyle( fontSize: ScreenUtil().setSp(16)),
+            //                   content: Container(
+            //                     height: ScreenUtil().setWidth(30),
+            //                     child: TextField(
+            //                     /*
+            //                     *  _textEditingController.text是当前文本
+            //                     *  initialValue + onChanged 也可以实现获取当前文本
+            //                     * 
+            //                     *  onChanged是专门用于监听文本变化
+            //                     *  而controller 除了能监听文本变化外,它还可以设置默认值、选择文本
+            //                     */
+            //                     controller: _textEditingController,
+            //                     // textInputAction: TextInputAction.go, // 输入框的确定按钮
+            //                     focusNode: _focusNode1,
+            //                     decoration: InputDecoration(
+            //                       contentPadding: EdgeInsets.only(left:ScreenUtil().setWidth(10),right:ScreenUtil().setWidth(5),),
+            //                       border: OutlineInputBorder(
+            //                           borderRadius: BorderRadius.circular(2.0),
+            //             //            borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
+            //                       ),
+            //                       // labelText: 'TextField', // 上标
+            //                       // icon: Icon(Icons.ac_unit), // Field外部
+            //                       hintText: '请输入', // hint 暗示
+            //                       // helperText: '左下角', // helper 帮手
+            //                       hasFloatingPlaceholder: false, // labelText是否漂浮
+            //                       // errorText: '错误文本',
+            //                       errorBorder: InputBorder.none, // 当error时的border
+            //                       // prefixIcon: Icon(Icons.phone_iphone), // Field前边
+            //                       // 后缀和前缀在focus时显示
+            //                       // prefixText: '前缀',  // 前缀
+            //                       // prefix: Text('prefix'),
+            //                       // suffixText: '后缀', // 后缀
+            //                       // counterText: '右下角', // 计数器
+            //                       filled: false, // 背景色
+            //                       // fillColor: Colors.cyan.withAlpha(35),
+            //                       focusedBorder: OutlineInputBorder(), // 当focus时的border
+            //                       // semanticCounterText: '222'
+            //                     ),
+            //                     // keyboardType: TextInputType.numberWithOptions(),
+            //                     cursorColor: Color(0xFF999999),
+            //                     obscureText: false, // 输入变成**
+            //                     onChanged: (val) {
+            //                       // xxx
+            //                     },
+            //                   ),
+            //                   ),
+            //                   contentPadding: EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
+            //                   contentTextStyle: TextStyle(fontSize: ScreenUtil().setSp(14)),
+            //                   actions: <Widget>[
+            //                     Container(
+            //                       height:36,
+            //                       decoration: BoxDecoration(
+            //                         gradient: const LinearGradient(
+            //                             colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
+            //                       ),
+            //                       child: FlatButton(
+            //                         child: Text('确认',style: TextStyle(color:Colors.white),),
+            //                         onPressed: (){
+            //                           print(_textEditingController.text);
+            //                           if(_textEditingController.text.trim()== null){
+            //                             toasts("请输入");
+            //                             return;
+            //                           }
+            //                           if(!isChinese(_textEditingController.text)){
+            //                             toasts("请输入中文");
+            //                             return;
+            //                           }
+            //                           NewApiService().addBrand(_textEditingController.text, onSuccess: (res) {
+            //                             toasts("自定义品牌成功");
+            //                             getBrandList();
+            //                             setState(() {});
+            //                             _textEditingController.text = "";
+            //                             Navigator.maybePop(context);
+            //                           }, onError: (code, msg) {
+            //                             toasts(msg);
+            //                             _textEditingController.text = "";
+            //                             Navigator.maybePop(context);
+            //                           });
                                       
-                                    },
-                                  ),
-                                ),
+            //                         },
+            //                       ),
+            //                     ),
                                 
-                                FlatButton(
-                                  color: Color(0xffcccccc),
-                                  child: Text('取消',style: TextStyle(color:Colors.white),),
-                                  onPressed: (){
-                                    Navigator.maybePop(context);
-                                    _textEditingController.text = "";
-                                  },
-                                ),
-                              ],
-                              semanticLabel: 'semanticLabel',
-                              shape: Border.all(color: Colors.white),
-                              elevation: 22
-                            ),
-                          );
-                        }
-                      );
+            //                     FlatButton(
+            //                       color: Color(0xffcccccc),
+            //                       child: Text('取消',style: TextStyle(color:Colors.white),),
+            //                       onPressed: (){
+            //                         Navigator.maybePop(context);
+            //                         _textEditingController.text = "";
+            //                       },
+            //                     ),
+            //                   ],
+            //                   semanticLabel: 'semanticLabel',
+            //                   shape: Border.all(color: Colors.white),
+            //                   elevation: 22
+            //                 ),
+            //               );
+            //             }
+            //           );
                       
-                    },
-                  )
+            //         },
+            //       )
                   
-                ),
+            //     ),
                  
             Container(
-              padding: EdgeInsets.only(top:ScreenUtil().setWidth(48)),
+              // padding: EdgeInsets.only(top:ScreenUtil().setWidth(48)),
               child:ListView(
                 controller:_scrollController,
                 children:<Widget>[

+ 726 - 0
lib/internal/bbs/page/chat_room copy.dart

@@ -0,0 +1,726 @@
+import 'package:flutter/material.dart';
+import 'package:liftmanager/widgets/app_bar.dart';
+import '../provide/websocket.dart';
+import 'package:flutter_screenutil/flutter_screenutil.dart';
+import '../common/style/style.dart';
+import './chat_detail/chat_content_view.dart';
+import '../model/conversation.dart';
+import 'package:provider/provider.dart';
+import 'package:liftmanager/widgets/load_image.dart';
+import 'package:liftmanager/internal/bbs/model/talk_model.dart';
+import 'package:liftmanager/utils/url.dart';
+import 'package:liftmanager/utils/log_util.dart';
+import 'dart:convert';
+import 'package:dart_notification_center/dart_notification_center.dart';
+import 'package:liftmanager/utils/fast_notification.dart';
+import 'package:liftmanager/routers/fluro_navigator.dart';
+import 'package:liftmanager/internal/friends/friends_router.dart';
+import 'package:liftmanager/routers/routers.dart';
+import 'package:liftmanager/common/common.dart';
+import 'package:flustars/flustars.dart' as flustars;
+import 'package:shared_preferences/shared_preferences.dart';
+import 'package:liftmanager/utils/toast.dart';
+import 'package:image_picker/image_picker.dart';
+import 'package:liftmanager/net/api_service.dart';
+import 'package:liftmanager/utils/theme_utils.dart';
+import 'package:liftmanager/widgets/chat_list_view.dart';
+
+class ChatDetailPage extends StatefulWidget {
+  ChatDetailPage(this.id, this.type,this.toUserId);
+  final String id;
+  final String type;
+  final String toUserId;
+  @override
+  _ChatDetailPageState createState() => _ChatDetailPageState();
+  // _ChatDetailPageState createState() => _ChatDetailPageState(type,index);
+}
+
+class _ChatDetailPageState extends State<ChatDetailPage> {
+  bool hasText = false;
+  // String type0;
+  // String index0;
+  int type = 0;
+  int index = 1;
+  List<dynamic> msgList = [];
+  bool showEmoji = false;
+
+  // int index = int.parse("3");
+  Conversation data;
+  // _ChatDetailPageState(this.type0,this.index0);
+  WebSocketProvide provider = WebSocketProvide();
+  ScrollController _scrollController;
+  List<dynamic> userList;
+  List<dynamic> storyList = [];
+  List<dynamic> storyListUserOnline = [];
+  //避免从附近的人打招呼重复的initRoom
+  bool isTrim = false;
+  int dataTable;
+
+  final controller = TextEditingController();
+  void _handleSubmitted(context, String text) {
+    FocusScope.of(context).requestFocus(FocusNode());
+    if (controller.text.length > 0) {
+      FocusScope.of(context).requestFocus(FocusNode());
+      print('发送${text}');
+      print(type);
+      // if(type == 1){
+      print(666);
+      Provider.of<WebSocketProvide>(context, listen: false)
+          .sendMessage(context, text, widget.id,1,dataTable,widget.toUserId);
+      showEmoji = false;
+      // }
+      // new Future.delayed(Duration(milliseconds: 1000),(){
+      //   setState(() {
+      //     hasText = false;
+      //     // messageList.add({'type':1,'text':text,});
+      //     msgList = Provider.of<WebSocketProvide>(context,listen: false).historyMessageqqq;
+      //   });
+      // });
+
+      controller.clear(); //清空输入框
+
+      FocusScope.of(context).requestFocus(FocusNode());
+      _jumpBottom();
+    } else {
+      toasts("请输入");
+    }
+  }
+
+  void _jumpBottom() {
+    //滚动到底部
+    _scrollController.animateTo(9999999999,
+        curve: Curves.easeOut, duration: Duration(milliseconds: 200));
+  }
+
+  String emoji = "😀,😁,😂,😃,😄,😅,😆,😉,😊,😋,😎,😍,😘,😗,😙,😚,😇,😐,😑,😶,😏,😣,😥,😮,😯,😪,😫,😴,😌,😛,😜,😝,😒,😓,😔,😕,😲,😷,😖,😞,😟,😤,😢,😭,😦,😧,😨,😬,😰,😱,😳,😵,😡,😠";
+  List<String>emojiList = [];
+  
+
+  void setWebSocket() async {
+    SharedPreferences prefs = await SharedPreferences.getInstance();
+
+    // Map<String,dynamic> sessionIdObjToGet = flustars.SpUtil.getObj("sessionIdObj", (v){
+    //                    return v;
+    //                  });
+    //                  LogUtil.d(sessionIdObjToGet);
+    // if(sessionIdObjToGet==null){
+    //   print(111);
+    //   Map<String,dynamic> nowObj = {
+    //                     widget.id:"hasSocket"
+    //                   };
+    //   flustars.SpUtil.putObject("sessionIdObj", nowObj);
+    //   new Future.delayed(Duration(milliseconds: 500),(){
+    //     Provider.of<WebSocketProvide>(context,listen: false).incomeRoom(widget.id);
+    //     // getMsgList();
+    //   });
+    // }else {
+    //   if(sessionIdObjToGet[widget.id]==null){
+    //     print(112);
+    //     Map<String,dynamic> thisItem = {
+    //                       widget.id:"hasSocket"
+    //                     };
+    //                     sessionIdObjToGet.addAll(thisItem);
+    //                     flustars.SpUtil.putObject("sessionIdObj", sessionIdObjToGet);
+    //                     new Future.delayed(Duration(milliseconds: 500),(){
+    //     Provider.of<WebSocketProvide>(context,listen: false).incomeRoom(widget.id);
+    //     // getMsgList();
+    //   });
+    //   }
+    // }
+    // if ((widget.type == "someToOne")&& isTrim==false) {
+    // if ((widget.type == "someToOne" || widget.type == "nearToOne")&& isTrim==false) {
+    //   new Future.delayed(Duration(milliseconds: 500), () {
+    //     Provider.of<WebSocketProvide>(context, listen: false)
+    //         .incomeRoom(widget.id);
+    //     getStringEvent(widget.id);
+    //   });
+    // } 
+    // // else if (widget.type == "nearToOne"){
+    // //   new Future.delayed(Duration(milliseconds: 500), () {
+    // //     Provider.of<WebSocketProvide>(context, listen: false)
+    // //         .loginAllSeconds(widget.id);
+    // //     getStringEvent(widget.id);
+    // //   });
+    // else {
+    // // } 
+    // // else if (widget.type == "oneToOne") {
+    //   new Future.delayed(Duration(milliseconds: 500), () {
+    //     Provider.of<WebSocketProvide>(context, listen: false)
+    //         .incomeFriend(widget.id);
+    //     getStringEvent(widget.id);
+    //   });
+    // }
+    // isTrim = false;
+
+    new Future.delayed(Duration(milliseconds: 500), () {
+        Provider.of<WebSocketProvide>(context, listen: false)
+            .incomeRoom(widget.id);
+        getStringEvent(widget.id);
+      });
+  }
+
+  void initJump() async {
+    new Future.delayed(Duration(milliseconds: 500), () {
+      FocusScope.of(context).requestFocus(FocusNode());
+      _jumpBottom();
+    });
+  }
+
+  void disposeJump() async {
+    new Future.delayed(Duration(milliseconds: 500), () {
+      Provider.of<WebSocketProvide>(context, listen: false).closeWebSocket();
+    });
+  }
+
+  void getMsgList() async {
+    new Future.delayed(Duration(milliseconds: 2000), () {
+      setState(() {
+        // msgList = storyList;
+        msgList = Provider.of<WebSocketProvide>(context, listen: false)
+            .historyMessageqqq;
+        print(JsonEncoder().convert(msgList));
+        print(444443);
+        _jumpBottom();
+      });
+      // LogUtil.d(msgList);
+      // print(44444484444);
+    });
+  }
+
+  @override
+  void initState() {
+    emojiList = emoji.split(',');
+    // print(emojiList);
+
+    if(widget.type == "nearToOne"){
+      dataTable = 3;
+    }else {
+      dataTable = null;
+    }
+    
+    
+    print(JsonEncoder().convert(emojiList));
+    print(66669999);
+    // DartNotificationCenter.registerChannel(channel: 'socket_event');
+    // DartNotificationCenter.post(
+    //   channel: "socket_event",
+    //   options: 'with options!!',
+    // );
+
+    FastNotification.addListener("chat_room", (historyMessageqqq) {
+      if (mounted) {
+        setState(() {
+          msgList = historyMessageqqq;
+          print(JsonEncoder().convert(msgList));
+          print(4444499);
+        });
+        _jumpBottom();
+      }
+    });
+    FastNotification.addListener("set_user", (setUserList) {
+      if (mounted) {
+        new Future.delayed(Duration(milliseconds: 1000), () {
+          setState(() {
+            userList = setUserList;
+          });
+        });
+      }
+    });
+
+    FastNotification.addListener("initSocket", (initThisSocket) {
+      if (mounted) {
+        isTrim = true;
+        setWebSocket();
+        _jumpBottom();
+        FocusScope.of(context).requestFocus(FocusNode());
+        toasts("聊天室已重连!");
+      }
+    });
+
+    print("开启123");
+    super.initState();
+    _scrollController = new ScrollController();
+
+    setWebSocket();
+    // getStringEvent(widget.id);
+
+    initJump();
+  }
+
+  @override
+  void didChangeDependencies() {
+    super.didChangeDependencies();
+  }
+
+  void getStringEvent(roomId) async {
+    SharedPreferences prefs = await SharedPreferences.getInstance();
+    List<dynamic> storyList = [];
+    List<dynamic> storyListUserOnline = [];
+    if (prefs.getStringList(roomId) != null) {
+      List<String> hisString = prefs.getStringList(roomId);
+      storyList = hisString.map((item) => jsonDecode(item)).toList();
+
+      // new Future.delayed(Duration(milliseconds: 1000),(){
+      //   setState(() {
+      //     msgList = storyList;
+      //     userList = storyListUserOnline;
+      //     print(JsonEncoder().convert(msgList));
+      //     print(444447);
+      //     _jumpBottom();
+      //   });
+      //   // LogUtil.d(msgList);
+      //   // print(44444484444);
+      // });
+
+    } else {
+      prefs.setStringList(roomId, []);
+    }
+
+    // if (flustars.SpUtil.getString(roomId + "userOnline") != null &&
+    //     flustars.SpUtil.getString(roomId + "userOnline") != "") {
+    //   // if(prefs.getString(roomId+"userOnline")!=null){
+    //   // String hisStringUserOnline = prefs.getString(roomId+"userOnline");
+    //   // flustars.SpUtil.putString(roomId+"userOnline", res.token);
+    //   String hisStringUserOnline =
+    //       flustars.SpUtil.getString(roomId + "userOnline");
+    //   for (var value in JsonDecoder().convert(hisStringUserOnline)) {
+    //     print(value);
+    //     storyListUserOnline.add(value);
+    //   }
+    //   ;
+    //   // storyListUserOnline = JsonDecoder().convert(hisStringUserOnline);
+    //   // storyListUserOnline = hisStringUserOnline.map((item)=>jsonDecode(item)).toList();
+
+    // } else {
+    //   //  prefs.setString(roomId+"userOnline",'');
+    // }
+
+    // print(JsonEncoder().convert(storyList));
+    // print(JsonEncoder().convert(storyListUserOnline));
+
+    new Future.delayed(Duration(milliseconds: 1000), () {
+      setState(() {
+        if (storyList.length > 0) {
+          msgList = storyList;
+        }
+        if (storyListUserOnline.length > 0) {
+          userList = storyListUserOnline;
+        }
+
+        print(JsonEncoder().convert(msgList));
+        print(444447);
+        _jumpBottom();
+      });
+      // LogUtil.d(msgList);
+      // print(44444484444);
+    });
+  }
+
+  // @override
+  // void didChangeDependencies() {
+  //   // Provider.of<WebSocketProvide>(context).closeWebSocket();
+  //   Provider.of<WebSocketProvide>(context,listen: false).closeWebSocket();
+  //   super.didChangeDependencies();
+  // }
+
+  FocusNode blankNode = FocusNode();
+
+  ///选择图片
+  void selectPicker() {
+    showDialog(
+        context: context,
+        builder: (BuildContext context) {
+          return SimpleDialog(
+              title: Text("选择方式"),
+              children: ["拍照", '从手机相册选择'].map((String value) {
+                print("$value");
+                return SimpleDialogOption(
+                  child: Text(
+                    "${value}",
+                    style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
+                  ),
+                  onPressed: () {
+                    _getImage(value == '拍照' ? 1 : 0);
+                    Navigator.of(context).pop();
+                  },
+                );
+              }).toList());
+        });
+  }
+
+  List<String>imagesList = [];
+  List<String>imagesListLast = [];
+
+  void _getImage(int key) async {
+    try {
+      var _imageFile = await ImagePicker.pickImage(
+          source: key == 1 ? ImageSource.camera : ImageSource.gallery,
+          maxWidth: 800,
+          imageQuality: 95);
+      print(_imageFile);
+      print(3333);
+      if (_imageFile != null) {
+        // images.add(_imageFile);
+        upLoadFileOnce(_imageFile.path);
+        // setState(() {});
+      }
+    } catch (e) {
+      toasts("没有权限,无法打开相册!");
+    }
+  }
+
+  
+
+  upLoadFileOnce(path) {
+    showLoading(context, "正在发送...");
+    NewApiService().upload(path, onSuccess: (res) {
+      // imagesUrl.add(res.path);
+      dismissLoading(context);
+      String imagesUrl;
+      imagesUrl = (res.pathUrl);
+      Provider.of<WebSocketProvide>(context, listen: false)
+          .sendMessage(context, imagesUrl, widget.id,2,dataTable,widget.toUserId);
+    }, onError: (code, msg) {
+      dismissLoading(context);
+      toasts(msg);
+    });
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    double width = MediaQuery.of(context).size.width;
+    // print(JsonEncoder().convert(msgList));
+    imagesList = [];
+    msgList.forEach((element) {
+      if(element["type"]==2){
+                            imagesList.add(element["msg"]);
+                          }
+    });
+    // print(1234567980);
+    
+    return ChangeNotifierProvider<WebSocketProvide>(
+      create: (_) => provider,
+      child: Scaffold(
+        appBar: MyAppBar(
+          centerTitle: "聊天室",
+          // onPressed:(){
+          //   NavigatorUtils.push(context, FriendsRouter.friendsList);
+          // }
+          isFun: true,
+          fun: () {
+            // Provider.of<WebSocketProvide>(context,listen: false).closeWebSocket();
+            // NavigatorUtils.push(context, FriendsRouter.friendsList);
+            Navigator.popUntil(context, ModalRoute.withName('/home'));
+            // NavigatorUtils.push(context, FriendsRouter.friendsList, clearStack: true);
+            // NavigatorUtils.push(context, Routers.home, clearStack: true);
+          },
+        ),
+        body: GestureDetector(
+          onTap: () {
+            // 点击空白页面关闭键盘
+            FocusScope.of(context).requestFocus(blankNode);
+          },
+          child: Stack(
+            children: <Widget>[
+              GestureDetector(
+                onTap: (){
+                  setState(() {
+                    showEmoji = false;
+                  });
+                },
+                child: Container(
+                padding: widget.type == "someToOne"
+                    ? EdgeInsets.only(top: ScreenUtil().setWidth(10))
+                    : EdgeInsets.only(top: ScreenUtil().setWidth(10)),
+                // color: Colors.red,
+                color: ThemeUtils.getTabsBg(context),
+                child: Column(
+                  children: <Widget>[
+                    Consumer<WebSocketProvide>(builder: (context, child, val) {
+                      return Expanded(
+                          child: ListView.builder(
+                        controller: _scrollController,
+                        physics: ClampingScrollPhysics(),
+                        itemBuilder: (BuildContext context, int index) {
+                          int typeUser;
+                          // print(msgList[index]["fromUser"]);
+                          // print(msgList[index]["msg"]);
+                          // print(jsonDecode(msgList[index])["fromUser"]);
+                          // print(1234567890);
+                          if (msgList[index]["fromUser"] ==
+                              flustars.SpUtil.getString(Constant.userId)) {
+                            typeUser = 1;
+                          } else {
+                            typeUser = 0;
+                          }
+                          
+                          // if(msgList[index]["type"]==2){
+                          //   imagesList.add(msgList[index]["msg"]);
+                          //   print(msgList[index]["msg"]);
+                          // }
+                          // print("///////////////////////////////////////////");
+                          // LogUtil.d(imagesList);
+                          // print("///////////////////////////////////////////");
+                          return ChatContentView(
+                            contentIndex:index,
+                            urlList:imagesList,
+                              type: typeUser,
+                              text: msgList[index]["msg"],
+                              msgType: msgList[index]["type"],
+                              avatar: msgList[index]["avatarUrl"],
+                              username: msgList[index]["name"],
+                              isNetwork: msgList[index]["avatarUrl"] != null
+                                  ? true
+                                  : false);
+                          // return ChatContentView(type:typeUser,text:msgList[index]["msg"],avatar:imgFontUrl+msgList[index]["avatarUrl"],username:msgList[index]["name"],isNetwork:msgList[index]["avatarUrl"]!=null?true:false);
+                        },
+                        itemCount: msgList.length,
+                        // itemCount:type == 1 ? list.length : messageList.length ,
+                      ));
+                    }),
+                    showEmoji?Container(
+                      padding: EdgeInsets.only(left:ScreenUtil().setWidth(6),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(10),right: ScreenUtil().setWidth(6)),
+                      color: Colors.white,
+                      height: ScreenUtil().setWidth(200),
+                      child: GridView.extent(
+                        //横轴的最大长度
+                        maxCrossAxisExtent: 35,
+                        //内边距
+                        padding: EdgeInsets.all(4.0),
+                        //垂直方向的间距
+                        mainAxisSpacing: 4.0,
+                        //水平方向的间距
+                        crossAxisSpacing: 4.0,
+                        children: emojiList.map((element) { 
+                          return GestureDetector(
+                            onTap: (){
+                              controller.text += element;
+                            },
+                            child: Text(
+                                element,
+                                style: TextStyle(
+                                    color: Color(0xff000000),
+                                    fontSize: ScreenUtil().setSp(22)),
+                                textAlign: TextAlign.center,
+                              ),
+                          );
+                        }).toList(),
+                      )
+                    ):Container(child: null,),
+                    Container(
+                      padding: EdgeInsets.only(
+                          top: ScreenUtil().setHeight(2.0),
+                          bottom: ScreenUtil().setHeight(2.0),
+                          left: 0,
+                          right: 0),
+                      color: ThemeUtils.getDialogTextFieldColor(context),
+                      child: Row(
+                        children: <Widget>[
+                          Container(
+                            width: ScreenUtil().setWidth(30.0),
+                            margin: EdgeInsets.only(
+                                right: ScreenUtil().setWidth(10.0)),
+                            child: IconButton(
+                                icon: Icon(ICons.ADD),
+                                onPressed: () {
+                                  selectPicker();
+                                  FocusScope.of(context).requestFocus(FocusNode());
+                                }),
+                          ),
+                          Expanded(
+                              child: Container(
+                            // padding: EdgeInsets.only(top: ScreenUtil().setHeight(8.0), bottom: ScreenUtil().setHeight(8.0)),
+                            height: ScreenUtil().setHeight(30.0),
+                            decoration: BoxDecoration(
+                                borderRadius:
+                                    BorderRadius.all(Radius.circular(5.0)),
+                                color: Colors.white),
+                            child: TextField(
+                              controller: controller,
+                              // decoration: InputDecoration.collapsed(hintText: null),
+                              decoration: InputDecoration(
+                                border: InputBorder.none,
+                              ),
+                              maxLines: 1,
+                              autocorrect: true,
+                              autofocus: false,
+                              textAlign: TextAlign.start,
+                              style: TextStyle(color: Colors.black),
+                              cursorColor: Colors.green,
+                              onChanged: (text) {
+                                setState(() {
+                                  hasText = text.length > 0 ? true : false;
+                                });
+                                // print('change=================== $text');
+                              },
+                              // onSubmitted:_handleSubmitted,
+                              enabled: true, //bu禁用
+                            ),
+                          )),
+                          Container(
+                            width: ScreenUtil().setWidth(30.0),
+                            child: IconButton(
+                                icon: Icon(ICons.FACES), //发送按钮图标
+                                onPressed: () {
+                                  print('打开表情面板');
+                                  setState(() {
+                                    showEmoji = !showEmoji;
+                                  });
+                                }),
+                          ),
+                          Container(
+                            width: ScreenUtil().setWidth(30.0),
+                            margin: EdgeInsets.only(
+                                right: ScreenUtil().setWidth(10.0)),
+                            child: IconButton(
+                                //发送按钮或者+按钮
+                                icon: Icon(Icons.send),
+                                onPressed: () {
+                                  if (controller.text == null || controller.text == '') {
+                                    toasts("请输入内容");
+                                  } else {
+                                    _handleSubmitted(context, controller.text);
+                                  }
+                                }),
+                          )
+                        ],
+                      ),
+                    )
+                  ],
+                ),
+              ),
+              ),
+              
+              // widget.type == "someToOne"
+              //     ? Positioned(
+              //         top: 0,
+              //         left: 0,
+              //         child: userList != null && userList != []
+              //             ? Container(
+              //                 width: width,
+              //                 height: ScreenUtil().setWidth(100),
+              //                 padding: EdgeInsets.only(
+              //                     top: ScreenUtil().setWidth(15),
+              //                     bottom: ScreenUtil().setWidth(10)),
+              //                 color: Colors.white,
+              //                 child: ListView(
+              //                     scrollDirection: Axis.horizontal,
+              //                     children: userList.asMap().keys.map((i) {
+              //                       if (i == 0) {
+              //                         return userList[i]["flag"]
+              //                             ? Container(
+              //                                 padding: EdgeInsets.only(
+              //                                     right:
+              //                                         ScreenUtil().setWidth(15),
+              //                                     left: ScreenUtil()
+              //                                         .setWidth(15)),
+              //                                 child: Column(children: <Widget>[
+              //                                   ClipRRect(
+              //                                       borderRadius:
+              //                                           BorderRadius.all(
+              //                                               Radius.circular(
+              //                                                   22)),
+              //                                       child: LoadNetworkImage(
+              //                                         userList[i]["avatarUrl"],
+              //                                         width: ScreenUtil()
+              //                                             .setWidth(43),
+              //                                         height: ScreenUtil()
+              //                                             .setWidth(43),
+              //                                       )
+              //                                       // userList[i]["avatarUrl"]!=null&&userList[i]["avatarUrl"]!=null ?
+              //                                       //   FadeInImage.assetNetwork(
+              //                                       //     placeholder: 'assets/images/temporary/avator2.png',
+              //                                       //     //预览图
+              //                                       //     fit: BoxFit.fitWidth,
+              //                                       //     image: imgFontUrl+userList[i]["avatarUrl"],
+              //                                       //     width: ScreenUtil().setWidth(43),
+              //                                       //               height:ScreenUtil().setWidth(43),
+              //                                       //   )
+              //                                       //   :Image.asset(
+              //                                       //     'assets/images/temporary/avator2.png',
+              //                                       //     fit: BoxFit.cover,
+              //                                       //     width: ScreenUtil().setWidth(43),
+              //                                       //               height:ScreenUtil().setWidth(43),
+              //                                       //   ),
+              //                                       ),
+              //                                   Container(
+              //                                       height: 5, child: null),
+              //                                   Text(
+              //                                     userList[i]["name"],
+              //                                     style: TextStyle(
+              //                                         color: Color(0xff000000),
+              //                                         fontSize: ScreenUtil()
+              //                                             .setSp(14)),
+              //                                     textAlign: TextAlign.start,
+              //                                   ),
+              //                                 ]),
+              //                               )
+              //                             : Container(child: null);
+              //                       } else {
+              //                         return userList[i]["flag"]
+              //                             ? Container(
+              //                                 padding: EdgeInsets.only(
+              //                                     right: ScreenUtil()
+              //                                         .setWidth(15)),
+              //                                 child: Column(children: <Widget>[
+              //                                   ClipRRect(
+              //                                     borderRadius:
+              //                                         BorderRadius.all(
+              //                                             Radius.circular(22)),
+              //                                     child: LoadNetworkImage(
+              //                                       userList[i]["avatarUrl"],
+              //                                       width: ScreenUtil()
+              //                                           .setWidth(43),
+              //                                       height: ScreenUtil()
+              //                                           .setWidth(43),
+              //                                     ),
+              //                                     // userList[i]["avatarUrl"]!=null&&userList[i]["avatarUrl"]!=null ?
+              //                                     //   FadeInImage.assetNetwork(
+              //                                     //     placeholder: 'assets/images/temporary/avator2.png',
+              //                                     //     //预览图
+              //                                     //     fit: BoxFit.fitWidth,
+              //                                     //     image: imgFontUrl+userList[i]["avatarUrl"],
+              //                                     //     width: ScreenUtil().setWidth(43),
+              //                                     //               height:ScreenUtil().setWidth(43),
+              //                                     //   )
+              //                                     //   :Image.asset(
+              //                                     //     'assets/images/temporary/avator2.png',
+              //                                     //     fit: BoxFit.cover,
+              //                                     //     width: ScreenUtil().setWidth(43),
+              //                                     //               height:ScreenUtil().setWidth(43),
+              //                                     //   ),
+              //                                   ),
+              //                                   Container(
+              //                                       height: 5, child: null),
+              //                                   Text(
+              //                                     userList[i]["name"],
+              //                                     style: TextStyle(
+              //                                         color: Color(0xff000000),
+              //                                         fontSize: ScreenUtil()
+              //                                             .setSp(14)),
+              //                                     textAlign: TextAlign.start,
+              //                                   ),
+              //                                 ]),
+              //                               )
+              //                             : Container(child: null);
+              //                       }
+              //                     }).toList()))
+              //             : Container(
+              //                 child: null,
+              //               ))
+              //     : Container(child: null)
+            ],
+          ),
+        ),
+      ),
+    );
+  }
+
+  // @override
+  // void dispose() {
+  //   Provider.of<WebSocketProvide>(context,listen: false).closeWebSocket();
+  //   // disposeJump();
+  //   super.dispose();
+
+  // }
+}

+ 254 - 107
lib/internal/bbs/page/chat_room.dart

@@ -23,6 +23,7 @@ import 'package:liftmanager/utils/toast.dart';
 import 'package:image_picker/image_picker.dart';
 import 'package:liftmanager/net/api_service.dart';
 import 'package:liftmanager/utils/theme_utils.dart';
+import 'package:liftmanager/widgets/chat_list_view.dart';
 
 class ChatDetailPage extends StatefulWidget {
   ChatDetailPage(this.id, this.type,this.toUserId);
@@ -41,8 +42,12 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
   int type = 0;
   int index = 1;
   List<dynamic> msgList = [];
+  List<dynamic> msgListBack = [];
+  List<dynamic> assList = [];
   bool showEmoji = false;
-
+  bool hasMore = true;
+  int _page = 0;
+  int pageSize = 10;
   // int index = int.parse("3");
   Conversation data;
   // _ChatDetailPageState(this.type0,this.index0);
@@ -67,6 +72,8 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
       Provider.of<WebSocketProvide>(context, listen: false)
           .sendMessage(context, text, widget.id,1,dataTable,widget.toUserId);
       showEmoji = false;
+      hasMore = true;
+      _page = 0;
       // }
       // new Future.delayed(Duration(milliseconds: 1000),(){
       //   setState(() {
@@ -79,7 +86,7 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
       controller.clear(); //清空输入框
 
       FocusScope.of(context).requestFocus(FocusNode());
-      _jumpBottom();
+      // _jumpBottom();
     } else {
       toasts("请输入");
     }
@@ -87,7 +94,7 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
 
   void _jumpBottom() {
     //滚动到底部
-    _scrollController.animateTo(9999999999,
+    _scrollController.animateTo(999999999,
         curve: Curves.easeOut, duration: Duration(milliseconds: 200));
   }
 
@@ -98,59 +105,6 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
   void setWebSocket() async {
     SharedPreferences prefs = await SharedPreferences.getInstance();
 
-    // Map<String,dynamic> sessionIdObjToGet = flustars.SpUtil.getObj("sessionIdObj", (v){
-    //                    return v;
-    //                  });
-    //                  LogUtil.d(sessionIdObjToGet);
-    // if(sessionIdObjToGet==null){
-    //   print(111);
-    //   Map<String,dynamic> nowObj = {
-    //                     widget.id:"hasSocket"
-    //                   };
-    //   flustars.SpUtil.putObject("sessionIdObj", nowObj);
-    //   new Future.delayed(Duration(milliseconds: 500),(){
-    //     Provider.of<WebSocketProvide>(context,listen: false).incomeRoom(widget.id);
-    //     // getMsgList();
-    //   });
-    // }else {
-    //   if(sessionIdObjToGet[widget.id]==null){
-    //     print(112);
-    //     Map<String,dynamic> thisItem = {
-    //                       widget.id:"hasSocket"
-    //                     };
-    //                     sessionIdObjToGet.addAll(thisItem);
-    //                     flustars.SpUtil.putObject("sessionIdObj", sessionIdObjToGet);
-    //                     new Future.delayed(Duration(milliseconds: 500),(){
-    //     Provider.of<WebSocketProvide>(context,listen: false).incomeRoom(widget.id);
-    //     // getMsgList();
-    //   });
-    //   }
-    // }
-    // if ((widget.type == "someToOne")&& isTrim==false) {
-    // if ((widget.type == "someToOne" || widget.type == "nearToOne")&& isTrim==false) {
-    //   new Future.delayed(Duration(milliseconds: 500), () {
-    //     Provider.of<WebSocketProvide>(context, listen: false)
-    //         .incomeRoom(widget.id);
-    //     getStringEvent(widget.id);
-    //   });
-    // } 
-    // // else if (widget.type == "nearToOne"){
-    // //   new Future.delayed(Duration(milliseconds: 500), () {
-    // //     Provider.of<WebSocketProvide>(context, listen: false)
-    // //         .loginAllSeconds(widget.id);
-    // //     getStringEvent(widget.id);
-    // //   });
-    // else {
-    // // } 
-    // // else if (widget.type == "oneToOne") {
-    //   new Future.delayed(Duration(milliseconds: 500), () {
-    //     Provider.of<WebSocketProvide>(context, listen: false)
-    //         .incomeFriend(widget.id);
-    //     getStringEvent(widget.id);
-    //   });
-    // }
-    // isTrim = false;
-
     new Future.delayed(Duration(milliseconds: 500), () {
         Provider.of<WebSocketProvide>(context, listen: false)
             .incomeRoom(widget.id);
@@ -189,8 +143,8 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
   @override
   void initState() {
     emojiList = emoji.split(',');
-    print(emojiList);
-
+    // print(emojiList);
+    assList = [];
     if(widget.type == "nearToOne"){
       dataTable = 3;
     }else {
@@ -199,6 +153,7 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
     
     
     print(JsonEncoder().convert(emojiList));
+    print(widget.id);
     print(66669999);
     // DartNotificationCenter.registerChannel(channel: 'socket_event');
     // DartNotificationCenter.post(
@@ -216,12 +171,22 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
         _jumpBottom();
       }
     });
+    FastNotification.addListener("chat_room_chat", (historyMessageqqq) {
+      if (mounted) {
+        setState(() {
+          msgList = historyMessageqqq;
+          print(JsonEncoder().convert(msgList));
+          print(444449911111111);
+        });
+        _jumpBottom();
+      }
+    });
     FastNotification.addListener("set_user", (setUserList) {
       if (mounted) {
         new Future.delayed(Duration(milliseconds: 1000), () {
-          setState(() {
-            userList = setUserList;
-          });
+          // setState(() {
+          //   userList = setUserList;
+          // });
         });
       }
     });
@@ -243,7 +208,7 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
     setWebSocket();
     // getStringEvent(widget.id);
 
-    initJump();
+    // initJump();
   }
 
   @override
@@ -301,6 +266,7 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
       setState(() {
         if (storyList.length > 0) {
           msgList = storyList;
+          // _onRefresh();
         }
         if (storyListUserOnline.length > 0) {
           userList = storyListUserOnline;
@@ -388,13 +354,22 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
   @override
   Widget build(BuildContext context) {
     double width = MediaQuery.of(context).size.width;
+    double height = MediaQuery.of(context).size.height;
     // print(JsonEncoder().convert(msgList));
     imagesList = [];
+    msgListBack = [];
     msgList.forEach((element) {
-      if(element["type"]==2){
-                            imagesList.add(element["msg"]);
-                          }
+      msgListBack.insert(0, element);
     });
+    print(JsonEncoder().convert(msgListBack));
+    print("/**/*/**///---------------------");
+    if(msgList.length > 0){
+      msgList.forEach((element) {
+        if(element["type"]==2){
+                              imagesList.add(element["msg"]);
+                            }
+      });
+    }
     // print(1234567980);
     
     return ChangeNotifierProvider<WebSocketProvide>(
@@ -434,49 +409,146 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
                 // color: Colors.red,
                 color: ThemeUtils.getTabsBg(context),
                 child: Column(
+                  // crossAxisAlignment: CrossAxisAlignment.end,
+                  // mainAxisAlignment: MainAxisAlignment.end,
                   children: <Widget>[
-                    Consumer<WebSocketProvide>(builder: (context, child, val) {
-                      return Expanded(
-                          child: ListView.builder(
-                        controller: _scrollController,
-                        physics: ClampingScrollPhysics(),
-                        itemBuilder: (BuildContext context, int index) {
-                          int typeUser;
-                          // print(msgList[index]["fromUser"]);
-                          // print(msgList[index]["msg"]);
-                          // print(jsonDecode(msgList[index])["fromUser"]);
-                          // print(1234567890);
-                          if (msgList[index]["fromUser"] ==
-                              flustars.SpUtil.getString(Constant.userId)) {
-                            typeUser = 1;
-                          } else {
-                            typeUser = 0;
-                          }
-                          
-                          // if(msgList[index]["type"]==2){
-                          //   imagesList.add(msgList[index]["msg"]);
-                          //   print(msgList[index]["msg"]);
-                          // }
-                          // print("///////////////////////////////////////////");
-                          // LogUtil.d(imagesList);
-                          // print("///////////////////////////////////////////");
-                          return ChatContentView(
-                            contentIndex:index,
-                            urlList:imagesList,
-                              type: typeUser,
-                              text: msgList[index]["msg"],
-                              msgType: msgList[index]["type"],
-                              avatar: msgList[index]["avatarUrl"],
-                              username: msgList[index]["name"],
-                              isNetwork: msgList[index]["avatarUrl"] != null
-                                  ? true
-                                  : false);
-                          // return ChatContentView(type:typeUser,text:msgList[index]["msg"],avatar:imgFontUrl+msgList[index]["avatarUrl"],username:msgList[index]["name"],isNetwork:msgList[index]["avatarUrl"]!=null?true:false);
-                        },
-                        itemCount: msgList.length,
-                        // itemCount:type == 1 ? list.length : messageList.length ,
-                      ));
-                    }),
+                    !hasMore?Container(
+                      padding: EdgeInsets.only(bottom:5),
+                      child: Text(
+                                "无更多历史记录~",
+                                style: TextStyle(
+                                    color: Color(0xff999999),
+                                    fontSize: ScreenUtil().setSp(14)),
+                                textAlign: TextAlign.center,
+                              ),
+                    ):Container(child: null,),
+                    Expanded(
+                          child: ChatListView(
+                          key: Key('chat_list'),
+                          scrollController: _scrollController,
+                          onRefresh:_loadMore,
+                          pageSize: 10,
+                          itemCount: msgList.length,
+                          hasMore: hasMore,
+                          itemBuilder: (_, index) {
+                            int typeUser;
+                            // print(msgList[index]["fromUser"]);
+                            // print(msgList[index]["msg"]);
+                            // print(jsonDecode(msgList[index])["fromUser"]);
+                            // print(1234567890);
+                            if (msgList[index]["fromUser"] ==
+                                flustars.SpUtil.getString(Constant.userId)) {
+                              typeUser = 1;
+                            } else {
+                              typeUser = 0;
+                            }
+
+                            // if(msgList[index]["type"]==2){
+                            //   imagesList.add(msgList[index]["msg"]);
+                            //   print(msgList[index]["msg"]);
+                            // }
+                            // print("///////////////////////////////////////////");
+                            // LogUtil.d(imagesList);
+                            // print("///////////////////////////////////////////");
+                            return ChatContentView(
+                              contentIndex:index,
+                              urlList:imagesList,
+                                type: typeUser,
+                                text: msgList[index]["msg"],
+                                msgType: msgList[index]["type"],
+                                avatar: msgList[index]["avatarUrl"],
+                                username: msgList[index]["name"],
+                                isNetwork: msgList[index]["avatarUrl"] != null
+                                    ? true
+                                    : false);
+                          },
+                        )
+                    ),
+                    // Consumer<WebSocketProvide>(builder: (context, child, val) {
+                    //   return 
+                    //   Expanded(
+                    //       child: ChatListView(
+                    //       key: Key('chat_list'),
+                    //       scrollController: _scrollController,
+                    //       onRefresh:_loadMore,
+                    //       pageSize: 10,
+                    //       itemCount: msgList.length,
+                    //       loadMore: _loadMore,
+                    //       hasMore: hasMore,
+                    //       itemBuilder: (_, index) {
+                    //         int typeUser;
+                    //         // print(msgList[index]["fromUser"]);
+                    //         // print(msgList[index]["msg"]);
+                    //         // print(jsonDecode(msgList[index])["fromUser"]);
+                    //         // print(1234567890);
+                    //         if (msgList[index]["fromUser"] ==
+                    //             flustars.SpUtil.getString(Constant.userId)) {
+                    //           typeUser = 1;
+                    //         } else {
+                    //           typeUser = 0;
+                    //         }
+
+                    //         // if(msgList[index]["type"]==2){
+                    //         //   imagesList.add(msgList[index]["msg"]);
+                    //         //   print(msgList[index]["msg"]);
+                    //         // }
+                    //         print("///////////////////////////////////////////");
+                    //         LogUtil.d(imagesList);
+                    //         print("///////////////////////////////////////////");
+                    //         return ChatContentView(
+                    //           contentIndex:index,
+                    //           urlList:imagesList,
+                    //             type: typeUser,
+                    //             text: msgList[index]["msg"],
+                    //             msgType: msgList[index]["type"],
+                    //             avatar: msgList[index]["avatarUrl"],
+                    //             username: msgList[index]["name"],
+                    //             isNetwork: msgList[index]["avatarUrl"] != null
+                    //                 ? true
+                    //                 : false);
+                    //       },
+                    //     )
+                    //     // ListView.builder(
+                    //     //   controller: _scrollController,
+                    //     //   physics: ClampingScrollPhysics(),
+                    //     //   itemBuilder: (BuildContext context, int index) {
+                    //     //     int typeUser;
+                    //     //     // print(msgList[index]["fromUser"]);
+                    //     //     // print(msgList[index]["msg"]);
+                    //     //     // print(jsonDecode(msgList[index])["fromUser"]);
+                    //     //     // print(1234567890);
+                    //     //     if (msgList[index]["fromUser"] ==
+                    //     //         flustars.SpUtil.getString(Constant.userId)) {
+                    //     //       typeUser = 1;
+                    //     //     } else {
+                    //     //       typeUser = 0;
+                    //     //     }
+                            
+                    //     //     // if(msgList[index]["type"]==2){
+                    //     //     //   imagesList.add(msgList[index]["msg"]);
+                    //     //     //   print(msgList[index]["msg"]);
+                    //     //     // }
+                    //     //     // print("///////////////////////////////////////////");
+                    //     //     // LogUtil.d(imagesList);
+                    //     //     // print("///////////////////////////////////////////");
+                    //     //     return ChatContentView(
+                    //     //       contentIndex:index,
+                    //     //       urlList:imagesList,
+                    //     //         type: typeUser,
+                    //     //         text: msgList[index]["msg"],
+                    //     //         msgType: msgList[index]["type"],
+                    //     //         avatar: msgList[index]["avatarUrl"],
+                    //     //         username: msgList[index]["name"],
+                    //     //         isNetwork: msgList[index]["avatarUrl"] != null
+                    //     //             ? true
+                    //     //             : false);
+                    //     //     // return ChatContentView(type:typeUser,text:msgList[index]["msg"],avatar:imgFontUrl+msgList[index]["avatarUrl"],username:msgList[index]["name"],isNetwork:msgList[index]["avatarUrl"]!=null?true:false);
+                    //     //   },
+                    //     //   itemCount: msgList.length,
+                    //     //   // itemCount:type == 1 ? list.length : messageList.length ,
+                    //     // )
+                    //   );
+                    // }),
                     showEmoji?Container(
                       padding: EdgeInsets.only(left:ScreenUtil().setWidth(6),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(10),right: ScreenUtil().setWidth(6)),
                       color: Colors.white,
@@ -722,4 +794,79 @@ class _ChatDetailPageState extends State<ChatDetailPage> {
   //   super.dispose();
 
   // }
+
+  Future _onRefresh() async {
+    _page = 1;
+     await NewApiService().getMsgHistoryList(
+       {
+         "pageNum":_page,
+         "pageSize":pageSize,
+         "sessionid":widget.id,
+      },
+      
+          onSuccess: (res) {
+        print("初始化数据");
+        print(JsonEncoder().convert(res));
+        List<dynamic> ass = [];
+        if(res != null && res.length > 0){
+          ass.addAll(res);
+        }
+        
+        ass.addAll(msgList);
+        setState(() {
+          
+          msgList = ass;
+          _jumpBottom();
+        });
+        print("初始化数据");
+      }, onError: (code, msg) {
+        toasts(msg);
+      });
+  }
+  Future _loadMore() async {
+    
+    if(hasMore){
+      _page++;
+    await NewApiService().getMsgHistoryList(
+       {
+         "pageNum":_page,
+         "pageSize":10,
+        //  "pageSize":pageSize,
+         "sessionid":widget.id,
+      },
+      
+          onSuccess: (res) {
+            print(JsonEncoder().convert(res));
+            print(123456111);
+        if (res != null && res.length > 0) {
+          print("初始化数据");
+        print(JsonEncoder().convert(res));
+        List<dynamic> ass = [];
+        ass.addAll(res);
+        if(assList.length == 0){
+          ass.addAll(msgList);
+        }else {
+          ass.addAll(assList);
+        }
+        assList = ass;
+        setState(() {
+          msgList = ass;
+          hasMore = true;
+          // _jumpBottom();
+        });
+        print("初始化数据");
+        }else {
+          setState(() {
+            hasMore = false;
+          });
+        }
+      }, onError: (code, msg) {
+        toasts(msg);
+      });
+    }else {
+      print("无更多历史记录!");
+    }
+    
+    print("加载更多了");
+  }
 }

+ 85 - 67
lib/internal/bbs/page/tab/video/video_detail.dart

@@ -28,6 +28,8 @@ import 'package:flustars/flustars.dart' as FlutterStars;
 import 'package:liftmanager/common/common.dart';
 import 'package:flutter/services.dart';
 import 'package:orientation/orientation.dart';
+import 'package:awsome_video_player/awsome_video_player.dart';
+import 'package:fijkplayer/fijkplayer.dart';
 
 class VideoDetail extends StatefulWidget {
   VideoDetail(this.id);
@@ -48,11 +50,28 @@ class VideoDetailState extends State<VideoDetail> {
     Future.delayed(Duration(milliseconds: 100),(){
       getVideoDetail();
     });
-    // SystemChrome.setPreferredOrientations([
-    //   DeviceOrientation.portraitUp,
-    // ]);
+
+    
   }
 
+  void _fijkValueListener() {
+    FijkValue value = player.value;
+
+    print(value.fullScreen);
+    print("fullScreenfullScreenfullScreenfullScreen------------------");
+    // if(value.fullScreen == false){
+    //   OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
+    // }
+}
+
+  final FijkPlayer player = FijkPlayer();
+  bool _isPlaying = false;
+  bool _isFullscreen = false;
+  bool get isPlaying => _isPlaying;
+  set isPlaying(bool playing) {
+    print("playing  $playing");
+    _isPlaying = playing;
+  }
   bool _hasData = false;
   VideoDetailModel detailObj;
   // var _storageLikeId;
@@ -70,9 +89,8 @@ class VideoDetailState extends State<VideoDetail> {
                                         Utils.getImagePath(detailObj.url) 
                                         // imgFontUrl + detailObj.url
                                         );
-        // _controller.addListener(() {
-        //   print(12011);
-        //  });
+        player.setDataSource(detailObj.url, autoPlay: false);
+        player.addListener(_fijkValueListener);
         setState(() {});
       }
     }, onError: (code, msg) {
@@ -140,29 +158,6 @@ class VideoDetailState extends State<VideoDetail> {
     });
   }
 
-  // Future saveLikeId(id,type) async {
-  //   SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
-  //   if(type==2){
-  //     sharedPreferences.setInt(
-  //       "video_like_id", id);
-  //   }else if(type==3){
-  //       sharedPreferences.setInt(
-  //       "video_fav_id", id);
-  //   }
-  // }
-
-  // Future getLikeCancelId(type) async {
-  //   SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
-  //   if(type==2){
-  //     _storageLikeId = sharedPreferences.get("video_like_id");
-  //     cancelLike(type);
-  //   }else if(type==3){
-  //     _storageFavId = sharedPreferences.get("video_fav_id");
-  //     cancelLike(type);
-  //   }
-
-  // }
-
   initCollect(){
     String collectInit = randomInt(1111,9999).toString() + DateTime.now().millisecondsSinceEpoch.toString();
     FastNotification.push("collectAction",collectInit);
@@ -179,7 +174,9 @@ class VideoDetailState extends State<VideoDetail> {
     // SystemChrome.setPreferredOrientations([
     //   DeviceOrientation.portraitUp,
     // ]);
-    OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
+    // OrientationPlugin.forceOrientation(DeviceOrientation.portraitUp);
+    player.release();
+    player.removeListener(_fijkValueListener);
     super.dispose();
   }
 
@@ -210,47 +207,68 @@ class VideoDetailState extends State<VideoDetail> {
                     mainAxisAlignment: MainAxisAlignment.start,
                     crossAxisAlignment: CrossAxisAlignment.start,
                     children: <Widget>[
+                      
                       Container(
-                          padding: EdgeInsets.only(
-                              left: ScreenUtil().setWidth(15),
-                              right: ScreenUtil().setWidth(15),
-                              top: ScreenUtil().setWidth(15)),
-                          child: ClipRRect(
-                            borderRadius: BorderRadius.circular(5),
-                            child: new Chewie(
-                              controller: ChewieController(
-                                videoPlayerController:
-                                    // VideoPlayerController.network(
-                                    //     imgFontUrl + detailObj.url
-                                    //     ),
-                                    _controller,
-                                aspectRatio: 3 / 2,
-                                autoPlay: false,
-                                looping: true,
-                                // startAt: Duration(seconds: 1,minutes: 1),
-                                showControls: true,
-                                deviceOrientationsAfterFullScreen:[DeviceOrientation.portraitUp],
-                                // 占位图
-                                // placeholder: Image.network(
-                                //     imgFontUrl+detailObj.cover,
-                                //     fit: BoxFit.contain,
+                        width: width,
+                        height: width*0.6,
+                        alignment: Alignment.center,
+                        child: FijkView(
+                          player: player,
+                          color: Colors.black,
+                          fit:FijkFit.contain,
+                          cover: new Image(image: detailObj.cover!=null?NetworkImage(detailObj.cover):AssetImage("assets/images/no_image.png"),).image,
+                          // 
+                        ),
+                      ),
 
-                                //   ),
 
-                                // 是否在 UI 构建的时候就加载视频
-                                autoInitialize: true,
+                      // Container(
+                      //     padding: EdgeInsets.only(
+                      //         left: ScreenUtil().setWidth(15),
+                      //         right: ScreenUtil().setWidth(15),
+                      //         top: ScreenUtil().setWidth(15)),
+                      //     child: ClipRRect(
+                      //       borderRadius: BorderRadius.circular(5),
+                      //       child: 
+                      //       new Chewie(
+                      //         controller: ChewieController(
+                      //           videoPlayerController:
+                      //               // VideoPlayerController.network(
+                      //               //     imgFontUrl + detailObj.url
+                      //               //     ),
+                      //               _controller,
+                      //           aspectRatio: 3 / 2,
+                      //           allowFullScreen:true,
+                      //           autoPlay: false,
+                      //           looping: true,
+                      //           // startAt: Duration(seconds: 1,minutes: 1),
+                      //           showControls: true,
+                      //           deviceOrientationsAfterFullScreen:[DeviceOrientation.portraitUp],
+                      //           // 占位图
+                      //           // placeholder: Image.network(
+                      //           //     imgFontUrl+detailObj.cover,
+                      //           //     fit: BoxFit.contain,
 
-                                // 拖动条样式颜色
-                                materialProgressColors:
-                                    new ChewieProgressColors(
-                                  playedColor: Colors.red,
-                                  handleColor: Colors.blue,
-                                  backgroundColor: Colors.grey,
-                                  bufferedColor: Colors.lightGreen,
-                                ),
-                              ),
-                            ),
-                          )),
+                      //           //   ),
+
+                      //           // 是否在 UI 构建的时候就加载视频
+                      //           autoInitialize: true,
+
+                      //           // 拖动条样式颜色
+                      //           materialProgressColors:
+                      //               new ChewieProgressColors(
+                      //             playedColor: Colors.red,
+                      //             handleColor: Colors.blue,
+                      //             backgroundColor: Colors.grey,
+                      //             bufferedColor: Colors.lightGreen,
+                      //           ),
+                      //         ),
+                      //       ),
+
+                            
+                            
+                      //     )
+                      // ),
                       Container(
                         width: width,
                         padding: EdgeInsets.only(

+ 1 - 1
lib/internal/bbs/provide/websocket.dart

@@ -191,7 +191,7 @@ class WebSocketProvide with ChangeNotifier{
         historyMessageString = strChat;
         print(222220);
         historyMessageqqq = historyMessageString.map((item)=>jsonDecode(item)).toList();
-        FastNotification.push("chat_room",historyMessageqqq);
+        FastNotification.push("chat_room_chat",historyMessageqqq);
       }
       
       prefs.setString("changeRoomId",obj["sessionid"]);

+ 12 - 0
lib/net/api_service.dart

@@ -1751,6 +1751,7 @@ class NewApiUrl {
   static const String becomeMasterUpdate = "/udream/api/applyExperts/update";
   static const String isDelayAddressUrl = "/udream/api/otherSettings/query-new";
   static const String startDelayAddressUrl = "/udream/api/motionTrails/addTrail";
+  static const String msgHistoryList = "/udream/api/chatMsgs/msgHistoryList";
   static const String user_order_update = "/udream/api/userOrderss/update";
   static const String apply_invoice = "/udream/api/applyInvoices/applyInvoice";
   static const String submit_comments = "/udream/api/expertComments/insert";
@@ -3346,4 +3347,15 @@ class NewApiService {
         onError: onError);
   }
 
+  //聊天历史记录
+  Future getMsgHistoryList(data,
+      {Function onSuccess, Function(int code, String msg) onError}) async {
+    await DioUtils().requestNetwork<Map>(
+        Method.post, "${NewApiUrl.msgHistoryList}",
+        isList: true,
+        params: data,
+        onSuccessList: onSuccess,
+        onError: onError);
+  }
+
 }

+ 150 - 0
lib/widgets/chat_list_view.dart

@@ -0,0 +1,150 @@
+
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+
+import 'package:liftmanager/res/resources.dart';
+import 'package:liftmanager/utils/theme_utils.dart';
+import 'package:liftmanager/widgets/state_layout.dart';
+
+/// 封装下拉刷新与加载更多
+class ChatListView extends StatefulWidget {
+
+  const ChatListView({
+    Key key,
+    @required this.itemCount,
+    @required this.itemBuilder,
+    @required this.onRefresh,
+    this.loadMore,
+    this.hasMore : false,
+    this.pageSize : 10,
+    this.padding,
+    this.itemExtent,
+    this.scrollController,
+  }): super(key: key);
+  final RefreshCallback onRefresh;
+  final LoadMoreCallback loadMore;
+  final int itemCount;
+  final bool hasMore;
+  final IndexedWidgetBuilder itemBuilder;
+  /// 一页的数量,默认为10
+  final int pageSize;
+  final EdgeInsetsGeometry padding;
+  final double itemExtent;
+  final ScrollController scrollController;
+
+  @override
+  _ChatListViewState createState() => _ChatListViewState();
+}
+
+typedef RefreshCallback = Future<void> Function();
+typedef LoadMoreCallback = Future<void> Function();
+
+class _ChatListViewState extends State<ChatListView> {
+
+  /// 是否正在加载数据
+  bool _isLoading = false;
+  
+  @override
+  Widget build(BuildContext context) {
+    return SafeArea(
+      child: NotificationListener(
+        onNotification: (ScrollNotification note){
+          /// 确保是垂直方向滚动,且滑动至顶部
+          // if (note.metrics.pixels == note.metrics.maxScrollExtent && note.metrics.axis == Axis.vertical){
+          if (note.metrics.pixels == 0.0 && note.metrics.axis == Axis.vertical && note.metrics.maxScrollExtent != 0.0 && note.metrics.extentBefore == 0.0){
+            print("到顶了。。。");
+          }
+          ScrollMetrics metrics = note.metrics;
+          // print(metrics.pixels);// 当前位置
+          // print(metrics.atEdge);//是否在顶部或底部
+          // print(metrics.axis);//垂直或水平滚动
+          // print(metrics.axisDirection);// 滚动方向是down还是up
+          // print(metrics.extentAfter);//视口底部距离列表底部有多大
+          // print(metrics.extentBefore);//视口顶部距离列表顶部有多大
+          // print(metrics.extentInside);//视口范围内的列表长度
+          // print(metrics.maxScrollExtent);//最大滚动距离,列表长度-视口长度
+          // print(metrics.minScrollExtent);//最小滚动距离
+          // print(metrics.viewportDimension);//视口长度
+          // print(metrics.outOfRange);//是否越过边界
+          // print('------------------------');
+          return true;
+        },
+        child: RefreshIndicator(
+          displacement:1.0,
+          onRefresh: widget.onRefresh,
+          child: ListView.builder(
+                // shrinkWrap: true,
+                itemCount: widget.loadMore == null ? widget.itemCount : widget.itemCount + 1,
+                controller: widget.scrollController,
+                reverse:false,
+                physics: new AlwaysScrollableScrollPhysics(),
+                padding: widget.padding,
+                itemExtent: widget.itemExtent,
+                itemBuilder: (BuildContext context, int index){
+                  /// 不需要加载更多则不需要添加FootView
+                  print(index);
+                  print(widget.itemCount);
+                  print("45622222--------");
+                  if (widget.loadMore == null){
+                    return widget.itemBuilder(context, index);
+                    
+                  }else{
+                    return index < widget.itemCount ? widget.itemBuilder(context, index) : Container(child:null);
+                    // return index < widget.itemCount ? widget.itemBuilder(context, index) : MoreWidget(widget.itemCount, widget.hasMore, widget.pageSize);
+                  }
+                }
+            ),
+        ),
+        
+      ),
+    );
+  }
+
+  Future _loadMore() async {
+    if (widget.loadMore == null){
+      return;
+    }
+    if (_isLoading) {
+      return;
+    }
+    if (!widget.hasMore){
+      return;
+    }
+    _isLoading = true;
+    await widget.loadMore();
+    _isLoading = false;
+  }
+
+}
+
+class MoreWidget extends StatelessWidget {
+
+  const MoreWidget(this.itemCount, this.hasMore, this.pageSize);
+
+  final int itemCount;
+  final bool hasMore;
+  final int pageSize;
+
+  @override
+  
+  Widget build(BuildContext context) {
+    final style =  const TextStyle(color: Color(0xff666666));
+    return Container(
+      color:ThemeUtils.getTabsBg(context),
+      child: Padding(
+      padding: EdgeInsets.only(top:10,bottom:30),
+      child: Row(
+        mainAxisAlignment: MainAxisAlignment.center,
+        crossAxisAlignment: CrossAxisAlignment.center,
+        children: <Widget>[
+          hasMore ? const CupertinoActivityIndicator() : Gaps.empty,
+          hasMore ? Gaps.hGap5 : Gaps.empty,
+          /// 只有一页的时候,就不显示FooterView了
+          Text(hasMore ? '正在加载中...' : (itemCount < pageSize ? '' : '没有了呦~'), style: style),
+        ],
+      ),
+    ),
+    );
+  }
+}
+

+ 2 - 0
pubspec.yaml

@@ -117,6 +117,8 @@ dependencies:
 
   orientation: ^1.2.0
 
+  fijkplayer: ^0.8.7
+
 dev_dependencies:
   flutter_test:
     sdk: flutter