@@ -2,6 +2,7 @@ import 'dart:io';
import 'dart:typed_data';
import 'dart:typed_data';
import 'package:chat/chat/ChatPageItem.dart';
import 'package:chat/chat/ChatPageItem.dart';
import 'package:chat/data/UserData.dart';
import 'package:chat/data/chat_data_mgr.dart';
import 'package:chat/data/chat_data_mgr.dart';
import 'package:chat/data/constants.dart';
import 'package:chat/data/constants.dart';
import 'package:chat/generated/i18n.dart';
import 'package:chat/generated/i18n.dart';
@@ -11,11 +12,13 @@ import 'package:chat/proto/chat.pb.dart';
import 'package:chat/r.dart';
import 'package:chat/r.dart';
import 'package:chat/utils/CustomUI.dart';
import 'package:chat/utils/CustomUI.dart';
import 'package:chat/utils/HttpUtil.dart';
import 'package:chat/utils/HttpUtil.dart';
import 'package:chat/utils/TokenMgr.dart';
import 'package:chat/utils/file_cache_mgr.dart';
import 'package:chat/utils/file_cache_mgr.dart';
import 'package:chat/utils/image_util.dart';
import 'package:chat/utils/image_util.dart';
import 'package:chat/utils/keyboard_utils.dart';
import 'package:chat/utils/keyboard_utils.dart';
import 'package:chat/utils/msgHandler.dart';
import 'package:chat/utils/msgHandler.dart';
import 'package:chat/utils/screen.dart';
import 'package:chat/utils/screen.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
@@ -31,7 +34,7 @@ class CompanyServerPage extends StatefulWidget {
class _CompanyServerPageState extends State<CompanyServerPage> {
class _CompanyServerPageState extends State<CompanyServerPage> {
final TextEditingController _textCtrl = TextEditingController();
final TextEditingController _textCtrl = TextEditingController();
FocusNode editFocus = NoKeyboardEditableTextFocusNode();
FocusNode editFocus = NoKeyboardEditableTextFocusNode();
bool _isComposingMessage = false;
// bool _isComposingMessage = false;
double keyboardHeight;
double keyboardHeight;
KeyboardBloc _bloc = KeyboardBloc();
KeyboardBloc _bloc = KeyboardBloc();
@@ -42,6 +45,8 @@ class _CompanyServerPageState extends State<CompanyServerPage> {
static int companyId = 10000;
static int companyId = 10000;
final ValueNotifier<bool> updateProgress = ValueNotifier<bool>(false);
UserInfo companyInfo = UserInfo(
UserInfo companyInfo = UserInfo(
userId: companyId,
userId: companyId,
headimgurl: R.assetsImagesServerIcon,
headimgurl: R.assetsImagesServerIcon,
@@ -123,7 +128,7 @@ class _CompanyServerPageState extends State<CompanyServerPage> {
friendId: companyId, channelType: ChatChannelType.CSD);
friendId: companyId, channelType: ChatChannelType.CSD);
setState(() {
setState(() {
_isComposingMessag e = _textCtrl.text.length > 0;
updateProgress.valu e = _textCtrl.text.length > 0;
});
});
sendMsg(msg);
sendMsg(msg);
@@ -165,16 +170,46 @@ class _CompanyServerPageState extends State<CompanyServerPage> {
),
),
);
);
// if (resultList != null && resultList.length > 0) {
// for (var i = 0; i < resultList.length; i++) {
// Asset photoEntity = resultList[i];
// ByteData byteData = await photoEntity.getByteData();
// File file = await FileCacheMgr().writeFile('temp-photo-${DateTime.now().millisecondsSinceEpoch}.png', byteData.buffer.asInt8List(0));
// _sendPhotoFile(file);
// }
// }
if (resultList != null && resultList.length > 0) {
if (resultList != null && resultList.length > 0) {
List<File> fileList = [];
for (var i = 0; i < resultList.length; i++) {
for (var i = 0; i < resultList.length; i++) {
Asset photoEntity = resultList[i];
Asset photoEntity = resultList[i];
print('名字:${photoEntity.name}');
ByteData byteData = await photoEntity.getByteData();
ByteData byteData = await photoEntity.getByteData();
File file = await FileCacheMgr().writeFile('temp-photo-${DateTime.now().millisecondsSinceEpoch}.png', byteData.buffer.asInt8List(0));
File file = await FileCacheMgr().writeFile('temp-photo-${DateTime.now().millisecondsSinceEpoch}.png', byteData.buffer.asInt8List(0));
_sendPhotoFile(file);
fileList.add(file);
}
print('文件列表${fileList.length}');
Map data = {"type": 3, "userId": UserData().basicInfo.userId};
data['sign'] = TokenMgr().getSign(data);
Response res = await HttpUtil().uploadFiles(
fileList, data, 'upload/post/postfiles', 'image',
isShowLoading: true);
var resData = res.data;
if (resData['code'] == 0 && resData['msg'] != null) {
List<String> imgUrlList = [];
imgUrlList.addAll(resData['msg'].split("|"));
for(int k=0;k<imgUrlList.length;k++){
_sendPhotoFile(fileList[k],imgUrlList[k]);
}
setState(() {});
}
}
}
}
} on Exception catch (e) {
} on Exception catch (e) {
print(e.toString());
print(e.toString());
}
}
@@ -196,33 +231,36 @@ class _CompanyServerPageState extends State<CompanyServerPage> {
// }
// }
}
}
void _sendPhotoFile(File imgFile) async {
var imgSize = await imgFile.length();
void _sendPhotoFile(File imgFile,String imageUrl) async {
// var imgSize = await imgFile.length();
//
// print('图片大小:${imgSize / 1024}KB');
// var sendImg;
//
// if (imgSize > 33 * 1024 * 1024) {
// showToast(I18n.of(context).video_more_big);
// return;
// }
// bool isNeedUpload = false;
// if (imgSize > ImgSizeLimit) {
// print('图片大于 $ImgSizeLimit,压缩');
// //发送压缩图
// sendImg = await WidgetUtil.getCompressImg(imgFile.absolute.path );
// isNeedUpload = true;
// } else {
// sendImg = imgFile.readAsBytesSync();
// }
print('图片大小:${imgSize / 1024}KB');
var sendImg;
if (imgSize > 33 * 1024 * 1024) {
showToast(I18n.of(context).video_more_big);
return;
}
bool isNeedUpload = false;
if (imgSize > ImgSizeLimit) {
print('图片大于 $ImgSizeLimit,压缩');
//发送压缩图
sendImg = await WidgetUtil.getCompressImg(imgFile.absolute.path );
isNeedUpload = true;
} else {
sendImg = imgFile.readAsBytesSync();
}
var sendImg = imgFile.readAsBytesSync();
var rect = await WidgetUtil.getImageWH(
var rect = await WidgetUtil.getImageWH(
image: Image.memory(Uint8List.fromList(sendImg)));
image: Image.memory(Uint8List.fromList(sendImg)));
print('图片大小 Rect : $rect');
print('图片大小 Rect : $rect');
int aspectRatio = rect.width * 100 ~/ rect.height;
int aspectRatio = rect.width * 100 ~/ rect.height;
var msg = MsgHandler.createSendMsg(ChatType.ImageChatType, sendImg ,
localFile: isNeedUpload ? i mgFile.absolute.path : null ,
var msg = MsgHandler.createSendMsg(ChatType.ImageChatType, imageUrl,
localFile: imgFile.absolute.path,
extra: aspectRatio,
extra: aspectRatio,
friendId: companyId,
friendId: companyId,
channelType: ChatChannelType.CSD);
channelType: ChatChannelType.CSD);
@@ -235,9 +273,7 @@ class _CompanyServerPageState extends State<CompanyServerPage> {
child: TextField(
child: TextField(
keyboardAppearance: Brightness.light,
keyboardAppearance: Brightness.light,
onChanged: (String messageText) {
onChanged: (String messageText) {
setState(() {
_isComposingMessage = _textCtrl.text.length > 0;
});
updateProgress.value = _textCtrl.text.length > 0;
},
},
cursorColor: Constants.BlueTextColor,
cursorColor: Constants.BlueTextColor,
style: TextStyle(
style: TextStyle(
@@ -262,25 +298,28 @@ class _CompanyServerPageState extends State<CompanyServerPage> {
),
),
);
);
return GestureDetecto r(
onTap: () {
print('放置触控隐藏键盘');
},
child: Container(
width: Screen.width,
color: Colors.white ,
return ValueListenableBuilde r(
builder: (BuildContext context, bool isComp,
Widget child) {
return GestureDetector(
onTap: () {
print('放置触控隐藏键盘');
} ,
child: Container(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 7, vertical: 7),
alignment: Alignment.topCenter,
decoration: BoxDecoration(
color: Colors.white,
border: Border(top: BorderSide(color: Color(0xFFDFDFDF)))),
child: Row(
children: <Widget>[
//输入框
Expanded(child: input), SizedBox(width: 10),
_isComposingMessage
? InkWell(
width: Screen.width,
color: Colors.white,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 7, vertical: 7),
alignment: Alignment.topCenter,
decoration: BoxDecoration(
color: Colors.white,
border: Border(top: BorderSide(color: Color(0xFFDFDFDF)))),
child: Row(
children: <Widget>[
//输入框
Expanded(child: input), SizedBox(width: 10),
isComp
? InkWell(
child: Padding(
child: Padding(
padding: EdgeInsets.fromLTRB(50, 2, 10, 2),
padding: EdgeInsets.fromLTRB(50, 2, 10, 2),
child: Icon(
child: Icon(
@@ -289,7 +328,7 @@ class _CompanyServerPageState extends State<CompanyServerPage> {
size: 28,
size: 28,
)),
)),
onTap: _sendTextMessage)
onTap: _sendTextMessage)
: InkWell(
: InkWell(
child: Icon(
child: Icon(
IconData(0xe60c,
IconData(0xe60c,
fontFamily: Constants.IconFontFamily),
fontFamily: Constants.IconFontFamily),
@@ -299,8 +338,13 @@ class _CompanyServerPageState extends State<CompanyServerPage> {
onTap: () {
onTap: () {
_openPhotoView();
_openPhotoView();
}),
}),
],
))));
],
))))
;
},
valueListenable: updateProgress,
);
}
}
Widget _buildMessageList() {
Widget _buildMessageList() {