Hibok
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

80 lines
1.9 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. }
  53. return Stack(
  54. children: <Widget>[
  55. Padding(
  56. padding: EdgeInsets.only(right: 2),
  57. child: widget.child,
  58. ),
  59. Positioned(
  60. right: 0,
  61. top: 0,
  62. child: Offstage(
  63. offstage: !isHasUnread,
  64. child: CircleAvatar(
  65. radius: 3.5,
  66. backgroundColor: Colors.red,
  67. )))
  68. ],
  69. );
  70. }
  71. }