feat: Initialize XtremFlow project with core structure, IPTV features, authentication, and video player.

This commit is contained in:
Michael committed 2025-12-05 09:17:11 +01:00
commit 2a28eb44d8
28 files changed
+3279

No files matched your search

@@ -0,0 +1,77 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';
import '../../../core/models/playlist_config.dart';
import '../widgets/live_tv_tab.dart';
import '../widgets/movies_tab.dart';
import '../widgets/series_tab.dart';
import '../widgets/settings_tab.dart';
class DashboardScreen extends ConsumerStatefulWidget {
final PlaylistConfig playlist;
const DashboardScreen({
super.key,
required this.playlist,
});
@override
ConsumerState<DashboardScreen> createState() => _DashboardScreenState();
}
class _DashboardScreenState extends ConsumerState<DashboardScreen> {
int _selectedIndex = 0;
late final List<Widget> _tabs;
@override
void initState() {
super.initState();
_tabs = [
LiveTVTab(playlist: widget.playlist),
MoviesTab(playlist: widget.playlist),
SeriesTab(playlist: widget.playlist),
const SettingsTab(),
];
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
widget.playlist.name,
style: GoogleFonts.roboto(fontWeight: FontWeight.w600),
),
centerTitle: false,
),
body: _tabs[_selectedIndex],
bottomNavigationBar: NavigationBar(
selectedIndex: _selectedIndex,
onDestinationSelected: (index) {
setState(() {
_selectedIndex = index;
});
},
destinations: const [
NavigationDestination(
icon: Icon(Icons.live_tv),
label: 'Live TV',
),
NavigationDestination(
icon: Icon(Icons.movie),
label: 'Movies',
),
NavigationDestination(
icon: Icon(Icons.tv),
label: 'Series',
),
NavigationDestination(
icon: Icon(Icons.settings),
label: 'Settings',
),
],
),
);
}
}
@@ -0,0 +1,168 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';
import '../../../core/database/hive_service.dart';
import '../../auth/providers/auth_provider.dart';
class PlaylistSelectionScreen extends ConsumerWidget {
const PlaylistSelectionScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final currentUser = ref.watch(authProvider).currentUser;
final playlistsBox = HiveService.playlistsBox;
// Filter playlists assigned to current user (or all if admin)
final availablePlaylists = playlistsBox.values.where((playlist) {
if (currentUser == null) return false;
if (currentUser.isAdmin) return playlist.isActive;
return currentUser.assignedPlaylistIds.contains(playlist.id) &&
playlist.isActive;
}).toList();
return Scaffold(
appBar: AppBar(
title: Text(
'Select Playlist',
style: GoogleFonts.roboto(fontWeight: FontWeight.w600),
),
actions: [
if (currentUser?.isAdmin ?? false)
IconButton(
icon: const Icon(Icons.admin_panel_settings),
onPressed: () => context.go('/admin'),
tooltip: 'Admin Panel',
),
IconButton(
icon: const Icon(Icons.logout),
onPressed: () {
ref.read(authProvider.notifier).logout();
context.go('/login');
},
tooltip: 'Logout',
),
],
),
body: availablePlaylists.isEmpty
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.playlist_remove,
size: 64,
color: Colors.grey.shade400,
),
const SizedBox(height: 16),
Text(
'No playlists available',
style: GoogleFonts.roboto(
fontSize: 18,
color: Colors.grey.shade600,
),
),
const SizedBox(height: 8),
Text(
currentUser?.isAdmin ?? false
? 'Add playlists in Admin Panel'
: 'Contact administrator',
style: GoogleFonts.roboto(
fontSize: 14,
color: Colors.grey.shade500,
),
),
],
),
)
: GridView.builder(
padding: const EdgeInsets.all(16),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
childAspectRatio: 1.5,
),
itemCount: availablePlaylists.length,
itemBuilder: (context, index) {
final playlist = availablePlaylists[index];
return _PlaylistCard(
playlist: playlist,
onTap: () {
context.go('/dashboard', extra: playlist);
},
);
},
),
);
}
}
class _PlaylistCard extends StatelessWidget {
final dynamic playlist;
final VoidCallback onTap;
const _PlaylistCard({
required this.playlist,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return Card(
elevation: 4,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: InkWell(
onTap: onTap,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Colors.blue.shade700,
Colors.blue.shade900,
],
),
),
padding: const EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
Icons.playlist_play,
size: 48,
color: Colors.white.withOpacity(0.9),
),
const SizedBox(height: 12),
Text(
playlist.name,
style: GoogleFonts.roboto(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Text(
Uri.parse(playlist.dns).host,
style: GoogleFonts.roboto(
fontSize: 12,
color: Colors.white.withOpacity(0.7),
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
);
}
}
@@ -0,0 +1,293 @@
import 'package:flutter/material.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart';
import 'package:google_fonts/google_fonts.dart';
class VideoPlayerScreen extends StatefulWidget {
final String streamUrl;
final String title;
final String? posterUrl;
const VideoPlayerScreen({
super.key,
required this.streamUrl,
required this.title,
this.posterUrl,
});
@override
State<VideoPlayerScreen> createState() => _VideoPlayerScreenState();
}
class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
late final Player _player;
late final VideoController _controller;
bool _isFullscreen = false;
bool _showControls = true;
@override
void initState() {
super.initState();
// Initialize media_kit player
_player = Player();
_controller = VideoController(_player);
// Load stream
_player.open(Media(widget.streamUrl));
_player.play();
}
@override
void dispose() {
_player.dispose();
super.dispose();
}
void _toggleFullscreen() {
setState(() {
_isFullscreen = !_isFullscreen;
});
}
void _toggleControls() {
setState(() {
_showControls = !_showControls;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: _isFullscreen
? null
: AppBar(
title: Text(
widget.title,
style: GoogleFonts.roboto(fontWeight: FontWeight.w600),
),
backgroundColor: Colors.black,
foregroundColor: Colors.white,
),
body: GestureDetector(
onTap: _toggleControls,
child: Stack(
children: [
// Video display
Center(
child: Video(
controller: _controller,
controls: NoVideoControls,
),
),
// Custom controls overlay
if (_showControls)
Positioned.fill(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.black54,
Colors.transparent,
Colors.transparent,
Colors.black87,
],
stops: const [0.0, 0.2, 0.7, 1.0],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// Top bar with title
if (!_isFullscreen)
const SizedBox.shrink()
else
SafeArea(
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
SafeArea(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Progress bar
StreamBuilder<Duration>(
stream: _player.stream.position,
builder: (context, positionSnapshot) {
return StreamBuilder<Duration>(
stream: _player.stream.duration,
builder: (context, durationSnapshot) {
final position = positionSnapshot.data ?? Duration.zero;
final duration = durationSnapshot.data ?? Duration.zero;
final progress = duration.inMilliseconds > 0
? position.inMilliseconds / duration.inMilliseconds
: 0.0;
return Column(
children: [
LinearProgressIndicator(
value: progress.clamp(0.0, 1.0),
backgroundColor: Colors.white24,
valueColor: const AlwaysStoppedAnimation<Color>(
Colors.red,
),
),
const SizedBox(height: 8),
if (duration.inSeconds > 0)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
_formatDuration(position),
style: const TextStyle(
color: Colors.white,
fontSize: 12,
),
),
Text(
_formatDuration(duration),
style: const TextStyle(
color: Colors.white,
fontSize: 12,
),
),
],
),
],
);
},
);
},
),
const SizedBox(height: 16),
// Playback controls
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Rewind
IconButton(
icon: const Icon(Icons.replay_10, size: 32),
color: Colors.white,
onPressed: () {
final currentPos = _player.state.position;
_player.seek(currentPos - const Duration(seconds: 10));
},
),
const SizedBox(width: 24),
// Play/Pause
StreamBuilder<bool>(
stream: _player.stream.playing,
builder: (context, snapshot) {
final isPlaying = snapshot.data ?? false;
return IconButton(
icon: Icon(
isPlaying ? Icons.pause : Icons.play_arrow,
size: 48,
),
color: Colors.white,
onPressed: () {
_player.playOrPause();
},
);
},
),
const SizedBox(width: 24),
// Forward
IconButton(
icon: const Icon(Icons.forward_10, size: 32),
color: Colors.white,
onPressed: () {
final currentPos = _player.state.position;
_player.seek(currentPos + const Duration(seconds: 10));
},
),
const Spacer(),
// Fullscreen toggle
IconButton(
icon: Icon(
_isFullscreen
? Icons.fullscreen_exit
: Icons.fullscreen,
size: 32,
),
color: Colors.white,
onPressed: _toggleFullscreen,
),
],
),
],
),
),
),
],
),
),
),
// Loading indicator
StreamBuilder<bool>(
stream: _player.stream.buffering,
builder: (context, snapshot) {
final isBuffering = snapshot.data ?? false;
if (!isBuffering) return const SizedBox.shrink();
return const Center(
child: CircularProgressIndicator(
color: Colors.red,
strokeWidth: 3,
),
);
},
),
],
),
),
);
}
String _formatDuration(Duration duration) {
String twoDigits(int n) => n.toString().padLeft(2, '0');
final hours = duration.inHours;
final minutes = duration.inMinutes.remainder(60);
final seconds = duration.inSeconds.remainder(60);
if (hours > 0) {
return '$hours:${twoDigits(minutes)}:${twoDigits(seconds)}';
}
return '${twoDigits(minutes)}:${twoDigits(seconds)}';
}
}