Untitled
unknown
dart
a year ago
16 kB
5
Indexable
class NotificationPage extends StatefulWidget { const NotificationPage( {Key? key, required this.id, required this.notificationTypeId, required this.isRead, this.notificationsData}) : super(key: key); final String id, notificationTypeId; final bool isRead; final NotificationsData? notificationsData; @override State<NotificationPage> createState() => _NotificationPageState(); } class _NotificationPageState extends State<NotificationPage> { late NotificationsNotifier notificationsNotifier; @override void initState() { _getData(); super.initState(); } void _getData() { notificationsNotifier = Provider.of<NotificationsNotifier>(context, listen: false); notificationsNotifier.executeNotificationDetails(widget.id); } @override void dispose() { // get last count of notifications if (!widget.isRead) { widget.notificationsData?.statusId = 1; notificationsNotifier.executeGetNotificationsCount(); } super.dispose(); } @override Widget build(BuildContext context) { final themeNotifier = Provider.of<ThemeNotifier>(context, listen: true); bool isDarkTheme = (themeNotifier.getTheme() == AppThemes().darkTheme); notificationsNotifier = Provider.of<NotificationsNotifier>(context, listen: true); return Scaffold( appBar: _appBar(isDarkTheme, context, themeNotifier), backgroundColor: Theme.of(context).primaryColorDark, body: Consumer<AuthNotifier>( builder: (context, authProvider, child) { if (authProvider.user != null && notificationsNotifier.notificationsEntity == null && !notificationsNotifier.isNotificationsLoading) { notificationsNotifier.executeNotificationDetails(widget.id); } return authProvider.user == null ? const LoginView( title: Strings.pleaseReSignIn, ) : notificationsNotifier.isNotificationsLoading ? const CircularProgressIndicator().center() : _notificationView(context, isDarkTheme, themeNotifier); }, ), ); } Widget _notificationView( BuildContext context, bool isDarkTheme, ThemeNotifier themeNotifier) { return notificationsNotifier.notificationsEntity?.success ?? false ? _stackView(context, isDarkTheme, themeNotifier) : _errorView(notificationsNotifier); } Center _errorView(NotificationsNotifier provider) { return Center( child: Text( provider.notificationsEntity?.message ?? Strings.networkError, )); } Widget _stackView( BuildContext context, bool isDarkTheme, ThemeNotifier themeNotifier) { var data = notificationsNotifier.notificationsEntity?.data; _setData(data?.notificationdetailsList); return Stack( children: [ Stack( children: [ if (image != null && html == null) FancyShimmerImage( width: double.maxFinite, boxFit: BoxFit.fill, height: AppSize.s160, errorWidget: const Icon( Icons.image_not_supported_sharp, size: 60, ), imageUrl: image!), if (html == null) SizedBox( width: double.infinity, height: MediaQuery.of(context).size.height, child: Padding( padding: const EdgeInsets.only(top: 140), child: _detiles(isDarkTheme)), ), if (html != null) _htmlView(), ], ), _footer(themeNotifier, isDarkTheme) ], ); } WinnersAppBar _appBar( bool isDarkTheme, BuildContext context, ThemeNotifier themeNotifier) { return WinnersAppBar( title: "", action: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ if (widget.notificationTypeId == "1") Padding( padding: const EdgeInsets.only(top: 10), child: InkWell( onTap: () { showModalBottomSheet( context: context, backgroundColor: themeNotifier.getTheme().primaryColorDark, shape: const RoundedRectangleBorder( borderRadius: BorderRadius.vertical(top: Radius.circular(15)), ), builder: (context) { return _actions(isDarkTheme, widget.id); }, ); }, child: const Icon( Icons.more_horiz, size: 30, ).padding( padding: const EdgeInsets.only( top: AppPadding.p6, right: AppPadding.p6, left: AppPadding.p6, bottom: 63)), ), ) ], ), ); } Widget _detiles(bool isDarkTheme) { return Container( decoration: BoxDecoration( borderRadius: const BorderRadius.only( topLeft: Radius.circular(30.0), topRight: Radius.circular(30.0), ), color: isDarkTheme ? const Color(0xFF14213C).withOpacity(1) : Theme.of(context).primaryColor, ), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const SizedBox( height: AppSize.s12, ), if (title != null) Text( title!, style: Theme.of(context) .textTheme .titleLarge! .copyWith(color: isDarkTheme ? null : Colors.black), ).padding( padding: const EdgeInsets.only( right: AppPadding.p12, left: AppPadding.p12, top: AppPadding.p8, bottom: AppPadding.p8)), if (desc != null) Text( desc!.replaceAll('/n', '\n'), ).padding( padding: const EdgeInsets.only( right: AppPadding.p12, left: AppPadding.p12, top: AppPadding.p8, bottom: AppPadding.p20)), ], ), ), ); } Widget _footer( ThemeNotifier themeNotifier, bool isDarkTheme, ) { bool isAction = actions.isNotEmpty; return Align( alignment: Alignment.bottomCenter, child: Container( height: isAction ? jackpotAmount != null ? AppSize.s260 : AppSize.s110 : AppSize.s160, width: double.infinity, decoration: isAction ? BoxDecoration( color: isDarkTheme ? const Color(0xFF14213C).withOpacity(1) : Theme.of(context).primaryColor, ) : null, child: Column( children: [_jackpotView(), if (isAction) _actionsList(themeNotifier)], ), ), ); } Column _jackpotView() { return Column( children: [ if (jackpotDesc != null) Text( jackpotDesc!, style: GoogleFonts.poppins( textStyle: getMediumStyle( color: jackpotColor == null ? ColorManager.accentColor : HexColor(jackpotColor!.trim()), fontSize: FontSize.s17)), ), if (jackpotImg != null) Padding( padding: const EdgeInsets.only(right: 15, left: 15, bottom: 10, top: 9), child: Stack( alignment: Alignment.center, children: [ FancyShimmerImage( imageUrl: jackpotImg!, height: 90, width: MediaQuery.of(context).size.width, errorWidget: Image.asset( Assets.shape, height: 90, fit: BoxFit.fill, ), ), Center( child: Text( jackpotAmount ?? '', style: Theme.of(context) .textTheme .titleLarge! .copyWith(fontSize: 20, color: Colors.white), ), ), ], ), ) ], ); } Column _actionsList(ThemeNotifier themeNotifier) { return Column(children: [ const Divider( thickness: 0.8, height: 0.10, ).padding(padding: const EdgeInsets.only(bottom: AppPadding.p6)), Padding( padding: const EdgeInsets.only(top: AppPadding.p12), child: SizedBox( height: 60, child: ListView.builder( scrollDirection: Axis.horizontal, itemBuilder: (context, index) { return Padding( padding: const EdgeInsets.only( top: AppPadding.p4, right: AppPadding.p12, left: AppPadding.p12), child: InkWell( onTap: () { if (actions[index].notificationTemplateActionId == 1) { NotificationsActions().onTap(notificationsNotifier .notificationsEntity?.data?.filters ?? {}); } else if (actions[index].notificationTemplateActionId == 2) { Navigator.of(context).pop(); } }, child: Container( constraints: const BoxConstraints( maxWidth: 180, ), height: 55, margin: EdgeInsets.only( right: 12, left: actions.length == 1 ? MediaQuery.of(context).size.width / 4 : 0), decoration: BoxDecoration( color: themeNotifier.getTheme().colorScheme.secondary, borderRadius: BorderRadius.circular(30)), padding: const EdgeInsets.symmetric( vertical: AppPadding.p16, horizontal: AppPadding.p20), child: Text( actions[index].notificationTemplateTypeValue!, style: GoogleFonts.poppins( textStyle: getMediumStyle( color: ColorManager.white, fontSize: FontSize.s17)), ).center(), ), ), ); }, itemCount: actions.length, )), ) ]); } Consumer<NotificationsNotifier> _actions(bool isDarkTheme, String id) { return Consumer<NotificationsNotifier>( builder: (context, provider, child) { return SizedBox( height: AppSize.s120, child: provider.deleteIsLoading ? const Center(child: CircularProgressIndicator()) : Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ const Icon( Icons.remove_outlined, size: 55, color: Colors.grey, ), TextButton.icon( onPressed: () async { provider .executeDeleteNotification(id) .whenComplete(() { Navigator.of(context).pop(); if (provider.deleteEntity?.success ?? false) { provider.executeGetNotifications(true); Navigator.of(context).pop(); } else { _showAlert( '', provider.deleteEntity?.message ?? Strings.errorMessage); } }); }, icon: SvgPicture.asset( Assets.delete, width: 20, color: !isDarkTheme ? Colors.black : null, ), label: const Text( Strings.delete, ), style: TextButton.styleFrom( foregroundColor: !isDarkTheme ? Colors.black : Colors.white, // Text Color )).padding(padding: const EdgeInsets.only(bottom: 15)) ], )); }, ); } void _showAlert(String tilte, String body) { var baseDialog = BaseAlertDialog( title: tilte, content: body, yesOnPressed: () { Navigator.of(context).pop(); }, yes: Strings.ok, ); showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) => baseDialog); } String? title, desc, image, jackpotDesc, jackpotColor, jackpotImg, jackpotAmount, html; List<NotificationDetailsList> actions = []; void _setData(List<NotificationDetailsList>? data) { actions = data! .where( (element) => element.notificationStructureTypeId == 6, ) .toList(); image = data.firstWhere( (element) => element.notificationStructureTypeId == 1, orElse: () { return const NotificationDetailsList(); }).notificationTemplateTypeValue; title = data.firstWhere( (element) => element.notificationStructureTypeId == 2, orElse: () { return const NotificationDetailsList(); }).notificationTemplateTypeValue; desc = data.firstWhere( (element) => element.notificationStructureTypeId == 3, orElse: () { return const NotificationDetailsList(); }).notificationTemplateTypeValue; jackpotDesc = data.firstWhere( (element) => element.notificationStructureTypeId == 8, orElse: () { return const NotificationDetailsList(); }).notificationTemplateTypeValue; jackpotColor = data.firstWhere( (element) => element.notificationStructureTypeId == 8, orElse: () { return const NotificationDetailsList(); }).notificationTemplateTypeColor; jackpotImg = data.firstWhere( (element) => element.notificationStructureTypeId == 9, orElse: () { return const NotificationDetailsList(); }).notificationTemplateTypeValue; jackpotAmount = data.firstWhere( (element) => element.notificationStructureTypeId == 7, orElse: () { return const NotificationDetailsList(); }).notificationTemplateTypeValue; html = data.firstWhere( (element) => element.notificationStructureTypeId == 5, orElse: () { return const NotificationDetailsList(); }).notificationTemplateTypeValue; } Widget _htmlView() { return SizedBox( width: double.infinity, height: MediaQuery.of(context).size.height, child: InAppWebView(initialData: InAppWebViewInitialData(data: html!))); } }
Editor is loading...
Leave a Comment