import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:medcify/components/loader.dart'; import 'package:medcify/constants.dart'; import 'package:medcify/models/notification_item.dart'; import 'package:medcify/navigation/navigation.dart'; import 'package:medcify/pages/main/notification/notification_card.dart'; import 'notification_bloc.dart'; class NotificationPage extends StatelessWidget { const NotificationPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Colors.white, elevation: 0.25, automaticallyImplyLeading: false, title: const Text("Notifications",style: TextStyle(color: Colors.black,fontSize: 17),), leading: IconButton( onPressed: (){ Navigation.instance.goBack(); }, icon: const Icon(Icons.keyboard_backspace_rounded,color: Colors.black,), ), ), body: BlocProvider( create: (context) => NotificationCubit(), child: ProductWidget(), ), ); } } class ProductWidget extends StatelessWidget { late NotificationCubit notificationCubit; @override Widget build(BuildContext context) { notificationCubit = BlocProvider.of(context); notificationCubit.fetchNotifications(); return BlocBuilder( builder: (context, state) { if(state is NotificationLoading){ return const Loader(); }else if(state is NotificationFailure){ return Container( alignment: Alignment.center, margin: const EdgeInsets.symmetric(horizontal: 24), child: Text(state.error,style: TextStyle(color: Colors.grey.shade800, fontSize: 13, height: 1.6),), ); }else{ return (notificationCubit.notifications.isEmpty) ? Container( alignment: Alignment.center, margin: const EdgeInsets.symmetric(horizontal: 24), child: Text("No notifications found",style: TextStyle(color: Colors.grey.shade800, fontSize: 13),), ) : ListView.builder( itemCount: notificationCubit.notifications.length, padding: const EdgeInsets.only(top: 16,bottom: 80,left: 16,right: 16), physics: const BouncingScrollPhysics(), itemBuilder: (context, pos){ NotificationItem notification = notificationCubit.notifications[pos]; return NotificationCard(item: notification,removeNotification: notificationCubit.removeNotification,); }, ); } } ); } }