Application/medcify/lib/pages/main/notification/notification_page.dart
2022-09-26 12:03:52 +05:30

73 lines
2.8 KiB
Dart

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<NotificationCubit>(
create: (context) => NotificationCubit(),
child: ProductWidget(),
),
);
}
}
class ProductWidget extends StatelessWidget {
late NotificationCubit notificationCubit;
@override
Widget build(BuildContext context) {
notificationCubit = BlocProvider.of<NotificationCubit>(context);
notificationCubit.fetchNotifications();
return BlocBuilder<NotificationCubit, NotificationState>(
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,);
},
);
}
}
);
}
}