| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- import 'package:e2ee_chat/common/global.dart';
- import 'package:e2ee_chat/presenter/session.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_slidable/flutter_slidable.dart';
- import 'package:provider/provider.dart';
- class MessageList extends StatefulWidget {
- @override
- _MessageListState createState() => _MessageListState();
- }
- class _MessageListState extends State<MessageList> {
- @override
- Widget build(BuildContext context) {
- return ChangeNotifierProvider<SessionListModel>(
- create: (context) {
- return SessionListModel();
- },
- child: Builder(
- builder: (context) {
- var provider = Provider.of<SessionListModel>(context);
- return ListView.builder(
- itemCount: provider.count,
- itemBuilder: (context, index) {
- var _item = provider.sessions[index];
- return Slidable(
- actionPane: SlidableDrawerActionPane(),
- actionExtentRatio: 0.25,
- secondaryActions: <Widget>[
- IconSlideAction(
- caption: '取消置顶',
- color: Colors.black45,
- icon: Icons.more_horiz,
- onTap: () {},
- ),
- IconSlideAction(
- caption: '删除',
- color: Colors.redAccent,
- icon: Icons.delete,
- onTap: () => {},
- ),
- ],
- child: Padding(
- padding: EdgeInsets.only(left: 36, bottom: 20, top: 20),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Expanded(child: MessageItem(_item)),
- _item.isStick
- ? Container(
- width: 40,
- height: 48,
- margin: EdgeInsets.only(top: 10, right: 10),
- child: Icon(Icons.star))
- : Padding(
- padding: EdgeInsets.symmetric(horizontal: 24),
- )
- ],
- ),
- ),
- );
- });
- },
- ),
- );
- }
- }
- class MessageItem extends StatelessWidget {
- final SessionModel model;
- MessageItem(this.model);
- @override
- Widget build(BuildContext context) {
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- model.avatar ?? Global.defaultAvatar,
- Expanded(
- child: Column(
- children: <Widget>[
- Padding(
- padding: EdgeInsets.symmetric(vertical: 8),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Expanded(
- child: Text(
- model.chatName,
- style: TextStyle(fontSize: 34),
- overflow: TextOverflow.ellipsis,
- ),
- ),
- Text(
- _formatDate(),
- style: TextStyle(fontSize: 26),
- overflow: TextOverflow.ellipsis,
- ),
- ],
- ),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Expanded(
- child: RichText(
- text: TextSpan(children: [
- TextSpan(
- text: model.isAtYou ? "[@你]" : "",
- style: TextStyle(fontSize: 28),
- ),
- TextSpan(
- text: model.isSpecialAttention ? "[特别关注]" : "",
- style: TextStyle(fontSize: 28),
- ),
- TextSpan(
- text: model.isAtAll ? "[@所有人]" : "",
- style: TextStyle(fontSize: 28),
- ),
- TextSpan(
- text: model.lastMessage.content.target!.plaintext,
- style: TextStyle(fontSize: 28),
- )
- ]),
- overflow: TextOverflow.ellipsis,
- ),
- ),
- (model.unReadCount > 0 && !model.isDND)
- ? Container(
- width: 32,
- height: 32,
- alignment: Alignment.center,
- decoration: BoxDecoration(borderRadius: BorderRadius.circular(20)),
- child: Text(
- model.unReadCount.toString(),
- style: TextStyle(color: Colors.white, fontSize: 26),
- ))
- : Container(),
- model.isDND
- ? Row(
- children: <Widget>[
- Icon(Icons.visibility_off),
- model.unReadCount > 0
- ? Icon(
- Icons.chat_bubble,
- color: Colors.red,
- ) // TODO: 小红点
- : Container()
- ],
- )
- : Container()
- ],
- )
- ],
- ),
- )
- ],
- );
- }
- String _formatDate() {
- DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(model.lastMessage.time);
- return "${dateTime.hour}:${dateTime.minute}";
- }
- }
|