mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-11 17:30:00 +02:00
Merge pull request #71 from R0m1k3/antigravity
feat: add security middleware for security headers, honeypot, and rat…
This commit is contained in:
4 files changed
+407
-142
No files matched your search
@@ -0,0 +1,110 @@
|
|||||||
|
import 'package:shelf/shelf.dart';
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
/// Security Middleware Collection
|
||||||
|
///
|
||||||
|
/// Includes:
|
||||||
|
/// - Honeypot Routes (Trap for bots)
|
||||||
|
/// - Security Headers (HSTS, XSS Protection)
|
||||||
|
/// - Rate Limiting (Basic DoS protection)
|
||||||
|
|
||||||
|
/// 1. Security Headers Middleware
|
||||||
|
/// Adds standard security headers to every response.
|
||||||
|
Middleware securityHeadersMiddleware() {
|
||||||
|
return (Handler handler) {
|
||||||
|
return (Request request) async {
|
||||||
|
final response = await handler(request);
|
||||||
|
|
||||||
|
return response.change(headers: {
|
||||||
|
'X-Content-Type-Options': 'nosniff',
|
||||||
|
'X-Frame-Options': 'DENY',
|
||||||
|
'X-XSS-Protection': '1; mode=block',
|
||||||
|
'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload',
|
||||||
|
'Referrer-Policy': 'strict-origin-when-cross-origin',
|
||||||
|
// Note: CSP is tricky with Flutter Web (requires 'unsafe-eval' for Dart),
|
||||||
|
// so we omit it here to avoid breaking the app, or use a permissive one.
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 2. Honeypot Middleware
|
||||||
|
/// Intercepts requests to common vulnerability scanning paths.
|
||||||
|
/// Returns a 403 Forbidden immediately and logs the incident.
|
||||||
|
Middleware honeypotMiddleware() {
|
||||||
|
// list of common bot targets
|
||||||
|
const honeypotPaths = [
|
||||||
|
'/admin/phpmyadmin',
|
||||||
|
'/phpmyadmin',
|
||||||
|
'/wp-admin',
|
||||||
|
'/wp-login.php',
|
||||||
|
'/.env',
|
||||||
|
'/config.php',
|
||||||
|
'/api/.env',
|
||||||
|
'/console',
|
||||||
|
'/actuator/health'
|
||||||
|
];
|
||||||
|
|
||||||
|
return (Handler handler) {
|
||||||
|
return (Request request) {
|
||||||
|
final path = request.url.path;
|
||||||
|
|
||||||
|
// Check if path contains any honeypot target
|
||||||
|
for (final trap in honeypotPaths) {
|
||||||
|
if (path.contains(trap.replaceAll('/', ''))) { // Simple check
|
||||||
|
print('SECURITY ALERT: Honeypot triggered by ${request.context['clientIp'] ?? 'unknown IP'} on path: $path');
|
||||||
|
return Response.forbidden('Access Denied');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return handler(request);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 3. Rate Limit Middleware (In-Memory)
|
||||||
|
/// Limits requests per IP address.
|
||||||
|
/// Default: 100 requests per minute per IP.
|
||||||
|
Middleware rateLimitMiddleware({int requestsPerMinute = 200}) {
|
||||||
|
final clientRequests = <String, List<DateTime>>{};
|
||||||
|
|
||||||
|
// Cleanup timer to remove old entries and prevent memory leaks
|
||||||
|
Timer.periodic(const Duration(minutes: 5), (_) {
|
||||||
|
final now = DateTime.now();
|
||||||
|
clientRequests.removeWhere((_, times) {
|
||||||
|
// Remove timestamps older than 1 minute
|
||||||
|
times.removeWhere((t) => now.difference(t).inMinutes > 1);
|
||||||
|
return times.isEmpty;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return (Handler handler) {
|
||||||
|
return (Request request) {
|
||||||
|
// Identify client by IP (passed from main server or headers)
|
||||||
|
// Note: In real prod behind Nginx, use X-Forwarded-For
|
||||||
|
// Here we assume direct or standard setup.
|
||||||
|
final clientIp = (request.context['clientIp'] as String?) ?? 'unknown';
|
||||||
|
|
||||||
|
if (clientIp != 'unknown' && clientIp != '127.0.0.1') {
|
||||||
|
final now = DateTime.now();
|
||||||
|
|
||||||
|
// Get or create history for this IP
|
||||||
|
final history = clientRequests.putIfAbsent(clientIp, () => []);
|
||||||
|
|
||||||
|
// Clean old requests (older than 1 minute)
|
||||||
|
history.removeWhere((t) => now.difference(t).inMinutes >= 1);
|
||||||
|
|
||||||
|
// Check limit
|
||||||
|
if (history.length >= requestsPerMinute) {
|
||||||
|
print('SECURITY WARN: Rate limit exceeded for $clientIp');
|
||||||
|
return Response(429, body: 'Too Many Requests');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add current request
|
||||||
|
history.add(now);
|
||||||
|
}
|
||||||
|
|
||||||
|
return handler(request);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import 'api/auth_handler.dart';
|
|||||||
import 'api/users_handler.dart';
|
import 'api/users_handler.dart';
|
||||||
import 'api/playlists_handler.dart';
|
import 'api/playlists_handler.dart';
|
||||||
import 'middleware/auth_middleware.dart';
|
import 'middleware/auth_middleware.dart';
|
||||||
|
import 'middleware/security_middleware.dart';
|
||||||
|
|
||||||
void main(List<String> args) async {
|
void main(List<String> args) async {
|
||||||
// Parse command line arguments
|
// Parse command line arguments
|
||||||
@@ -62,9 +63,14 @@ void main(List<String> args) async {
|
|||||||
.add(staticHandler)
|
.add(staticHandler)
|
||||||
.handler;
|
.handler;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Add middleware
|
// Add middleware
|
||||||
final pipeline = Pipeline()
|
final pipeline = Pipeline()
|
||||||
.addMiddleware(logRequests())
|
.addMiddleware(logRequests())
|
||||||
|
.addMiddleware(securityHeadersMiddleware()) // Basic Headers
|
||||||
|
.addMiddleware(honeypotMiddleware()) // Trap Bots
|
||||||
|
.addMiddleware(rateLimitMiddleware()) // Anti-DoS
|
||||||
.addMiddleware(_corsMiddleware())
|
.addMiddleware(_corsMiddleware())
|
||||||
.addHandler(handler);
|
.addHandler(handler);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import '../../../core/models/iptv_models.dart';
|
|||||||
|
|
||||||
import '../../../core/widgets/themed_loading_screen.dart';
|
import '../../../core/widgets/themed_loading_screen.dart';
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||||
|
import 'dart:ui' as ui; // Essential for BackdropFilter
|
||||||
|
import '../../../core/theme/app_colors.dart';
|
||||||
|
|
||||||
/// Stream type enum for player
|
/// Stream type enum for player
|
||||||
enum StreamType { live, vod, series }
|
enum StreamType { live, vod, series }
|
||||||
@@ -100,8 +102,13 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
|||||||
|
|
||||||
void _sendMessage(Map<String, dynamic> message) {
|
void _sendMessage(Map<String, dynamic> message) {
|
||||||
// Helper to send message to iframe
|
// Helper to send message to iframe
|
||||||
|
debugPrint('Sending message to iframe ($_viewId): $message');
|
||||||
final iframe = html.document.getElementById(_viewId) as html.IFrameElement?;
|
final iframe = html.document.getElementById(_viewId) as html.IFrameElement?;
|
||||||
iframe?.contentWindow?.postMessage(message, '*');
|
if (iframe == null) {
|
||||||
|
debugPrint('ERROR: Iframe with ID $_viewId not found!');
|
||||||
|
} else {
|
||||||
|
iframe.contentWindow?.postMessage(message, '*');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setAspectRatio(String mode) {
|
void _setAspectRatio(String mode) {
|
||||||
@@ -296,87 +303,160 @@ class _PlayerScreenState extends ConsumerState<PlayerScreen> {
|
|||||||
void _showSettingsDialog() {
|
void _showSettingsDialog() {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
useRootNavigator: true, // Ensure it's on top
|
useRootNavigator: true,
|
||||||
builder: (context) => PointerInterceptor(
|
builder: (context) => PointerInterceptor(
|
||||||
child: Theme(
|
child: Dialog(
|
||||||
data: Theme.of(context).copyWith(dialogBackgroundColor: const Color(0xFF1C1C1E)),
|
backgroundColor: Colors.transparent,
|
||||||
child: AlertDialog(
|
insetPadding: const EdgeInsets.all(24),
|
||||||
backgroundColor: const Color(0xFF1C1C1E).withOpacity(0.95),
|
child: TweenAnimationBuilder<double>(
|
||||||
shape: RoundedRectangleBorder(
|
tween: Tween(begin: 0.0, end: 1.0),
|
||||||
borderRadius: BorderRadius.circular(16),
|
duration: const Duration(milliseconds: 300),
|
||||||
side: BorderSide(color: Colors.white.withOpacity(0.1)),
|
curve: Curves.easeOutCubic,
|
||||||
|
builder: (context, value, child) => Transform.scale(
|
||||||
|
scale: 0.9 + (0.1 * value),
|
||||||
|
child: Opacity(
|
||||||
|
opacity: value,
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
title: const Text('Réglages', style: TextStyle(color: Colors.white, fontWeight: FontWeight.w600)),
|
child: Container(
|
||||||
content: SizedBox(
|
|
||||||
width: 400,
|
width: 400,
|
||||||
child: Column(
|
decoration: BoxDecoration(
|
||||||
mainAxisSize: MainAxisSize.min,
|
color: AppColors.surface.withOpacity(0.8),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
borderRadius: BorderRadius.circular(24),
|
||||||
children: [
|
border: Border.all(color: Colors.white.withOpacity(0.1)),
|
||||||
const Text('Format d\'image', style: TextStyle(color: Colors.white54, fontSize: 13, fontWeight: FontWeight.bold)),
|
boxShadow: [
|
||||||
const SizedBox(height: 12),
|
BoxShadow(
|
||||||
Wrap(
|
color: Colors.black.withOpacity(0.5),
|
||||||
spacing: 8,
|
blurRadius: 30,
|
||||||
runSpacing: 8,
|
offset: const Offset(0, 10),
|
||||||
children: [
|
|
||||||
_buildAspectRatioChip('Original', 'contain'),
|
|
||||||
_buildAspectRatioChip('Remplir', 'cover'),
|
|
||||||
_buildAspectRatioChip('Étirer', 'fill'),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
if (_audioTracks.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
const Text('Pistes Audio', style: TextStyle(color: Colors.white54, fontSize: 13, fontWeight: FontWeight.bold)),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Container(
|
|
||||||
constraints: const BoxConstraints(maxHeight: 200),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white.withOpacity(0.05),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Column(
|
|
||||||
children: _audioTracks.map((track) {
|
|
||||||
return ListTile(
|
|
||||||
title: Text(track['label'] ?? 'Piste ${track['id']}', style: const TextStyle(color: Colors.white, fontSize: 14)),
|
|
||||||
subtitle: Text(track['lang'] ?? '', style: const TextStyle(color: Colors.white54, fontSize: 12)),
|
|
||||||
onTap: () => _setAudioTrack(track['id']),
|
|
||||||
dense: true,
|
|
||||||
leading: const Icon(Icons.audiotrack, size: 20, color: Colors.white54),
|
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
|
||||||
hoverColor: Colors.white.withOpacity(0.1),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
child: ClipRRect(
|
||||||
actions: [
|
borderRadius: BorderRadius.circular(24),
|
||||||
TextButton(
|
child: BackdropFilter(
|
||||||
onPressed: () => Navigator.pop(context),
|
filter: ui.ImageFilter.blur(sigmaX: 20, sigmaY: 20),
|
||||||
style: TextButton.styleFrom(foregroundColor: Colors.white),
|
child: Padding(
|
||||||
child: const Text('Fermer'),
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
'Réglages',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: Colors.white,
|
||||||
|
letterSpacing: -0.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.close, color: Colors.white54),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
tooltip: 'Fermer',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
const Text('FORMAT D\'IMAGE', style: TextStyle(color: AppColors.textSecondary, fontSize: 12, fontWeight: FontWeight.bold, letterSpacing: 1)),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.black26,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
_buildRatioOption('Original', 'contain', Icons.crop_original),
|
||||||
|
_buildRatioOption('Remplir', 'cover', Icons.crop_free),
|
||||||
|
_buildRatioOption('Étirer', 'fill', Icons.aspect_ratio),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (_audioTracks.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
const Text('AUDIO', style: TextStyle(color: AppColors.textSecondary, fontSize: 12, fontWeight: FontWeight.bold, letterSpacing: 1)),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Container(
|
||||||
|
constraints: const BoxConstraints(maxHeight: 200),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.black26,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
border: Border.all(color: Colors.white.withOpacity(0.05)),
|
||||||
|
),
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
children: _audioTracks.map((track) {
|
||||||
|
return Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: ListTile(
|
||||||
|
title: Text(track['label'] ?? 'Piste ${track['id']}', style: const TextStyle(color: Colors.white, fontSize: 14)),
|
||||||
|
subtitle: Text(track['lang'] ?? '', style: const TextStyle(color: Colors.white54, fontSize: 12)),
|
||||||
|
onTap: () => _setAudioTrack(track['id']),
|
||||||
|
dense: true,
|
||||||
|
leading: const Icon(Icons.audiotrack, size: 18, color: Colors.white54),
|
||||||
|
hoverColor: Colors.white.withOpacity(0.1),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildAspectRatioChip(String label, String value) {
|
Widget _buildRatioOption(String label, String value, IconData icon) {
|
||||||
final isSelected = _aspectRatio == value;
|
final isSelected = _aspectRatio == value;
|
||||||
return ChoiceChip(
|
return Expanded(
|
||||||
label: Text(label),
|
child: GestureDetector(
|
||||||
selected: isSelected,
|
onTap: () {
|
||||||
onSelected: (_) => _setAspectRatio(value),
|
debugPrint('Changing Aspect Ratio to: $value');
|
||||||
backgroundColor: Colors.black26,
|
_setAspectRatio(value);
|
||||||
selectedColor: Theme.of(context).primaryColor,
|
},
|
||||||
labelStyle: TextStyle(color: isSelected ? Colors.white : Colors.white70),
|
child: AnimatedContainer(
|
||||||
side: BorderSide.none,
|
duration: const Duration(milliseconds: 200),
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: isSelected ? AppColors.surfaceVariant : Colors.transparent,
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
border: isSelected ? Border.all(color: Colors.white12) : null,
|
||||||
|
boxShadow: isSelected ? [BoxShadow(color: Colors.black12, blurRadius: 4, offset: const Offset(0, 2))] : null,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Icon(icon, color: isSelected ? Colors.white : Colors.white54, size: 20),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
style: TextStyle(
|
||||||
|
color: isSelected ? Colors.white : Colors.white54,
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:media_kit/media_kit.dart';
|
import 'package:media_kit/media_kit.dart';
|
||||||
import 'package:media_kit_video/media_kit_video.dart';
|
import 'package:media_kit_video/media_kit_video.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
import '../../../core/theme/app_colors.dart';
|
||||||
|
|
||||||
class VideoPlayerScreen extends StatefulWidget {
|
class VideoPlayerScreen extends StatefulWidget {
|
||||||
final String streamUrl;
|
final String streamUrl;
|
||||||
@@ -19,11 +20,10 @@ class VideoPlayerScreen extends StatefulWidget {
|
|||||||
State<VideoPlayerScreen> createState() => _VideoPlayerScreenState();
|
State<VideoPlayerScreen> createState() => _VideoPlayerScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
// Premium Features State
|
||||||
late final Player _player;
|
BoxFit _fit = BoxFit.contain;
|
||||||
late final VideoController _controller;
|
List<AudioTrack> _audioTracks = [];
|
||||||
bool _isFullscreen = false;
|
AudioTrack? _currentAudioTrack;
|
||||||
bool _showControls = true;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -36,40 +36,120 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
|||||||
// Load stream
|
// Load stream
|
||||||
_player.open(Media(widget.streamUrl));
|
_player.open(Media(widget.streamUrl));
|
||||||
_player.play();
|
_player.play();
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
// Listen to tracks
|
||||||
void dispose() {
|
_player.stream.tracks.listen((tracks) {
|
||||||
_player.dispose();
|
setState(() {
|
||||||
super.dispose();
|
_audioTracks = tracks.audio;
|
||||||
}
|
_currentAudioTrack = _player.state.track.audio;
|
||||||
|
});
|
||||||
void _toggleFullscreen() {
|
|
||||||
setState(() {
|
|
||||||
_isFullscreen = !_isFullscreen;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _toggleControls() {
|
void _cycleAspectRatio() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_showControls = !_showControls;
|
if (_fit == BoxFit.contain) {
|
||||||
|
_fit = BoxFit.cover;
|
||||||
|
} else if (_fit == BoxFit.cover) {
|
||||||
|
_fit = BoxFit.fill;
|
||||||
|
} else {
|
||||||
|
_fit = BoxFit.contain;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _showSettingsDialog() {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
backgroundColor: const Color(0xFF1C1C1E),
|
||||||
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||||
|
),
|
||||||
|
builder: (context) => Container(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const Text('Format d\'image', style: TextStyle(color: Colors.white54, fontSize: 13, fontWeight: FontWeight.bold)),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
children: [
|
||||||
|
_buildRatioChip('Original', BoxFit.contain),
|
||||||
|
_buildRatioChip('Remplir', BoxFit.cover),
|
||||||
|
_buildRatioChip('Étirer', BoxFit.fill),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (_audioTracks.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
const Text('Pistes Audio', style: TextStyle(color: Colors.white54, fontSize: 13, fontWeight: FontWeight.bold)),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
itemCount: _audioTracks.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final track = _audioTracks[index];
|
||||||
|
final isSelected = track == _currentAudioTrack;
|
||||||
|
return ListTile(
|
||||||
|
title: Text(track.language ?? track.label ?? 'Piste ${index + 1}', style: const TextStyle(color: Colors.white)),
|
||||||
|
subtitle: Text(track.id, style: const TextStyle(color: Colors.white54, fontSize: 10)),
|
||||||
|
trailing: isSelected ? const Icon(Icons.check, color: AppColors.primary) : null,
|
||||||
|
onTap: () {
|
||||||
|
_player.setAudioTrack(track);
|
||||||
|
setState(() => _currentAudioTrack = track);
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildRatioChip(String label, BoxFit fit) {
|
||||||
|
final isSelected = _fit == fit;
|
||||||
|
return ChoiceChip(
|
||||||
|
label: Text(label),
|
||||||
|
selected: isSelected,
|
||||||
|
onSelected: (_) {
|
||||||
|
setState(() => _fit = fit);
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
backgroundColor: Colors.white10,
|
||||||
|
selectedColor: AppColors.primary,
|
||||||
|
labelStyle: TextStyle(color: isSelected ? Colors.black : Colors.white),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.black,
|
backgroundColor: AppColors.background,
|
||||||
appBar: _isFullscreen
|
appBar: _isFullscreen
|
||||||
? null
|
? null
|
||||||
: AppBar(
|
: AppBar(
|
||||||
title: Text(
|
title: Text(
|
||||||
widget.title,
|
widget.title,
|
||||||
style: GoogleFonts.roboto(fontWeight: FontWeight.w600),
|
style: GoogleFonts.outfit(fontWeight: FontWeight.w600),
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.black,
|
backgroundColor: Colors.transparent, // Glass effect handled by body
|
||||||
|
elevation: 0,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.settings),
|
||||||
|
onPressed: _showSettingsDialog,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
|
extendBodyBehindAppBar: true,
|
||||||
body: GestureDetector(
|
body: GestureDetector(
|
||||||
onTap: _toggleControls,
|
onTap: _toggleControls,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
@@ -79,6 +159,7 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
|||||||
child: Video(
|
child: Video(
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
controls: NoVideoControls,
|
controls: NoVideoControls,
|
||||||
|
fit: _fit,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -91,7 +172,7 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
|||||||
begin: Alignment.topCenter,
|
begin: Alignment.topCenter,
|
||||||
end: Alignment.bottomCenter,
|
end: Alignment.bottomCenter,
|
||||||
colors: [
|
colors: [
|
||||||
Colors.black54,
|
Colors.black87,
|
||||||
Colors.transparent,
|
Colors.transparent,
|
||||||
Colors.transparent,
|
Colors.transparent,
|
||||||
Colors.black87,
|
Colors.black87,
|
||||||
@@ -102,41 +183,16 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
// Top bar with title
|
// SAFE AREA SPACER FOR APPBAR
|
||||||
if (!_isFullscreen)
|
if (!_isFullscreen)
|
||||||
const SizedBox.shrink()
|
const SizedBox(height: 80)
|
||||||
else
|
else
|
||||||
SafeArea(
|
const SizedBox.shrink(),
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
widget.title,
|
|
||||||
style: GoogleFonts.roboto(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
// Bottom controls
|
// Bottom controls
|
||||||
SafeArea(
|
SafeArea(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(24.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
@@ -159,7 +215,7 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
|||||||
value: progress.clamp(0.0, 1.0),
|
value: progress.clamp(0.0, 1.0),
|
||||||
backgroundColor: Colors.white24,
|
backgroundColor: Colors.white24,
|
||||||
valueColor: const AlwaysStoppedAnimation<Color>(
|
valueColor: const AlwaysStoppedAnimation<Color>(
|
||||||
Colors.red,
|
AppColors.primary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
@@ -170,15 +226,17 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
|||||||
Text(
|
Text(
|
||||||
_formatDuration(position),
|
_formatDuration(position),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white70,
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
_formatDuration(duration),
|
_formatDuration(duration),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white70,
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -189,7 +247,7 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 32),
|
||||||
|
|
||||||
// Playback controls
|
// Playback controls
|
||||||
Row(
|
Row(
|
||||||
@@ -197,54 +255,65 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
|||||||
children: [
|
children: [
|
||||||
// Rewind
|
// Rewind
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.replay_10, size: 32),
|
icon: const Icon(Icons.replay_10, size: 36),
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
final currentPos = _player.state.position;
|
final currentPos = _player.state.position;
|
||||||
_player.seek(currentPos - const Duration(seconds: 10));
|
_player.seek(currentPos - const Duration(seconds: 10));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(width: 24),
|
const SizedBox(width: 32),
|
||||||
|
|
||||||
// Play/Pause
|
// Play/Pause
|
||||||
StreamBuilder<bool>(
|
StreamBuilder<bool>(
|
||||||
stream: _player.stream.playing,
|
stream: _player.stream.playing,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
final isPlaying = snapshot.data ?? false;
|
final isPlaying = snapshot.data ?? false;
|
||||||
return IconButton(
|
return Container(
|
||||||
icon: Icon(
|
padding: const EdgeInsets.all(12),
|
||||||
isPlaying ? Icons.pause : Icons.play_arrow,
|
decoration: BoxDecoration(
|
||||||
size: 48,
|
color: Colors.white.withOpacity(0.1),
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(color: Colors.white24),
|
||||||
|
),
|
||||||
|
child: IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
isPlaying ? Icons.pause : Icons.play_arrow,
|
||||||
|
size: 48,
|
||||||
|
),
|
||||||
|
color: Colors.white,
|
||||||
|
onPressed: () {
|
||||||
|
_player.playOrPause();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
color: Colors.white,
|
|
||||||
onPressed: () {
|
|
||||||
_player.playOrPause();
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(width: 24),
|
const SizedBox(width: 32),
|
||||||
|
|
||||||
// Forward
|
// Forward
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.forward_10, size: 32),
|
icon: const Icon(Icons.forward_10, size: 36),
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
final currentPos = _player.state.position;
|
final currentPos = _player.state.position;
|
||||||
_player.seek(currentPos + const Duration(seconds: 10));
|
_player.seek(currentPos + const Duration(seconds: 10));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const Spacer(),
|
],
|
||||||
|
),
|
||||||
|
|
||||||
// Fullscreen toggle
|
const SizedBox(height: 24),
|
||||||
|
|
||||||
|
// Footer Utils
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
_isFullscreen
|
_isFullscreen ? Icons.fullscreen_exit : Icons.fullscreen,
|
||||||
? Icons.fullscreen_exit
|
color: Colors.white70,
|
||||||
: Icons.fullscreen,
|
|
||||||
size: 32,
|
|
||||||
),
|
),
|
||||||
color: Colors.white,
|
|
||||||
onPressed: _toggleFullscreen,
|
onPressed: _toggleFullscreen,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -267,7 +336,7 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
|||||||
|
|
||||||
return const Center(
|
return const Center(
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
color: Colors.red,
|
color: AppColors.primary,
|
||||||
strokeWidth: 3,
|
strokeWidth: 3,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user