Files
xtremobile/lib/core/widgets/components/hero_carousel.dart
T
MichaelandClaude Opus 5 694b1257b9 fix(theme): remove every hardcoded Apple/Material colour left in the UI
Porting the palette was not enough: the Warm Cinema charter only reached the
widgets that read from AppColors. Nineteen screen and widget files still painted
Apple TV values inline, so the app kept showing blue — most visibly on the
selected navigation pill.

Swept out:
- 0xFF0A84FF (Apple blue) on the selected nav pill, category card icons and the
  "add playlist" button
- 0xFF4FC3F7 and 0xFF1565C0 in the player overlays
- Colors.blueAccent / Colors.blue in dialogs
- Apple greys 1C1C1E / 2C2C2E / 3A3A3C / 8E8E93 -> warm charcoals
- 128 Colors.white* -> the onSurfaceNN cream ladder (a pure white on a warm
  ground reads blue, which is the charter's whole point)
- Colors.red / green / amber / yellow / grey* -> error, success, ratingGold,
  outlineVariant
- pure black ink on light fills -> onPrimaryFixed, a warm near-black
- the white focus glow -> an ember glow

Deliberately left true black: the video surface backgrounds and the scrims over
posters and video, where a warm tint would clash with the picture.

Adds the onPrimaryFixed / primaryFixed / onSurface70 tokens the sweep needed.

Verified: no Material or Apple colour literal remains outside lib/core/theme;
flutter analyze reports no errors; 19/19 tests pass; release APK builds.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 20:39:58 +02:00

273 lines
9.0 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import '../../utils/image_cache_config.dart';
import 'package:google_fonts/google_fonts.dart';
import '../../theme/app_colors.dart';
import '../../theme/app_theme.dart';
class HeroCarousel extends StatefulWidget {
final List<HeroItem> items;
final Function(HeroItem) onTap;
const HeroCarousel({
super.key,
required this.items,
required this.onTap,
});
@override
State<HeroCarousel> createState() => _HeroCarouselState();
}
class _HeroCarouselState extends State<HeroCarousel> {
late PageController _pageController;
int _currentPage = 0;
Timer? _timer;
@override
void initState() {
super.initState();
_pageController = PageController(viewportFraction: 0.9);
_startAutoPlay();
}
@override
void dispose() {
_pageController.dispose();
_stopAutoPlay();
super.dispose();
}
void _startAutoPlay() {
_timer = Timer.periodic(const Duration(seconds: 8), (timer) {
if (_currentPage < widget.items.length - 1) {
_currentPage++;
} else {
_currentPage = 0;
}
if (_pageController.hasClients) {
_pageController.animateToPage(
_currentPage,
duration: const Duration(milliseconds: 800),
curve: Curves.fastOutSlowIn,
);
}
});
}
void _stopAutoPlay() {
_timer?.cancel();
}
@override
Widget build(BuildContext context) {
if (widget.items.isEmpty) return const SizedBox.shrink();
return SizedBox(
height: 400,
child: PageView.builder(
controller: _pageController,
onPageChanged: (index) {
setState(() => _currentPage = index);
},
itemCount: widget.items.length,
itemBuilder: (context, index) {
final item = widget.items[index];
final isActive = index == _currentPage;
return AnimatedScale(
duration: const Duration(milliseconds: 500),
scale: isActive ? 1.0 : 0.9,
child: AnimatedOpacity(
duration: const Duration(milliseconds: 500),
opacity: isActive ? 1.0 : 0.5,
child: GestureDetector(
onTap: () => widget.onTap(item),
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(AppTheme.radiusLg),
boxShadow: [
if (isActive)
BoxShadow(
color: Colors.black.withOpacity(0.5),
blurRadius: 20,
offset: const Offset(0, 10),
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(AppTheme.radiusLg),
child: Stack(
fit: StackFit.expand,
children: [
// Background Image
// [P1-2 FIX] Optimize carousel image cache (500x300 display)
CachedNetworkImage(
imageUrl: item.imageUrl,
fit: BoxFit.cover,
memCacheWidth: 600,
memCacheHeight: 360,
maxWidthDiskCache: 600,
maxHeightDiskCache: 360,
cacheManager: AppCacheManager.instance,
placeholder: (context, url) => Container(color: AppColors.surfaceVariant),
errorWidget: (context, url, error) => Container(
color: AppColors.surfaceVariant,
child: const Icon(Icons.movie, size: 64, color: AppColors.textTertiary),
),
),
// Gradient Overlay
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.transparent,
Colors.black.withOpacity(0.2),
Colors.black.withOpacity(0.9),
],
stops: const [0.0, 0.5, 1.0],
),
),
),
// Content
Positioned(
bottom: 32,
left: 32,
right: 32,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
item.title,
style: GoogleFonts.outfit(
fontSize: 32,
fontWeight: FontWeight.bold,
color: AppColors.onSurface,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
if (item.subtitle != null) ...[
const SizedBox(height: 8),
Text(
item.subtitle!,
style: GoogleFonts.inter(
fontSize: 16,
color: AppColors.onSurface.withOpacity(0.8),
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
const SizedBox(height: 16),
Row(
children: [
_HeroButton(
icon: Icons.play_arrow,
label: 'Lecture',
onPressed: () => widget.onTap(item),
isPrimary: true,
),
],
),
],
),
),
],
),
),
),
),
),
);
},
),
);
}
}
class _HeroButton extends StatefulWidget {
final IconData icon;
final String label;
final VoidCallback onPressed;
final bool isPrimary;
const _HeroButton({
required this.icon,
required this.label,
required this.onPressed,
required this.isPrimary,
});
@override
State<_HeroButton> createState() => _HeroButtonState();
}
class _HeroButtonState extends State<_HeroButton> {
bool _isHovered = false;
@override
Widget build(BuildContext context) {
return MouseRegion(
onEnter: (_) => setState(() => _isHovered = true),
onExit: (_) => setState(() => _isHovered = false),
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: widget.onPressed,
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
decoration: BoxDecoration(
color: widget.isPrimary
? (_isHovered ? AppColors.onSurface : AppColors.onSurface.withOpacity(0.9))
: (_isHovered ? AppColors.onSurface.withOpacity(0.2) : AppColors.onSurface.withOpacity(0.1)),
borderRadius: BorderRadius.circular(AppTheme.radiusFull),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
widget.icon,
color: widget.isPrimary ? AppColors.onPrimaryFixed : AppColors.onSurface,
size: 20,
),
const SizedBox(width: 8),
Text(
widget.label,
style: GoogleFonts.inter(
color: widget.isPrimary ? AppColors.onPrimaryFixed : AppColors.onSurface,
fontWeight: FontWeight.w600,
),
),
],
),
),
),
);
}
}
class HeroItem {
final String id;
final String title;
final String imageUrl;
final String? subtitle;
final VoidCallback? onMoreInfo;
HeroItem({
required this.id,
required this.title,
required this.imageUrl,
this.subtitle,
this.onMoreInfo,
});
}