chat_list_item.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import 'package:e2ee_chat/common/global.dart';
  2. import 'package:e2ee_chat/presenter/chat_list.dart';
  3. import 'package:e2ee_chat/presenter/user_chat.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_slidable/flutter_slidable.dart';
  6. import 'package:provider/provider.dart';
  7. class ChatListItem extends StatelessWidget {
  8. final UserChatPresenter model;
  9. ChatListItem(this.model);
  10. @override
  11. Widget build(BuildContext context) {
  12. final message = model.lastMessage;
  13. return Row(
  14. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  15. children: <Widget>[
  16. model.avatar ?? Global.defaultAvatar,
  17. Expanded(
  18. child: Column(
  19. children: <Widget>[
  20. Padding(
  21. padding: EdgeInsets.symmetric(vertical: 8),
  22. child: Row(
  23. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  24. children: <Widget>[
  25. Expanded(
  26. child: Text(
  27. model.chatName,
  28. style: TextStyle(fontSize: 34),
  29. overflow: TextOverflow.ellipsis,
  30. ),
  31. ),
  32. Text(
  33. _formatDate(),
  34. style: TextStyle(fontSize: 26),
  35. overflow: TextOverflow.ellipsis,
  36. ),
  37. ],
  38. ),
  39. ),
  40. Row(
  41. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  42. children: <Widget>[
  43. Expanded(
  44. child: RichText(
  45. text: TextSpan(children: [
  46. TextSpan(
  47. text: model.isAtYou ? "[@你]" : "",
  48. style: TextStyle(fontSize: 28),
  49. ),
  50. TextSpan(
  51. text: model.isSpecialAttention ? "[特别关注]" : "",
  52. style: TextStyle(fontSize: 28),
  53. ),
  54. TextSpan(
  55. text: model.isAtAll ? "[@所有人]" : "",
  56. style: TextStyle(fontSize: 28),
  57. ),
  58. TextSpan(
  59. text: model.lastMessage?.plaintext ?? "",
  60. style: TextStyle(fontSize: 28),
  61. )
  62. ]),
  63. overflow: TextOverflow.ellipsis,
  64. ),
  65. ),
  66. (model.unReadCount > 0 && !model.isDND)
  67. ? Container(
  68. width: 32,
  69. height: 32,
  70. alignment: Alignment.center,
  71. decoration: BoxDecoration(borderRadius: BorderRadius.circular(20)),
  72. child: Text(
  73. model.unReadCount.toString(),
  74. style: TextStyle(color: Colors.white, fontSize: 26),
  75. ))
  76. : Container(),
  77. model.isDND
  78. ? Row(
  79. children: <Widget>[
  80. Icon(Icons.visibility_off),
  81. model.unReadCount > 0
  82. ? Icon(
  83. Icons.chat_bubble,
  84. color: Colors.red,
  85. ) // TODO: 小红点
  86. : Container()
  87. ],
  88. )
  89. : Container()
  90. ],
  91. )
  92. ],
  93. ),
  94. )
  95. ],
  96. );
  97. }
  98. String _formatDate() {
  99. return "1234";
  100. }
  101. }