|
| 1 | + |
| 2 | +import 'package:anymex/controllers/notification/notification_controller.dart'; |
| 3 | +import 'package:anymex/models/Media/media.dart'; |
| 4 | +import 'package:anymex/utils/function.dart'; |
| 5 | +import 'package:anymex/utils/theme_extensions.dart'; |
| 6 | +import 'package:anymex/widgets/common/glow.dart'; |
| 7 | +import 'package:cached_network_image/cached_network_image.dart'; |
| 8 | +import 'package:flutter/material.dart'; |
| 9 | +import 'package:get/get.dart'; |
| 10 | +import 'package:iconsax/iconsax.dart'; |
| 11 | + |
| 12 | +class NotificationPage extends StatelessWidget { |
| 13 | + const NotificationPage({super.key}); |
| 14 | + |
| 15 | + @override |
| 16 | + Widget build(BuildContext context) { |
| 17 | + final controller = Get.find<NotificationController>(); |
| 18 | + final theme = Theme.of(context); |
| 19 | + |
| 20 | + return Glow( |
| 21 | + child: Scaffold( |
| 22 | + body: Column( |
| 23 | + children: [ |
| 24 | + const NestedHeader(title: 'Notifications'), |
| 25 | + Expanded( |
| 26 | + child: Obx(() { |
| 27 | + if (controller.isLoading.value) { |
| 28 | + return const Center(child: CircularProgressIndicator()); |
| 29 | + } |
| 30 | + |
| 31 | + if (controller.airingSchedule.isEmpty) { |
| 32 | + return Center( |
| 33 | + child: Column( |
| 34 | + mainAxisAlignment: MainAxisAlignment.center, |
| 35 | + children: [ |
| 36 | + Icon(Iconsax.notification, size: 64, color: theme.colorScheme.primary.withOpacity(0.5)), |
| 37 | + const SizedBox(height: 16), |
| 38 | + Text( |
| 39 | + "No notifications yet", |
| 40 | + style: theme.textTheme.titleMedium, |
| 41 | + ), |
| 42 | + ], |
| 43 | + ), |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + return ListView.builder( |
| 48 | + padding: const EdgeInsets.all(0), |
| 49 | + itemCount: controller.airingSchedule.length, |
| 50 | + itemBuilder: (context, index) { |
| 51 | + final media = controller.airingSchedule[index]; |
| 52 | + return _NotificationTile(media: media); |
| 53 | + }, |
| 54 | + ); |
| 55 | + }), |
| 56 | + ), |
| 57 | + ], |
| 58 | + ), |
| 59 | + ), |
| 60 | + ); |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +class NestedHeader extends StatelessWidget { |
| 65 | + final String title; |
| 66 | + const NestedHeader({super.key, required this.title}); |
| 67 | + |
| 68 | + @override |
| 69 | + Widget build(BuildContext context) { |
| 70 | + final theme = Theme.of(context); |
| 71 | + return Container( |
| 72 | + padding: const EdgeInsets.only(top: 50, left: 20, right: 20, bottom: 20), |
| 73 | + decoration: BoxDecoration( |
| 74 | + color: theme.colorScheme.surface.opaque(0.4), |
| 75 | + border: Border( |
| 76 | + bottom: BorderSide( |
| 77 | + color: theme.colorScheme.outline.opaque(0.2, iReallyMeanIt: true), |
| 78 | + width: 1, |
| 79 | + ), |
| 80 | + ), |
| 81 | + ), |
| 82 | + child: Row( |
| 83 | + children: [ |
| 84 | + IconButton( |
| 85 | + onPressed: () => Navigator.of(context).pop(), |
| 86 | + icon: Icon( |
| 87 | + Icons.arrow_back_ios_rounded, |
| 88 | + color: theme.colorScheme.onSurface, |
| 89 | + ), |
| 90 | + style: IconButton.styleFrom( |
| 91 | + backgroundColor: theme.colorScheme.surfaceContainer |
| 92 | + .opaque(0.3, iReallyMeanIt: true), |
| 93 | + padding: const EdgeInsets.all(12), |
| 94 | + ), |
| 95 | + ), |
| 96 | + const SizedBox(width: 12), |
| 97 | + Expanded( |
| 98 | + child: Text( |
| 99 | + title, |
| 100 | + style: TextStyle( |
| 101 | + color: theme.colorScheme.onSurface, |
| 102 | + fontWeight: FontWeight.w600, |
| 103 | + fontSize: 22, |
| 104 | + ), |
| 105 | + ), |
| 106 | + ), |
| 107 | + ], |
| 108 | + ), |
| 109 | + ); |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +class _NotificationTile extends StatelessWidget { |
| 114 | + final Media media; |
| 115 | + const _NotificationTile({required this.media}); |
| 116 | + |
| 117 | + @override |
| 118 | + Widget build(BuildContext context) { |
| 119 | + final theme = Theme.of(context); |
| 120 | + return Padding( |
| 121 | + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8), |
| 122 | + child: Container( |
| 123 | + padding: const EdgeInsets.all(12), |
| 124 | + decoration: BoxDecoration( |
| 125 | + color: theme.colorScheme.surfaceContainer.withOpacity(0.3), |
| 126 | + borderRadius: BorderRadius.circular(16), |
| 127 | + border: Border.all( |
| 128 | + color: theme.colorScheme.outline.withOpacity(0.1), |
| 129 | + ), |
| 130 | + ), |
| 131 | + child: Row( |
| 132 | + children: [ |
| 133 | + ClipRRect( |
| 134 | + borderRadius: BorderRadius.circular(12), |
| 135 | + child: CachedNetworkImage( |
| 136 | + imageUrl: media.cover ?? '', |
| 137 | + width: 60, |
| 138 | + height: 80, |
| 139 | + fit: BoxFit.cover, |
| 140 | + ), |
| 141 | + ), |
| 142 | + const SizedBox(width: 16), |
| 143 | + Expanded( |
| 144 | + child: Column( |
| 145 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 146 | + children: [ |
| 147 | + Text( |
| 148 | + media.title ?? 'Unknown', |
| 149 | + style: theme.textTheme.titleMedium?.copyWith( |
| 150 | + fontWeight: FontWeight.bold, |
| 151 | + ), |
| 152 | + maxLines: 1, |
| 153 | + overflow: TextOverflow.ellipsis, |
| 154 | + ), |
| 155 | + const SizedBox(height: 4), |
| 156 | + Text( |
| 157 | + "Episode ${media.nextAiringEpisode}", |
| 158 | + style: theme.textTheme.bodyMedium?.copyWith( |
| 159 | + color: theme.colorScheme.primary, |
| 160 | + fontWeight: FontWeight.w600, |
| 161 | + ), |
| 162 | + ), |
| 163 | + const SizedBox(height: 4), |
| 164 | + Text( |
| 165 | + media.description ?? '', // Contains relative time string set in controller |
| 166 | + style: theme.textTheme.bodySmall?.copyWith( |
| 167 | + color: theme.colorScheme.onSurfaceVariant, |
| 168 | + ), |
| 169 | + maxLines: 2, |
| 170 | + overflow: TextOverflow.ellipsis, |
| 171 | + ), |
| 172 | + ], |
| 173 | + ), |
| 174 | + ), |
| 175 | + ], |
| 176 | + ), |
| 177 | + ), |
| 178 | + ); |
| 179 | + } |
| 180 | +} |
0 commit comments