|
@@ -10,6 +10,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:sport/bean/message.dart';
|
|
import 'package:sport/bean/message.dart';
|
|
import 'package:sport/bean/post.dart';
|
|
import 'package:sport/bean/post.dart';
|
|
import 'package:sport/bean/post_user.dart';
|
|
import 'package:sport/bean/post_user.dart';
|
|
|
|
+import 'package:sport/bean/user_info.dart';
|
|
import 'package:sport/db/message_db.dart';
|
|
import 'package:sport/db/message_db.dart';
|
|
import 'package:sport/pages/social/post_detail_page.dart';
|
|
import 'package:sport/pages/social/post_detail_page.dart';
|
|
import 'package:sport/pages/social/share_webview.dart';
|
|
import 'package:sport/pages/social/share_webview.dart';
|
|
@@ -46,11 +47,10 @@ final List<String> avatarList = [
|
|
];
|
|
];
|
|
|
|
|
|
class ChatPage extends StatefulWidget {
|
|
class ChatPage extends StatefulWidget {
|
|
- final String userName;
|
|
|
|
- final int userId;
|
|
|
|
|
|
+ final UserInfo user;
|
|
final Post post;
|
|
final Post post;
|
|
|
|
|
|
- ChatPage(this.userName, this.userId, {this.post});
|
|
|
|
|
|
+ ChatPage(this.user, {this.post});
|
|
|
|
|
|
@override
|
|
@override
|
|
State<StatefulWidget> createState() => _ChatPageState();
|
|
State<StatefulWidget> createState() => _ChatPageState();
|
|
@@ -63,7 +63,7 @@ class _ChatPageState extends State<ChatPage>
|
|
|
|
|
|
StreamSubscription _streamSubscription;
|
|
StreamSubscription _streamSubscription;
|
|
List<MessageItem> messageList = [];
|
|
List<MessageItem> messageList = [];
|
|
-
|
|
|
|
|
|
+// String othersAvatarUrl = "";
|
|
GlobalKey SCROLLVIEW = new GlobalKey();
|
|
GlobalKey SCROLLVIEW = new GlobalKey();
|
|
|
|
|
|
dispose() {
|
|
dispose() {
|
|
@@ -85,13 +85,13 @@ class _ChatPageState extends State<ChatPage>
|
|
initMessageList() async {
|
|
initMessageList() async {
|
|
// List<MessageItem> messageList = [];
|
|
// List<MessageItem> messageList = [];
|
|
List<MessageItem> data = [];
|
|
List<MessageItem> data = [];
|
|
- var list = await MessageDB().getMessageForUserId(widget.userId);
|
|
|
|
|
|
+ var list = await MessageDB().getMessageForUserId(widget.user.id);
|
|
for (var item in list) {
|
|
for (var item in list) {
|
|
MessageItem _item = MessageItem.fromJson(item);
|
|
MessageItem _item = MessageItem.fromJson(item);
|
|
data.add(_item);
|
|
data.add(_item);
|
|
}
|
|
}
|
|
// 读过就操作一手...
|
|
// 读过就操作一手...
|
|
- await MessageDB().updateStatus(widget.userId);
|
|
|
|
|
|
+ await MessageDB().updateStatus(widget.user.id);
|
|
|
|
|
|
// messageList.addAll(data);
|
|
// messageList.addAll(data);
|
|
data.forEach((element) {
|
|
data.forEach((element) {
|
|
@@ -108,11 +108,11 @@ class _ChatPageState extends State<ChatPage>
|
|
if (widget.post != null) {
|
|
if (widget.post != null) {
|
|
// 拿到后还得 存
|
|
// 拿到后还得 存
|
|
MessageInstance _instance = (await api.shareForwardSubject(
|
|
MessageInstance _instance = (await api.shareForwardSubject(
|
|
- int.parse(widget.post.id), widget.userId))
|
|
|
|
|
|
+ int.parse(widget.post.id), widget.user.id))
|
|
.data;
|
|
.data;
|
|
|
|
|
|
await MessageDB().insert(new MessageItem(
|
|
await MessageDB().insert(new MessageItem(
|
|
- message: _instance, status: 0, curId: 0, userId: widget.userId));
|
|
|
|
|
|
+ message: _instance, status: 0, curId: 0, userId: widget.user.id));
|
|
|
|
|
|
addMessageToPage(_instance);
|
|
addMessageToPage(_instance);
|
|
}
|
|
}
|
|
@@ -127,7 +127,7 @@ class _ChatPageState extends State<ChatPage>
|
|
for (MessageInstance item in list) {
|
|
for (MessageInstance item in list) {
|
|
addMessageToPage(item);
|
|
addMessageToPage(item);
|
|
}
|
|
}
|
|
- await MessageDB().updateStatus(widget.userId);
|
|
|
|
|
|
+ await MessageDB().updateStatus(widget.user.id);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
//
|
|
//
|
|
@@ -159,15 +159,6 @@ class _ChatPageState extends State<ChatPage>
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-// @override
|
|
|
|
-// void didChangeMetrics() {
|
|
|
|
-// super.didChangeMetrics();
|
|
|
|
-// WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
-// // 当前是安卓系统并且在焦点聚焦的情况下
|
|
|
|
-//// _menuController.scrollToBottom();
|
|
|
|
-// });
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
// 封装的聊天msg
|
|
// 封装的聊天msg
|
|
// @who 判断是用户自己的还是 聊的那个人
|
|
// @who 判断是用户自己的还是 聊的那个人
|
|
// @msg 信息 聊天的那个
|
|
// @msg 信息 聊天的那个
|
|
@@ -303,35 +294,36 @@ class _ChatPageState extends State<ChatPage>
|
|
// 链接..
|
|
// 链接..
|
|
if (type == "link") {
|
|
if (type == "link") {
|
|
return InkWell(
|
|
return InkWell(
|
|
- child: Row(
|
|
|
|
- crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
- children: <Widget>[
|
|
|
|
- CachedNetworkImage(
|
|
|
|
- imageUrl: data.data.logo,
|
|
|
|
- width: 60.0,
|
|
|
|
- height: 60.0,
|
|
|
|
- ),
|
|
|
|
- Space(
|
|
|
|
- width: 5.0,
|
|
|
|
- ),
|
|
|
|
- Expanded(
|
|
|
|
- child: RichText(
|
|
|
|
- text: TextSpan(children: [
|
|
|
|
- TextSpan(
|
|
|
|
- text: data.data.user.name,
|
|
|
|
- style: Theme.of(context)
|
|
|
|
- .textTheme
|
|
|
|
- .headline6
|
|
|
|
- .copyWith(color: Color(0xFFFFC400))),
|
|
|
|
- TextSpan(
|
|
|
|
- text: data.data.text,
|
|
|
|
- style: Theme.of(context).textTheme.subtitle1),
|
|
|
|
- ]),
|
|
|
|
|
|
+ child: Row(
|
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
+ children: <Widget>[
|
|
|
|
+ CachedNetworkImage(
|
|
|
|
+ imageUrl: data.data.logo,
|
|
|
|
+ width: 60.0,
|
|
|
|
+ height: 60.0,
|
|
),
|
|
),
|
|
- )
|
|
|
|
- ]),
|
|
|
|
- onTap: () async{
|
|
|
|
- await NavigatorUtil.goPage(context, (context) => WebViewSharePage(data.data.url));
|
|
|
|
|
|
+ Space(
|
|
|
|
+ width: 5.0,
|
|
|
|
+ ),
|
|
|
|
+ Expanded(
|
|
|
|
+ child: RichText(
|
|
|
|
+ text: TextSpan(children: [
|
|
|
|
+ TextSpan(
|
|
|
|
+ text: data.data.user.name,
|
|
|
|
+ style: Theme.of(context)
|
|
|
|
+ .textTheme
|
|
|
|
+ .headline6
|
|
|
|
+ .copyWith(color: Color(0xFFFFC400))),
|
|
|
|
+ TextSpan(
|
|
|
|
+ text: data.data.text,
|
|
|
|
+ style: Theme.of(context).textTheme.subtitle1),
|
|
|
|
+ ]),
|
|
|
|
+ ),
|
|
|
|
+ )
|
|
|
|
+ ]),
|
|
|
|
+ onTap: () async {
|
|
|
|
+ await NavigatorUtil.goPage(
|
|
|
|
+ context, (context) => WebViewSharePage(data.data.url));
|
|
},
|
|
},
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -422,6 +414,10 @@ class _ChatPageState extends State<ChatPage>
|
|
width: 12,
|
|
width: 12,
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ String avatarUrl = data.fromUser?.id == int.parse(selfId)
|
|
|
|
+ ? Provider.of<UserModel>(context, listen: false).user.avatar
|
|
|
|
+ : widget.user.avatar;
|
|
|
|
+
|
|
Widget avatar = InkWell(
|
|
Widget avatar = InkWell(
|
|
onTap: () async {
|
|
onTap: () async {
|
|
await NavigatorUtil.goPage(
|
|
await NavigatorUtil.goPage(
|
|
@@ -429,12 +425,10 @@ class _ChatPageState extends State<ChatPage>
|
|
(context) => UserDetailPage(PostUser(
|
|
(context) => UserDetailPage(PostUser(
|
|
id: "${data.fromUser?.id}",
|
|
id: "${data.fromUser?.id}",
|
|
name: data.fromUser?.name,
|
|
name: data.fromUser?.name,
|
|
- avatar: data.fromUser?.id == selfId
|
|
|
|
- ? Provider.of<UserModel>(context, listen: false).user.avatar
|
|
|
|
- : data.fromUser.avatar)));
|
|
|
|
|
|
+ avatar: avatarUrl)));
|
|
},
|
|
},
|
|
child: CircleAvatar(
|
|
child: CircleAvatar(
|
|
- backgroundImage: CachedNetworkImageProvider(userAvatar),
|
|
|
|
|
|
+ backgroundImage: CachedNetworkImageProvider(avatarUrl),
|
|
radius: 20,
|
|
radius: 20,
|
|
),
|
|
),
|
|
);
|
|
);
|
|
@@ -458,7 +452,7 @@ class _ChatPageState extends State<ChatPage>
|
|
return Scaffold(
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
appBar: AppBar(
|
|
title: Text(
|
|
title: Text(
|
|
- "${widget.userName}",
|
|
|
|
|
|
+ "${widget.user.name}",
|
|
style: titleStyle,
|
|
style: titleStyle,
|
|
),
|
|
),
|
|
leading: buildBackButton(context),
|
|
leading: buildBackButton(context),
|
|
@@ -484,7 +478,7 @@ class _ChatPageState extends State<ChatPage>
|
|
],
|
|
],
|
|
),
|
|
),
|
|
menuIdentity:
|
|
menuIdentity:
|
|
- new MenuIdentity(menuScene: "chat", userId: widget.userId),
|
|
|
|
|
|
+ new MenuIdentity(menuScene: "chat", userId: widget.user.id),
|
|
inputField: "",
|
|
inputField: "",
|
|
// scrollToBottom: _menuController.scrollToBottom, // 暂时可以废弃...
|
|
// scrollToBottom: _menuController.scrollToBottom, // 暂时可以废弃...
|
|
sendCallBack: addMessageToPage,
|
|
sendCallBack: addMessageToPage,
|