|
@@ -5,8 +5,11 @@ import 'dart:math';
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
+import 'package:flutter/rendering.dart';
|
|
|
+import 'package:flutter/scheduler.dart';
|
|
|
import 'package:flutter/services.dart';
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
+import 'package:sport/bean/image.dart' as photo;
|
|
|
import 'package:sport/bean/message.dart';
|
|
|
import 'package:sport/bean/post.dart';
|
|
|
import 'package:sport/bean/post_user.dart';
|
|
@@ -22,6 +25,7 @@ import 'package:sport/router/navigator_util.dart';
|
|
|
import 'package:sport/services/api/inject_api.dart';
|
|
|
import 'package:sport/services/api/resp.dart';
|
|
|
import 'package:sport/services/userid.dart';
|
|
|
+import 'package:sport/utils/DateFormat.dart';
|
|
|
import 'package:sport/utils/print_map.dart';
|
|
|
import 'package:sport/utils/toast.dart';
|
|
|
import 'package:sport/widgets/appbar.dart';
|
|
@@ -32,6 +36,8 @@ import 'package:sport/widgets/space.dart';
|
|
|
import 'package:sport/widgets/dialog/popupmenu.dart' as menu;
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
+import 'gallery_photo_view.dart';
|
|
|
+
|
|
|
final List<String> avatarList = [
|
|
|
"https://wx3.sinaimg.cn/mw1024/a6bdcd78gy1gfna8yznv5j20m90m9tbz.jpg",
|
|
|
"https://wx2.sinaimg.cn/mw1024/a6bdcd78gy1gfna8x3nbzj20m90m943a.jpg",
|
|
@@ -48,9 +54,10 @@ final List<String> avatarList = [
|
|
|
|
|
|
class ChatPage extends StatefulWidget {
|
|
|
final UserInfo user;
|
|
|
- final Post post;
|
|
|
-
|
|
|
- ChatPage(this.user, {this.post});
|
|
|
+ final Post post; // 分享来的帖子
|
|
|
+ final String hash; // 分享来的link
|
|
|
+ final String image; // 分享来的图片 ...
|
|
|
+ ChatPage(this.user, {this.post, this.hash, this.image});
|
|
|
|
|
|
@override
|
|
|
State<StatefulWidget> createState() => _ChatPageState();
|
|
@@ -60,11 +67,12 @@ class ChatPage extends StatefulWidget {
|
|
|
class _ChatPageState extends State<ChatPage>
|
|
|
with InjectLoginApi, InjectApi, UserId, WidgetsBindingObserver {
|
|
|
GetMenuController _menuController = new GetMenuController();
|
|
|
-
|
|
|
+// ScrollController scrollMenuController = new ScrollController();
|
|
|
StreamSubscription _streamSubscription;
|
|
|
List<MessageItem> messageList = [];
|
|
|
// String othersAvatarUrl = "";
|
|
|
GlobalKey SCROLLVIEW = new GlobalKey();
|
|
|
+ double emptyHeight;
|
|
|
|
|
|
dispose() {
|
|
|
super.dispose();
|
|
@@ -79,21 +87,32 @@ class _ChatPageState extends State<ChatPage>
|
|
|
addPost(); // 这里是分享过来的 ...
|
|
|
// initScrollBottom();
|
|
|
// print("${Provider.of<UserModel>(context, listen: false).user.toJson()}");
|
|
|
+// _menuController.scroll();
|
|
|
}
|
|
|
|
|
|
// 这个是初始化 聊天列表的...
|
|
|
initMessageList() async {
|
|
|
+// await Future.delayed(Duration(milliseconds: 1000));
|
|
|
// List<MessageItem> messageList = [];
|
|
|
List<MessageItem> data = [];
|
|
|
var list = await MessageDB().getMessageForUserId(widget.user.id);
|
|
|
+ int day = -1;
|
|
|
for (var item in list) {
|
|
|
MessageItem _item = MessageItem.fromJson(item);
|
|
|
+ if (_item.day != day) {
|
|
|
+ day = _item.day;
|
|
|
+ data.add(new MessageItem(
|
|
|
+ messageType: "time",
|
|
|
+ dateTime:
|
|
|
+ DateFormat.format(DateTime.parse(_item.message.createdAt))));
|
|
|
+ }
|
|
|
data.add(_item);
|
|
|
}
|
|
|
// 读过就操作一手...
|
|
|
await MessageDB().updateStatus(widget.user.id);
|
|
|
|
|
|
// messageList.addAll(data);
|
|
|
+ int cout = 0;
|
|
|
data.forEach((element) {
|
|
|
messageList.insert(0, element);
|
|
|
});
|
|
@@ -102,9 +121,17 @@ class _ChatPageState extends State<ChatPage>
|
|
|
setState(() {
|
|
|
messageList = messageList;
|
|
|
});
|
|
|
+// SchedulerBinding.instance.addPostFrameCallback((_) {
|
|
|
+////here the sublist is already build
|
|
|
+// scrollMenuController.jumpTo(scrollMenuController.position.maxScrollExtent);
|
|
|
+// print("2222222222222222222222222");
|
|
|
+// print("${scrollMenuController.position.minScrollExtent} - ${scrollMenuController.position.maxScrollExtent}");
|
|
|
+// });
|
|
|
+ _menuController.scroll();
|
|
|
}
|
|
|
|
|
|
Future addPost() async {
|
|
|
+ // 这里是拿到了 帖子
|
|
|
if (widget.post != null) {
|
|
|
// 拿到后还得 存
|
|
|
MessageInstance _instance = (await api.shareForwardSubject(
|
|
@@ -116,6 +143,25 @@ class _ChatPageState extends State<ChatPage>
|
|
|
|
|
|
addMessageToPage(_instance);
|
|
|
}
|
|
|
+ // 也可能是拿到了 link
|
|
|
+ else if (widget.hash != null) {
|
|
|
+ MessageInstance _instance =
|
|
|
+ (await api.getshareForwardSport(widget.hash, widget.user.id)).data;
|
|
|
+
|
|
|
+ await MessageDB().insert(new MessageItem(
|
|
|
+ message: _instance, status: 0, curId: 0, userId: widget.user.id));
|
|
|
+
|
|
|
+ addMessageToPage(_instance);
|
|
|
+ } else if (widget.image != null) {
|
|
|
+ MessageInstance _instance = (await api.postChatSend(
|
|
|
+ widget.user.id, "image", '{"url":"${widget.image}"}'))
|
|
|
+ .data;
|
|
|
+
|
|
|
+ await MessageDB().insert(new MessageItem(
|
|
|
+ message: _instance, status: 0, curId: 0, userId: widget.user.id));
|
|
|
+
|
|
|
+ addMessageToPage(_instance);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 在本页中如果收到了就 ...
|
|
@@ -151,9 +197,9 @@ class _ChatPageState extends State<ChatPage>
|
|
|
// 各种来自别的地方收到的消息 输出到 页面上
|
|
|
addMessageToPage(MessageInstance _instance) {
|
|
|
MessageItem item = instanceToItem(_instance);
|
|
|
- messageList.insert(0, item);
|
|
|
+// messageList.insert(0, item);
|
|
|
// messageList.add(item);
|
|
|
-// messageList.insert(0, item); // 到头插...
|
|
|
+ messageList.insert(0, item); // 到头插...
|
|
|
setState(() {
|
|
|
messageList = messageList;
|
|
|
});
|
|
@@ -165,6 +211,17 @@ class _ChatPageState extends State<ChatPage>
|
|
|
// @type 聊天的类型 可能是通过分享过来的那种 ? 游戏 或者是 别的 社区 或者是 链接 ?
|
|
|
|
|
|
Widget _buildChatItem(MessageItem item) {
|
|
|
+ // type 是时间 还是 消息...
|
|
|
+ print("${item.toJson()}----------------------------------");
|
|
|
+ if (item.messageType != null) {
|
|
|
+ return Padding(
|
|
|
+ padding: EdgeInsets.symmetric(vertical: 5.0),
|
|
|
+ child: Center(
|
|
|
+ child: Text("${item.dateTime}"),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
GlobalKey anchorKey = GlobalKey();
|
|
|
|
|
|
MessageInstance data = item.message;
|
|
@@ -177,6 +234,8 @@ class _ChatPageState extends State<ChatPage>
|
|
|
String userAvatar = data.fromUser.avatar;
|
|
|
|
|
|
Widget chatItemOfType(String type) {
|
|
|
+ List<photo.Image> images = [];
|
|
|
+ images.add(photo.Image(id: "1", src: data.data.url));
|
|
|
// 文本或者是图片...
|
|
|
if (type == "text" || type == "image") {
|
|
|
return Column(
|
|
@@ -191,26 +250,31 @@ class _ChatPageState extends State<ChatPage>
|
|
|
key: anchorKey,
|
|
|
),
|
|
|
if (data.data.url != null)
|
|
|
- CachedNetworkImage(imageUrl: data.data.url)
|
|
|
-// SizedBox(
|
|
|
-// height: 10.0,
|
|
|
-// ),
|
|
|
-// if (imageUrls?.length != null)
|
|
|
-// GridView.count(
|
|
|
-// physics: new NeverScrollableScrollPhysics(),
|
|
|
-// shrinkWrap: true,
|
|
|
-// padding: EdgeInsets.zero,
|
|
|
-// crossAxisSpacing: 10.0,
|
|
|
-// crossAxisCount: imageUrls.length > 3 ? 3 : imageUrls.length,
|
|
|
-// mainAxisSpacing: 10.0,
|
|
|
-// children: imageUrls
|
|
|
-// .asMap()
|
|
|
-// .keys
|
|
|
-// .map((i) => CachedNetworkImage(
|
|
|
-// imageUrl: imageUrls[i],
|
|
|
-// fit: BoxFit.cover,
|
|
|
-// ))
|
|
|
-// .toList())
|
|
|
+ InkWell(
|
|
|
+ child: Container(
|
|
|
+ constraints: BoxConstraints(
|
|
|
+ maxHeight: MediaQuery.of(context).size.height,
|
|
|
+ maxWidth: MediaQuery.of(context).size.width,
|
|
|
+ ),
|
|
|
+ child: CachedNetworkImage(imageUrl: data.data.url),
|
|
|
+ ),
|
|
|
+ onTap: () {
|
|
|
+ Navigator.push(
|
|
|
+ context,
|
|
|
+ FadeRoute(
|
|
|
+ page: GalleryPhotoViewWrapper(
|
|
|
+ galleryItems: images,
|
|
|
+ backgroundDecoration: const BoxDecoration(
|
|
|
+ color: Colors.black,
|
|
|
+ ),
|
|
|
+ initialIndex: 1,
|
|
|
+ scrollDirection: Axis.horizontal,
|
|
|
+ loadingBuilder: (_, __) => RequestLoadingWidget(),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ },
|
|
|
+ )
|
|
|
],
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
);
|
|
@@ -292,13 +356,14 @@ class _ChatPageState extends State<ChatPage>
|
|
|
);
|
|
|
}
|
|
|
// 链接..
|
|
|
- if (type == "link") {
|
|
|
+ if (type == "share") {
|
|
|
+ print("${data.toJson()}--------------------------------------");
|
|
|
return InkWell(
|
|
|
child: Row(
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
children: <Widget>[
|
|
|
CachedNetworkImage(
|
|
|
- imageUrl: data.data.logo,
|
|
|
+ imageUrl: avatarList[9],
|
|
|
width: 60.0,
|
|
|
height: 60.0,
|
|
|
),
|
|
@@ -309,13 +374,13 @@ class _ChatPageState extends State<ChatPage>
|
|
|
child: RichText(
|
|
|
text: TextSpan(children: [
|
|
|
TextSpan(
|
|
|
- text: data.data.user.name,
|
|
|
+ text: data.fromUser.name,
|
|
|
style: Theme.of(context)
|
|
|
.textTheme
|
|
|
.headline6
|
|
|
.copyWith(color: Color(0xFFFFC400))),
|
|
|
TextSpan(
|
|
|
- text: data.data.text,
|
|
|
+ text: "分享了他的运动记录,快来围观吧~",
|
|
|
style: Theme.of(context).textTheme.subtitle1),
|
|
|
]),
|
|
|
),
|
|
@@ -323,7 +388,11 @@ class _ChatPageState extends State<ChatPage>
|
|
|
]),
|
|
|
onTap: () async {
|
|
|
await NavigatorUtil.goPage(
|
|
|
- context, (context) => WebViewSharePage(data.data.url));
|
|
|
+ context,
|
|
|
+ (context) => WebViewSharePage(
|
|
|
+ data.data.url,
|
|
|
+ hash: data.data.share.hash,
|
|
|
+ ));
|
|
|
},
|
|
|
);
|
|
|
}
|
|
@@ -339,6 +408,7 @@ class _ChatPageState extends State<ChatPage>
|
|
|
? EdgeInsets.fromLTRB(12, 6, 20, 8)
|
|
|
: EdgeInsets.fromLTRB(20, 6, 12, 8),
|
|
|
child: GestureDetector(
|
|
|
+ behavior: HitTestBehavior.opaque,
|
|
|
onLongPressStart: (e) {
|
|
|
RenderBox renderBox =
|
|
|
anchorKey.currentContext.findRenderObject();
|
|
@@ -395,10 +465,27 @@ class _ChatPageState extends State<ChatPage>
|
|
|
who == 1
|
|
|
? menuItem(
|
|
|
imgUrl: "linkpop_icon_del.png",
|
|
|
- text: "删除")
|
|
|
+ text: "删除",
|
|
|
+ callBack: () async {
|
|
|
+ await MessageDB()
|
|
|
+ .deleteMessageIdMessage(
|
|
|
+ item.messageId);
|
|
|
+ messageList.remove(item);
|
|
|
+ setState(() {
|
|
|
+ messageList = messageList;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ )
|
|
|
: menuItem(
|
|
|
imgUrl: "linkpop_icon_modify_1.png",
|
|
|
- text: "举报"),
|
|
|
+ text: "举报",
|
|
|
+ callBack: () async {
|
|
|
+ await api.postForumReport(
|
|
|
+ userId: item.userId,
|
|
|
+ content:
|
|
|
+ "该用户涉嫌发送不良消息内容为:${item.message.data.text}");
|
|
|
+ ToastUtil.show("举报已受理...");
|
|
|
+ }),
|
|
|
menuItem(
|
|
|
imgUrl: "linkpop_icon_cancel.png", text: "取消")
|
|
|
],
|
|
@@ -415,8 +502,12 @@ class _ChatPageState extends State<ChatPage>
|
|
|
);
|
|
|
|
|
|
String avatarUrl = data.fromUser?.id == int.parse(selfId)
|
|
|
- ? Provider.of<UserModel>(context, listen: false).user.avatar
|
|
|
- : widget.user.avatar;
|
|
|
+ ? Provider.of<UserModel>(context, listen: false).user?.avatar == null
|
|
|
+ ? avatarList[4]
|
|
|
+ : Provider.of<UserModel>(context, listen: false).user?.avatar
|
|
|
+ : widget.user?.avatar == null
|
|
|
+ ? data.fromUser.avatar
|
|
|
+ : widget.user?.avatar;
|
|
|
|
|
|
Widget avatar = InkWell(
|
|
|
onTap: () async {
|
|
@@ -457,33 +548,45 @@ class _ChatPageState extends State<ChatPage>
|
|
|
),
|
|
|
leading: buildBackButton(context),
|
|
|
),
|
|
|
- resizeToAvoidBottomInset: false, // 透传MediaQuery 的高度?
|
|
|
- body: MenuBar(
|
|
|
- CustomScrollView(
|
|
|
- key: SCROLLVIEW,
|
|
|
- reverse: true,
|
|
|
- controller: _menuController.scrollMenuController,
|
|
|
- slivers: <Widget>[
|
|
|
- if (messageList?.length == 0)
|
|
|
- SliverToBoxAdapter(
|
|
|
- child: Container(),
|
|
|
- ),
|
|
|
- if (messageList?.length != 0)
|
|
|
- SliverList(
|
|
|
- delegate: SliverChildBuilderDelegate((content, index) {
|
|
|
+// resizeToAvoidBottomInset: false, // 透传MediaQuery 的高度?
|
|
|
+ body: WillPopScope(
|
|
|
+ onWillPop: () async {
|
|
|
+ // 这是分享.... 只能一步一步pop 出去
|
|
|
+ if(widget.post != null || widget.hash != null || widget.image != null){
|
|
|
+ print("${widget.post}=============");
|
|
|
+ Navigator.pop(context,true);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ child: MenuBar(
|
|
|
+ CustomScrollView(
|
|
|
+ key: SCROLLVIEW,
|
|
|
+ shrinkWrap: true,
|
|
|
+ reverse: true,
|
|
|
+ controller: _menuController.scrollMenuController,
|
|
|
+// controller: scrollMenuController,
|
|
|
+ slivers: <Widget>[
|
|
|
+ if (messageList?.length == 0)
|
|
|
+ SliverToBoxAdapter(
|
|
|
+ child: Container(),
|
|
|
+ ),
|
|
|
+ if (messageList?.length != 0)
|
|
|
+ SliverList(
|
|
|
+ delegate: SliverChildBuilderDelegate((content, index) {
|
|
|
// MessageInstance data = messageList[index];
|
|
|
- return _buildChatItem(messageList[index]);
|
|
|
- }, childCount: messageList.length),
|
|
|
- ),
|
|
|
- ],
|
|
|
- ),
|
|
|
- menuIdentity:
|
|
|
- new MenuIdentity(menuScene: "chat", userId: widget.user.id),
|
|
|
- inputField: "",
|
|
|
-// scrollToBottom: _menuController.scrollToBottom, // 暂时可以废弃...
|
|
|
- sendCallBack: addMessageToPage,
|
|
|
- globalkey: SCROLLVIEW,
|
|
|
- ));
|
|
|
+ return _buildChatItem(messageList[index]);
|
|
|
+ }, childCount: messageList.length),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ menuIdentity:
|
|
|
+ new MenuIdentity(menuScene: "chat", userId: widget.user.id),
|
|
|
+ inputField: "",
|
|
|
+ scrollToBottom: _menuController.scroll, // 暂时可以废弃...
|
|
|
+ sendCallBack: addMessageToPage,
|
|
|
+ globalkey: SCROLLVIEW,
|
|
|
+ )));
|
|
|
}
|
|
|
}
|
|
|
|