|
| 1 | +import 'package:cached_network_image/cached_network_image.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:go_router/go_router.dart'; |
| 4 | + |
| 5 | +import '../../../core/theme/app_colors.dart'; |
| 6 | +import '../../features/watch/data/models/watch_position_model.dart'; |
| 7 | + |
| 8 | +/// Widget "Tiếp tục xem" hiển thị trên trang chủ |
| 9 | +class ContinueWatchingWidget extends StatelessWidget { |
| 10 | + final List<WatchPosition> items; |
| 11 | + |
| 12 | + const ContinueWatchingWidget({super.key, required this.items}); |
| 13 | + |
| 14 | + @override |
| 15 | + Widget build(BuildContext context) { |
| 16 | + if (items.isEmpty) return const SizedBox.shrink(); |
| 17 | + |
| 18 | + return Column( |
| 19 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 20 | + children: [ |
| 21 | + const Padding( |
| 22 | + padding: EdgeInsets.fromLTRB(16, 16, 16, 8), |
| 23 | + child: Row( |
| 24 | + children: [ |
| 25 | + Icon(Icons.play_circle_fill, color: AppColors.primary, size: 20), |
| 26 | + SizedBox(width: 8), |
| 27 | + Text( |
| 28 | + 'Tiếp tục xem', |
| 29 | + style: TextStyle( |
| 30 | + color: Colors.white, |
| 31 | + fontSize: 16, |
| 32 | + fontWeight: FontWeight.bold, |
| 33 | + ), |
| 34 | + ), |
| 35 | + ], |
| 36 | + ), |
| 37 | + ), |
| 38 | + SizedBox( |
| 39 | + height: 160, |
| 40 | + child: ListView.separated( |
| 41 | + scrollDirection: Axis.horizontal, |
| 42 | + padding: const EdgeInsets.symmetric(horizontal: 16), |
| 43 | + itemCount: items.length, |
| 44 | + separatorBuilder: (_, __) => const SizedBox(width: 12), |
| 45 | + itemBuilder: (context, index) { |
| 46 | + return _ContinueCard(item: items[index]); |
| 47 | + }, |
| 48 | + ), |
| 49 | + ), |
| 50 | + ], |
| 51 | + ); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +class _ContinueCard extends StatelessWidget { |
| 56 | + final WatchPosition item; |
| 57 | + |
| 58 | + const _ContinueCard({required this.item}); |
| 59 | + |
| 60 | + @override |
| 61 | + Widget build(BuildContext context) { |
| 62 | + return GestureDetector( |
| 63 | + onTap: () { |
| 64 | + context.push('/watch/${item.movieSlug}/${item.episodeSlug}'); |
| 65 | + }, |
| 66 | + child: SizedBox( |
| 67 | + width: 140, |
| 68 | + child: Column( |
| 69 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 70 | + children: [ |
| 71 | + // Thumbnail with progress |
| 72 | + ClipRRect( |
| 73 | + borderRadius: BorderRadius.circular(8), |
| 74 | + child: SizedBox( |
| 75 | + height: 80, |
| 76 | + width: 140, |
| 77 | + child: Stack( |
| 78 | + fit: StackFit.expand, |
| 79 | + children: [ |
| 80 | + CachedNetworkImage( |
| 81 | + imageUrl: item.posterUrl, |
| 82 | + fit: BoxFit.cover, |
| 83 | + errorWidget: (_, __, ___) => |
| 84 | + Container(color: AppColors.cardDark), |
| 85 | + ), |
| 86 | + // Play icon overlay |
| 87 | + Container( |
| 88 | + color: Colors.black26, |
| 89 | + child: const Center( |
| 90 | + child: Icon( |
| 91 | + Icons.play_circle_outline, |
| 92 | + color: Colors.white70, |
| 93 | + size: 36, |
| 94 | + ), |
| 95 | + ), |
| 96 | + ), |
| 97 | + // Progress bar |
| 98 | + Positioned( |
| 99 | + bottom: 0, |
| 100 | + left: 0, |
| 101 | + right: 0, |
| 102 | + child: LinearProgressIndicator( |
| 103 | + value: item.progress.clamp(0.0, 1.0), |
| 104 | + backgroundColor: Colors.black54, |
| 105 | + valueColor: const AlwaysStoppedAnimation<Color>( |
| 106 | + AppColors.primary), |
| 107 | + minHeight: 3, |
| 108 | + ), |
| 109 | + ), |
| 110 | + ], |
| 111 | + ), |
| 112 | + ), |
| 113 | + ), |
| 114 | + const SizedBox(height: 8), |
| 115 | + // Movie name |
| 116 | + Text( |
| 117 | + item.movieName, |
| 118 | + maxLines: 1, |
| 119 | + overflow: TextOverflow.ellipsis, |
| 120 | + style: const TextStyle( |
| 121 | + color: Colors.white, |
| 122 | + fontSize: 12, |
| 123 | + fontWeight: FontWeight.w500, |
| 124 | + ), |
| 125 | + ), |
| 126 | + const SizedBox(height: 2), |
| 127 | + // Episode name |
| 128 | + Text( |
| 129 | + item.episodeName, |
| 130 | + maxLines: 1, |
| 131 | + overflow: TextOverflow.ellipsis, |
| 132 | + style: const TextStyle(color: Colors.white38, fontSize: 11), |
| 133 | + ), |
| 134 | + ], |
| 135 | + ), |
| 136 | + ), |
| 137 | + ); |
| 138 | + } |
| 139 | +} |
0 commit comments