| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- import 'package:e2ee_chat/azlistview/azlistview.dart';
- import 'package:e2ee_chat/common/global.dart';
- import 'package:e2ee_chat/model/message.dart';
- import 'package:e2ee_chat/presenter/contact_list.dart';
- import 'package:e2ee_chat/presenter/session.dart';
- import 'package:e2ee_chat/widgets/utils.dart';
- import 'package:flutter/material.dart';
- import 'package:provider/provider.dart';
- class ContactListPage extends StatefulWidget {
- @override
- _ContactListPageState createState() => _ContactListPageState();
- }
- class _ContactListPageState extends State<ContactListPage> {
- @override
- void initState() {
- super.initState();
- ContactListPresenter().freshContacts().then((_) => setState(() {}));
- }
- @override
- Widget build(BuildContext context) {
- return ChangeNotifierProvider<ContactListPresenter>(
- create: (context) => ContactListPresenter(),
- child: Builder(
- builder: (context) {
- var provider = Provider.of<ContactListPresenter>(context);
- var contacts = provider.contacts;
- return AzListView(
- data: contacts,
- itemCount: contacts.length,
- itemBuilder: (context, index) {
- var info = contacts[index];
- return Utils.getWeChatListItem(
- context,
- info,
- defHeaderBgColor: Color(0xFFE5E5E5),
- );
- },
- physics: BouncingScrollPhysics(),
- susItemBuilder: (BuildContext context, int index) {
- ContactInfo model = contacts[index];
- if ('↑' == model.getSuspensionTag()) {
- return Container();
- }
- return Utils.getSusItem(context, model.getSuspensionTag());
- },
- indexBarData: ['↑', '☆', ...kIndexBarData],
- indexBarOptions: IndexBarOptions(
- needRebuild: true,
- ignoreDragCancel: true,
- downTextStyle: TextStyle(fontSize: 12, color: Colors.white),
- downItemDecoration:
- BoxDecoration(shape: BoxShape.circle, color: Colors.green),
- indexHintWidth: 120 / 2,
- indexHintHeight: 100 / 2,
- indexHintDecoration: BoxDecoration(
- image: DecorationImage(
- image: AssetImage(Utils.getImgPath('ic_index_bar_bubble_gray')),
- fit: BoxFit.contain,
- ),
- ),
- indexHintAlignment: Alignment.centerRight,
- indexHintChildAlignment: Alignment(-0.25, 0.0),
- indexHintOffset: Offset(-20, 0),
- ),
- );
- },
- ),
- );
- }
- }
- class ContactItem extends StatelessWidget {
- final SessionModel model;
- ContactItem(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() {
- try {
- DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(model.lastMessage!.time);
- return "${dateTime.hour}:${dateTime.minute}";
- } catch (e) {
- return "";
- }
- }
- }
|