init: Initial Flutter project setup with Android and iOS platform files.

This commit is contained in:
Michael committed 2025-12-09 08:40:50 +01:00
1 parent 0dd3edfc79
commit d0c5c4ff3a
73 files changed
+3288 -329

No files matched your search

@@ -0,0 +1,437 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/models/playlist_config.dart';
import '../../../../core/theme/app_colors.dart';
import '../../../theme/mobile_theme.dart';
import '../../../services/local_playlist_service.dart';
import 'mobile_dashboard_screen.dart';
/// Provider for local playlists
final localPlaylistsProvider = FutureProvider<List<PlaylistConfig>>((ref) async {
final service = LocalPlaylistService();
return service.getPlaylists();
});
/// Mobile playlist selection screen - simplified without auth
class MobilePlaylistScreen extends ConsumerStatefulWidget {
const MobilePlaylistScreen({super.key});
@override
ConsumerState<MobilePlaylistScreen> createState() => _MobilePlaylistScreenState();
}
class _MobilePlaylistScreenState extends ConsumerState<MobilePlaylistScreen> {
final LocalPlaylistService _playlistService = LocalPlaylistService();
@override
void initState() {
super.initState();
_playlistService.init();
}
void _refreshPlaylists() {
ref.invalidate(localPlaylistsProvider);
}
void _navigateToDashboard(PlaylistConfig playlist) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MobileDashboardScreen(playlist: playlist),
),
);
}
void _showAddPlaylistDialog() {
final nameController = TextEditingController();
final dnsController = TextEditingController();
final usernameController = TextEditingController();
final passwordController = TextEditingController();
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) => Container(
decoration: const BoxDecoration(
color: AppColors.surface,
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Handle bar
Center(
child: Container(
width: 40,
height: 4,
decoration: BoxDecoration(
color: AppColors.textTertiary,
borderRadius: BorderRadius.circular(2),
),
),
),
const SizedBox(height: 24),
// Title
const Text(
'Ajouter une playlist',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: AppColors.textPrimary,
),
),
const SizedBox(height: 24),
// Form fields
_buildTextField(
controller: nameController,
label: 'Nom',
hint: 'Ma Playlist IPTV',
icon: Icons.label_outline,
),
const SizedBox(height: 16),
_buildTextField(
controller: dnsController,
label: 'Serveur URL',
hint: 'http://example.com:8080',
icon: Icons.dns_outlined,
keyboardType: TextInputType.url,
),
const SizedBox(height: 16),
_buildTextField(
controller: usernameController,
label: 'Nom d\'utilisateur',
hint: 'username',
icon: Icons.person_outline,
),
const SizedBox(height: 16),
_buildTextField(
controller: passwordController,
label: 'Mot de passe',
hint: '••••••••',
icon: Icons.lock_outline,
obscureText: true,
),
const SizedBox(height: 32),
// Save button
SizedBox(
width: double.infinity,
child: FilledButton.icon(
onPressed: () async {
if (nameController.text.isEmpty ||
dnsController.text.isEmpty ||
usernameController.text.isEmpty ||
passwordController.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Veuillez remplir tous les champs'),
backgroundColor: AppColors.error,
),
);
return;
}
await _playlistService.addPlaylist(
name: nameController.text,
dns: dnsController.text,
username: usernameController.text,
password: passwordController.text,
);
if (mounted) {
Navigator.pop(context);
_refreshPlaylists();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Playlist ajoutée avec succès'),
backgroundColor: Colors.green,
),
);
}
},
icon: const Icon(Icons.add),
label: const Text('Ajouter'),
style: FilledButton.styleFrom(
backgroundColor: AppColors.primary,
padding: const EdgeInsets.symmetric(vertical: 16),
),
),
),
const SizedBox(height: 16),
],
),
),
),
);
}
Widget _buildTextField({
required TextEditingController controller,
required String label,
required String hint,
required IconData icon,
bool obscureText = false,
TextInputType? keyboardType,
}) {
return TextField(
controller: controller,
obscureText: obscureText,
keyboardType: keyboardType,
style: const TextStyle(color: AppColors.textPrimary),
decoration: InputDecoration(
labelText: label,
hintText: hint,
prefixIcon: Icon(icon, color: AppColors.textSecondary),
labelStyle: const TextStyle(color: AppColors.textSecondary),
hintStyle: const TextStyle(color: AppColors.textTertiary),
filled: true,
fillColor: AppColors.background,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: AppColors.primary),
),
),
);
}
void _showDeleteConfirmation(PlaylistConfig playlist) {
showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: AppColors.surface,
title: const Text('Supprimer la playlist ?',
style: TextStyle(color: AppColors.textPrimary)),
content: Text('Voulez-vous supprimer "${playlist.name}" ?',
style: const TextStyle(color: AppColors.textSecondary)),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Annuler'),
),
FilledButton(
onPressed: () async {
await _playlistService.deletePlaylist(playlist.id);
if (mounted) {
Navigator.pop(context);
_refreshPlaylists();
}
},
style: FilledButton.styleFrom(backgroundColor: AppColors.error),
child: const Text('Supprimer'),
),
],
),
);
}
@override
Widget build(BuildContext context) {
final playlistsAsync = ref.watch(localPlaylistsProvider);
return Theme(
data: MobileTheme.darkTheme,
child: Scaffold(
backgroundColor: AppColors.background,
appBar: AppBar(
title: const Text('XtremFlow'),
centerTitle: true,
backgroundColor: AppColors.background,
elevation: 0,
),
body: playlistsAsync.when(
loading: () => const Center(
child: CircularProgressIndicator(color: AppColors.primary),
),
error: (error, stack) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, size: 48, color: AppColors.error),
const SizedBox(height: 16),
const Text('Erreur de chargement',
style: TextStyle(color: AppColors.textPrimary)),
const SizedBox(height: 8),
Text(error.toString(),
style: const TextStyle(color: AppColors.textSecondary, fontSize: 12)),
const SizedBox(height: 16),
TextButton.icon(
onPressed: _refreshPlaylists,
icon: const Icon(Icons.refresh),
label: const Text('Réessayer'),
),
],
),
),
data: (playlists) {
if (playlists.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
color: AppColors.surface,
borderRadius: BorderRadius.circular(20),
),
child: const Icon(
Icons.playlist_add,
size: 40,
color: AppColors.textTertiary,
),
),
const SizedBox(height: 24),
const Text(
'Aucune playlist',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: AppColors.textPrimary,
),
),
const SizedBox(height: 8),
const Text(
'Ajoutez votre première playlist IPTV',
style: TextStyle(
color: AppColors.textSecondary,
),
),
const SizedBox(height: 32),
FilledButton.icon(
onPressed: _showAddPlaylistDialog,
icon: const Icon(Icons.add),
label: const Text('Ajouter une playlist'),
style: FilledButton.styleFrom(
backgroundColor: AppColors.primary,
padding: const EdgeInsets.symmetric(
horizontal: 24,
vertical: 12,
),
),
),
],
),
);
}
return ListView.separated(
padding: const EdgeInsets.all(16),
itemCount: playlists.length,
separatorBuilder: (context, index) => const SizedBox(height: 12),
itemBuilder: (context, index) {
final playlist = playlists[index];
return _PlaylistCard(
playlist: playlist,
onTap: () => _navigateToDashboard(playlist),
onLongPress: () => _showDeleteConfirmation(playlist),
);
},
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: _showAddPlaylistDialog,
backgroundColor: AppColors.primary,
child: const Icon(Icons.add),
),
),
);
}
}
class _PlaylistCard extends StatelessWidget {
final PlaylistConfig playlist;
final VoidCallback onTap;
final VoidCallback onLongPress;
const _PlaylistCard({
required this.playlist,
required this.onTap,
required this.onLongPress,
});
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: AppColors.surface,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: AppColors.border.withOpacity(0.3)),
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
onLongPress: onLongPress,
borderRadius: BorderRadius.circular(16),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Container(
width: 52,
height: 52,
decoration: BoxDecoration(
color: AppColors.primary.withOpacity(0.15),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(
Icons.playlist_play,
color: AppColors.primary,
size: 28,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
playlist.name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColors.textPrimary,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Text(
Uri.tryParse(playlist.dns)?.host ?? playlist.dns,
style: const TextStyle(
fontSize: 13,
color: AppColors.textSecondary,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
const Icon(
Icons.chevron_right,
color: AppColors.textTertiary,
),
],
),
),
),
),
);
}
}
@@ -4,9 +4,9 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:google_fonts/google_fonts.dart';
import '../../../../core/models/playlist_config.dart';
import '../../../../features/iptv/models/xtream_models.dart';
import '../../../../features/iptv/providers/xtream_provider.dart';
import '../../../../features/iptv/providers/watch_history_provider.dart';
import 'mobile_player_screen.dart';
import '../../../providers/mobile_xtream_providers.dart';
import '../../../providers/mobile_settings_providers.dart';
import 'native_player_screen.dart';
import '../../../../core/theme/app_colors.dart';
class MobileSeriesDetailScreen extends ConsumerStatefulWidget {
@@ -51,8 +51,8 @@ class _MobileSeriesDetailScreenState extends ConsumerState<MobileSeriesDetailScr
_error = null;
});
final service = ref.read(xtreamServiceProvider(widget.playlist));
final info = await service.getSeriesInfo(widget.series.seriesId);
final service = ref.read(mobileXtreamServiceProvider(widget.playlist));
final info = await service.getSeriesInfo(widget.series.seriesId.toString());
if (mounted) {
setState(() {
@@ -254,8 +254,8 @@ class _MobileSeriesDetailScreenState extends ConsumerState<MobileSeriesDetailScr
}
Widget _buildEpisodeTile(Episode episode) {
final watchHistory = ref.watch(watchHistoryProvider);
final episodeKey = WatchHistory.episodeKey(
final watchHistory = ref.watch(mobileWatchHistoryProvider);
final episodeKey = MobileWatchHistory.episodeKey(
widget.series.seriesId,
_selectedSeason,
episode.episodeNum,
@@ -264,11 +264,11 @@ class _MobileSeriesDetailScreenState extends ConsumerState<MobileSeriesDetailScr
return InkWell(
onTap: () {
ref.read(watchHistoryProvider.notifier).markEpisodeWatched(episodeKey);
ref.read(mobileWatchHistoryProvider.notifier).markEpisodeWatched(episodeKey);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MobilePlayerScreen(
builder: (context) => NativePlayerScreen(
streamId: episode.id,
title: '${widget.series.name} - ${episode.title}',
playlist: widget.playlist,
@@ -0,0 +1,364 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
import '../../../../core/models/playlist_config.dart';
import '../../../../core/models/iptv_models.dart';
import '../../../../core/theme/app_colors.dart';
import '../../../../features/iptv/services/xtream_service_mobile.dart';
/// Stream type enum for player
enum StreamType { live, vod, series }
/// Native video player screen for Android/iOS
/// Uses video_player + chewie for HLS/MP4 playback
class NativePlayerScreen extends ConsumerStatefulWidget {
final String streamId;
final String title;
final StreamType streamType;
final String containerExtension;
final PlaylistConfig playlist;
final List<Channel>? channels;
final int initialIndex;
const NativePlayerScreen({
super.key,
required this.streamId,
required this.title,
required this.playlist,
this.streamType = StreamType.live,
this.containerExtension = 'mp4',
this.channels,
this.initialIndex = 0,
});
@override
ConsumerState<NativePlayerScreen> createState() => _NativePlayerScreenState();
}
class _NativePlayerScreenState extends ConsumerState<NativePlayerScreen> {
VideoPlayerController? _videoController;
ChewieController? _chewieController;
bool _isLoading = true;
String? _errorMessage;
late int _currentIndex;
late XtreamServiceMobile _xtreamService;
@override
void initState() {
super.initState();
_currentIndex = widget.initialIndex;
_xtreamService = XtreamServiceMobile();
_xtreamService.setPlaylist(widget.playlist);
// Lock to landscape for video playback
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
_initializePlayer();
}
Future<void> _initializePlayer() async {
try {
setState(() {
_isLoading = true;
_errorMessage = null;
});
// Dispose previous controllers if switching channels
await _disposeControllers();
// Determine effective Stream ID
final currentStreamId = widget.channels != null && widget.channels!.isNotEmpty
? widget.channels![_currentIndex].streamId
: widget.streamId;
// Build stream URL based on type
String streamUrl;
if (widget.streamType == StreamType.live) {
// Live TV - use HLS format for best mobile compatibility
streamUrl = _xtreamService.getLiveStreamUrl(currentStreamId);
} else if (widget.streamType == StreamType.vod) {
// Movies
streamUrl = _xtreamService.getVodStreamUrl(currentStreamId, widget.containerExtension);
} else {
// Series
streamUrl = _xtreamService.getSeriesStreamUrl(currentStreamId, widget.containerExtension);
}
debugPrint('NativePlayer: Loading stream: $streamUrl');
// Initialize video controller
_videoController = VideoPlayerController.networkUrl(
Uri.parse(streamUrl),
httpHeaders: {
'User-Agent': 'XtremFlow/1.0',
},
);
await _videoController!.initialize();
// Initialize chewie controller with custom options
_chewieController = ChewieController(
videoPlayerController: _videoController!,
autoPlay: true,
looping: widget.streamType == StreamType.live, // Loop live streams
allowFullScreen: true,
allowMuting: true,
showControls: true,
showControlsOnInitialize: false,
hideControlsTimer: const Duration(seconds: 3),
materialProgressColors: ChewieProgressColors(
playedColor: AppColors.primary,
handleColor: AppColors.primary,
backgroundColor: Colors.white24,
bufferedColor: Colors.white38,
),
placeholder: Container(
color: Colors.black,
child: const Center(
child: CircularProgressIndicator(color: AppColors.primary),
),
),
errorBuilder: (context, errorMessage) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.error_outline, color: Colors.red, size: 48),
const SizedBox(height: 16),
Text(
'Erreur de lecture',
style: const TextStyle(color: Colors.white, fontSize: 18),
),
const SizedBox(height: 8),
Text(
errorMessage,
style: const TextStyle(color: Colors.white70, fontSize: 14),
textAlign: TextAlign.center,
),
],
),
);
},
);
setState(() {
_isLoading = false;
});
} catch (e) {
debugPrint('NativePlayer error: $e');
setState(() {
_isLoading = false;
_errorMessage = e.toString();
});
}
}
Future<void> _disposeControllers() async {
_chewieController?.dispose();
_chewieController = null;
await _videoController?.dispose();
_videoController = null;
}
void _playNext() {
if (widget.channels == null || widget.channels!.isEmpty) return;
final nextIndex = (_currentIndex + 1) % widget.channels!.length;
_switchChannel(nextIndex);
}
void _playPrevious() {
if (widget.channels == null || widget.channels!.isEmpty) return;
final prevIndex = (_currentIndex - 1 + widget.channels!.length) % widget.channels!.length;
_switchChannel(prevIndex);
}
void _switchChannel(int index) {
setState(() {
_currentIndex = index;
});
_initializePlayer();
}
@override
void dispose() {
_disposeControllers();
_xtreamService.dispose();
// Restore normal orientation
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
super.dispose();
}
@override
Widget build(BuildContext context) {
final title = widget.channels != null && widget.channels!.isNotEmpty
? widget.channels![_currentIndex].name
: widget.title;
return Scaffold(
backgroundColor: Colors.black,
body: Stack(
children: [
// Video Player
if (_errorMessage != null)
_buildErrorView()
else if (_isLoading)
_buildLoadingView()
else if (_chewieController != null)
Center(
child: Chewie(controller: _chewieController!),
)
else
_buildLoadingView(),
// Custom top bar for channel switching (live TV only)
if (widget.channels != null && widget.channels!.isNotEmpty)
Positioned(
top: 0,
left: 0,
right: 0,
child: SafeArea(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.black.withOpacity(0.7),
Colors.transparent,
],
),
),
child: Row(
children: [
IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.pop(context),
),
Expanded(
child: Text(
title,
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w600,
),
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
IconButton(
icon: const Icon(Icons.skip_previous, color: Colors.white),
onPressed: _playPrevious,
),
IconButton(
icon: const Icon(Icons.skip_next, color: Colors.white),
onPressed: _playNext,
),
],
),
),
),
),
// Back button for VOD/Series (no channel switching)
if (widget.channels == null || widget.channels!.isEmpty)
Positioned(
top: 0,
left: 0,
child: SafeArea(
child: IconButton(
icon: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.black45,
shape: BoxShape.circle,
),
child: const Icon(Icons.arrow_back, color: Colors.white),
),
onPressed: () => Navigator.pop(context),
),
),
),
],
),
);
}
Widget _buildLoadingView() {
return const Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(color: AppColors.primary),
SizedBox(height: 16),
Text(
'Chargement...',
style: TextStyle(color: Colors.white70),
),
],
),
);
}
Widget _buildErrorView() {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.error_outline, size: 64, color: Colors.red),
const SizedBox(height: 16),
const Text(
'Erreur de lecture',
style: TextStyle(color: Colors.white, fontSize: 18),
),
const SizedBox(height: 8),
Text(
_errorMessage ?? 'Une erreur inconnue est survenue',
style: const TextStyle(color: Colors.white70),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
Row(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton.icon(
onPressed: () => Navigator.pop(context),
icon: const Icon(Icons.arrow_back),
label: const Text('Retour'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.grey[800],
),
),
const SizedBox(width: 16),
ElevatedButton.icon(
onPressed: _initializePlayer,
icon: const Icon(Icons.refresh),
label: const Text('Réessayer'),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.primary,
),
),
],
),
],
),
);
}
}