2019-02-10 08:37:27 +08:00
|
|
|
import "package:flutter/material.dart";
|
2019-02-13 22:44:20 +08:00
|
|
|
|
2019-06-22 17:07:50 +08:00
|
|
|
import "../../models/user_model.dart";
|
|
|
|
import "../../models/conversation_model.dart";
|
|
|
|
import "../../blocs/conversation_bloc.dart";
|
|
|
|
import "../../blocs/message_bloc.dart";
|
2019-02-17 17:57:55 +08:00
|
|
|
|
2019-06-22 17:07:50 +08:00
|
|
|
import "../widgets/user_avatar.dart";
|
2019-02-10 08:37:27 +08:00
|
|
|
|
2019-02-17 17:57:55 +08:00
|
|
|
class ConversationItem extends StatefulWidget {
|
|
|
|
final Conversation conversation;
|
|
|
|
|
|
|
|
ConversationItem({@required this.conversation});
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _ConversationItemState(conversation: conversation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ConversationItemState extends State<ConversationItem> {
|
|
|
|
final bloc;
|
|
|
|
final Conversation conversation;
|
|
|
|
|
|
|
|
_ConversationItemState({@required this.conversation})
|
|
|
|
: bloc = ConversationMembersBloc(conversation.id);
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2019-02-17 18:18:14 +08:00
|
|
|
bloc.fetchMembers();
|
2019-02-17 17:57:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
bloc.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2019-02-10 08:37:27 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-05-19 11:05:27 +08:00
|
|
|
return Material(
|
|
|
|
type: MaterialType.transparency,
|
2019-06-14 08:41:49 +08:00
|
|
|
elevation: 1,
|
2019-05-19 11:05:27 +08:00
|
|
|
child: InkWell(
|
|
|
|
onTap: () async {
|
2019-06-22 16:41:00 +08:00
|
|
|
await messageChannel.publish({
|
|
|
|
"target": "home",
|
|
|
|
"state": "connect",
|
|
|
|
"conversationId": conversation.id
|
|
|
|
});
|
2019-05-19 11:05:27 +08:00
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.only(
|
2019-06-15 07:26:18 +08:00
|
|
|
top: 8.0, left: 10.0, right: 10.0, bottom: 8.0),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
StreamBuilder(
|
|
|
|
stream: bloc.members,
|
|
|
|
builder:
|
|
|
|
(context, AsyncSnapshot<List<User>> snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
return avatarBuilder(snapshot.data);
|
|
|
|
} else if (snapshot.hasError) {
|
|
|
|
return Text(snapshot.error.toString());
|
|
|
|
}
|
|
|
|
return SizedBox(width: 18.0, height: 18.0);
|
|
|
|
}),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.only(left: 10.0, right: 5.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(conversation.title,
|
|
|
|
style:
|
|
|
|
Theme.of(context).textTheme.title),
|
|
|
|
Text("yaddaydaadadyasdhbsjdfhsbjdfhsbdug",
|
|
|
|
maxLines: 2,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.subtitle
|
|
|
|
.copyWith(
|
|
|
|
color: Color(0xFF455A64))),
|
|
|
|
]))),
|
|
|
|
Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
2019-06-13 16:00:55 +08:00
|
|
|
Text("12:25 PM",
|
2019-05-19 11:05:27 +08:00
|
|
|
style: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
2019-06-14 10:48:38 +08:00
|
|
|
.display2
|
2019-05-19 11:05:27 +08:00
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context).primaryColorDark)),
|
2019-06-15 07:26:18 +08:00
|
|
|
])
|
|
|
|
]))));
|
2019-02-10 08:37:27 +08:00
|
|
|
}
|
2019-02-17 17:57:55 +08:00
|
|
|
|
2019-06-15 07:26:18 +08:00
|
|
|
Widget avatarBuilder(List<User> data) {
|
|
|
|
if (data.length == 1) {
|
|
|
|
return UserAvatar(radius: 25.0, user: data[0]);
|
|
|
|
} else if (data.length > 1) {
|
|
|
|
final groupUser = new User("0", conversation.title, "", "");
|
|
|
|
return UserAvatar(radius: 25.0, user: groupUser);
|
|
|
|
} else {
|
|
|
|
return Container();
|
|
|
|
}
|
2019-02-17 17:57:55 +08:00
|
|
|
}
|
2019-02-10 08:37:27 +08:00
|
|
|
}
|