Hibok
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

82 行
2.0 KiB

  1. import 'package:chat/data/chat_data_mgr.dart';
  2. import 'package:chat/home/ConversActionPage.dart';
  3. import 'package:chat/utils/MessageMgr.dart';
  4. import 'package:flutter/material.dart';
  5. import 'friend_page.dart';
  6. class UnreadDot extends StatefulWidget {
  7. final Widget child;
  8. final int type;
  9. UnreadDot({this.child, this.type = 1});
  10. @override
  11. _UnreadDotState createState() => _UnreadDotState();
  12. }
  13. class _UnreadDotState extends State<UnreadDot> {
  14. @override
  15. void initState() {
  16. super.initState();
  17. MessageMgr().on('Update UnreadCount', updateDotState);
  18. }
  19. @override
  20. void dispose() {
  21. MessageMgr().off('Update UnreadCount', updateDotState);
  22. super.dispose();
  23. }
  24. updateDotState(args) {
  25. print('更新未读状态');
  26. Future.delayed(Duration(milliseconds: 100), () {
  27. if (mounted) {
  28. setState(() {});
  29. }
  30. });
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. bool isHasUnread = false;
  35. switch (widget.type) {
  36. case 1:
  37. isHasUnread = ChatDataMgr().unreadCountProvider.checkUnreadMsg();
  38. break;
  39. case 2:
  40. isHasUnread = isShowMsg();
  41. break;
  42. case 3:
  43. isHasUnread =
  44. ChatDataMgr().unreadCountProvider.checkUnreadMsg() || isShowMsg();
  45. break;
  46. case 4:
  47. isHasUnread = ChatDataMgr().groupUnreadProvider.checkUnreadMsg();
  48. break;
  49. case 5:
  50. isHasUnread = isHaveNewFriends();
  51. break;
  52. case 6:
  53. isHasUnread = ChatDataMgr().unreadCountProvider.checkUnreadMsg() ||
  54. isShowMsg() ||
  55. ChatDataMgr().groupUnreadProvider.checkUnreadMsg();
  56. break;
  57. }
  58. return Stack(
  59. children: <Widget>[
  60. widget.child,
  61. Positioned(
  62. right: 0,
  63. top: 0,
  64. child: Offstage(
  65. offstage: !isHasUnread,
  66. child: CircleAvatar(
  67. radius: 3.5,
  68. backgroundColor: Colors.red,
  69. )))
  70. ],
  71. );
  72. }
  73. }