|
@@ -48,8 +48,7 @@ class MenuBar extends StatefulWidget {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class _MenuBarState extends State<MenuBar>
|
|
|
- with WidgetsBindingObserver, InjectApi {
|
|
|
+class _MenuBarState extends State<MenuBar> with WidgetsBindingObserver, InjectApi {
|
|
|
GlobalKey _myKey = new GlobalKey(); // 用来定位Message位置
|
|
|
|
|
|
List<Asset> imageList = []; // 选图片的列表
|
|
@@ -62,6 +61,8 @@ class _MenuBarState extends State<MenuBar>
|
|
|
|
|
|
FocusNode _focusNode = new FocusNode(); // TextField 的 focus
|
|
|
|
|
|
+ ValueNotifier<bool> _postable = ValueNotifier(false);
|
|
|
+
|
|
|
double keyBoardHeight = 270.0; // 初始化下面menu的高度 后续会动态调整后 优化
|
|
|
|
|
|
bool isFirst = true; // flag 优化menu高度的操作
|
|
@@ -87,7 +88,10 @@ class _MenuBarState extends State<MenuBar>
|
|
|
|
|
|
initEmoji();
|
|
|
|
|
|
- _controller = TextEditingController();
|
|
|
+ _controller = TextEditingController()
|
|
|
+ ..addListener(() {
|
|
|
+ _postable.value = _controller.value.text.isNotEmpty;
|
|
|
+ });
|
|
|
// _focusNode.addListener(() {
|
|
|
// if (_focusNode.hasFocus) {
|
|
|
//// setState(() {
|
|
@@ -99,8 +103,7 @@ class _MenuBarState extends State<MenuBar>
|
|
|
|
|
|
// 直接进来就请求了 不要 搞这些骚的....
|
|
|
void initEmoji() async {
|
|
|
- String json = await DefaultAssetBundle.of(context)
|
|
|
- .loadString("lib/assets/json/emoji_list.json");
|
|
|
+ String json = await DefaultAssetBundle.of(context).loadString("lib/assets/json/emoji_list.json");
|
|
|
setState(() {
|
|
|
emojiJson = json;
|
|
|
});
|
|
@@ -111,21 +114,21 @@ class _MenuBarState extends State<MenuBar>
|
|
|
void dispose() {
|
|
|
super.dispose();
|
|
|
//释放
|
|
|
- _focusNode.dispose();
|
|
|
+ _focusNode?.dispose();
|
|
|
_timer?.cancel();
|
|
|
+ _postable?.dispose();
|
|
|
+ _controller?.dispose();
|
|
|
}
|
|
|
|
|
|
// 这里 插库 + 渲染更新...
|
|
|
Future add(MessageInstance message) async {
|
|
|
// 聊天的时候 是没有返回 curId的 本地存储的时候 就得自己构造一个? 或者是不存?
|
|
|
- await MessageDB().insert(new MessageItem(
|
|
|
- message: message, status: 0, userId: message.toUser.id, curId: 0));
|
|
|
+ await MessageDB().insert(new MessageItem(message: message, status: 0, userId: message.toUser.id, curId: 0));
|
|
|
|
|
|
var list = await MessageDB().findHasUserId(message.toUser.id);
|
|
|
|
|
|
if (list.length == 0) {
|
|
|
- await MessageDB()
|
|
|
- .insertUser(new UserTableInfo(userId: message.toUser.id, isTop: 0));
|
|
|
+ await MessageDB().insertUser(new UserTableInfo(userId: message.toUser.id, isTop: 0));
|
|
|
}
|
|
|
|
|
|
// view 上setstate 渲染的...
|
|
@@ -134,8 +137,7 @@ class _MenuBarState extends State<MenuBar>
|
|
|
|
|
|
_postFeedBackpostFeedBack(String content, {int typeId = 0}) async {
|
|
|
typeId == null ? typeId = 0 : typeId = typeId;
|
|
|
- await api.postFeedback(typeId, content,
|
|
|
- extra: await Application.getDeviceInfo());
|
|
|
+ await api.postFeedback(typeId, content, extra: await Application.getDeviceInfo());
|
|
|
}
|
|
|
|
|
|
Widget extMenuItem(
|
|
@@ -174,8 +176,7 @@ class _MenuBarState extends State<MenuBar>
|
|
|
for (var i = 0; i < resultList.length; i++) {
|
|
|
Asset asset = resultList[i];
|
|
|
ByteData byteData = await asset.getByteData(quality: 85);
|
|
|
- File file = File(
|
|
|
- '${directory.path}/${DateTime.now().millisecondsSinceEpoch}_$i.jpg');
|
|
|
+ File file = File('${directory.path}/${DateTime.now().millisecondsSinceEpoch}_$i.jpg');
|
|
|
List<int> bytes = byteData.buffer.asUint8List().toList();
|
|
|
print('临时文件 ${file.path} ${bytes.length}');
|
|
|
file.writeAsBytesSync(bytes);
|
|
@@ -188,11 +189,7 @@ class _MenuBarState extends State<MenuBar>
|
|
|
if (widget.menuIdentity.menuScene == "chat") {
|
|
|
if (urls.length > 0) {
|
|
|
for (int i = 0; i < urls.length; i++) {
|
|
|
- MessageInstance message = (await api.postChatSend(
|
|
|
- widget.menuIdentity.userId,
|
|
|
- "image",
|
|
|
- '{"url":"${urls[i]}"}'))
|
|
|
- .data;
|
|
|
+ MessageInstance message = (await api.postChatSend(widget.menuIdentity.userId, "image", '{"url":"${urls[i]}"}')).data;
|
|
|
add(message);
|
|
|
}
|
|
|
}
|
|
@@ -205,8 +202,7 @@ class _MenuBarState extends State<MenuBar>
|
|
|
void getPhoto() async {
|
|
|
try {
|
|
|
// 拍完直接发...
|
|
|
- final pickedFile = await new ImagePicker()
|
|
|
- .getImage(source: ImageSource.camera, imageQuality: 70);
|
|
|
+ final pickedFile = await new ImagePicker().getImage(source: ImageSource.camera, imageQuality: 70);
|
|
|
|
|
|
// 如果是聊天 直接发 ...
|
|
|
if (widget.menuIdentity.menuScene == "chat") {
|
|
@@ -215,11 +211,7 @@ class _MenuBarState extends State<MenuBar>
|
|
|
var data = (await api.postChatUpload(File(pickedFile.path))).data;
|
|
|
print(data['url']);
|
|
|
// print("${data}-----------------------------");
|
|
|
- MessageInstance message = (await api.postChatSend(
|
|
|
- widget.menuIdentity.userId,
|
|
|
- "image",
|
|
|
- '{ "url":"${data['url']}" }'))
|
|
|
- .data;
|
|
|
+ MessageInstance message = (await api.postChatSend(widget.menuIdentity.userId, "image", '{ "url":"${data['url']}" }')).data;
|
|
|
add(message);
|
|
|
});
|
|
|
}
|
|
@@ -260,10 +252,7 @@ class _MenuBarState extends State<MenuBar>
|
|
|
return Container(
|
|
|
height: keyBoardHeight,
|
|
|
padding: EdgeInsets.only(left: 5, top: 5, right: 5, bottom: 5),
|
|
|
- decoration: BoxDecoration(
|
|
|
- color: Colors.white,
|
|
|
- border:
|
|
|
- Border(top: BorderSide(width: 1.0, color: Color(0xFFDCDCDC)))),
|
|
|
+ decoration: BoxDecoration(color: Colors.white, border: Border(top: BorderSide(width: 1.0, color: Color(0xFFDCDCDC)))),
|
|
|
child: GridView.custom(
|
|
|
padding: EdgeInsets.all(3),
|
|
|
shrinkWrap: true,
|
|
@@ -276,17 +265,14 @@ class _MenuBarState extends State<MenuBar>
|
|
|
(context, index) {
|
|
|
return GestureDetector(
|
|
|
onTap: () {
|
|
|
- String intPutString = _controller.text +
|
|
|
- String.fromCharCode(data[index]["unicode"]);
|
|
|
+ String intPutString = _controller.text + String.fromCharCode(data[index]["unicode"]);
|
|
|
|
|
|
var content = intPutString;
|
|
|
_controller.value = TextEditingValue(
|
|
|
// 设置内容
|
|
|
text: content,
|
|
|
// 保持光标在最后
|
|
|
- selection: TextSelection.fromPosition(TextPosition(
|
|
|
- affinity: TextAffinity.downstream,
|
|
|
- offset: content.length)));
|
|
|
+ selection: TextSelection.fromPosition(TextPosition(affinity: TextAffinity.downstream, offset: content.length)));
|
|
|
// 主要是 onchange 没有办法 加上 表情 ...
|
|
|
setState(() {});
|
|
|
},
|
|
@@ -316,10 +302,7 @@ class _MenuBarState extends State<MenuBar>
|
|
|
Container(
|
|
|
height: keyBoardHeight,
|
|
|
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
|
|
- decoration: BoxDecoration(
|
|
|
- color: Colors.white,
|
|
|
- border: Border(
|
|
|
- top: BorderSide(width: 1.0, color: Color(0xFFDCDCDC)))),
|
|
|
+ decoration: BoxDecoration(color: Colors.white, border: Border(top: BorderSide(width: 1.0, color: Color(0xFFDCDCDC)))),
|
|
|
child: GridView(
|
|
|
shrinkWrap: true,
|
|
|
padding: EdgeInsets.only(top: 24.0),
|
|
@@ -375,16 +358,14 @@ class _MenuBarState extends State<MenuBar>
|
|
|
// ],
|
|
|
// ),
|
|
|
Container(
|
|
|
- padding: const EdgeInsets.symmetric(
|
|
|
- vertical: 8.0, horizontal: 12.0),
|
|
|
+ padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
|
|
|
decoration: shadowTop(),
|
|
|
child: Row(
|
|
|
children: <Widget>[
|
|
|
GestureDetector(
|
|
|
onTap: () async {
|
|
|
if (_focusNode.hasFocus) {
|
|
|
- await SystemChannels.textInput
|
|
|
- .invokeMethod('TextInput.hide');
|
|
|
+ await SystemChannels.textInput.invokeMethod('TextInput.hide');
|
|
|
setState(() {
|
|
|
isShowMenuBottomIndex = 2;
|
|
|
});
|
|
@@ -396,8 +377,7 @@ class _MenuBarState extends State<MenuBar>
|
|
|
},
|
|
|
child: Padding(
|
|
|
// padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
|
|
|
- child: Image.asset(
|
|
|
- "lib/assets/img/bbs_icon_addmore.png"),
|
|
|
+ child: Image.asset("lib/assets/img/bbs_icon_addmore.png"),
|
|
|
padding: EdgeInsets.only(right: 12.0),
|
|
|
),
|
|
|
),
|
|
@@ -407,15 +387,13 @@ class _MenuBarState extends State<MenuBar>
|
|
|
isShowMenuBottomIndex = 3;
|
|
|
FocusScope.of(context).requestFocus(_focusNode);
|
|
|
if (_focusNode.hasFocus) {
|
|
|
- SystemChannels.textInput
|
|
|
- .invokeMethod('TextInput.hide');
|
|
|
+ SystemChannels.textInput.invokeMethod('TextInput.hide');
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
child: Padding(
|
|
|
// padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
|
|
|
- child: Image.asset(
|
|
|
- "lib/assets/img/bbs_icon_expression.png"),
|
|
|
+ child: Image.asset("lib/assets/img/bbs_icon_expression.png"),
|
|
|
padding: EdgeInsets.only(right: 12.0),
|
|
|
),
|
|
|
),
|
|
@@ -442,47 +420,39 @@ class _MenuBarState extends State<MenuBar>
|
|
|
});
|
|
|
widget.scrollToBottom();
|
|
|
},
|
|
|
- decoration: BoxDecoration(
|
|
|
- shape: BoxShape.rectangle,
|
|
|
- borderRadius: BorderRadius.all(Radius.circular(10)),
|
|
|
- color: Color(0xfff1f1f1)
|
|
|
- ),
|
|
|
+ decoration: BoxDecoration(shape: BoxShape.rectangle, borderRadius: BorderRadius.all(Radius.circular(10)), color: Color(0xfff1f1f1)),
|
|
|
),
|
|
|
),
|
|
|
Space(
|
|
|
width: 5.0,
|
|
|
),
|
|
|
- PrimaryButton(
|
|
|
- width: 75,
|
|
|
- height: 35.0,
|
|
|
- content: "发送",
|
|
|
- callback: () async {
|
|
|
- if (_controller.text.length <= 0) {
|
|
|
- ToastUtil.show("请输入正确的内容");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (widget.menuIdentity.menuScene == "chat") {
|
|
|
- MessageInstance message = (await api.postChatSend(
|
|
|
- widget.menuIdentity.userId,
|
|
|
- "text",
|
|
|
- '{"text":"${_controller.text}"}'))
|
|
|
- .data;
|
|
|
-
|
|
|
- await add(
|
|
|
- message); // await 是等待的标志 我等待完 在做后面的init 的事?
|
|
|
- _controller.text = "";
|
|
|
- }
|
|
|
- if (widget.menuIdentity.menuScene == "feedback") {
|
|
|
- await _postFeedBackpostFeedBack(_textFieldValue);
|
|
|
- }
|
|
|
-
|
|
|
- // 这里可能传不了 callback 所有需要的值都在menu bar里面 只能通过传 不同的 场景 进行 不同的操作
|
|
|
- },
|
|
|
- shadow: _controller.text.length <= 0 ? false : true,
|
|
|
- buttonColor:
|
|
|
- _controller.text == "" ? Color(0xffd2d2d2) : null,
|
|
|
- ),
|
|
|
+ ValueListenableBuilder(
|
|
|
+ valueListenable: _postable,
|
|
|
+ builder: (_, able, __) => PrimaryButton(
|
|
|
+ width: 75,
|
|
|
+ height: 35.0,
|
|
|
+ content: "发送",
|
|
|
+ callback: () async {
|
|
|
+ if (_controller.text.length <= 0) {
|
|
|
+ ToastUtil.show("请输入正确的内容");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (widget.menuIdentity.menuScene == "chat") {
|
|
|
+ MessageInstance message = (await api.postChatSend(widget.menuIdentity.userId, "text", '{"text":"${_controller.text}"}')).data;
|
|
|
+
|
|
|
+ await add(message); // await 是等待的标志 我等待完 在做后面的init 的事?
|
|
|
+ _controller.text = "";
|
|
|
+ }
|
|
|
+ if (widget.menuIdentity.menuScene == "feedback") {
|
|
|
+ await _postFeedBackpostFeedBack(_textFieldValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 这里可能传不了 callback 所有需要的值都在menu bar里面 只能通过传 不同的 场景 进行 不同的操作
|
|
|
+ },
|
|
|
+ shadow: able == true,
|
|
|
+ buttonColor: able == false ? Color(0xffd2d2d2) : null,
|
|
|
+ )),
|
|
|
],
|
|
|
)),
|
|
|
// 底部的骚操作
|