mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-17 12:19:16 +02:00
feat: security hardening, streaming overhaul, design polish, tests
Security: - Replace unsalted SHA-256 password hashing with bcrypt (lazy rehash on login) - Add authenticated /api/xtream-api gateway: Xtream credentials are injected server-side and never sent to the frontend; /api/playlists no longer returns passwords - Redact credentials from all logs (login body, proxy/FFmpeg/scheduler URLs) - Add auth to recordings, EPG, season-passes and streaming routes (HttpOnly session cookie for hls.js; loopback bypass for local FFmpeg) - Lock player postMessage to same-origin in both directions - Vendor and pin hls.js 1.6.7 / mpegts.js 1.7.3 (drop CDN @latest) - Fix rate limiter (client IP was never resolved), add login rate limit, restrict CORS, add CSP Report-Only, block private-IP SSRF targets, fix path traversal in recording log retrieval, chmod 777 -> 770 - Remove dead HiveService (seeded admin/admin into IndexedDB with SHA-256) - Fix authMiddleware not populating 'user' context (getPlaylist ignored the logged-in user; admin purge always returned 403) Streaming: - New FfmpegSessionManager: process registry, idle reaper (4 min live / 15 min VOD), orphan cleanup at startup, clean SIGTERM shutdown, fast-fail with stderr instead of 30 s timeout - Quality selection (source/high/medium/low) for live and VOD; source mode streams with -c:v copy (zero transcoding); selector wired into the player - Concurrent recordings (MAX_CONCURRENT_RECORDINGS, default 2); conflicts retry on the next tick instead of silently failing - Lower live latency (HLS window 20 -> 10 segments, liveSync 10 -> 3) - Fix recording log lookup (.mp4 vs .mkv mismatch) Design: - Replace hardcoded colors with AppColors tokens (12 files) - web/theme.css syncs HTML players with the Flutter palette - DPAD/keyboard navigation (arrow-key focus, player shortcuts) - Tooltips on player icon buttons, Semantics on content cards - Remove 7 dead widgets broken since the Stitch merge Quality: - bin/test/: 21 unit tests (bcrypt, redaction, traversal, SSRF, recording conflicts) plus a quality-selector widget test - GitHub Actions CI (analyze + test + build web) - Archive stale status docs into docs/archive/ Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb5eca7547
commit
60d3f42901
107 files changed
+4525
-3815
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'dart:html' as html;
|
||||
|
||||
/// API Client for communicating with the backend
|
||||
@@ -17,11 +18,14 @@ class ApiClient {
|
||||
receiveTimeout: const Duration(seconds: 60),
|
||||
),);
|
||||
|
||||
// Add interceptor for logging
|
||||
_dio.interceptors.add(LogInterceptor(
|
||||
requestBody: true,
|
||||
responseBody: true,
|
||||
),);
|
||||
// Debug-only logging; request bodies are never logged (login payloads
|
||||
// contain passwords).
|
||||
if (kDebugMode) {
|
||||
_dio.interceptors.add(LogInterceptor(
|
||||
requestBody: false,
|
||||
responseBody: false,
|
||||
),);
|
||||
}
|
||||
|
||||
// Restore token from localStorage on initialization
|
||||
_restoreTokenFromStorage();
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import '../models/app_user.dart';
|
||||
import '../models/playlist_config.dart';
|
||||
|
||||
class HiveService {
|
||||
static const String _usersBoxName = 'users';
|
||||
static const String _playlistsBoxName = 'playlists';
|
||||
|
||||
static bool _initialized = false;
|
||||
static List<int>? _encryptionKey;
|
||||
|
||||
/// Initialize Hive for Web with encryption
|
||||
static Future<void> init() async {
|
||||
if (_initialized) return;
|
||||
|
||||
// Initialize Hive for Web (uses IndexedDB)
|
||||
await Hive.initFlutter();
|
||||
|
||||
// Register adapters
|
||||
Hive.registerAdapter(AppUserAdapter());
|
||||
Hive.registerAdapter(PlaylistConfigAdapter());
|
||||
|
||||
// Open boxes WITHOUT encryption on Web
|
||||
// Note: On Web, IndexedDB is already isolated by origin,
|
||||
// and session-based encryption keys cause decrypt errors on reload
|
||||
await Hive.openBox<AppUser>(_usersBoxName);
|
||||
await Hive.openBox<PlaylistConfig>(_playlistsBoxName);
|
||||
|
||||
// Seed default admin if no users exist
|
||||
await _seedDefaultAdmin();
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
/// Get or create 256-bit encryption key (web-compatible)
|
||||
static Future<List<int>> _getOrCreateEncryptionKey() async {
|
||||
// For web: use session-based key (regenerated each session)
|
||||
// Note: Data persists in IndexedDB but encryption key is not stored
|
||||
if (_encryptionKey != null) {
|
||||
return _encryptionKey!;
|
||||
}
|
||||
|
||||
// Generate new 256-bit key
|
||||
_encryptionKey = Hive.generateSecureKey();
|
||||
|
||||
return _encryptionKey!;
|
||||
}
|
||||
|
||||
/// Seed default admin user (admin/admin)
|
||||
static Future<void> _seedDefaultAdmin() async {
|
||||
final usersBox = Hive.box<AppUser>(_usersBoxName);
|
||||
|
||||
if (usersBox.isEmpty) {
|
||||
final adminId = const Uuid().v4();
|
||||
final passwordHash = _hashPassword('admin');
|
||||
|
||||
final admin = AppUser(
|
||||
id: adminId,
|
||||
username: 'admin',
|
||||
passwordHash: passwordHash,
|
||||
isAdmin: true,
|
||||
assignedPlaylistIds: const [],
|
||||
createdAt: DateTime.now(),
|
||||
);
|
||||
|
||||
await usersBox.put(adminId, admin);
|
||||
}
|
||||
}
|
||||
|
||||
/// Hash password using SHA-256 with salt
|
||||
static String _hashPassword(String password) {
|
||||
// Generate a random salt using the first 16 chars of a UUID
|
||||
final salt = const Uuid().v4().substring(0, 16);
|
||||
final bytes = utf8.encode(password + salt);
|
||||
final digest = sha256.convert(bytes);
|
||||
return '$salt:${digest.toString()}';
|
||||
}
|
||||
|
||||
/// Verify password against stored hash
|
||||
static bool verifyPassword(String password, String storedHash) {
|
||||
try {
|
||||
final parts = storedHash.split(':');
|
||||
if (parts.length != 2) {
|
||||
// Legacy hash without salt - fallback to direct comparison
|
||||
final legacyHash = sha256.convert(utf8.encode(password)).toString();
|
||||
return legacyHash == storedHash;
|
||||
}
|
||||
|
||||
final salt = parts[0];
|
||||
final expectedHash = parts[1];
|
||||
final bytes = utf8.encode(password + salt);
|
||||
final actualHash = sha256.convert(bytes).toString();
|
||||
|
||||
return actualHash == expectedHash;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Public method to hash passwords (used by auth)
|
||||
static String hashPassword(String password) => _hashPassword(password);
|
||||
|
||||
/// Get users box
|
||||
static Box<AppUser> get usersBox => Hive.box<AppUser>(_usersBoxName);
|
||||
|
||||
/// Get playlists box
|
||||
static Box<PlaylistConfig> get playlistsBox =>
|
||||
Hive.box<PlaylistConfig>(_playlistsBoxName);
|
||||
|
||||
/// Close all boxes (cleanup)
|
||||
static Future<void> dispose() async {
|
||||
await Hive.close();
|
||||
_initialized = false;
|
||||
}
|
||||
}
|
||||
@@ -1,346 +0,0 @@
|
||||
/// Adaptive Bitrate (ABR) Streaming Handler for HLS
|
||||
///
|
||||
/// Supports multi-bitrate HLS playlists for adaptive streaming
|
||||
/// with fallback options for poor network conditions
|
||||
library;
|
||||
|
||||
/// Represents a video quality level for adaptive bitrate streaming
|
||||
class QualityLevel {
|
||||
final String resolution;
|
||||
final int bitrateBps;
|
||||
final int width;
|
||||
final int height;
|
||||
final String ffmpegPreset; // ultrafast, fast, medium, slow
|
||||
final String label;
|
||||
|
||||
const QualityLevel({
|
||||
required this.resolution,
|
||||
required this.bitrateBps,
|
||||
required this.width,
|
||||
required this.height,
|
||||
this.ffmpegPreset = 'medium',
|
||||
required this.label,
|
||||
});
|
||||
|
||||
/// Get FFmpeg video bitrate argument
|
||||
String get videoBitrateArg => '${(bitrateBps * 0.75).toInt() ~/ 1000}k';
|
||||
|
||||
/// Get FFmpeg maxrate argument (150% of bitrate)
|
||||
String get maxRateArg => '${((bitrateBps * 1.5).toInt() ~/ 1000)}k';
|
||||
|
||||
/// Get FFmpeg buffer size argument
|
||||
String get bufferSizeArg => '${((bitrateBps * 2).toInt() ~/ 1000)}k';
|
||||
|
||||
@override
|
||||
String toString() => '$label ($resolution - ${bitrateBps ~/ 1000000}Mbps)';
|
||||
}
|
||||
|
||||
/// Standard quality profiles for adaptive streaming
|
||||
class QualityProfiles {
|
||||
// Mobile & Low Bandwidth
|
||||
static const mobile240p = QualityLevel(
|
||||
resolution: '426x240',
|
||||
bitrateBps: 500000, // 0.5 Mbps
|
||||
width: 426,
|
||||
height: 240,
|
||||
ffmpegPreset: 'ultrafast',
|
||||
label: '240p (Low)',
|
||||
);
|
||||
|
||||
static const mobile360p = QualityLevel(
|
||||
resolution: '640x360',
|
||||
bitrateBps: 1200000, // 1.2 Mbps
|
||||
width: 640,
|
||||
height: 360,
|
||||
ffmpegPreset: 'ultrafast',
|
||||
label: '360p (Mobile)',
|
||||
);
|
||||
|
||||
// Standard Quality
|
||||
static const hd480p = QualityLevel(
|
||||
resolution: '854x480',
|
||||
bitrateBps: 2500000, // 2.5 Mbps
|
||||
width: 854,
|
||||
height: 480,
|
||||
ffmpegPreset: 'fast',
|
||||
label: '480p (SD)',
|
||||
);
|
||||
|
||||
static const hd720p = QualityLevel(
|
||||
resolution: '1280x720',
|
||||
bitrateBps: 5000000, // 5 Mbps
|
||||
width: 1280,
|
||||
height: 720,
|
||||
ffmpegPreset: 'medium',
|
||||
label: '720p (HD)',
|
||||
);
|
||||
|
||||
// High Quality
|
||||
static const fhd1080p = QualityLevel(
|
||||
resolution: '1920x1080',
|
||||
bitrateBps: 8000000, // 8 Mbps
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
ffmpegPreset: 'medium',
|
||||
label: '1080p (Full HD)',
|
||||
);
|
||||
|
||||
// Ultra HD
|
||||
static const uhd2k = QualityLevel(
|
||||
resolution: '2560x1440',
|
||||
bitrateBps: 15000000, // 15 Mbps
|
||||
width: 2560,
|
||||
height: 1440,
|
||||
ffmpegPreset: 'slow',
|
||||
label: '2K (QHD)',
|
||||
);
|
||||
|
||||
static const uhd4k = QualityLevel(
|
||||
resolution: '3840x2160',
|
||||
bitrateBps: 25000000, // 25 Mbps
|
||||
width: 3840,
|
||||
height: 2160,
|
||||
ffmpegPreset: 'slow',
|
||||
label: '4K',
|
||||
);
|
||||
|
||||
/// Get default profiles for balanced streaming
|
||||
static List<QualityLevel> getBalancedProfiles() => [
|
||||
mobile240p,
|
||||
mobile360p,
|
||||
hd480p,
|
||||
hd720p,
|
||||
fhd1080p,
|
||||
];
|
||||
|
||||
/// Get all available profiles
|
||||
static List<QualityLevel> getAllProfiles() => [
|
||||
mobile240p,
|
||||
mobile360p,
|
||||
hd480p,
|
||||
hd720p,
|
||||
fhd1080p,
|
||||
uhd2k,
|
||||
uhd4k,
|
||||
];
|
||||
|
||||
/// Get profiles suitable for streaming type
|
||||
static List<QualityLevel> getProfiles({
|
||||
required String type, // 'live', 'vod', 'low-bandwidth'
|
||||
int? maxBitrateBps,
|
||||
}) {
|
||||
List<QualityLevel> profiles = getBalancedProfiles();
|
||||
|
||||
// Filter by streaming type
|
||||
if (type == 'live') {
|
||||
// Live TV prefers lower bitrates for stability
|
||||
profiles = [mobile240p, mobile360p, hd480p, hd720p];
|
||||
} else if (type == 'low-bandwidth') {
|
||||
// Mobile/low bandwidth - only lower profiles
|
||||
profiles = [mobile240p, mobile360p, hd480p];
|
||||
}
|
||||
|
||||
// Filter by max bitrate if specified
|
||||
if (maxBitrateBps != null) {
|
||||
profiles = profiles.where((p) => p.bitrateBps <= maxBitrateBps).toList();
|
||||
}
|
||||
|
||||
// Ensure at least one profile
|
||||
if (profiles.isEmpty) {
|
||||
profiles = [mobile240p];
|
||||
}
|
||||
|
||||
return profiles;
|
||||
}
|
||||
}
|
||||
|
||||
/// Bandwidth detector for adaptive bitrate selection
|
||||
class BandwidthDetector {
|
||||
final _samples = <DateTime, int>{}; // timestamp -> bytes downloaded
|
||||
final int _totalBytesLastPeriod = 0;
|
||||
final Duration _sampleWindow = const Duration(seconds: 10);
|
||||
|
||||
/// Record bytes downloaded at current time
|
||||
void recordBytes(int bytes) {
|
||||
final now = DateTime.now();
|
||||
_samples[now] = bytes;
|
||||
|
||||
// Clean up old samples
|
||||
final cutoff = now.subtract(_sampleWindow);
|
||||
_samples.removeWhere((time, _) => time.isBefore(cutoff));
|
||||
}
|
||||
|
||||
/// Estimate current bandwidth in bps
|
||||
int estimateBandwidthBps() {
|
||||
if (_samples.isEmpty) return 0;
|
||||
|
||||
int totalBytes = 0;
|
||||
for (var bytes in _samples.values) {
|
||||
totalBytes += bytes;
|
||||
}
|
||||
|
||||
final timeSpan = DateTime.now()
|
||||
.difference(
|
||||
_samples.keys.reduce((a, b) => a.isBefore(b) ? a : b),
|
||||
)
|
||||
.inMilliseconds;
|
||||
|
||||
if (timeSpan == 0) return 0;
|
||||
|
||||
// bytes per second * 8 = bits per second
|
||||
return ((totalBytes / (timeSpan / 1000)) * 8).toInt();
|
||||
}
|
||||
|
||||
/// Get estimated bandwidth in Mbps
|
||||
double estimateBandwidthMbps() {
|
||||
return estimateBandwidthBps() / 1000000;
|
||||
}
|
||||
|
||||
/// Select best quality level based on bandwidth
|
||||
static QualityLevel selectBestQuality(
|
||||
int bandwidthBps,
|
||||
List<QualityLevel> availableProfiles,
|
||||
) {
|
||||
// Use 75% of detected bandwidth for conservative selection
|
||||
final targetBitrate = (bandwidthBps * 0.75).toInt();
|
||||
|
||||
// Find highest quality that fits our bandwidth
|
||||
var best = availableProfiles[0];
|
||||
for (final profile in availableProfiles) {
|
||||
if (profile.bitrateBps <= targetBitrate) {
|
||||
best = profile;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
}
|
||||
|
||||
/// Master playlist generator for HLS variant streams
|
||||
class HlsMasterPlaylistGenerator {
|
||||
/// Generate M3U8 master playlist with multiple quality variants
|
||||
static String generateMasterPlaylist({
|
||||
required List<QualityLevel> qualityLevels,
|
||||
required String baseUrl,
|
||||
bool includeSubtitles = false,
|
||||
}) {
|
||||
final buffer = StringBuffer();
|
||||
|
||||
// HLS version 3 for compatibility
|
||||
buffer.writeln('#EXTM3U');
|
||||
buffer.writeln('#EXT-X-VERSION:3');
|
||||
buffer.writeln('#EXT-X-TARGET-DURATION:10');
|
||||
buffer.writeln('#EXT-X-MEDIA-SEQUENCE:0');
|
||||
|
||||
// Variant streams (quality levels)
|
||||
for (final quality in qualityLevels) {
|
||||
buffer.writeln('#EXT-X-STREAM-INF:BANDWIDTH=${quality.bitrateBps},'
|
||||
'RESOLUTION=${quality.width}x${quality.height}');
|
||||
buffer
|
||||
.writeln('$baseUrl/variant_${quality.width}x${quality.height}.m3u8');
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/// Generate variant playlist for specific quality level
|
||||
static String generateVariantPlaylist({
|
||||
required String segmentPrefix,
|
||||
required int totalSegments,
|
||||
required double targetDuration,
|
||||
required bool isFinal,
|
||||
}) {
|
||||
final buffer = StringBuffer();
|
||||
|
||||
buffer.writeln('#EXTM3U');
|
||||
buffer.writeln('#EXT-X-VERSION:3');
|
||||
buffer.writeln('#EXT-X-TARGET-DURATION:${targetDuration.ceil()}');
|
||||
buffer.writeln('#EXT-X-MEDIA-SEQUENCE:0');
|
||||
|
||||
// Add segment entries
|
||||
for (int i = 0; i < totalSegments; i++) {
|
||||
buffer.writeln('#EXTINF:$targetDuration,');
|
||||
buffer.writeln('${segmentPrefix}_$i.ts');
|
||||
}
|
||||
|
||||
if (isFinal) {
|
||||
buffer.writeln('#EXT-X-ENDLIST');
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/// Quality selector based on network conditions
|
||||
class QualitySelector {
|
||||
final _detector = BandwidthDetector();
|
||||
QualityLevel _currentQuality;
|
||||
final _listeners = <VoidCallback>[];
|
||||
|
||||
QualitySelector({
|
||||
required QualityLevel initialQuality,
|
||||
}) : _currentQuality = initialQuality;
|
||||
|
||||
QualityLevel get currentQuality => _currentQuality;
|
||||
|
||||
/// Record bandwidth and auto-adjust quality
|
||||
void recordBandwidth(int bytesDownloaded) {
|
||||
_detector.recordBytes(bytesDownloaded);
|
||||
|
||||
// Check if we should switch quality
|
||||
_maybeAdjustQuality();
|
||||
}
|
||||
|
||||
/// Manually set quality
|
||||
void setQuality(QualityLevel quality) {
|
||||
if (_currentQuality != quality) {
|
||||
_currentQuality = quality;
|
||||
_notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// Force rebuffer wait before switching down
|
||||
void rebufferDetected() {
|
||||
// Switch to lower quality if rebuffering occurs
|
||||
final allProfiles = QualityProfiles.getAllProfiles();
|
||||
final currentIndex = allProfiles.indexOf(_currentQuality);
|
||||
if (currentIndex > 0) {
|
||||
setQuality(allProfiles[currentIndex - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
void _maybeAdjustQuality() {
|
||||
final bandwidthBps = _detector.estimateBandwidthBps();
|
||||
final availableProfiles = QualityProfiles.getBalancedProfiles();
|
||||
|
||||
// Only switch if significantly different from current
|
||||
final overhead = _currentQuality.bitrateBps * 1.2;
|
||||
if (bandwidthBps > overhead ||
|
||||
bandwidthBps < _currentQuality.bitrateBps * 0.5) {
|
||||
final bestQuality =
|
||||
BandwidthDetector.selectBestQuality(bandwidthBps, availableProfiles);
|
||||
setQuality(bestQuality);
|
||||
}
|
||||
}
|
||||
|
||||
void addListener(VoidCallback listener) {
|
||||
_listeners.add(listener);
|
||||
}
|
||||
|
||||
void removeListener(VoidCallback listener) {
|
||||
_listeners.remove(listener);
|
||||
}
|
||||
|
||||
void _notifyListeners() {
|
||||
for (final listener in _listeners) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
|
||||
double getEstimatedBandwidthMbps() => _detector.estimateBandwidthMbps();
|
||||
}
|
||||
|
||||
// Type alias for void callback
|
||||
typedef VoidCallback = void Function();
|
||||
@@ -1,267 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/services/adaptive_bitrate_service.dart';
|
||||
|
||||
/// Video streaming performance metrics
|
||||
class StreamingMetrics {
|
||||
final double averageNetworkBitrate;
|
||||
final double currentNetworkBitrate;
|
||||
final int bufferDurationMs;
|
||||
final int segmentDownloadTimeMs;
|
||||
final int rebufferCount;
|
||||
final DateTime startTime;
|
||||
final DateTime? endTime;
|
||||
|
||||
StreamingMetrics({
|
||||
required this.averageNetworkBitrate,
|
||||
required this.currentNetworkBitrate,
|
||||
required this.bufferDurationMs,
|
||||
required this.segmentDownloadTimeMs,
|
||||
required this.rebufferCount,
|
||||
required this.startTime,
|
||||
this.endTime,
|
||||
});
|
||||
|
||||
double get totalPlaybackSeconds =>
|
||||
(endTime ?? DateTime.now()).difference(startTime).inSeconds.toDouble();
|
||||
|
||||
double get qualityScore {
|
||||
// Score based on metrics
|
||||
var score = 100.0;
|
||||
|
||||
// Penalize for rebuffering
|
||||
score -= rebufferCount * 10;
|
||||
|
||||
// Penalize for low bitrate
|
||||
if (currentNetworkBitrate < 1000000) score -= 20;
|
||||
if (currentNetworkBitrate < 500000) score -= 30;
|
||||
|
||||
// Reward for smooth playback
|
||||
if (rebufferCount == 0) score += 10;
|
||||
|
||||
return (score).clamp(0, 100);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => '''
|
||||
StreamingMetrics:
|
||||
- Avg Bitrate: ${(averageNetworkBitrate / 1000000).toStringAsFixed(2)} Mbps
|
||||
- Current Bitrate: ${(currentNetworkBitrate / 1000000).toStringAsFixed(2)} Mbps
|
||||
- Buffer: ${bufferDurationMs}ms
|
||||
- Segment DL Time: ${segmentDownloadTimeMs}ms
|
||||
- Rebuffers: $rebufferCount
|
||||
- Quality Score: ${qualityScore.toStringAsFixed(1)}
|
||||
- Duration: $totalPlaybackSeconds seconds
|
||||
''';
|
||||
}
|
||||
|
||||
/// Advanced streaming optimizer
|
||||
class StreamingOptimizer {
|
||||
final QualitySelector qualitySelector;
|
||||
final _metrics = <StreamingMetrics>[];
|
||||
late StreamingMetrics _currentMetrics;
|
||||
final StreamController<StreamingMetrics> _metricsController =
|
||||
StreamController.broadcast();
|
||||
late Timer _metricsTimer;
|
||||
|
||||
final int _segmentStartTime = 0;
|
||||
int _totalBytesDownloaded = 0;
|
||||
int _rebufferCount = 0;
|
||||
int _lastBufferNotificationTime = 0;
|
||||
|
||||
StreamingOptimizer({required this.qualitySelector}) {
|
||||
_initializeMetrics();
|
||||
_startMetricsCollection();
|
||||
}
|
||||
|
||||
void _initializeMetrics() {
|
||||
_currentMetrics = StreamingMetrics(
|
||||
averageNetworkBitrate: 0,
|
||||
currentNetworkBitrate: 0,
|
||||
bufferDurationMs: 0,
|
||||
segmentDownloadTimeMs: 0,
|
||||
rebufferCount: 0,
|
||||
startTime: DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
void _startMetricsCollection() {
|
||||
_metricsTimer = Timer.periodic(const Duration(seconds: 5), (timer) {
|
||||
_updateMetrics();
|
||||
});
|
||||
}
|
||||
|
||||
void _updateMetrics() {
|
||||
final bandwidthBps = qualitySelector.getEstimatedBandwidthMbps() * 1000000;
|
||||
_currentMetrics = StreamingMetrics(
|
||||
averageNetworkBitrate: _totalBytesDownloaded > 0
|
||||
? (_totalBytesDownloaded * 8 / _currentMetrics.totalPlaybackSeconds)
|
||||
: 0,
|
||||
currentNetworkBitrate: bandwidthBps,
|
||||
bufferDurationMs: _currentMetrics.bufferDurationMs,
|
||||
segmentDownloadTimeMs: _currentMetrics.segmentDownloadTimeMs,
|
||||
rebufferCount: _rebufferCount,
|
||||
startTime: _currentMetrics.startTime,
|
||||
);
|
||||
|
||||
_metrics.add(_currentMetrics);
|
||||
_metricsController.add(_currentMetrics);
|
||||
}
|
||||
|
||||
/// Record segment download
|
||||
void recordSegmentDownload(int bytes, Duration downloadTime) {
|
||||
_totalBytesDownloaded += bytes;
|
||||
final downloadMs = downloadTime.inMilliseconds;
|
||||
|
||||
_currentMetrics = _currentMetrics;
|
||||
qualitySelector.recordBandwidth(bytes);
|
||||
}
|
||||
|
||||
/// Handle rebuffer event
|
||||
void rebufferDetected(Duration duration) {
|
||||
_rebufferCount++;
|
||||
_lastBufferNotificationTime = DateTime.now().millisecondsSinceEpoch;
|
||||
|
||||
_currentMetrics = StreamingMetrics(
|
||||
averageNetworkBitrate: _currentMetrics.averageNetworkBitrate,
|
||||
currentNetworkBitrate: _currentMetrics.currentNetworkBitrate,
|
||||
bufferDurationMs: duration.inMilliseconds,
|
||||
segmentDownloadTimeMs: _currentMetrics.segmentDownloadTimeMs,
|
||||
rebufferCount: _rebufferCount,
|
||||
startTime: _currentMetrics.startTime,
|
||||
);
|
||||
|
||||
// Auto downgrade quality on rebuffer
|
||||
qualitySelector.rebufferDetected();
|
||||
}
|
||||
|
||||
/// Get current streaming metrics
|
||||
StreamingMetrics getMetrics() => _currentMetrics;
|
||||
|
||||
/// Get metrics stream for real-time monitoring
|
||||
Stream<StreamingMetrics> get metricsStream => _metricsController.stream;
|
||||
|
||||
/// Get metrics history
|
||||
List<StreamingMetrics> getMetricsHistory() => List.from(_metrics);
|
||||
|
||||
/// Finalize streaming session
|
||||
void finalize() {
|
||||
_currentMetrics = StreamingMetrics(
|
||||
averageNetworkBitrate: _currentMetrics.averageNetworkBitrate,
|
||||
currentNetworkBitrate: _currentMetrics.currentNetworkBitrate,
|
||||
bufferDurationMs: _currentMetrics.bufferDurationMs,
|
||||
segmentDownloadTimeMs: _currentMetrics.segmentDownloadTimeMs,
|
||||
rebufferCount: _rebufferCount,
|
||||
startTime: _currentMetrics.startTime,
|
||||
endTime: DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Clean up resources
|
||||
void dispose() {
|
||||
_metricsTimer.cancel();
|
||||
_metricsController.close();
|
||||
}
|
||||
}
|
||||
|
||||
/// Buffer size calculator for adaptive streaming
|
||||
class BufferCalculator {
|
||||
static const _minBufferMs = 1000; // 1 second
|
||||
static const _targetBufferMs = 8000; // 8 seconds
|
||||
static const _maxBufferMs = 30000; // 30 seconds
|
||||
|
||||
/// Calculate optimal buffer size based on bandwidth
|
||||
static int calculateOptimalBuffer(
|
||||
int estimatedBandwidthBps,
|
||||
int bitrateOfCurrentQuality,
|
||||
) {
|
||||
// Rule: buffer should be able to hold 8 seconds worth of content
|
||||
final neededBytes = (bitrateOfCurrentQuality * _targetBufferMs) ~/ 8000;
|
||||
final availableBytes = (estimatedBandwidthBps * _targetBufferMs) ~/ 8000;
|
||||
|
||||
// If we can't sustain the bitrate + have buffer, reduce target
|
||||
if (availableBytes < neededBytes) {
|
||||
return _minBufferMs;
|
||||
}
|
||||
|
||||
// Normal case
|
||||
return _targetBufferMs;
|
||||
}
|
||||
|
||||
/// Calculate recommended segment duration
|
||||
static Duration calculateSegmentDuration(int estimatedBandwidthBps) {
|
||||
if (estimatedBandwidthBps < 500000) {
|
||||
// Very low bandwidth: shorter segments
|
||||
return const Duration(seconds: 2);
|
||||
} else if (estimatedBandwidthBps < 2000000) {
|
||||
// Low bandwidth
|
||||
return const Duration(seconds: 4);
|
||||
} else {
|
||||
// Good bandwidth
|
||||
return const Duration(seconds: 6);
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculate maximum playback quality
|
||||
static QualityLevel selectQualityForBandwidth(
|
||||
int estimatedBandwidthBps,
|
||||
) {
|
||||
final availableProfiles = QualityProfiles.getBalancedProfiles();
|
||||
return BandwidthDetector.selectBestQuality(
|
||||
estimatedBandwidthBps,
|
||||
availableProfiles,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Riverpod providers
|
||||
|
||||
final streamingOptimizerProvider =
|
||||
StateNotifierProvider<StreamingOptimizerNotifier, StreamingMetrics>((ref) {
|
||||
final qualitySelector = ref.watch(qualitySelectorProvider);
|
||||
return StreamingOptimizerNotifier(qualitySelector);
|
||||
});
|
||||
|
||||
final qualitySelectorProvider = Provider<QualitySelector>((ref) {
|
||||
return QualitySelector(initialQuality: QualityProfiles.hd720p);
|
||||
});
|
||||
|
||||
class StreamingOptimizerNotifier extends StateNotifier<StreamingMetrics> {
|
||||
final QualitySelector _qualitySelector;
|
||||
late StreamingOptimizer _optimizer;
|
||||
|
||||
StreamingOptimizerNotifier(this._qualitySelector)
|
||||
: super(
|
||||
StreamingMetrics(
|
||||
averageNetworkBitrate: 0,
|
||||
currentNetworkBitrate: 0,
|
||||
bufferDurationMs: 0,
|
||||
segmentDownloadTimeMs: 0,
|
||||
rebufferCount: 0,
|
||||
startTime: DateTime.now(),
|
||||
),
|
||||
) {
|
||||
_optimizer = StreamingOptimizer(qualitySelector: _qualitySelector);
|
||||
|
||||
// Listen to metrics updates
|
||||
_optimizer.metricsStream.listen((metrics) {
|
||||
state = metrics;
|
||||
});
|
||||
}
|
||||
|
||||
void recordSegmentDownload(int bytes, Duration duration) {
|
||||
_optimizer.recordSegmentDownload(bytes, duration);
|
||||
}
|
||||
|
||||
void rebufferDetected(Duration duration) {
|
||||
_optimizer.rebufferDetected(duration);
|
||||
}
|
||||
|
||||
List<StreamingMetrics> getHistory() => _optimizer.getMetricsHistory();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_optimizer.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ class ThemedLoading extends StatelessWidget {
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Color(0xFF0F1014), // Deep Space Dark
|
||||
Color(0xFF121317), // Stitch background
|
||||
AppColors.baseLevel0,
|
||||
AppColors.background,
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -24,7 +24,7 @@ class ThemedLoading extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const CircularProgressIndicator(
|
||||
color: Color(0xFF4b8eff), // AppColors.primaryContainer
|
||||
color: AppColors.primaryContainer,
|
||||
strokeWidth: 3,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
/// Apple TV Modern Channel Grid
|
||||
///
|
||||
/// Responsive grid layout for channels with:
|
||||
/// - Flexible column count based on screen size
|
||||
/// - Smooth animations
|
||||
/// - Focus-aware spacing
|
||||
class TvChannelGrid extends StatelessWidget {
|
||||
final List<Widget> children;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final double horizontalSpacing;
|
||||
final double verticalSpacing;
|
||||
final ScrollController? scrollController;
|
||||
final ScrollPhysics physics;
|
||||
|
||||
const TvChannelGrid({
|
||||
super.key,
|
||||
required this.children,
|
||||
this.padding = const EdgeInsets.fromLTRB(32, 24, 32, 32),
|
||||
this.horizontalSpacing = 20,
|
||||
this.verticalSpacing = 20,
|
||||
this.scrollController,
|
||||
this.physics = const AlwaysScrollableScrollPhysics(),
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
// Guard: during first Flutter Web layout pass, size may be 0 or NaN.
|
||||
// LayoutBuilder will re-trigger build once the real size is known.
|
||||
if (screenWidth <= 0 || screenWidth.isNaN || screenWidth.isInfinite) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
// Responsive column count
|
||||
final int columnCount;
|
||||
if (screenWidth > 1920) {
|
||||
columnCount = 6;
|
||||
} else if (screenWidth > 1600) {
|
||||
columnCount = 5;
|
||||
} else if (screenWidth > 1280) {
|
||||
columnCount = 4;
|
||||
} else if (screenWidth > 960) {
|
||||
columnCount = 3;
|
||||
} else {
|
||||
columnCount = 2;
|
||||
}
|
||||
|
||||
// Calculate horizontal padding safely using resolved EdgeInsets.
|
||||
final resolvedPadding = padding.resolve(TextDirection.ltr);
|
||||
final horizontalPadding = resolvedPadding.left + resolvedPadding.right;
|
||||
|
||||
// Compute item width, clamped to avoid negative/NaN values.
|
||||
final totalSpacing = horizontalSpacing * (columnCount - 1);
|
||||
final availableWidth = screenWidth - horizontalPadding - totalSpacing;
|
||||
final itemWidth =
|
||||
(availableWidth / columnCount).clamp(1.0, double.infinity);
|
||||
|
||||
return SingleChildScrollView(
|
||||
controller: scrollController,
|
||||
physics: physics,
|
||||
padding: padding,
|
||||
child: Wrap(
|
||||
spacing: horizontalSpacing,
|
||||
runSpacing: verticalSpacing,
|
||||
children: [
|
||||
for (int i = 0; i < children.length; i++)
|
||||
SizedBox(
|
||||
width: itemWidth,
|
||||
child: children[i],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Apple TV Modern Horizontal Scrollable List
|
||||
class TvHorizontalList extends StatelessWidget {
|
||||
final List<Widget> children;
|
||||
final String? title;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final double itemWidth;
|
||||
final double spacing;
|
||||
final ScrollController? scrollController;
|
||||
|
||||
const TvHorizontalList({
|
||||
super.key,
|
||||
required this.children,
|
||||
this.title,
|
||||
this.padding = const EdgeInsets.symmetric(vertical: 16),
|
||||
this.itemWidth = 200,
|
||||
this.spacing = 16,
|
||||
this.scrollController,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Title
|
||||
if (title != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppTheme.spacing32,
|
||||
vertical: AppTheme.spacing16,
|
||||
),
|
||||
child: Text(
|
||||
title!,
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Horizontal list
|
||||
SizedBox(
|
||||
height: 280,
|
||||
child: ListView.separated(
|
||||
controller: scrollController,
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 32,
|
||||
// Resolve EdgeInsetsGeometry to a concrete EdgeInsets before
|
||||
// accessing vertical — casting EdgeInsetsGeometry to double throws.
|
||||
vertical: padding.resolve(TextDirection.ltr).top,
|
||||
),
|
||||
itemCount: children.length,
|
||||
separatorBuilder: (_, __) => SizedBox(width: spacing),
|
||||
itemBuilder: (context, index) => SizedBox(
|
||||
width: itemWidth,
|
||||
child: children[index],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,9 @@ class TvFocusableCard extends StatefulWidget {
|
||||
final bool autofocus;
|
||||
final double borderRadius;
|
||||
|
||||
/// Accessibility label announced by screen readers (e.g. channel title).
|
||||
final String? semanticLabel;
|
||||
|
||||
const TvFocusableCard({
|
||||
super.key,
|
||||
required this.child,
|
||||
@@ -24,6 +27,7 @@ class TvFocusableCard extends StatefulWidget {
|
||||
this.focusColor,
|
||||
this.autofocus = false,
|
||||
this.borderRadius = 12.0,
|
||||
this.semanticLabel,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -84,7 +88,10 @@ class _TvFocusableCardState extends State<TvFocusableCard>
|
||||
final isActive = _isFocused || _isHovered;
|
||||
final focusColor = widget.focusColor ?? AppColors.primaryContainer;
|
||||
|
||||
return MouseRegion(
|
||||
return Semantics(
|
||||
button: widget.onTap != null,
|
||||
label: widget.semanticLabel,
|
||||
child: MouseRegion(
|
||||
onEnter: (_) => _handleHover(true),
|
||||
onExit: (_) => _handleHover(false),
|
||||
cursor: SystemMouseCursors.click,
|
||||
@@ -148,6 +155,7 @@ class _TvFocusableCardState extends State<TvFocusableCard>
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,340 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import 'glass_container.dart';
|
||||
|
||||
/// Apple TV Modern Content Card
|
||||
///
|
||||
/// Premium card for displaying movies, shows, or other content with:
|
||||
/// - Poster image with skeleton loading
|
||||
/// - Title and metadata
|
||||
/// - Rating/score display
|
||||
/// - Interactive hover states
|
||||
/// - Context menu support
|
||||
class TvModernCard extends StatefulWidget {
|
||||
final String id;
|
||||
final String title;
|
||||
final String? imageUrl;
|
||||
final String? rating;
|
||||
final String? year;
|
||||
final String? badge;
|
||||
final Color? badgeColor;
|
||||
final VoidCallback? onTap;
|
||||
final VoidCallback? onPlayTap;
|
||||
final VoidCallback? onMoreTap;
|
||||
final bool isWatching;
|
||||
final double? progress;
|
||||
|
||||
const TvModernCard({
|
||||
super.key,
|
||||
required this.id,
|
||||
required this.title,
|
||||
this.imageUrl,
|
||||
this.rating,
|
||||
this.year,
|
||||
this.badge,
|
||||
this.badgeColor,
|
||||
this.onTap,
|
||||
this.onPlayTap,
|
||||
this.onMoreTap,
|
||||
this.isWatching = false,
|
||||
this.progress,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TvModernCard> createState() => _TvModernCardState();
|
||||
}
|
||||
|
||||
class _TvModernCardState extends State<TvModernCard>
|
||||
with SingleTickerProviderStateMixin {
|
||||
bool _isHovered = false;
|
||||
late AnimationController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: AppTheme.durationMd,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MouseRegion(
|
||||
onEnter: (_) {
|
||||
setState(() => _isHovered = true);
|
||||
_controller.forward();
|
||||
},
|
||||
onExit: (_) {
|
||||
setState(() => _isHovered = false);
|
||||
_controller.reverse();
|
||||
},
|
||||
child: GestureDetector(
|
||||
onTap: widget.onTap,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// ============ POSTER IMAGE ============
|
||||
AnimatedScale(
|
||||
scale: _isHovered ? 1.06 : 1.0,
|
||||
duration: AppTheme.durationMd,
|
||||
curve: AppTheme.curveDefault,
|
||||
child: GlassCard(
|
||||
borderRadius: AppTheme.radiusLg,
|
||||
padding: EdgeInsets.zero,
|
||||
interactive: true,
|
||||
onTap: widget.onTap,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Poster image
|
||||
_buildPosterImage(),
|
||||
|
||||
// Overlay
|
||||
if (_isHovered)
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.transparent,
|
||||
Colors.black.withOpacity(0.7),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Badge
|
||||
if (widget.badge != null)
|
||||
Positioned(
|
||||
top: 12,
|
||||
right: 12,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: widget.badgeColor ?? AppColors.primary,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
widget.badge!,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.black,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Progress indicator (if watching)
|
||||
if (widget.isWatching && widget.progress != null)
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
height: 3,
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.vertical(
|
||||
bottom: Radius.circular(AppTheme.radiusLg),
|
||||
),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
bottom: Radius.circular(AppTheme.radiusLg),
|
||||
),
|
||||
child: LinearProgressIndicator(
|
||||
value: widget.progress,
|
||||
backgroundColor: AppColors.surfaceVariant,
|
||||
valueColor: const AlwaysStoppedAnimation(
|
||||
AppColors.primary,
|
||||
),
|
||||
minHeight: 3,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Action buttons (on hover)
|
||||
if (_isHovered &&
|
||||
(widget.onPlayTap != null || widget.onMoreTap != null))
|
||||
Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (widget.onPlayTap != null)
|
||||
_buildActionButton(
|
||||
icon: Icons.play_arrow,
|
||||
label: 'Play',
|
||||
onTap: widget.onPlayTap!,
|
||||
),
|
||||
if (widget.onPlayTap != null &&
|
||||
widget.onMoreTap != null)
|
||||
const SizedBox(width: 16),
|
||||
if (widget.onMoreTap != null)
|
||||
_buildActionButton(
|
||||
icon: Icons.info_outline,
|
||||
label: 'Info',
|
||||
onTap: widget.onMoreTap!,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// ============ METADATA ============
|
||||
// Title
|
||||
Text(
|
||||
widget.title,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
|
||||
// Rating & Year
|
||||
if (widget.rating != null || widget.year != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
if (widget.rating != null) ...[
|
||||
const Icon(
|
||||
Icons.star,
|
||||
size: 14,
|
||||
color: AppColors.ratingGold,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
widget.rating!,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (widget.rating != null && widget.year != null)
|
||||
const SizedBox(width: 12),
|
||||
if (widget.year != null)
|
||||
Text(
|
||||
widget.year!,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPosterImage() {
|
||||
if (widget.imageUrl == null || widget.imageUrl!.isEmpty) {
|
||||
return Container(
|
||||
color: AppColors.surface,
|
||||
child: const Center(
|
||||
child: Icon(
|
||||
Icons.image_outlined,
|
||||
color: AppColors.textSecondary,
|
||||
size: 48,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return CachedNetworkImage(
|
||||
imageUrl: widget.imageUrl!,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
color: AppColors.shimmer,
|
||||
child: const Center(
|
||||
child: SizedBox(
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
errorWidget: (context, url, error) => Container(
|
||||
color: AppColors.surface,
|
||||
child: const Center(
|
||||
child: Icon(
|
||||
Icons.broken_image_outlined,
|
||||
color: AppColors.textSecondary,
|
||||
size: 48,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActionButton({
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.4),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, color: Colors.black, size: 18),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
label,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,397 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import 'glass_container.dart';
|
||||
|
||||
/// Apple TV Modern Top Navigation Bar
|
||||
///
|
||||
/// Premium navigation header with:
|
||||
/// - Logo/branding
|
||||
/// - Search integration
|
||||
/// - User menu
|
||||
/// - Glassmorphism effect
|
||||
class TvTopNavBar extends StatefulWidget {
|
||||
final String title;
|
||||
final VoidCallback? onSearch;
|
||||
final VoidCallback? onProfile;
|
||||
final VoidCallback? onNotifications;
|
||||
final int notificationCount;
|
||||
final Widget? leading;
|
||||
final List<Widget>? actions;
|
||||
|
||||
const TvTopNavBar({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.onSearch,
|
||||
this.onProfile,
|
||||
this.onNotifications,
|
||||
this.notificationCount = 0,
|
||||
this.leading,
|
||||
this.actions,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TvTopNavBar> createState() => _TvTopNavBarState();
|
||||
}
|
||||
|
||||
class _TvTopNavBarState extends State<TvTopNavBar> {
|
||||
bool _isHovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _isHovered = true),
|
||||
onExit: (_) => setState(() => _isHovered = false),
|
||||
child: GlassContainer(
|
||||
borderRadius: 0,
|
||||
hasBorder: false,
|
||||
showShadow: false,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppTheme.spacing32,
|
||||
vertical: AppTheme.spacing16,
|
||||
),
|
||||
margin: EdgeInsets.zero,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Left: Logo + Title
|
||||
Row(
|
||||
children: [
|
||||
if (widget.leading != null) widget.leading!,
|
||||
const SizedBox(width: AppTheme.spacing16),
|
||||
Text(
|
||||
widget.title,
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.textPrimary,
|
||||
letterSpacing: -0.3,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// Right: Actions
|
||||
Row(
|
||||
children: [
|
||||
if (widget.onSearch != null) ...[
|
||||
_buildIconButton(
|
||||
icon: Icons.search,
|
||||
onTap: widget.onSearch!,
|
||||
tooltip: 'Search',
|
||||
),
|
||||
const SizedBox(width: AppTheme.spacing16),
|
||||
],
|
||||
|
||||
if (widget.onNotifications != null) ...[
|
||||
_buildIconButton(
|
||||
icon: Icons.notifications_none,
|
||||
onTap: widget.onNotifications!,
|
||||
tooltip: 'Notifications',
|
||||
badge: widget.notificationCount > 0
|
||||
? widget.notificationCount.toString()
|
||||
: null,
|
||||
),
|
||||
const SizedBox(width: AppTheme.spacing16),
|
||||
],
|
||||
|
||||
if (widget.onProfile != null)
|
||||
_buildIconButton(
|
||||
icon: Icons.account_circle,
|
||||
onTap: widget.onProfile!,
|
||||
tooltip: 'Profile',
|
||||
),
|
||||
|
||||
if (widget.actions != null) ...[
|
||||
const SizedBox(width: AppTheme.spacing16),
|
||||
...widget.actions!,
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIconButton({
|
||||
required IconData icon,
|
||||
required VoidCallback onTap,
|
||||
required String tooltip,
|
||||
String? badge,
|
||||
}) {
|
||||
return Tooltip(
|
||||
message: tooltip,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: _isHovered ? AppColors.surface : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: AppColors.textPrimary,
|
||||
size: 24,
|
||||
),
|
||||
if (badge != null)
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.error,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Text(
|
||||
badge,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Apple TV Modern Side Navigation
|
||||
///
|
||||
/// Vertical navigation menu with:
|
||||
/// - Window navigation items
|
||||
/// - Collapsible menu
|
||||
/// - Smooth animations
|
||||
/// - Category grouping
|
||||
class TvSideNav extends StatefulWidget {
|
||||
final List<TvNavItem> items;
|
||||
final int selectedIndex;
|
||||
final ValueChanged<int> onItemSelected;
|
||||
final bool expanded;
|
||||
final VoidCallback? onToggleExpanded;
|
||||
|
||||
const TvSideNav({
|
||||
super.key,
|
||||
required this.items,
|
||||
this.selectedIndex = 0,
|
||||
required this.onItemSelected,
|
||||
this.expanded = true,
|
||||
this.onToggleExpanded,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TvSideNav> createState() => _TvSideNavState();
|
||||
}
|
||||
|
||||
class _TvSideNavState extends State<TvSideNav> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GlassContainer(
|
||||
borderRadius: 0,
|
||||
hasBorder: false,
|
||||
showShadow: false,
|
||||
padding: const EdgeInsets.symmetric(vertical: AppTheme.spacing16),
|
||||
margin: EdgeInsets.zero,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: List.generate(
|
||||
widget.items.length,
|
||||
(index) => _buildNavItem(
|
||||
item: widget.items[index],
|
||||
isSelected: index == widget.selectedIndex,
|
||||
onTap: () => widget.onItemSelected(index),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNavItem({
|
||||
required TvNavItem item,
|
||||
required bool isSelected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppTheme.spacing16,
|
||||
vertical: AppTheme.spacing8,
|
||||
),
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppTheme.spacing16,
|
||||
vertical: AppTheme.spacing12,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? AppColors.primary : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
|
||||
border: !isSelected
|
||||
? Border.all(color: AppColors.border)
|
||||
: null,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
item.icon,
|
||||
color: isSelected ? Colors.black : AppColors.textSecondary,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: AppTheme.spacing12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.label,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isSelected ? Colors.black : AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Navigation item model
|
||||
class TvNavItem {
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final String? badge;
|
||||
|
||||
TvNavItem({
|
||||
required this.label,
|
||||
required this.icon,
|
||||
this.badge,
|
||||
});
|
||||
}
|
||||
|
||||
/// Apple TV Modern Floating Action Menu
|
||||
///
|
||||
/// Context-aware floating menu with:
|
||||
/// - Multiple action buttons
|
||||
/// - Smooth reveal animation
|
||||
/// - Accessible positioning
|
||||
class TvFloatingMenu extends StatefulWidget {
|
||||
final List<TvMenuAction> actions;
|
||||
final VoidCallback? onClose;
|
||||
|
||||
const TvFloatingMenu({
|
||||
super.key,
|
||||
required this.actions,
|
||||
this.onClose,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TvFloatingMenu> createState() => _TvFloatingMenuState();
|
||||
}
|
||||
|
||||
class _TvFloatingMenuState extends State<TvFloatingMenu>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: AppTheme.durationMd,
|
||||
)..forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ScaleTransition(
|
||||
scale: _controller,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppTheme.spacing12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusLg),
|
||||
border: Border.all(color: AppColors.border),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
blurRadius: 24,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: List.generate(
|
||||
widget.actions.length,
|
||||
(index) => GestureDetector(
|
||||
onTap: () {
|
||||
widget.actions[index].onTap?.call();
|
||||
widget.onClose?.call();
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppTheme.spacing16,
|
||||
vertical: AppTheme.spacing12,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
widget.actions[index].icon,
|
||||
color: widget.actions[index].color ?? AppColors.textPrimary,
|
||||
),
|
||||
const SizedBox(width: AppTheme.spacing12),
|
||||
Text(
|
||||
widget.actions[index].label,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Menu action model
|
||||
class TvMenuAction {
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final Color? color;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
TvMenuAction({
|
||||
required this.label,
|
||||
required this.icon,
|
||||
this.color,
|
||||
this.onTap,
|
||||
});
|
||||
}
|
||||
@@ -58,9 +58,9 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xFF050505),
|
||||
AppColors.surfaceContainerLowest,
|
||||
AppColors.background,
|
||||
Color(0xFF0A0A0A),
|
||||
AppColors.baseLevel0,
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -30,9 +30,6 @@ class LiveChannel {
|
||||
);
|
||||
}
|
||||
|
||||
String getStreamUrl(String dns, String username, String password) {
|
||||
return '$dns/live/$username/$password/$streamId.ts';
|
||||
}
|
||||
}
|
||||
|
||||
class Movie {
|
||||
@@ -75,9 +72,6 @@ class Movie {
|
||||
);
|
||||
}
|
||||
|
||||
String getStreamUrl(String dns, String username, String password) {
|
||||
return '$dns/movie/$username/$password/$streamId.$containerExtension';
|
||||
}
|
||||
}
|
||||
|
||||
class Series {
|
||||
@@ -165,9 +159,6 @@ class Episode {
|
||||
);
|
||||
}
|
||||
|
||||
String getStreamUrl(String dns, String username, String password) {
|
||||
return '$dns/series/$username/$password/$id.${containerExtension ?? 'mkv'}';
|
||||
}
|
||||
}
|
||||
|
||||
/// Series info with seasons and episodes
|
||||
|
||||
@@ -1,253 +0,0 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/models/playlist_config.dart';
|
||||
import '../models/playlist.dart';
|
||||
|
||||
/// Represents a content recommendation
|
||||
class Recommendation {
|
||||
final Playlist item;
|
||||
final RecommendationType type;
|
||||
final double score;
|
||||
final String reason;
|
||||
|
||||
Recommendation({
|
||||
required this.item,
|
||||
required this.type,
|
||||
this.score = 0.0,
|
||||
required this.reason,
|
||||
});
|
||||
}
|
||||
|
||||
enum RecommendationType {
|
||||
continueWatching,
|
||||
trending,
|
||||
recentlyAdded,
|
||||
similarContent,
|
||||
topRated,
|
||||
forYou,
|
||||
}
|
||||
|
||||
class RecommendationService {
|
||||
/// Get continue watching items based on watch history
|
||||
static List<Recommendation> getContinueWatching(
|
||||
Map<String, dynamic> watchHistory,
|
||||
List<Playlist> allContent,
|
||||
) {
|
||||
final recommendations = <Recommendation>[];
|
||||
|
||||
for (final item in allContent) {
|
||||
final historyKey = item.streamId.toString();
|
||||
if (watchHistory.containsKey(historyKey)) {
|
||||
final lastPosition = watchHistory[historyKey] as double? ?? 0.0;
|
||||
|
||||
// Only show if watched more than 5 seconds ago and less than 95% complete
|
||||
if (lastPosition > 5 && lastPosition < 95) {
|
||||
recommendations.add(
|
||||
Recommendation(
|
||||
item: item,
|
||||
type: RecommendationType.continueWatching,
|
||||
score: 100.0 - lastPosition, // Score higher if recently started
|
||||
reason:
|
||||
'Continue watching from ${lastPosition.toStringAsFixed(0)}%',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by last watched (highest incomplete progress first)
|
||||
recommendations.sort((a, b) => b.score.compareTo(a.score));
|
||||
return recommendations.take(10).toList();
|
||||
}
|
||||
|
||||
/// Get trending content based on view counts
|
||||
static List<Recommendation> getTrending(
|
||||
Map<String, int> viewCounts,
|
||||
List<Playlist> allContent,
|
||||
) {
|
||||
final recommendations = <Recommendation>[];
|
||||
|
||||
for (final item in allContent) {
|
||||
final views = viewCounts[item.streamId.toString()] ?? 0;
|
||||
if (views > 0) {
|
||||
recommendations.add(
|
||||
Recommendation(
|
||||
item: item,
|
||||
type: RecommendationType.trending,
|
||||
score: views.toDouble(),
|
||||
reason: '$views views - Trending now',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
recommendations.sort((a, b) => b.score.compareTo(a.score));
|
||||
return recommendations.take(10).toList();
|
||||
}
|
||||
|
||||
/// Get recently added content
|
||||
static List<Recommendation> getRecentlyAdded(List<Playlist> allContent) {
|
||||
final recommendations = <Recommendation>[];
|
||||
|
||||
// Sort by added date (most recent first)
|
||||
final sorted = [...allContent];
|
||||
sorted.sort((a, b) {
|
||||
final aDate = DateTime.tryParse(a.added ?? '') ?? DateTime(2000);
|
||||
final bDate = DateTime.tryParse(b.added ?? '') ?? DateTime(2000);
|
||||
return bDate.compareTo(aDate);
|
||||
});
|
||||
|
||||
for (final item in sorted.take(20)) {
|
||||
final daysAgo = DateTime.now()
|
||||
.difference(DateTime.tryParse(item.added ?? '') ?? DateTime(2000))
|
||||
.inDays;
|
||||
|
||||
recommendations.add(
|
||||
Recommendation(
|
||||
item: item,
|
||||
type: RecommendationType.recentlyAdded,
|
||||
score: (20 - daysAgo).toDouble().clamp(0, 100),
|
||||
reason: 'Added $daysAgo days ago',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return recommendations.take(10).toList();
|
||||
}
|
||||
|
||||
/// Get personalized recommendations based on watch history
|
||||
static List<Recommendation> getForYou(
|
||||
Map<String, dynamic> watchHistory,
|
||||
List<Playlist> allContent,
|
||||
) {
|
||||
final recommendations = <Recommendation>[];
|
||||
|
||||
// Collect watched categories
|
||||
final watchedCategories = <String>{};
|
||||
watchHistory.forEach((key, value) {
|
||||
if (value is Map && value.containsKey('category')) {
|
||||
watchedCategories.add(value['category'] as String);
|
||||
}
|
||||
});
|
||||
|
||||
// Recommend similar content
|
||||
for (final item in allContent) {
|
||||
if (watchedCategories.contains(item.categoryId)) {
|
||||
recommendations.add(
|
||||
Recommendation(
|
||||
item: item,
|
||||
type: RecommendationType.forYou,
|
||||
score: 75.0,
|
||||
reason: 'Based on your interests',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Add highly rated content
|
||||
var ratedContent = [...allContent];
|
||||
ratedContent.sort((a, b) {
|
||||
final aRating = double.tryParse(a.rating ?? '0') ?? 0.0;
|
||||
final bRating = double.tryParse(b.rating ?? '0') ?? 0.0;
|
||||
return bRating.compareTo(aRating);
|
||||
});
|
||||
|
||||
for (final item in ratedContent.where((i) {
|
||||
final rating = double.tryParse(i.rating ?? '0') ?? 0.0;
|
||||
return rating >= 7.5;
|
||||
}).take(5)) {
|
||||
recommendations.add(
|
||||
Recommendation(
|
||||
item: item,
|
||||
type: RecommendationType.topRated,
|
||||
score: double.tryParse(item.rating ?? '0') ?? 0.0,
|
||||
reason: 'Highly rated - ${item.rating}/10',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Remove duplicates and limit
|
||||
final seen = <int>{};
|
||||
final unique = <Recommendation>[];
|
||||
for (final rec in recommendations) {
|
||||
if (!seen.contains(rec.item.streamId)) {
|
||||
unique.add(rec);
|
||||
seen.add(rec.item.streamId);
|
||||
}
|
||||
}
|
||||
|
||||
return unique.take(15).toList();
|
||||
}
|
||||
}
|
||||
|
||||
/// Provider for watch history
|
||||
final watchHistoryProvider =
|
||||
StateNotifierProvider<WatchHistoryNotifier, Map<String, dynamic>>((ref) {
|
||||
return WatchHistoryNotifier();
|
||||
});
|
||||
|
||||
class WatchHistoryNotifier extends StateNotifier<Map<String, dynamic>> {
|
||||
WatchHistoryNotifier() : super({});
|
||||
|
||||
void updateWatchTime(int streamId, double percentage) {
|
||||
state = {
|
||||
...state,
|
||||
streamId.toString(): {
|
||||
'percentage': percentage,
|
||||
'timestamp': DateTime.now().toIso8601String(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
void clearHistory() {
|
||||
state = {};
|
||||
}
|
||||
}
|
||||
|
||||
/// Provider for view counts/trending
|
||||
final trendingProvider =
|
||||
StateNotifierProvider<TrendingNotifier, Map<String, int>>((ref) {
|
||||
return TrendingNotifier();
|
||||
});
|
||||
|
||||
class TrendingNotifier extends StateNotifier<Map<String, int>> {
|
||||
TrendingNotifier() : super({});
|
||||
|
||||
void incrementViewCount(int streamId) {
|
||||
final key = streamId.toString();
|
||||
state = {
|
||||
...state,
|
||||
key: (state[key] ?? 0) + 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Provider for recommendations
|
||||
final recommendationsProvider = FutureProvider.family<List<Recommendation>,
|
||||
(Playlist, Map<String, dynamic>, Map<String, int>, List<Playlist>)>(
|
||||
(ref, params) async {
|
||||
final (playlist, watchHistory, trending, allContent) = params;
|
||||
|
||||
// Combine all recommendation types
|
||||
final allRecommendations = <Recommendation>[
|
||||
...RecommendationService.getContinueWatching(watchHistory, allContent),
|
||||
...RecommendationService.getTrending(trending, allContent),
|
||||
...RecommendationService.getRecentlyAdded(allContent),
|
||||
...RecommendationService.getForYou(watchHistory, allContent),
|
||||
];
|
||||
|
||||
// Deduplicate and score
|
||||
final seen = <int>{};
|
||||
final scored = <Recommendation>[];
|
||||
|
||||
for (final rec in allRecommendations) {
|
||||
if (!seen.contains(rec.item.streamId)) {
|
||||
scored.add(rec);
|
||||
seen.add(rec.item.streamId);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by score
|
||||
scored.sort((a, b) => b.score.compareTo(a.score));
|
||||
return scored;
|
||||
},
|
||||
);
|
||||
@@ -54,9 +54,9 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xFF050505), // Very dark top
|
||||
AppColors.surfaceContainerLowest, // Very dark top
|
||||
AppColors.background, // Black bottom
|
||||
Color(0xFF0A0A0A), // Slightly darker for depth
|
||||
AppColors.baseLevel0, // Slightly darker for depth
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'dart:html' as html;
|
||||
import 'dart:ui_web' as ui_web;
|
||||
@@ -7,6 +8,7 @@ import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||
import '../providers/xtream_provider.dart';
|
||||
import '../providers/playback_positions_provider.dart';
|
||||
import '../widgets/quality_selector_widget.dart';
|
||||
|
||||
// ... (existing imports)
|
||||
// ... (existing imports)
|
||||
@@ -63,6 +65,12 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
bool _isMuted = false;
|
||||
bool _ignoreStatusUpdates = false;
|
||||
|
||||
/// Server-side transcoding quality. Live TV defaults to `source`
|
||||
/// (direct MPEG-TS proxy, zero transcoding); VOD defaults to `high`.
|
||||
late StreamQuality _quality = widget.streamType == StreamType.live
|
||||
? StreamQuality.source
|
||||
: StreamQuality.high;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -109,8 +117,10 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
// Stable view ID for the instance to prevent iframe reload on rebuild (orientation change)
|
||||
_viewId = 'iptv-player-$currentStreamId-$_viewIdPrefix';
|
||||
// Stable view ID for the instance to prevent iframe reload on rebuild
|
||||
// (orientation change). Includes quality so a quality switch forces a
|
||||
// fresh iframe.
|
||||
_viewId = 'iptv-player-$currentStreamId-${_quality.value}-$_viewIdPrefix';
|
||||
|
||||
final service = ref.read(xtreamServiceProvider(widget.playlist));
|
||||
String streamUrl = '';
|
||||
@@ -118,14 +128,21 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
// Generate Stream URL based on type
|
||||
// NOTE: Logic is now handled by the backend routes /api/live/ and /api/vod/
|
||||
if (widget.streamType == StreamType.live) {
|
||||
streamUrl = service.getLiveStreamUrl(currentStreamId);
|
||||
streamUrl = service.getLiveStreamUrl(
|
||||
currentStreamId,
|
||||
quality: _quality.value,
|
||||
);
|
||||
} else if (widget.streamType == StreamType.vod) {
|
||||
streamUrl =
|
||||
service.getVodStreamUrl(currentStreamId, widget.containerExtension);
|
||||
streamUrl = service.getVodStreamUrl(
|
||||
currentStreamId,
|
||||
widget.containerExtension,
|
||||
quality: _quality.value,
|
||||
);
|
||||
} else if (widget.streamType == StreamType.series) {
|
||||
streamUrl = service.getSeriesStreamUrl(
|
||||
currentStreamId,
|
||||
widget.containerExtension,
|
||||
quality: _quality.value,
|
||||
);
|
||||
} else if (widget.streamType == StreamType.recording) {
|
||||
streamUrl = '${service.backendBaseUrl}/api/recordings/stream/$currentStreamId/playlist.m3u8';
|
||||
@@ -135,8 +152,9 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
final isMobile = MediaQuery.of(context).size.width < 600;
|
||||
final isLiveTV = widget.streamType == StreamType.live;
|
||||
|
||||
// TURBO-START: Use direct MPEG-TS for Live TV on Desktop/Android for instant zapping
|
||||
if (isLiveTV && !isMobile) {
|
||||
// TURBO-START: in `source` quality, Live TV on desktop uses the direct
|
||||
// MPEG-TS proxy (mpegts.js) for instant zapping with zero transcoding.
|
||||
if (isLiveTV && !isMobile && _quality == StreamQuality.source) {
|
||||
streamUrl = service.getLiveStreamUrlTs(currentStreamId);
|
||||
}
|
||||
|
||||
@@ -215,6 +233,8 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
|
||||
void _setupMessageListener() {
|
||||
_messageSubscription = html.window.onMessage.listen((event) {
|
||||
// The player iframes are same-origin; drop messages from anywhere else.
|
||||
if (event.origin != html.window.location.origin) return;
|
||||
final data = event.data;
|
||||
if (data == null) return;
|
||||
|
||||
@@ -271,8 +291,8 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
}
|
||||
|
||||
if (iframe != null) {
|
||||
print('[PlayerScreen] Sending message to iframe: $message');
|
||||
iframe.contentWindow?.postMessage(message, '*');
|
||||
iframe.contentWindow
|
||||
?.postMessage(message, html.window.location.origin);
|
||||
} else {
|
||||
print(
|
||||
'[PlayerScreen] Error: Could not find iframe to send message: $message',
|
||||
@@ -331,6 +351,16 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
_sendMessage({'type': 'set_volume', 'value': _isMuted ? 0.0 : 1.0});
|
||||
}
|
||||
|
||||
void _changeQuality(StreamQuality quality) {
|
||||
if (quality == _quality) return;
|
||||
setState(() => _quality = quality);
|
||||
// Rebuild the iframe with the new quality; VOD resumes at the
|
||||
// current position, live restarts at the live edge.
|
||||
final resumeAt =
|
||||
widget.streamType == StreamType.live ? null : _currentPosition;
|
||||
_initializePlayer(startTimeOverride: resumeAt, isChannelSwitch: true);
|
||||
}
|
||||
|
||||
void _previousChannel() {
|
||||
if (widget.channels != null && widget.channels!.isNotEmpty) {
|
||||
setState(() {
|
||||
@@ -357,6 +387,68 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Keyboard / TV remote controls:
|
||||
/// space-enter = play/pause, ←/→ = seek ±10s (VOD) or zap (live),
|
||||
/// ↑/↓ = zap (live), M = mute, Esc = exit player.
|
||||
KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) {
|
||||
if (event is! KeyDownEvent) return KeyEventResult.ignored;
|
||||
final isLive = widget.streamType == StreamType.live;
|
||||
final key = event.logicalKey;
|
||||
|
||||
if (key == LogicalKeyboardKey.space ||
|
||||
key == LogicalKeyboardKey.enter ||
|
||||
key == LogicalKeyboardKey.select ||
|
||||
key == LogicalKeyboardKey.mediaPlayPause) {
|
||||
_togglePlayPause();
|
||||
_onHover();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (key == LogicalKeyboardKey.escape) {
|
||||
Navigator.pop(context);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (key == LogicalKeyboardKey.keyM) {
|
||||
_toggleMute();
|
||||
_onHover();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (key == LogicalKeyboardKey.arrowLeft) {
|
||||
if (isLive) {
|
||||
_previousChannel();
|
||||
} else {
|
||||
_sendMessage({
|
||||
'type': 'seek',
|
||||
'value': (_currentPosition - 10).clamp(0, _totalDuration),
|
||||
});
|
||||
}
|
||||
_onHover();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (key == LogicalKeyboardKey.arrowRight) {
|
||||
if (isLive) {
|
||||
_nextChannel();
|
||||
} else {
|
||||
_sendMessage({
|
||||
'type': 'seek',
|
||||
'value': (_currentPosition + 10).clamp(0, _totalDuration),
|
||||
});
|
||||
}
|
||||
_onHover();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (isLive && key == LogicalKeyboardKey.arrowUp) {
|
||||
_nextChannel();
|
||||
_onHover();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (isLive && key == LogicalKeyboardKey.arrowDown) {
|
||||
_previousChannel();
|
||||
_onHover();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
|
||||
String _formatDuration(Duration d) {
|
||||
String twoDigits(int n) => n.toString().padLeft(2, '0');
|
||||
final hours = twoDigits(d.inHours);
|
||||
@@ -371,7 +463,10 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
|
||||
// LITE PLAYER MODE for Live TV - Simplified UI (no BackdropFilter)
|
||||
if (isLiveTV) {
|
||||
return Scaffold(
|
||||
return Focus(
|
||||
autofocus: true,
|
||||
onKeyEvent: _onKeyEvent,
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
@@ -425,6 +520,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
_buildSimpleIconButton(
|
||||
icon: Icons.arrow_back_rounded,
|
||||
onTap: () => Navigator.pop(context),
|
||||
tooltip: 'Retour',
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
@@ -554,11 +650,15 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// STANDARD PLAYER MODE (VOD/Series)
|
||||
return Scaffold(
|
||||
return Focus(
|
||||
autofocus: true,
|
||||
onKeyEvent: _onKeyEvent,
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
@@ -607,6 +707,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
_buildGlassIconButton(
|
||||
icon: Icons.arrow_back_rounded,
|
||||
onTap: () => Navigator.pop(context),
|
||||
tooltip: 'Retour',
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
@@ -725,6 +826,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
.clamp(0, _totalDuration),
|
||||
}),
|
||||
transparent: true,
|
||||
tooltip: 'Reculer de 10 s',
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
_buildGlassIconButton(
|
||||
@@ -734,6 +836,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
onTap: _togglePlayPause,
|
||||
size: 56,
|
||||
iconSize: 32,
|
||||
tooltip: _isPlaying ? 'Pause' : 'Lecture',
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
_buildGlassIconButton(
|
||||
@@ -744,20 +847,30 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
.clamp(0, _totalDuration),
|
||||
}),
|
||||
transparent: true,
|
||||
tooltip: 'Avancer de 10 s',
|
||||
),
|
||||
const Spacer(),
|
||||
QualitySelectorButton(
|
||||
current: _quality,
|
||||
onSelected: _changeQuality,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
_buildGlassIconButton(
|
||||
icon: _isMuted
|
||||
? Icons.volume_off_rounded
|
||||
: Icons.volume_up_rounded,
|
||||
onTap: _toggleMute,
|
||||
transparent: true,
|
||||
tooltip: _isMuted
|
||||
? 'Activer le son'
|
||||
: 'Couper le son',
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
_buildGlassIconButton(
|
||||
icon: Icons.aspect_ratio_rounded,
|
||||
onTap: _toggleFullscreen,
|
||||
transparent: true,
|
||||
tooltip: 'Plein écran',
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -772,6 +885,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -781,16 +895,14 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
bool transparent = false,
|
||||
double size = 48,
|
||||
double iconSize = 24,
|
||||
String? tooltip,
|
||||
}) {
|
||||
// Button with direct Material/InkWell - PointerInterceptor is on outer container
|
||||
return Material(
|
||||
final button = Material(
|
||||
color: transparent ? Colors.transparent : Colors.white.withOpacity(0.1),
|
||||
shape: const CircleBorder(),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
print('[PlayerScreen] Button tapped: $icon');
|
||||
onTap();
|
||||
},
|
||||
onTap: onTap,
|
||||
customBorder: const CircleBorder(),
|
||||
child: Container(
|
||||
width: size,
|
||||
@@ -806,6 +918,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
),
|
||||
),
|
||||
);
|
||||
return tooltip != null ? Tooltip(message: tooltip, child: button) : button;
|
||||
}
|
||||
|
||||
List<Widget> _buildControlButtons(bool isSmallScreen) {
|
||||
@@ -820,6 +933,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
icon: Icons.skip_previous_rounded,
|
||||
onTap: _previousChannel,
|
||||
size: buttonSize,
|
||||
tooltip: 'Chaîne précédente',
|
||||
),
|
||||
|
||||
if (widget.channels != null && widget.channels!.length > 1)
|
||||
@@ -832,6 +946,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
size: playButtonSize,
|
||||
iconSize: isSmallScreen ? 24 : 28,
|
||||
highlighted: true,
|
||||
tooltip: _isPlaying ? 'Pause' : 'Lecture',
|
||||
),
|
||||
|
||||
if (widget.channels != null && widget.channels!.length > 1)
|
||||
@@ -843,6 +958,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
icon: Icons.skip_next_rounded,
|
||||
onTap: _nextChannel,
|
||||
size: buttonSize,
|
||||
tooltip: 'Chaîne suivante',
|
||||
),
|
||||
|
||||
SizedBox(width: spacing),
|
||||
@@ -852,6 +968,16 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
icon: _isMuted ? Icons.volume_off_rounded : Icons.volume_up_rounded,
|
||||
onTap: _toggleMute,
|
||||
size: buttonSize,
|
||||
tooltip: _isMuted ? 'Activer le son' : 'Couper le son',
|
||||
),
|
||||
|
||||
SizedBox(width: spacing),
|
||||
|
||||
// Quality selector
|
||||
QualitySelectorButton(
|
||||
current: _quality,
|
||||
onSelected: _changeQuality,
|
||||
size: buttonSize,
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -863,17 +989,15 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
double size = 48,
|
||||
double iconSize = 24,
|
||||
bool highlighted = false,
|
||||
String? tooltip,
|
||||
}) {
|
||||
return Material(
|
||||
final button = Material(
|
||||
color: highlighted
|
||||
? AppColors.primary.withOpacity(0.2)
|
||||
: Colors.white.withOpacity(0.1),
|
||||
shape: const CircleBorder(),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
print('[PlayerScreen] Simple button tapped: $icon');
|
||||
onTap();
|
||||
},
|
||||
onTap: onTap,
|
||||
customBorder: const CircleBorder(),
|
||||
splashColor: AppColors.primary.withOpacity(0.3),
|
||||
highlightColor: AppColors.primary.withOpacity(0.1),
|
||||
@@ -898,6 +1022,7 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
||||
),
|
||||
),
|
||||
);
|
||||
return tooltip != null ? Tooltip(message: tooltip, child: button) : button;
|
||||
}
|
||||
|
||||
/// Build inline EPG info for the unified control bar
|
||||
|
||||
@@ -62,9 +62,9 @@ class PlaylistSelectionScreen extends ConsumerWidget {
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xFF050505),
|
||||
AppColors.surfaceContainerLowest,
|
||||
AppColors.background,
|
||||
Color(0xFF0A0A0A),
|
||||
AppColors.baseLevel0,
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -42,6 +42,36 @@ class XtreamService {
|
||||
);
|
||||
|
||||
_dio.interceptors.add(DioCacheInterceptor(options: _cacheOptions));
|
||||
|
||||
// Attach the backend session token: the Xtream gateway
|
||||
// (/api/xtream-api) requires authentication and injects the IPTV
|
||||
// credentials server-side.
|
||||
_dio.interceptors.add(
|
||||
InterceptorsWrapper(
|
||||
onRequest: (options, handler) {
|
||||
if (kIsWeb) {
|
||||
final token = html.window.localStorage['auth_token'];
|
||||
if (token != null && token.isNotEmpty) {
|
||||
options.headers['Authorization'] = 'Bearer $token';
|
||||
}
|
||||
}
|
||||
handler.next(options);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// GET on the authenticated Xtream gateway. Credentials are injected by
|
||||
/// the backend; the client only passes the action and its parameters.
|
||||
Future<Response<dynamic>> _apiGet(
|
||||
Map<String, String> params, {
|
||||
Options? options,
|
||||
}) {
|
||||
return _dio.get(
|
||||
'$_backendBaseUrl/api/xtream-api',
|
||||
queryParameters: params,
|
||||
options: options ?? Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
}
|
||||
|
||||
String? _manualBackendUrl;
|
||||
@@ -84,47 +114,45 @@ class XtreamService {
|
||||
_dio.options.sendTimeout = Duration(seconds: seconds);
|
||||
}
|
||||
|
||||
/// Wrap URL with proxy for all external IPTV URLs
|
||||
String _wrapWithProxy(String url) {
|
||||
if (url.startsWith('http')) {
|
||||
return '$_backendBaseUrl/api/xtream/$url';
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/// Initialize connection with a playlist
|
||||
void setPlaylist(PlaylistConfig playlist) {
|
||||
_currentPlaylist = playlist;
|
||||
}
|
||||
|
||||
/// Generate stream URL for live TV (HLS)
|
||||
String getLiveStreamUrl(String streamId) {
|
||||
/// [quality]: source | high | medium | low (server-side FFmpeg preset)
|
||||
String getLiveStreamUrl(String streamId, {String quality = 'high'}) {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
return '$_backendBaseUrl/api/live/$streamId/playlist.m3u8';
|
||||
return '$_backendBaseUrl/api/live/$streamId/$quality/playlist.m3u8';
|
||||
}
|
||||
|
||||
/// Generate stream URL for live TV (Direct MPEG-TS)
|
||||
/// Faster zapping on compatible players (mpegts.js)
|
||||
String getLiveStreamUrlTs(String streamId) {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
// Direct link to the .ts stream through our proxy
|
||||
final dns = _currentPlaylist!.dns;
|
||||
final user = _currentPlaylist!.username;
|
||||
final pass = _currentPlaylist!.password;
|
||||
final url = '$dns/live/$user/$pass/$streamId.ts';
|
||||
return '$_backendBaseUrl/api/xtream/${Uri.encodeComponent(url)}';
|
||||
// Backend route injects the Xtream credentials server-side
|
||||
return '$_backendBaseUrl/api/live/$streamId.ts';
|
||||
}
|
||||
|
||||
/// Generate stream URL for VOD (movies)
|
||||
String getVodStreamUrl(String streamId, String containerExtension) {
|
||||
/// [quality]: source | high | medium | low (server-side FFmpeg preset)
|
||||
String getVodStreamUrl(
|
||||
String streamId,
|
||||
String containerExtension, {
|
||||
String quality = 'high',
|
||||
}) {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
return '$_backendBaseUrl/api/vod/$streamId/playlist.m3u8';
|
||||
return '$_backendBaseUrl/api/vod/$streamId/$quality/playlist.m3u8';
|
||||
}
|
||||
|
||||
/// Generate stream URL for series episodes
|
||||
String getSeriesStreamUrl(String streamId, String containerExtension) {
|
||||
String getSeriesStreamUrl(
|
||||
String streamId,
|
||||
String containerExtension, {
|
||||
String quality = 'high',
|
||||
}) {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
return '$_backendBaseUrl/api/vod/$streamId/playlist.m3u8?type=series';
|
||||
return '$_backendBaseUrl/api/vod/$streamId/$quality/playlist.m3u8?type=series';
|
||||
}
|
||||
|
||||
/// Authenticate and get server info
|
||||
@@ -132,14 +160,7 @@ class XtreamService {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
},
|
||||
options: Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
final response = await _apiGet({});
|
||||
|
||||
return response.data as Map<String, dynamic>;
|
||||
} catch (e) {
|
||||
@@ -152,15 +173,7 @@ class XtreamService {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_live_categories',
|
||||
},
|
||||
options: Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
final response = await _apiGet({'action': 'get_live_categories'});
|
||||
|
||||
final List<dynamic> categories = response.data as List<dynamic>;
|
||||
final Map<String, String> categoryMap = {};
|
||||
@@ -198,13 +211,8 @@ class XtreamService {
|
||||
// Parallelize categories and streams fetching
|
||||
final results = await Future.wait([
|
||||
_getLiveCategories(),
|
||||
_dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_live_streams',
|
||||
},
|
||||
_apiGet(
|
||||
{'action': 'get_live_streams'},
|
||||
options: Options(extra: options),
|
||||
),
|
||||
]);
|
||||
@@ -279,15 +287,7 @@ class XtreamService {
|
||||
if (_currentPlaylist == null) return {};
|
||||
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_vod_categories',
|
||||
},
|
||||
options: Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
final response = await _apiGet({'action': 'get_vod_categories'});
|
||||
|
||||
final List<dynamic> categories = response.data as List<dynamic>;
|
||||
final Map<String, String> categoryMap = {};
|
||||
@@ -319,13 +319,8 @@ class XtreamService {
|
||||
// Parallelize VOD categories and streams fetching
|
||||
final results = await Future.wait([
|
||||
_getVodCategories(),
|
||||
_dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_vod_streams',
|
||||
},
|
||||
_apiGet(
|
||||
{'action': 'get_vod_streams'},
|
||||
options: Options(extra: options),
|
||||
),
|
||||
]);
|
||||
@@ -364,15 +359,7 @@ class XtreamService {
|
||||
if (_currentPlaylist == null) return {};
|
||||
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_series_categories',
|
||||
},
|
||||
options: Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
final response = await _apiGet({'action': 'get_series_categories'});
|
||||
|
||||
final List<dynamic> categories = response.data as List<dynamic>;
|
||||
final Map<String, String> categoryMap = {};
|
||||
@@ -404,13 +391,8 @@ class XtreamService {
|
||||
// Parallelize Series categories and streams fetching
|
||||
final results = await Future.wait([
|
||||
_getSeriesCategories(),
|
||||
_dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_series',
|
||||
},
|
||||
_apiGet(
|
||||
{'action': 'get_series'},
|
||||
options: Options(extra: options),
|
||||
),
|
||||
]);
|
||||
@@ -455,15 +437,7 @@ class XtreamService {
|
||||
// Load categories for mapping
|
||||
final categoryMap = await _getVodCategories();
|
||||
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_vod_streams',
|
||||
},
|
||||
options: Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
final response = await _apiGet({'action': 'get_vod_streams'});
|
||||
|
||||
final List<dynamic> allMovies = response.data as List<dynamic>;
|
||||
|
||||
@@ -494,15 +468,7 @@ class XtreamService {
|
||||
try {
|
||||
final categoryMap = await _getVodCategories();
|
||||
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_vod_streams',
|
||||
},
|
||||
options: Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
final response = await _apiGet({'action': 'get_vod_streams'});
|
||||
|
||||
final List<dynamic> allMovies = response.data as List<dynamic>;
|
||||
final queryLower = query.toLowerCase();
|
||||
@@ -537,15 +503,7 @@ class XtreamService {
|
||||
// Load categories for mapping
|
||||
final categoryMap = await _getSeriesCategories();
|
||||
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_series',
|
||||
},
|
||||
options: Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
final response = await _apiGet({'action': 'get_series'});
|
||||
|
||||
final List<dynamic> allSeries = response.data as List<dynamic>;
|
||||
|
||||
@@ -576,15 +534,7 @@ class XtreamService {
|
||||
try {
|
||||
final categoryMap = await _getSeriesCategories();
|
||||
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_series',
|
||||
},
|
||||
options: Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
final response = await _apiGet({'action': 'get_series'});
|
||||
|
||||
final List<dynamic> allSeries = response.data as List<dynamic>;
|
||||
final queryLower = query.toLowerCase();
|
||||
@@ -613,16 +563,10 @@ class XtreamService {
|
||||
if (_currentPlaylist == null) throw Exception('No playlist configured');
|
||||
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_series_info',
|
||||
'series_id': seriesId,
|
||||
},
|
||||
options: Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
final response = await _apiGet({
|
||||
'action': 'get_series_info',
|
||||
'series_id': seriesId,
|
||||
});
|
||||
|
||||
return xm.SeriesInfo.fromJson(response.data as Map<String, dynamic>);
|
||||
} catch (e) {
|
||||
@@ -637,16 +581,10 @@ class XtreamService {
|
||||
if (_currentPlaylist == null) return null;
|
||||
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
'action': 'get_vod_info',
|
||||
'vod_id': vodId,
|
||||
},
|
||||
options: Options(extra: _cacheOptions.toExtra()),
|
||||
);
|
||||
final response = await _apiGet({
|
||||
'action': 'get_vod_info',
|
||||
'vod_id': vodId,
|
||||
});
|
||||
|
||||
final data = response.data as Map<String, dynamic>;
|
||||
|
||||
@@ -698,11 +636,8 @@ class XtreamService {
|
||||
}
|
||||
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
final response = await _apiGet(
|
||||
{
|
||||
'action': 'get_short_epg',
|
||||
'stream_id': streamId,
|
||||
},
|
||||
@@ -740,11 +675,8 @@ class XtreamService {
|
||||
}
|
||||
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
_wrapWithProxy(_currentPlaylist!.apiBaseUrl),
|
||||
queryParameters: {
|
||||
'username': _currentPlaylist!.username,
|
||||
'password': _currentPlaylist!.password,
|
||||
final response = await _apiGet(
|
||||
{
|
||||
'action': 'get_short_epg',
|
||||
'stream_id': streamId,
|
||||
},
|
||||
|
||||
@@ -1,227 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
|
||||
class ChannelCard extends StatefulWidget {
|
||||
final String channelNumber;
|
||||
final String channelName;
|
||||
final String? channelLogo;
|
||||
final String? currentProgram;
|
||||
final String? programTime;
|
||||
final bool isFavorite;
|
||||
final VoidCallback? onTap;
|
||||
final VoidCallback? onFavoriteTap;
|
||||
final bool isActive;
|
||||
|
||||
const ChannelCard({
|
||||
super.key,
|
||||
required this.channelNumber,
|
||||
required this.channelName,
|
||||
this.channelLogo,
|
||||
this.currentProgram,
|
||||
this.programTime,
|
||||
this.isFavorite = false,
|
||||
this.onTap,
|
||||
this.onFavoriteTap,
|
||||
this.isActive = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ChannelCard> createState() => _ChannelCardState();
|
||||
}
|
||||
|
||||
class _ChannelCardState extends State<ChannelCard>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _pulseController;
|
||||
late Animation<double> _pulseAnimation;
|
||||
bool _isHovered = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_pulseController = AnimationController(
|
||||
vsync: this,
|
||||
duration: AppTheme.durationMd,
|
||||
)..repeat(reverse: true);
|
||||
|
||||
_pulseAnimation = Tween<double>(begin: 1.0, end: 1.05).animate(
|
||||
CurvedAnimation(parent: _pulseController, curve: AppTheme.curveSmooth),
|
||||
);
|
||||
|
||||
if (widget.isActive) {
|
||||
_pulseController.forward();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ChannelCard oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.isActive && !oldWidget.isActive) {
|
||||
_pulseController.forward();
|
||||
} else if (!widget.isActive && oldWidget.isActive) {
|
||||
_pulseController.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pulseController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => _isHovered = true),
|
||||
onExit: (_) => setState(() => _isHovered = false),
|
||||
child: GestureDetector(
|
||||
onTap: widget.onTap,
|
||||
child: ScaleTransition(
|
||||
scale: widget.isActive
|
||||
? _pulseAnimation
|
||||
: const AlwaysStoppedAnimation(1.0),
|
||||
child: AnimatedContainer(
|
||||
duration: AppTheme.durationMd,
|
||||
curve: AppTheme.curveDefault,
|
||||
decoration: BoxDecoration(
|
||||
color: widget.isActive
|
||||
? AppColors.primary.withOpacity(0.15)
|
||||
: AppColors.surface,
|
||||
border: Border.all(
|
||||
color: widget.isActive
|
||||
? AppColors.primary
|
||||
: (_isHovered
|
||||
? AppColors.border
|
||||
: AppColors.border.withOpacity(0.5)),
|
||||
width: widget.isActive ? 2.5 : 1.5,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
|
||||
boxShadow: [
|
||||
if (_isHovered || widget.isActive)
|
||||
BoxShadow(
|
||||
color: widget.isActive
|
||||
? AppColors.primary.withOpacity(0.25)
|
||||
: AppColors.primary.withOpacity(0.1),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4),
|
||||
spreadRadius: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(AppTheme.spacingMd),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.channelNumber,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textSecondary,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
SizedBox(height: AppTheme.spacingXs),
|
||||
Text(
|
||||
widget.channelName,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: GoogleFonts.outfit(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: widget.onFavoriteTap,
|
||||
child: AnimatedScale(
|
||||
scale: widget.isFavorite ? 1.1 : 1.0,
|
||||
duration: AppTheme.durationXs,
|
||||
child: Icon(
|
||||
widget.isFavorite
|
||||
? Icons.favorite
|
||||
: Icons.favorite_border,
|
||||
color: widget.isFavorite
|
||||
? AppColors.secondary
|
||||
: AppColors.textSecondary,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: AppTheme.spacingSm),
|
||||
if (widget.currentProgram != null)
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.currentProgram!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
if (widget.programTime != null) ...[
|
||||
SizedBox(height: AppTheme.spacingXs),
|
||||
Text(
|
||||
widget.programTime!,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (widget.isActive)
|
||||
Positioned(
|
||||
top: AppTheme.spacingSm,
|
||||
right: AppTheme.spacingSm,
|
||||
child: Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.6),
|
||||
blurRadius: 8,
|
||||
spreadRadius: 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,543 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import '../providers/recommendations_provider.dart';
|
||||
import '../../../core/models/playlist_config.dart';
|
||||
import '../models/playlist.dart';
|
||||
|
||||
/// Widget showing "Continue Watching" section
|
||||
class ContinueWatchingWidget extends ConsumerStatefulWidget {
|
||||
final Playlist playlist;
|
||||
final List<Playlist> content;
|
||||
final VoidCallback? onItemTap;
|
||||
|
||||
const ContinueWatchingWidget({
|
||||
super.key,
|
||||
required this.playlist,
|
||||
required this.content,
|
||||
this.onItemTap,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<ContinueWatchingWidget> createState() =>
|
||||
_ContinueWatchingWidgetState();
|
||||
}
|
||||
|
||||
class _ContinueWatchingWidgetState
|
||||
extends ConsumerState<ContinueWatchingWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final watchHistory = ref.watch(watchHistoryProvider);
|
||||
final continueWatching =
|
||||
RecommendationService.getContinueWatching(watchHistory, widget.content);
|
||||
|
||||
if (continueWatching.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Continue Watching',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// Navigate to full continue watching list
|
||||
},
|
||||
child: const Text('View All'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
...continueWatching.take(5).map((rec) {
|
||||
final item = rec.item;
|
||||
final percentage =
|
||||
watchHistory[item.streamId.toString()] is Map
|
||||
? (watchHistory[item.streamId.toString()]
|
||||
as Map)['percentage'] as double? ??
|
||||
0.0
|
||||
: 0.0;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(right: 12),
|
||||
child: _ContinueWatchingCard(
|
||||
item: item,
|
||||
progress: percentage,
|
||||
onTap: widget.onItemTap,
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ContinueWatchingCard extends StatelessWidget {
|
||||
final Playlist item;
|
||||
final double progress;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _ContinueWatchingCard({
|
||||
required this.item,
|
||||
required this.progress,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Poster with progress bar
|
||||
Container(
|
||||
width: 160,
|
||||
height: 240,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Poster image
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: item.cover ?? '',
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
errorWidget: (context, url, error) => Icon(
|
||||
Icons.image_not_supported,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Dark overlay at bottom
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.transparent,
|
||||
Colors.black.withOpacity(0.8),
|
||||
],
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Progress bar
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
child: LinearProgressIndicator(
|
||||
value: progress / 100.0,
|
||||
minHeight: 3,
|
||||
backgroundColor: Colors.white30,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
_getProgressColor(progress),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${progress.toStringAsFixed(0)}% watched',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Play button overlay on hover
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue.withOpacity(0.7),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
margin: const EdgeInsets.all(8),
|
||||
child: const Icon(
|
||||
Icons.play_arrow,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Title
|
||||
SizedBox(
|
||||
width: 160,
|
||||
child: Text(
|
||||
item.name ?? 'Unknown',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getProgressColor(double progress) {
|
||||
if (progress < 30) return Colors.red;
|
||||
if (progress < 70) return Colors.orange;
|
||||
return Colors.green;
|
||||
}
|
||||
}
|
||||
|
||||
/// Widget showing trending/popular content
|
||||
class TrendingWidget extends ConsumerWidget {
|
||||
final Playlist playlist;
|
||||
final List<Playlist> content;
|
||||
final VoidCallback? onItemTap;
|
||||
|
||||
const TrendingWidget({
|
||||
super.key,
|
||||
required this.playlist,
|
||||
required this.content,
|
||||
this.onItemTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final trending = ref.watch(trendingProvider);
|
||||
final trendingContent =
|
||||
RecommendationService.getTrending(trending, content);
|
||||
|
||||
if (trendingContent.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.local_fire_department,
|
||||
color: Colors.red,
|
||||
size: 24,
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Text(
|
||||
'Trending Now',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text('View All'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
...trendingContent.take(5).map((rec) {
|
||||
final item = rec.item;
|
||||
final rank = trendingContent.indexOf(rec) + 1;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(right: 12),
|
||||
child: _TrendingCard(
|
||||
item: item,
|
||||
rank: rank,
|
||||
onTap: onItemTap,
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TrendingCard extends StatelessWidget {
|
||||
final Playlist item;
|
||||
final int rank;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _TrendingCard({
|
||||
required this.item,
|
||||
required this.rank,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Stack(
|
||||
children: [
|
||||
// Card
|
||||
Container(
|
||||
width: 180,
|
||||
height: 260,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Image
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(12),
|
||||
topRight: Radius.circular(12),
|
||||
),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: item.cover ?? '',
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
errorWidget: (context, url, error) => Icon(
|
||||
Icons.image_not_supported,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Info
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.name ?? 'Unknown',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
if (item.rating != null)
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.star,
|
||||
color: Colors.amber,
|
||||
size: 12,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
item.rating ?? '0',
|
||||
style: const TextStyle(fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Rank badge
|
||||
Positioned(
|
||||
top: 8,
|
||||
left: 8,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _getRankColor(rank),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'#$rank',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getRankColor(int rank) {
|
||||
switch (rank) {
|
||||
case 1:
|
||||
return Colors.amber.shade700;
|
||||
case 2:
|
||||
return Colors.grey.shade600;
|
||||
case 3:
|
||||
return Colors.orange.shade700;
|
||||
default:
|
||||
return Colors.blue.shade700;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Widget showing recently added content
|
||||
class RecentlyAddedWidget extends ConsumerWidget {
|
||||
final Playlist playlist;
|
||||
final List<Playlist> content;
|
||||
final VoidCallback? onItemTap;
|
||||
|
||||
const RecentlyAddedWidget({
|
||||
super.key,
|
||||
required this.playlist,
|
||||
required this.content,
|
||||
this.onItemTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final recent = RecommendationService.getRecentlyAdded(content);
|
||||
|
||||
if (recent.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
'Recently Added',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
...recent.take(5).map((rec) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(right: 12),
|
||||
child: _RecentCard(
|
||||
item: rec.item,
|
||||
onTap: onItemTap,
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RecentCard extends StatelessWidget {
|
||||
final Playlist item;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _RecentCard({
|
||||
required this.item,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 140,
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: item.cover ?? '',
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
errorWidget: (context, url, error) =>
|
||||
Icon(Icons.image_not_supported, color: Colors.grey[600]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ class EpgOverlay extends ConsumerWidget {
|
||||
margin: const EdgeInsets.fromLTRB(0, 0, 24, 0),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1A1A2E)
|
||||
color: AppColors.surfaceContainerLow
|
||||
.withOpacity(0.85), // Match Native player controls
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(color: Colors.white.withOpacity(0.1)),
|
||||
|
||||
@@ -371,6 +371,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
return TvFocusableCard(
|
||||
onTap: () => _playChannel(channel, channels),
|
||||
borderRadius: 12,
|
||||
semanticLabel: 'Chaîne ${channel.name}',
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceVariant,
|
||||
@@ -481,7 +482,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
return Text(
|
||||
currentProgram.title,
|
||||
style: GoogleFonts.inter(
|
||||
color: const Color(0xFFFFD700),
|
||||
color: AppColors.ratingGold,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
|
||||
@@ -341,6 +341,7 @@ class _MoviesTabState extends ConsumerState<MoviesTab> {
|
||||
return TvFocusableCard(
|
||||
onTap: () => _playMovie(movie),
|
||||
borderRadius: 12,
|
||||
semanticLabel: 'Film ${movie.name}',
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
@@ -420,7 +421,7 @@ class _MoviesTabState extends ConsumerState<MoviesTab> {
|
||||
const Icon(
|
||||
Icons.star,
|
||||
size: 10,
|
||||
color: Color(0xFFFFD700),
|
||||
color: AppColors.ratingGold,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
|
||||
@@ -1,253 +1,107 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../core/services/adaptive_bitrate_service.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
|
||||
/// Widget for displaying and selecting video quality during playback
|
||||
class QualitySelectorWidget extends ConsumerStatefulWidget {
|
||||
final QualitySelector qualitySelector;
|
||||
final VoidCallback onClose;
|
||||
/// Stream quality presets handled server-side by FFmpeg
|
||||
/// (see bin/api/streaming_handler.dart).
|
||||
enum StreamQuality {
|
||||
source('source', 'Source', 'Flux direct, zéro transcodage'),
|
||||
high('high', 'Haute', '1080p · 6-8 Mbps'),
|
||||
medium('medium', 'Moyenne', '3 Mbps'),
|
||||
low('low', 'Basse', '720p · 1.5 Mbps');
|
||||
|
||||
const QualitySelectorWidget({
|
||||
super.key,
|
||||
required this.qualitySelector,
|
||||
required this.onClose,
|
||||
});
|
||||
const StreamQuality(this.value, this.label, this.description);
|
||||
|
||||
@override
|
||||
ConsumerState<QualitySelectorWidget> createState() =>
|
||||
_QualitySelectorWidgetState();
|
||||
final String value;
|
||||
final String label;
|
||||
final String description;
|
||||
}
|
||||
|
||||
class _QualitySelectorWidgetState extends ConsumerState<QualitySelectorWidget> {
|
||||
late List<QualityLevel> _availableQualities;
|
||||
late QualityLevel _selectedQuality;
|
||||
/// Popup button to switch the transcoding quality of the current stream.
|
||||
class QualitySelectorButton extends StatelessWidget {
|
||||
final StreamQuality current;
|
||||
final ValueChanged<StreamQuality> onSelected;
|
||||
final double size;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_availableQualities = QualityProfiles.getBalancedProfiles();
|
||||
_selectedQuality = widget.qualitySelector.currentQuality;
|
||||
}
|
||||
const QualitySelectorButton({
|
||||
super.key,
|
||||
required this.current,
|
||||
required this.onSelected,
|
||||
this.size = 44,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final currentQuality = widget.qualitySelector.currentQuality;
|
||||
final bandwidthMbps = widget.qualitySelector.getEstimatedBandwidthMbps();
|
||||
|
||||
return Dialog(
|
||||
backgroundColor: Colors.black87,
|
||||
insetPadding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(color: Colors.white24),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Video Quality',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.white),
|
||||
onPressed: widget.onClose,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Network Info
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white10,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Current Bandwidth:',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14),
|
||||
),
|
||||
Text(
|
||||
'${bandwidthMbps.toStringAsFixed(1)} Mbps',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
return Tooltip(
|
||||
message: 'Qualité : ${current.label}',
|
||||
child: PopupMenuButton<StreamQuality>(
|
||||
initialValue: current,
|
||||
color: AppColors.surfaceContainerHigh,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
onSelected: onSelected,
|
||||
itemBuilder: (context) => StreamQuality.values
|
||||
.map(
|
||||
(q) => PopupMenuItem<StreamQuality>(
|
||||
value: q,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
q == current
|
||||
? Icons.radio_button_checked_rounded
|
||||
: Icons.radio_button_off_rounded,
|
||||
size: 18,
|
||||
color: q == current
|
||||
? AppColors.primary
|
||||
: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Quality Options
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: _availableQualities.length,
|
||||
itemBuilder: (context, index) {
|
||||
final quality = _availableQualities[index];
|
||||
final isSelected = quality == currentQuality;
|
||||
|
||||
return ListTile(
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
||||
leading: isSelected
|
||||
? const Icon(Icons.check_circle, color: Colors.blue)
|
||||
: const Icon(
|
||||
Icons.radio_button_unchecked,
|
||||
color: Colors.white30,
|
||||
const SizedBox(width: 12),
|
||||
Flexible(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
q.label,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.textPrimary,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
q.description,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: GoogleFonts.inter(
|
||||
color: AppColors.textTertiary,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
title: Text(
|
||||
quality.label,
|
||||
style: TextStyle(
|
||||
color: isSelected ? Colors.blue : Colors.white,
|
||||
fontWeight:
|
||||
isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: Text(
|
||||
'${quality.bitrateBps ~/ 1000000} Mbps',
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
onTap: () {
|
||||
widget.qualitySelector.setQuality(quality);
|
||||
setState(() {
|
||||
_selectedQuality = quality;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
child: Container(
|
||||
width: size,
|
||||
height: size,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white.withOpacity(0.2)),
|
||||
),
|
||||
|
||||
// Auto Quality Option
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(color: Colors.white24),
|
||||
),
|
||||
),
|
||||
child: ListTile(
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
leading: const Icon(Icons.auto_awesome, color: Colors.amber),
|
||||
title: const Text(
|
||||
'Auto Quality',
|
||||
style: TextStyle(
|
||||
color: Colors.amber,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
subtitle: const Text(
|
||||
'Adjusts based on network speed',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
onTap: () {
|
||||
// Auto mode would be handled by the player
|
||||
widget.onClose();
|
||||
},
|
||||
),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.high_quality_rounded,
|
||||
color: Colors.white,
|
||||
size: 22,
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Floating quality indicator (minimal UI during playback)
|
||||
class QualityIndicator extends ConsumerWidget {
|
||||
final QualitySelector qualitySelector;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const QualityIndicator({
|
||||
super.key,
|
||||
required this.qualitySelector,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final quality = qualitySelector.currentQuality;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.high_quality, color: Colors.white, size: 16),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
quality.resolution.split('x')[1], // Show just the height
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Bandwidth monitor widget (for debugging/info)
|
||||
class BandwidthMonitor extends ConsumerWidget {
|
||||
final QualitySelector qualitySelector;
|
||||
|
||||
const BandwidthMonitor({
|
||||
super.key,
|
||||
required this.qualitySelector,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black54,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.speed, color: Colors.green, size: 14),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'${qualitySelector.getEstimatedBandwidthMbps().toStringAsFixed(1)} Mbps',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../../../core/models/iptv_models.dart';
|
||||
import '../../../core/models/playlist_config.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../providers/xtream_provider.dart';
|
||||
import '../providers/settings_provider.dart';
|
||||
import '../screens/player_screen.dart';
|
||||
@@ -363,7 +364,7 @@ class _EpgGuideViewState extends ConsumerState<_EpgGuideView>
|
||||
const Icon(
|
||||
Icons.tv_off,
|
||||
size: 64,
|
||||
color: Color(0x1FFFFFFF),
|
||||
color: AppColors.glassLevel1Border,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
@@ -512,7 +513,7 @@ class _ProgrammeCard extends StatelessWidget {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: const Color(0xFF1E1E2E),
|
||||
backgroundColor: AppColors.surfaceContainer,
|
||||
title: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
@@ -823,7 +824,7 @@ class _RecordingsListViewState extends State<_RecordingsListView> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: const Color(0xFF1E1E2E),
|
||||
backgroundColor: AppColors.surfaceContainer,
|
||||
title: Text(
|
||||
title,
|
||||
style: GoogleFonts.outfit(color: Colors.white, fontSize: 14),
|
||||
@@ -918,7 +919,7 @@ class _RecordingsListViewState extends State<_RecordingsListView> {
|
||||
const Icon(
|
||||
Icons.videocam_off,
|
||||
size: 64,
|
||||
color: Color(0x1FFFFFFF),
|
||||
color: AppColors.glassLevel1Border,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
@@ -1124,7 +1125,7 @@ class _SeasonPassesViewState extends State<_SeasonPassesView> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: const Color(0xFF1E1E2E),
|
||||
backgroundColor: AppColors.surfaceContainer,
|
||||
title: Row(
|
||||
children: [
|
||||
const Icon(Icons.repeat, color: Colors.purpleAccent),
|
||||
@@ -1282,7 +1283,7 @@ class _SeasonPassesViewState extends State<_SeasonPassesView> {
|
||||
const Icon(
|
||||
Icons.repeat,
|
||||
size: 64,
|
||||
color: Color(0x1FFFFFFF),
|
||||
color: AppColors.glassLevel1Border,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
|
||||
@@ -333,6 +333,7 @@ class _SeriesTabState extends ConsumerState<SeriesTab> {
|
||||
return TvFocusableCard(
|
||||
onTap: () => _openSeries(serie),
|
||||
borderRadius: 12,
|
||||
semanticLabel: 'Série ${serie.name}',
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
@@ -434,7 +435,7 @@ class _SeriesTabState extends ConsumerState<SeriesTab> {
|
||||
const Icon(
|
||||
Icons.star,
|
||||
size: 10,
|
||||
color: Color(0xFFFFD700),
|
||||
color: AppColors.ratingGold,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
|
||||
@@ -482,7 +482,7 @@ class _SettingsTabState extends ConsumerState<SettingsTab>
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: const Color(0xFF1E1E1E),
|
||||
backgroundColor: AppColors.surfaceContainer,
|
||||
title: const Text(
|
||||
'Vider le cache ?',
|
||||
style: TextStyle(color: AppColors.onSurface),
|
||||
|
||||
@@ -287,7 +287,7 @@ class StreamingSettingsTab extends ConsumerWidget {
|
||||
trailing: DropdownButton<T>(
|
||||
value: value,
|
||||
underline: const SizedBox(),
|
||||
dropdownColor: const Color(0xFF1C1C1E), // Dark background for dropdown
|
||||
dropdownColor: AppColors.surfaceContainer, // Dark background for dropdown
|
||||
items: items.map((item) {
|
||||
return DropdownMenuItem<T>(
|
||||
value: item,
|
||||
|
||||
+16
-1
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'core/router/app_router.dart';
|
||||
import 'core/theme/app_theme.dart';
|
||||
@@ -24,7 +25,21 @@ class MyApp extends ConsumerWidget {
|
||||
darkTheme: AppTheme.darkTheme,
|
||||
themeMode: themeState.themeMode,
|
||||
routerConfig: router,
|
||||
// DPAD / keyboard navigation (TV remotes, keyboards): arrow keys move
|
||||
// focus between focusable widgets, Enter/Select activates.
|
||||
shortcuts: {
|
||||
...WidgetsApp.defaultShortcuts,
|
||||
const SingleActivator(LogicalKeyboardKey.arrowUp):
|
||||
const DirectionalFocusIntent(TraversalDirection.up),
|
||||
const SingleActivator(LogicalKeyboardKey.arrowDown):
|
||||
const DirectionalFocusIntent(TraversalDirection.down),
|
||||
const SingleActivator(LogicalKeyboardKey.arrowLeft):
|
||||
const DirectionalFocusIntent(TraversalDirection.left),
|
||||
const SingleActivator(LogicalKeyboardKey.arrowRight):
|
||||
const DirectionalFocusIntent(TraversalDirection.right),
|
||||
const SingleActivator(LogicalKeyboardKey.select):
|
||||
const ActivateIntent(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,9 +68,9 @@ class _MobileLoginScreenState extends ConsumerState<MobileLoginScreen> {
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Color(0xFF000000), // Deep Black
|
||||
Color(0xFF0F0F12), // Subtle Gray
|
||||
Color(0xFF000000), // Back to Black
|
||||
AppColors.baseLevel0,
|
||||
AppColors.surfaceContainerLowest,
|
||||
AppColors.baseLevel0,
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user