mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-22 06:28:04 +02:00
feat: add IPTV player screen with basic controls and iframe integration for web playback.
This commit is contained in:
1 parent
ae404622ad
commit
985a46f777
4 files changed
+877
-1325
No files matched your search
@@ -12,9 +12,10 @@ import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/utils/responsive_layout.dart';
|
||||
import '../../../core/widgets/components/ui_components.dart';
|
||||
import '../../../core/widgets/themed_loading_screen.dart';
|
||||
import '../../../core/widgets/glass_container.dart';
|
||||
import '../../../core/widgets/tv_focusable_card.dart';
|
||||
import 'channel_card.dart';
|
||||
|
||||
/// Live TV tab - Apple TV Style with Horizontal Category Filter
|
||||
class LiveTVTab extends ConsumerStatefulWidget {
|
||||
final PlaylistConfig playlist;
|
||||
|
||||
@@ -27,25 +28,18 @@ class LiveTVTab extends ConsumerStatefulWidget {
|
||||
class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
|
||||
// State
|
||||
String? _selectedCategory;
|
||||
|
||||
// UI State
|
||||
bool _isGridView = true;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
bool _showFavoritesOnly = false;
|
||||
String _searchQuery = '';
|
||||
|
||||
// Scroll Controllers
|
||||
final ScrollController _mainScrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_searchController.addListener(() {
|
||||
setState(() {
|
||||
_searchQuery = _searchController.text.toLowerCase();
|
||||
});
|
||||
setState(() => _searchQuery = _searchController.text.toLowerCase());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,152 +65,151 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
backgroundColor: Colors.transparent,
|
||||
body: channelsAsync.when(
|
||||
loading: () => const ThemedLoading(),
|
||||
error: (e, s) => Center(child: Text('Error: $e')),
|
||||
error: (e, s) => Center(child: Text('Error: $e', style: const TextStyle(color: Colors.white))),
|
||||
data: (groupedChannels) {
|
||||
// Groups
|
||||
var categories = groupedChannels.keys.toList();
|
||||
if (settings.liveTvKeywords.isNotEmpty) {
|
||||
categories = categories.where((cat) => settings.matchesLiveTvFilter(cat)).toList();
|
||||
}
|
||||
categories.sort();
|
||||
|
||||
// Filter Logic
|
||||
List<Channel> displayedChannels = [];
|
||||
bool showingCategoryGrid = false;
|
||||
|
||||
if (_searchQuery.isNotEmpty) {
|
||||
// Global Search
|
||||
displayedChannels = groupedChannels.values.expand((l) => l)
|
||||
.where((c) => c.name.toLowerCase().contains(_searchQuery))
|
||||
.toList();
|
||||
} else if (_showFavoritesOnly) {
|
||||
// Favorites
|
||||
displayedChannels = groupedChannels.values.expand((l) => l)
|
||||
.where((c) => favorites.contains(c.streamId))
|
||||
.toList();
|
||||
} else if (_selectedCategory != null) {
|
||||
// Selected Category View
|
||||
displayedChannels = groupedChannels[_selectedCategory] ?? [];
|
||||
} else {
|
||||
// Category Grid View (Default)
|
||||
showingCategoryGrid = true;
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
// HEADER (Glass)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(24, 16, 24, 16),
|
||||
child: Row(
|
||||
children: [
|
||||
// Back Button (if in category view and not searching)
|
||||
if (_selectedCategory != null && _searchQuery.isEmpty && !_showFavoritesOnly) ...[
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_back, color: AppColors.textPrimary),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_selectedCategory = null;
|
||||
_mainScrollController.jumpTo(0);
|
||||
});
|
||||
},
|
||||
tooltip: 'Back to Categories',
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
|
||||
Text(
|
||||
_searchQuery.isNotEmpty ? 'Search Results' :
|
||||
_showFavoritesOnly ? 'Favorites' :
|
||||
_selectedCategory ?? 'Live TV',
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
|
||||
// Search Pill
|
||||
Container(
|
||||
width: 300,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusFull),
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.search, size: 20, color: AppColors.textSecondary),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
style: const TextStyle(fontSize: 14, color: Colors.white),
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Rechercher...',
|
||||
hintStyle: TextStyle(color: Colors.white54),
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
contentPadding: EdgeInsets.only(bottom: 11),
|
||||
),
|
||||
child: GlassContainer(
|
||||
borderRadius: 16,
|
||||
opacity: 0.6,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
if (_selectedCategory != null && _searchQuery.isEmpty && !_showFavoritesOnly) ...[
|
||||
TvFocusableCard(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedCategory = null;
|
||||
_mainScrollController.jumpTo(0);
|
||||
});
|
||||
},
|
||||
borderRadius: 50,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.arrow_back, color: Colors.white),
|
||||
),
|
||||
if (_searchQuery.isNotEmpty)
|
||||
GestureDetector(
|
||||
onTap: () => _searchController.clear(),
|
||||
child: const Icon(Icons.close, size: 16, color: AppColors.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Favorites Toggle
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
_showFavoritesOnly ? Icons.favorite : Icons.favorite_border,
|
||||
color: _showFavoritesOnly ? AppColors.error : AppColors.textSecondary,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_showFavoritesOnly = !_showFavoritesOnly;
|
||||
if (_showFavoritesOnly) _searchController.clear();
|
||||
_selectedCategory = null; // Reset selection when toggling favorites
|
||||
});
|
||||
},
|
||||
tooltip: 'Favorites Only',
|
||||
),
|
||||
|
||||
// View Toggle (Only show when not in category grid)
|
||||
if (!showingCategoryGrid)
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
_isGridView ? Icons.view_list : Icons.grid_view,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
onPressed: () => setState(() => _isGridView = !_isGridView),
|
||||
tooltip: 'Toggle View',
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
|
||||
Expanded(
|
||||
child: Text(
|
||||
_searchQuery.isNotEmpty ? 'Search Results' :
|
||||
_showFavoritesOnly ? 'Favorites' :
|
||||
_selectedCategory ?? 'Live TV',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// Search Bar
|
||||
Container(
|
||||
width: 250,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
style: GoogleFonts.inter(color: Colors.white),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search channels...',
|
||||
hintStyle: GoogleFonts.inter(color: Colors.white54),
|
||||
prefixIcon: const Icon(Icons.search, color: Colors.white54),
|
||||
border: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
suffixIcon: _searchQuery.isNotEmpty
|
||||
? IconButton(icon: const Icon(Icons.clear, color: Colors.white), onPressed: _searchController.clear)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// Favorites Toggle
|
||||
TvFocusableCard(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_showFavoritesOnly = !_showFavoritesOnly;
|
||||
if (_showFavoritesOnly) _searchController.clear();
|
||||
_selectedCategory = null;
|
||||
});
|
||||
},
|
||||
borderRadius: 12,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: _showFavoritesOnly ? AppColors.live.withOpacity(0.2) : Colors.white.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: _showFavoritesOnly ? Border.all(color: AppColors.live) : null,
|
||||
),
|
||||
child: Icon(
|
||||
_showFavoritesOnly ? Icons.favorite : Icons.favorite_border,
|
||||
color: _showFavoritesOnly ? AppColors.live : Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Content
|
||||
// GRID / LIST AREA
|
||||
Expanded(
|
||||
child: showingCategoryGrid
|
||||
? _buildCategoryGrid(categories, groupedChannels)
|
||||
: displayedChannels.isEmpty
|
||||
? Center(
|
||||
child: Text(
|
||||
_searchQuery.isNotEmpty ? 'No channels found' :
|
||||
_showFavoritesOnly ? 'No favorites' : 'No channels in this group',
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: AppColors.textSecondary),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.tv_off, size: 64, color: Colors.white.withOpacity(0.3)),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'No channels found',
|
||||
style: GoogleFonts.inter(color: Colors.white54, fontSize: 18),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: _isGridView
|
||||
? _buildChannelGrid(displayedChannels)
|
||||
: _buildChannelList(displayedChannels),
|
||||
// Use raw grid for now, but wrapped in focusable cards
|
||||
: _buildChannelGrid(displayedChannels),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -230,7 +223,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
context,
|
||||
mobile: 2,
|
||||
tablet: 3,
|
||||
desktop: 5,
|
||||
desktop: 4,
|
||||
);
|
||||
|
||||
return GridView.builder(
|
||||
@@ -238,73 +231,71 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
padding: const EdgeInsets.all(24),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: columns,
|
||||
mainAxisSpacing: 16,
|
||||
crossAxisSpacing: 16,
|
||||
childAspectRatio: 1.5,
|
||||
mainAxisSpacing: 24,
|
||||
crossAxisSpacing: 24,
|
||||
childAspectRatio: 1.6,
|
||||
),
|
||||
itemCount: categories.length,
|
||||
itemBuilder: (context, index) {
|
||||
final category = categories[index];
|
||||
final count = groupedChannels[category]?.length ?? 0;
|
||||
|
||||
return Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedCategory = category;
|
||||
_mainScrollController.jumpTo(0);
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.surfaceVariant,
|
||||
AppColors.surfaceVariant.withOpacity(0.8),
|
||||
],
|
||||
return TvFocusableCard(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedCategory = category;
|
||||
_mainScrollController.jumpTo(0);
|
||||
});
|
||||
},
|
||||
borderRadius: 16,
|
||||
child: GlassContainer(
|
||||
borderRadius: 16,
|
||||
opacity: 0.2, // Darker glass
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: Stack(
|
||||
children: [
|
||||
// Background Gradient
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Colors.white.withOpacity(0.05),
|
||||
Colors.blue.withOpacity(0.05),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
border: Border.all(color: Colors.white.withOpacity(0.2)),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.folder_open, color: AppColors.primary, size: 32),
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.folder_copy_outlined, color: Colors.white.withOpacity(0.9), size: 32),
|
||||
const SizedBox(height: 12),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
category,
|
||||
textAlign: TextAlign.center,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'$count Channels',
|
||||
style: GoogleFonts.inter(fontSize: 13, color: Colors.white54),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
category,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'$count Channels',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -317,7 +308,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
context,
|
||||
mobile: 2,
|
||||
tablet: 4,
|
||||
desktop: 6,
|
||||
desktop: 5,
|
||||
);
|
||||
|
||||
return GridView.builder(
|
||||
@@ -327,41 +318,65 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
crossAxisCount: columns,
|
||||
mainAxisSpacing: 16,
|
||||
crossAxisSpacing: 16,
|
||||
childAspectRatio: 1.3,
|
||||
childAspectRatio: 1.0, // Square-ish cards
|
||||
),
|
||||
itemCount: channels.length,
|
||||
itemBuilder: (context, index) {
|
||||
final channel = channels[index];
|
||||
return ChannelCard(
|
||||
streamId: channel.streamId,
|
||||
name: channel.name,
|
||||
iconUrl: _getProxiedIconUrl(channel.streamIcon),
|
||||
currentProgram: null,
|
||||
playlist: widget.playlist,
|
||||
return TvFocusableCard(
|
||||
onTap: () => _playChannel(channel, channels),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildChannelList(List<Channel> channels) {
|
||||
return ListView.separated(
|
||||
controller: _mainScrollController,
|
||||
padding: const EdgeInsets.fromLTRB(24, 0, 24, 24),
|
||||
itemCount: channels.length,
|
||||
separatorBuilder: (_, __) => const SizedBox(height: 8),
|
||||
itemBuilder: (context, index) {
|
||||
final channel = channels[index];
|
||||
return SizedBox(
|
||||
height: 70,
|
||||
child: ChannelCard(
|
||||
streamId: channel.streamId,
|
||||
name: channel.name,
|
||||
iconUrl: _getProxiedIconUrl(channel.streamIcon),
|
||||
height: 70,
|
||||
width: double.infinity,
|
||||
playlist: widget.playlist,
|
||||
onTap: () => _playChannel(channel, channels),
|
||||
borderRadius: 12,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceVariant,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Icon Area
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: channel.streamIcon.isNotEmpty
|
||||
? Image.network(
|
||||
_getProxiedIconUrl(channel.streamIcon)!,
|
||||
errorBuilder: (_,__,___) => const Icon(Icons.tv, color: Colors.grey, size: 40),
|
||||
)
|
||||
: Text(
|
||||
channel.name.characters.first.toUpperCase(),
|
||||
style: GoogleFonts.inter(fontSize: 40, fontWeight: FontWeight.bold, color: Colors.black12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Footer
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
color: Colors.black54,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
channel.name,
|
||||
style: GoogleFonts.inter(color: Colors.white, fontSize: 13, fontWeight: FontWeight.w500),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Text(
|
||||
'Channel #${channel.num}',
|
||||
style: GoogleFonts.inter(color: Colors.white54, fontSize: 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -377,7 +392,6 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
}
|
||||
|
||||
void _playChannel(Channel channel, List<Channel> contextList) {
|
||||
final index = contextList.indexOf(channel);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PlayerScreen(
|
||||
@@ -386,7 +400,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
|
||||
playlist: widget.playlist,
|
||||
streamType: StreamType.live,
|
||||
channels: contextList,
|
||||
initialIndex: index,
|
||||
initialIndex: contextList.indexOf(channel),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user