Advertisement
AbiMulya

Comment Notif without Pull Refresh

Nov 24th, 2021
1,186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 13.62 KB | None | 0 0
  1. part of 'notification_page.dart';
  2.  
  3. class CommentsContentView extends StatelessWidget {
  4.   const CommentsContentView({
  5.     Key? key,
  6.     this.notif,
  7.   }) : super(key: key);
  8.  
  9.   final NotifComment? notif;
  10.  
  11.   @override
  12.   Widget build(BuildContext context) {
  13.     debugPrint('Build: $runtimeType');
  14.     final _lang = LangUtil.of(context);
  15.     final _refreshController = RefreshController(initialRefresh: false);
  16.  
  17.     Future<void> _onHide(int index) async {
  18.       final result = await showOkCancelAlertDialog(
  19.         context: context,
  20.         title: _lang.trans('global_confirm_delete_header'),
  21.         message: _lang.trans('global_confirm_delete'),
  22.         okLabel: _lang.trans('global_ok'),
  23.         cancelLabel: _lang.trans('global_cancel'),
  24.       );
  25.       debugPrint(result.toString());
  26.  
  27.       if (result.toString() == 'OkCancelResult.ok') {
  28.         getIt<ContentCommentBloc>().add(
  29.           ContentCommentSaveEv(
  30.             moduleId: notif!.data[index].moduleId,
  31.             hideInNotif: '1',
  32.             id: notif!.data[index].id,
  33.           ),
  34.         );
  35.         debugPrint('OkCancelResult.ok');
  36.  
  37.         Future.delayed(const Duration(seconds: 2), () {
  38.           context.read<UserNotificationCubit>().fetchUserNotification();
  39.         });
  40.       }
  41.     }
  42.  
  43.     if (notif != null && notif!.data.isEmpty) {
  44.       return PullRefreshWidget(
  45.           controller: _refreshController,
  46.           onRefresh: () {
  47.             context.read<UserNotificationCubit>().fetchUserNotification();
  48.             _refreshController.refreshCompleted();
  49.           },
  50.           child: const InfoWidgetNoData());
  51.     } else {
  52.       if (notif != null) {
  53.         return PullRefreshWidget(
  54.           controller: _refreshController,
  55.           onRefresh: () {
  56.             context.read<UserNotificationCubit>().fetchUserNotification();
  57.             _refreshController.refreshCompleted();
  58.           },
  59.           child: ListView.builder(
  60.             itemBuilder: (BuildContext context, int index) {
  61.               _refreshController.refreshCompleted();
  62.               return ContentWidgetNotif(
  63.                 title: notif!.data[index].title,
  64.                 message: notif!.data[index].message,
  65.                 widgetMessage: notif!.data[index].parentData != null
  66.                     ? Dismissible(
  67.                         direction: DismissDirection.endToStart,
  68.                         key: Key(notif!.data[index].id),
  69.                         background: ContainerWidgetSlideBackgroud(
  70.                           title: _lang.trans('global_delete'),
  71.                           iconData: Icons.delete,
  72.                           color: Colors.red,
  73.                         ),
  74.                         onDismissed: (direction) {
  75.                           debugPrint('onDismissed');
  76.                         },
  77.                         confirmDismiss: (direction) async {
  78.                           if (direction == DismissDirection.endToStart) {
  79.                             await _onHide(index);
  80.                           }
  81.                         },
  82.                         child: Row(
  83.                           mainAxisAlignment: MainAxisAlignment.spaceBetween,
  84.                           children: [
  85.                             Expanded(
  86.                               child: ContainerWidgetBox(
  87.                                 color: Colors.transparent,
  88.                                 boxBorder: Border.all(
  89.                                   color: Colors.grey.shade300,
  90.                                   width: 0.5.r,
  91.                                   style: BorderStyle.solid,
  92.                                 ),
  93.                                 padding: 5.r,
  94.                                 child: Column(
  95.                                   children: [
  96.                                     CommentWidgetList2(
  97.                                       authorName: notif!
  98.                                           .data[index].parentData!.authorName,
  99.                                       authorAvatarUrl: notif!.data[index]
  100.                                           .parentData!.authorAvatarUrl,
  101.                                       dateTime: notif!
  102.                                           .data[index].parentData!.datetime,
  103.                                       comment: notif!
  104.                                           .data[index].parentData!.comment,
  105.                                       avatarSize: 'small',
  106.                                       bgColor:
  107.                                           Theme.of(context).backgroundColor,
  108.                                     ),
  109.                                     CommentWidgetList2(
  110.                                       authorName: notif!.data[index].authorName,
  111.                                       authorAvatarUrl:
  112.                                           notif!.data[index].authorAvatarUrl,
  113.                                       dateTime:
  114.                                           notif!.data[index].createdDatetime!,
  115.                                       comment: notif!.data[index].message,
  116.                                       avatarSize: 'small',
  117.                                     ),
  118.                                   ],
  119.                                 ),
  120.                               ),
  121.                             ),
  122.                             SpaceWidgetWidth(width: 5.r),
  123.                             if (notif!.data[index].notif == '1') ...[
  124.                               Icon(
  125.                                 Icons.circle,
  126.                                 size: 7.sp,
  127.                                 color: Colors.blue,
  128.                               ),
  129.                             ] else ...[
  130.                               SpaceWidgetWidth(width: 5.r),
  131.                             ]
  132.                           ],
  133.                         ),
  134.                       )
  135.                     : Dismissible(
  136.                         direction: DismissDirection.endToStart,
  137.                         key: Key(notif!.data[index].id),
  138.                         background: ContainerWidgetSlideBackgroud(
  139.                           title: _lang.trans('global_delete'),
  140.                           iconData: Icons.delete,
  141.                           color: Colors.red,
  142.                         ),
  143.                         onDismissed: (direction) {
  144.                           debugPrint('onDismissed');
  145.                         },
  146.                         confirmDismiss: (direction) async {
  147.                           if (direction == DismissDirection.endToStart) {
  148.                             await _onHide(index);
  149.                           }
  150.                         },
  151.                         child: Container(
  152.                           padding: EdgeInsets.only(left: 5.r, right: 5.r),
  153.                           child: Row(
  154.                             mainAxisAlignment: MainAxisAlignment.spaceBetween,
  155.                             children: [
  156.                               Expanded(
  157.                                 child: CommentWidgetList2(
  158.                                   authorName: notif!.data[index].authorName,
  159.                                   authorAvatarUrl:
  160.                                       notif!.data[index].authorAvatarUrl,
  161.                                   dateTime: notif!.data[index].createdDatetime!,
  162.                                   comment: notif!.data[index].message,
  163.                                   avatarSize: 'small',
  164.                                 ),
  165.                               ),
  166.                               SpaceWidgetWidth(width: 5.r),
  167.                               if (notif!.data[index].notif == '1') ...[
  168.                                 Icon(
  169.                                   Icons.circle,
  170.                                   size: 7.sp,
  171.                                   color: Colors.blue,
  172.                                 ),
  173.                               ] else ...[
  174.                                 SpaceWidgetWidth(width: 5.r),
  175.                               ]
  176.                             ],
  177.                           ),
  178.                         ),
  179.                       ),
  180.                 datetime: notif!.data[index].createdDatetime!,
  181.                 onTitleTap: () {
  182.                   if (notif!.data[index].module ==
  183.                       'content_articles_posts_new') {
  184.                     nextScreenPopupUtil(
  185.                       context,
  186.                       ContentPostCommentPage(
  187.                         module: notif!.data[index].module,
  188.                         moduleId: notif!.data[index].moduleId,
  189.                         moduleTitle: notif!.data[index].moduleTitle,
  190.                         moduleAuthorName: notif!.data[index].moduleAuthorName,
  191.                         moduleAuthorAvatarUrl:
  192.                             notif!.data[index].moduleAuthorAvatarUrl,
  193.                         moduleAuthorId: notif!.data[index].moduleAuthorId,
  194.                         moduleTotalLike: notif!.data[index].moduleTotalLike,
  195.                         moduleTotalComment:
  196.                             notif!.data[index].moduleTotalComment,
  197.                       ),
  198.                     );
  199.                   }
  200.                 },
  201.                 onMessageTap: () async {
  202.                   if (notif!.data[index].module ==
  203.                       'content_articles_posts_new') {
  204.                     if (notif!.data[index].notif == '1') {
  205.                       debugPrint('notifs: ${notif!.data[index].notif}');
  206.                       getIt<ContentCommentBloc>().add(
  207.                         ContentCommentSaveEv(
  208.                           moduleId: notif!.data[index].moduleId,
  209.                           isNotif: '0',
  210.                           id: notif!.data[index].id,
  211.                         ),
  212.                       );
  213.                     }
  214.  
  215.                     if (notif!.data[index].parentData != null) {
  216.                       nextScreenUtil(
  217.                         context,
  218.                         ContentPostCommentPage(
  219.                           module: notif!.data[index].module,
  220.                           moduleId: notif!.data[index].moduleId,
  221.                           moduleTitle: notif!.data[index].moduleTitle,
  222.                           moduleAuthorName: notif!.data[index].moduleAuthorName,
  223.                           moduleAuthorAvatarUrl:
  224.                               notif!.data[index].moduleAuthorAvatarUrl,
  225.                           moduleAuthorId: notif!.data[index].moduleAuthorId,
  226.                           moduleTotalLike: notif!.data[index].moduleTotalLike,
  227.                           moduleTotalComment:
  228.                               notif!.data[index].moduleTotalComment,
  229.                           redirectReply: () {
  230.                             nextScreenUtil(
  231.                               context,
  232.                               ContentPostCommentPage(
  233.                                 module: notif!.data[index].module,
  234.                                 moduleId: notif!.data[index].moduleId,
  235.                                 moduleTitle: notif!.data[index].moduleTitle,
  236.                                 moduleAuthorName:
  237.                                     notif!.data[index].moduleAuthorName,
  238.                                 moduleAuthorAvatarUrl:
  239.                                     notif!.data[index].moduleAuthorAvatarUrl,
  240.                                 moduleAuthorId:
  241.                                     notif!.data[index].moduleAuthorId,
  242.                                 moduleTotalLike:
  243.                                     notif!.data[index].moduleTotalLike,
  244.                                 moduleTotalComment:
  245.                                     notif!.data[index].moduleTotalComment,
  246.                                 parentData: notif!.data[index].parentData,
  247.                               ),
  248.                             );
  249.                           },
  250.                         ),
  251.                       ).then((value) {
  252.                         if (notif!.data[index].notif == '1') {
  253.                           debugPrint(
  254.                               'refresh notifs: ${notif!.data[index].notif}');
  255.                           context
  256.                               .read<UserNotificationCubit>()
  257.                               .fetchUserNotification();
  258.                         }
  259.                       });
  260.                     } else {
  261.                       nextScreenUtil(
  262.                         context,
  263.                         ContentPostCommentPage(
  264.                           module: notif!.data[index].module,
  265.                           moduleId: notif!.data[index].moduleId,
  266.                           moduleTitle: notif!.data[index].moduleTitle,
  267.                           moduleAuthorName: notif!.data[index].moduleAuthorName,
  268.                           moduleAuthorAvatarUrl:
  269.                               notif!.data[index].moduleAuthorAvatarUrl,
  270.                           moduleAuthorId: notif!.data[index].moduleAuthorId,
  271.                           moduleTotalLike: notif!.data[index].moduleTotalLike,
  272.                           moduleTotalComment:
  273.                               notif!.data[index].moduleTotalComment,
  274.                         ),
  275.                       ).then((value) {
  276.                         if (notif!.data[index].notif == '1') {
  277.                           debugPrint(
  278.                               'refresh notifs: ${notif!.data[index].notif}');
  279.                           context
  280.                               .read<UserNotificationCubit>()
  281.                               .fetchUserNotification();
  282.                         }
  283.                       });
  284.                     }
  285.                   }
  286.                 },
  287.               );
  288.             },
  289.             itemCount: notif!.data.length,
  290.           ),
  291.         );
  292.       }
  293.  
  294.       return const SizedBox();
  295.     }
  296.   }
  297. }
  298.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement