feat: Add mobile-specific Riverpod providers for Xtream service, live TV, movies, series, and EPG data, along with UI state management.

This commit is contained in:
Michael committed 2026-03-27 13:34:06 +01:00
1 parent f85f43e42f
commit e1a0802a0c
18 files changed
+1619 -574

No files matched your search

@@ -33,7 +33,7 @@ class _MobileDashboardScreenState extends ConsumerState<MobileDashboardScreen> {
// This enables instant tab switching and preserves user scroll position, search state, etc.
// The AutomaticKeepAliveClientMixin in each tab will keep them in the widget tree
return Theme(
data: MobileTheme.darkTheme,
data: MobileTheme.themeOf(context),
child: MobileScaffold(
currentIndex: currentIndex,
onIndexChanged: (index) {
@@ -388,14 +388,11 @@ class _MobilePlaylistScreenState extends ConsumerState<MobilePlaylistScreen> {
final playlistsAsync = ref.watch(localPlaylistsProvider);
return Theme(
data: MobileTheme.darkTheme,
data: MobileTheme.themeOf(context),
child: Scaffold(
backgroundColor: AppColors.background,
appBar: AppBar(
title: const Text('XtremFlow'),
centerTitle: true,
backgroundColor: AppColors.background,
elevation: 0,
),
body: playlistsAsync.when(
loading: () => const Center(
@@ -203,7 +203,7 @@ class _MobilePlaylistSelectionScreenState
final playlistsAsync = ref.watch(playlistsProvider);
return Theme(
data: MobileTheme.darkTheme,
data: MobileTheme.themeOf(context),
child: Scaffold(
extendBodyBehindAppBar: true, // For gradient
appBar: AppBar(
@@ -132,7 +132,7 @@ class XtreamServiceMobile {
return batch[streamId] ??
model.ShortEPG(
id: streamId,
title: 'No Program',
title: '',
start: DateTime.now().toIso8601String(),
end: DateTime.now().add(const Duration(hours: 1)).toIso8601String(),
);
@@ -178,60 +178,71 @@ class XtreamServiceMobile {
}
}
/// Internal: Load EPG batch from API
/// Internal: Load EPG for a single stream
/// NOTE: Xtream API get_short_epg only returns results for ONE stream_id at a time.
/// Response format: {"epg_listings": [...]} where title/description are Base64 encoded.
Future<Map<String, model.ShortEPG>> _loadEpgBatch(
List<String> streamIds,
String cacheKey,
) async {
try {
final result = <String, model.ShortEPG>{};
final result = <String, model.ShortEPG>{};
// Join stream IDs for API call
final streamIdParam = streamIds.join(',');
// Load EPG for each stream_id individually (API doesn't support true batch)
for (final streamId in streamIds) {
try {
final response = await _dio.get(
'$_baseUrl/player_api.php',
queryParameters: {
'username': _username,
'password': _password,
'action': 'get_short_epg',
'stream_id': streamId,
},
options: Options(
receiveTimeout: const Duration(seconds: 10),
sendTimeout: const Duration(seconds: 10),
),
).timeout(const Duration(seconds: 10));
final response = await _dio.get(
'$_baseUrl/player_api.php',
queryParameters: {
'username': _username,
'password': _password,
'action': 'get_short_epg',
'stream_id': streamIdParam,
},
options: Options(
receiveTimeout: const Duration(seconds: 20),
sendTimeout: const Duration(seconds: 20),
),
);
if (response.statusCode == 200 && response.data is Map) {
final data = response.data as Map;
final listings = data['epg_listings'];
if (response.statusCode == 200 && response.data is List) {
final items = (response.data as List);
if (listings is List && listings.isNotEmpty) {
// Find the currently airing program
final now = DateTime.now();
Map<String, dynamic>? current;
for (var item in items) {
if (item is Map && item.containsKey('stream_id')) {
final streamId = item['stream_id'].toString();
// Assuming the API returns a list of EPG entries for this stream
if (item['epg_listings'] is List &&
(item['epg_listings'] as List).isNotEmpty) {
final epgJson = (item['epg_listings'] as List).first;
result[streamId] = model.ShortEPG.fromJson({
...epgJson,
'id': streamId,
});
for (final item in listings) {
if (item is! Map) continue;
try {
final start = DateTime.parse(item['start'].toString());
final end = DateTime.parse(item['end'].toString());
if (now.isAfter(start) && now.isBefore(end)) {
current = Map<String, dynamic>.from(item);
break;
}
} catch (_) {}
}
// Fallback to first entry if no current program found
current ??= Map<String, dynamic>.from(listings.first as Map);
result[streamId] = model.ShortEPG.fromJson({
...current,
'id': streamId,
});
}
}
if (kDebugMode) {
print(
'✅ Loaded EPG for ${result.length}/${streamIds.length} channels');
}
} catch (e) {
if (kDebugMode) print('⚠️ EPG failed for $streamId: $e');
}
return result;
} catch (e) {
if (kDebugMode) print('❌ Error loading EPG batch: $e');
return {};
}
if (kDebugMode) {
print('✅ EPG loaded: ${result.length}/${streamIds.length} channels');
}
return result;
}
/// Get live TV categories
+348 -253
View File
@@ -9,11 +9,12 @@ import 'package:xtremobile/mobile/providers/mobile_settings_providers.dart';
import 'package:xtremobile/features/iptv/screens/native_player_screen.dart';
import 'package:xtremobile/core/models/iptv_models.dart';
import 'package:xtremobile/core/models/playlist_config.dart';
import 'package:xtremobile/core/theme/app_colors.dart';
import 'package:xtremobile/core/theme/app_decorations.dart';
import 'package:xtremobile/mobile/widgets/tv_focusable.dart';
import 'package:xtremobile/features/iptv/screens/lite_player_screen.dart';
import 'package:flutter/services.dart';
import 'package:xtremobile/core/services/ip_service.dart';
import 'package:xtremobile/core/models/iptv_models.dart' as model;
class MobileLiveTVTab extends ConsumerStatefulWidget {
final PlaylistConfig playlist;
@@ -33,6 +34,8 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
bool _justReturnedFromPlayer =
false; // Flag to prevent PopScope interception after player
Timer? _searchTimer;
@override
void initState() {
super.initState();
@@ -54,8 +57,6 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
});
}
Timer? _searchTimer;
@override
void dispose() {
_searchController.dispose();
@@ -70,15 +71,21 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
@override
Widget build(BuildContext context) {
super.build(context);
final channelsAsync =
ref.watch(mobileLiveChannelsProvider(widget.playlist));
final favorites = ref.watch(mobileFavoritesProvider);
// Phase 1: always watch categories (fast, ~1 second)
final categoriesAsync =
ref.watch(mobileLiveCategoriesProvider(widget.playlist));
final settings = ref.watch(mobileSettingsProvider);
final uiState = ref.watch(mobileLiveTvUiStateProvider);
final uiNotifier = ref.read(mobileLiveTvUiStateProvider.notifier);
// Determine if we should show the category grid
final bool showGrid = uiState.isCategoryView &&
_searchQuery.isEmpty &&
!_showFavoritesOnly;
return Container(
decoration: const BoxDecoration(gradient: AppColors.appleTvGradient),
decoration: AppDecorations.background(context),
child: Scaffold(
backgroundColor: Colors.transparent,
body: PopScope(
@@ -141,7 +148,7 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
}
}
},
child: channelsAsync.when(
child: categoriesAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (e, s) => Center(
child: Padding(
@@ -153,55 +160,36 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
),
),
),
data: (groupedChannels) {
// Prepare categories
var categories =
groupedChannels.map((c) => c.categoryName).toSet().toList();
data: (allCategories) {
// Apply keyword filter and smart geo-sort on categories
List<model.Category> categories;
if (settings.liveTvKeywords.isNotEmpty) {
categories = categories
.where((cat) => settings.matchesLiveTvFilter(cat))
categories = allCategories
.where(
(cat) => settings.matchesLiveTvFilter(cat.categoryName),)
.toList();
categories.sort();
categories.sort(
(a, b) => a.categoryName.compareTo(b.categoryName),
);
} else {
// Smart Sort (GeoIP)
final userCountry = IpService().country;
categories = List.of(allCategories);
categories.sort((a, b) {
if (userCountry != null) {
final aMatches =
a.toLowerCase().contains(userCountry.toLowerCase());
final bMatches =
b.toLowerCase().contains(userCountry.toLowerCase());
final aMatches = a.categoryName
.toLowerCase()
.contains(userCountry.toLowerCase());
final bMatches = b.categoryName
.toLowerCase()
.contains(userCountry.toLowerCase());
if (aMatches && !bMatches) return -1;
if (!aMatches && bMatches) return 1;
}
return a.compareTo(b);
return a.categoryName.compareTo(b.categoryName);
});
}
// Prepare channels
List<Channel> displayedChannels = [];
// Determine mode based on search/favorites/selection
bool showGrid = uiState.isCategoryView &&
_searchQuery.isEmpty &&
!_showFavoritesOnly;
if (!showGrid) {
if (_searchQuery.isNotEmpty) {
displayedChannels = groupedChannels
.where((c) => c.name.toLowerCase().contains(_searchQuery))
.toList();
} else if (_showFavoritesOnly) {
displayedChannels = groupedChannels
.where((c) => favorites.contains(c.streamId))
.toList();
} else if (uiState.selectedCategory != null) {
displayedChannels = groupedChannels
.where((c) => c.categoryName == uiState.selectedCategory)
.toList();
}
}
return SafeArea(
bottom: false,
child: Column(
@@ -230,37 +218,31 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
borderRadius: BorderRadius.circular(12),
child: Container(
height: 48,
decoration: BoxDecoration(
color: AppColors.surface,
borderRadius: BorderRadius.circular(12),
// Removed internal editing border here to prevent conflict and "inside frame" look
),
decoration: AppDecorations.searchBar(context),
padding:
const EdgeInsets.symmetric(horizontal: 12),
child: Row(
children: [
const Icon(
Icon(
Icons.search,
color: AppColors.textSecondary,
color: AppDecorations.textSecondary(context),
),
const SizedBox(width: 8),
Expanded(
child: ExcludeFocus(
excluding: !_isSearchEditing,
child: TextField(
cursorColor:
Colors.white, // Extra safety
cursorColor: Colors.white,
controller: _searchController,
focusNode: _searchFocusNode,
readOnly: !_isSearchEditing,
style: const TextStyle(
color: AppColors.textPrimary,
style: TextStyle(
color: AppDecorations.textPrimary(context),
),
decoration: const InputDecoration(
hintText: 'Rechercher une chaîne...',
border: InputBorder.none,
focusedBorder: InputBorder
.none, // Explicitly remove focus border
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
isDense: true,
),
@@ -273,9 +255,9 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
if (_searchQuery.isNotEmpty)
GestureDetector(
onTap: () => _searchController.clear(),
child: const Icon(
child: Icon(
Icons.close,
color: AppColors.textSecondary,
color: AppDecorations.textSecondary(context),
),
),
],
@@ -292,9 +274,9 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
_showFavoritesOnly ||
_searchQuery.isNotEmpty) ...[
IconButton(
icon: const Icon(
icon: Icon(
Icons.arrow_back,
color: AppColors.textPrimary,
color: AppDecorations.textPrimary(context),
),
onPressed: () {
if (_searchQuery.isNotEmpty) {
@@ -324,8 +306,8 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
? 'Catégories'
: uiState.selectedCategory ??
'Chaînes',
style: const TextStyle(
color: AppColors.textPrimary,
style: TextStyle(
color: AppDecorations.textPrimary(context),
fontWeight: FontWeight.bold,
fontSize: 18,
),
@@ -338,8 +320,8 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
? Icons.favorite
: Icons.favorite_border,
color: _showFavoritesOnly
? AppColors.error
: AppColors.textSecondary,
? const Color(0xFFFF453A)
: AppDecorations.textSecondary(context),
),
onPressed: () => setState(() {
_showFavoritesOnly = !_showFavoritesOnly;
@@ -348,7 +330,7 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
uiNotifier.state =
uiState.copyWith(isCategoryView: false);
}
// If exiting favorites, default depends on logic (here back to category grid if was previously)
// If exiting favorites, default back to category grid
if (!_showFavoritesOnly) {
uiNotifier.state =
uiState.copyWith(isCategoryView: true);
@@ -364,8 +346,21 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
// Main Content
Expanded(
child: showGrid
? _buildCategoryGrid(categories)
: _buildChannelList(displayedChannels),
? _buildCategoryGrid(categories, uiNotifier, uiState)
: _ChannelListView(
playlist: widget.playlist,
uiState: uiState,
searchQuery: _searchQuery,
showFavoritesOnly: _showFavoritesOnly,
onPlay: (channel, channels, index) =>
_playChannel(
context,
channel,
channels,
widget.playlist,
index,
),
),
),
],
),
@@ -377,12 +372,16 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
);
}
Widget _buildCategoryGrid(List<String> categories) {
Widget _buildCategoryGrid(
List<model.Category> categories,
StateController<LiveTvUiState> uiNotifier,
LiveTvUiState uiState,
) {
if (categories.isEmpty) {
return Center(
child: Text(
'Aucune catégorie trouvée',
style: GoogleFonts.inter(color: AppColors.textSecondary),
style: GoogleFonts.inter(color: AppDecorations.textSecondary(context)),
),
);
}
@@ -400,93 +399,64 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
final category = categories[index];
return TVFocusable(
onPressed: () {
ref.read(mobileLiveTvUiStateProvider.notifier).state =
LiveTvUiState(
selectedCategory: category,
uiNotifier.state = LiveTvUiState(
selectedCategory: category.categoryName,
selectedCategoryId: category.categoryId,
isCategoryView: false,
);
},
borderRadius: BorderRadius.circular(16),
child: Container(
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xFF4A4A4C), // Lighter grey top
Color(0xFF2C2C2E), // Medium grey bottom
],
child: Stack(
children: [
// Base gradient (theme-aware)
Container(decoration: AppDecorations.glossyCard(context)),
// Glossy highlight overlay (top shimmer)
Positioned(
top: 0,
left: 0,
right: 0,
height: 60,
child: Container(
decoration: AppDecorations.glossShimmer(context),
),
),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Colors.white.withOpacity(0.05)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
blurRadius: 8,
offset: const Offset(0, 4),
// Content (icon + text) — Positioned.fill ensures Column fills the card
Positioned.fill(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Icon(
Icons.live_tv_rounded,
color: Color(0xFF0A84FF),
size: 36,
),
const SizedBox(height: 10),
Text(
category.categoryName,
style: TextStyle(
color: AppDecorations.textPrimary(context),
fontWeight: FontWeight.w600,
fontSize: 13,
letterSpacing: 0.2,
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
],
),
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.tv,
color: AppColors.primary,
size: 32,
),
const SizedBox(height: 12),
Text(
category,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14,
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
), // closes Positioned.fill
],
),
);
},
);
}
Widget _buildChannelList(List<Channel> channels) {
if (channels.isEmpty) {
return Center(
child: Text(
'Aucune chaîne trouvée',
style: GoogleFonts.inter(color: AppColors.textSecondary),
),
);
}
return GridView.builder(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 80),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 6,
childAspectRatio: 0.85,
crossAxisSpacing: 12,
mainAxisSpacing: 12,
),
itemCount: channels.length,
itemBuilder: (context, index) {
final channel = channels[index];
return _MobileChannelCard(
channel: channel,
playlist: widget.playlist,
onTap: () =>
_playChannel(context, channel, channels, widget.playlist, index),
);
},
);
}
void _playChannel(
BuildContext context,
Channel channel,
@@ -538,6 +508,122 @@ class _MobileLiveTVTabState extends ConsumerState<MobileLiveTVTab>
}
}
/// Phase 2 widget: loads channels for the selected category (or handles search/favorites)
class _ChannelListView extends ConsumerWidget {
final PlaylistConfig playlist;
final LiveTvUiState uiState;
final String searchQuery;
final bool showFavoritesOnly;
final void Function(Channel, List<Channel>, int) onPlay;
const _ChannelListView({
required this.playlist,
required this.uiState,
required this.searchQuery,
required this.showFavoritesOnly,
required this.onPlay,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final favorites = ref.watch(mobileFavoritesProvider);
// Determine which category to fetch channels for
final categoryId = uiState.selectedCategoryId;
if (categoryId == null && !showFavoritesOnly && searchQuery.isEmpty) {
// No category selected and no filter → go back to categories
return Center(
child: Text(
'Aucune catégorie sélectionnée',
style: GoogleFonts.inter(color: AppDecorations.textSecondary(context)),
),
);
}
// Phase 2: load channels for selected category
final channelsAsync = categoryId != null
? ref.watch(
mobileLiveChannelsByCategoryProvider((playlist, categoryId)),)
: null;
if (channelsAsync == null) {
// Favorites or search without category: need channels — show loading
// For favorites/search without a category, we can't load without a categoryId.
// Show a message directing user to select a category first.
return Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Text(
showFavoritesOnly
? 'Sélectionnez une catégorie pour voir vos favoris'
: 'Sélectionnez une catégorie pour rechercher',
style: GoogleFonts.inter(color: AppDecorations.textSecondary(context)),
textAlign: TextAlign.center,
),
),
);
}
return channelsAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (e, s) => Center(
child: Padding(
padding: const EdgeInsets.all(16),
child: Text(
'Erreur: $e',
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
),
),
),
data: (channels) {
// Apply search or favorites filter
List<Channel> displayedChannels;
if (searchQuery.isNotEmpty) {
displayedChannels = channels
.where((c) => c.name.toLowerCase().contains(searchQuery))
.toList();
} else if (showFavoritesOnly) {
displayedChannels = channels
.where((c) => favorites.contains(c.streamId))
.toList();
} else {
displayedChannels = channels;
}
if (displayedChannels.isEmpty) {
return Center(
child: Text(
'Aucune chaîne trouvée',
style: GoogleFonts.inter(color: AppDecorations.textSecondary(context)),
),
);
}
return GridView.builder(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 80),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 6,
childAspectRatio: 0.85,
crossAxisSpacing: 12,
mainAxisSpacing: 12,
),
itemCount: displayedChannels.length,
itemBuilder: (context, index) {
final channel = displayedChannels[index];
return _MobileChannelCard(
channel: channel,
playlist: playlist,
onTap: () => onPlay(channel, displayedChannels, index),
);
},
);
},
);
}
}
class _MobileChannelCard extends ConsumerStatefulWidget {
final Channel channel;
final VoidCallback onTap;
@@ -594,122 +680,131 @@ class _MobileChannelCardState extends ConsumerState<_MobileChannelCard> {
.read(mobileFavoritesProvider.notifier)
.toggle(widget.channel.streamId);
},
child: Container(
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xFF4A4A4C), // Lighter grey top
Color(0xFF2C2C2E), // Medium grey bottom
],
),
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Stack(
children: [
// Channel Logo
Expanded(
flex: 3,
// Base card (theme-aware)
Container(
decoration: AppDecorations.glossyCard(context, radius: 12),
),
// Glossy highlight overlay (top shimmer)
Positioned(
top: 0,
left: 0,
right: 0,
height: 50,
child: Container(
width: double.infinity,
decoration: const BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
),
child: Stack(
children: [
// Logo
// [P1-2 FIX] Optimize channel icon cache (40x40 display)
Center(
child: iconUrl != null
? CachedNetworkImage(
imageUrl: iconUrl,
fit: BoxFit.contain,
memCacheWidth: 50,
memCacheHeight: 50,
maxWidthDiskCache: 50,
maxHeightDiskCache: 50,
cacheManager: AppCacheManager.instance,
errorWidget: (_, __, ___) => const Icon(
Icons.tv,
color: Colors.white38,
size: 40,
decoration: AppDecorations.glossShimmer(context, radius: 12),
),
),
// Content
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Channel Logo
Expanded(
flex: 3,
child: Container(
width: double.infinity,
decoration: AppDecorations.channelCardBase(context),
child: Stack(
children: [
// Logo
// [P1-2 FIX] Optimize channel icon cache (40x40 display)
Center(
child: iconUrl != null
? CachedNetworkImage(
imageUrl: iconUrl,
fit: BoxFit.contain,
memCacheWidth: 50,
memCacheHeight: 50,
maxWidthDiskCache: 50,
maxHeightDiskCache: 50,
cacheManager: AppCacheManager.instance,
errorWidget: (_, __, ___) => Icon(
Icons.tv,
color: AppDecorations.iconMuted(context),
size: 40,
),
placeholder: (_, __) => Icon(
Icons.tv,
color: AppDecorations.iconMuted(context),
size: 40,
),
)
: Icon(
Icons.tv,
color: AppDecorations.iconMuted(context),
size: 40,
),
),
// Favorite badge
if (isFavorite)
Positioned(
top: 4,
right: 4,
child: Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(12),
),
placeholder: (_, __) => const Icon(
Icons.tv,
color: Colors.white24,
size: 40,
child: const Icon(
Icons.favorite,
color: Colors.white,
size: 12,
),
)
: const Icon(
Icons.tv,
color: Colors.white38,
size: 40,
),
),
// Favorite badge
if (isFavorite)
Positioned(
top: 4,
right: 4,
child: Container(
padding: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(12),
),
child: const Icon(
Icons.favorite,
color: Colors.white,
size: 12,
),
),
),
],
),
),
),
// Channel Name
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
widget.channel.name,
style: const TextStyle(
color: AppColors.textPrimary,
fontWeight: FontWeight.w500,
fontSize: 11,
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
],
),
if (_epgTitle != null) ...[
const SizedBox(height: 2),
Text(
_epgTitle!,
style: const TextStyle(
color: Colors.yellow,
fontSize: 9,
),
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
],
),
),
),
),
// Channel Name
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 4,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
widget.channel.name,
style: TextStyle(
color: AppDecorations.textPrimary(context),
fontWeight: FontWeight.w500,
fontSize: 11,
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
if (_epgTitle != null) ...[
const SizedBox(height: 2),
Text(
_epgTitle!,
style: const TextStyle(
color: Colors.yellow,
fontSize: 9,
),
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
],
),
),
),
],
), // end channel card content
],
),
),
);
), // end Stack
), // end ClipRRect
); // end TVFocusable
}
}
@@ -5,7 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:xtremobile/mobile/widgets/tv_focusable.dart';
import 'package:xtremobile/mobile/widgets/mobile_poster_card.dart';
import 'package:xtremobile/core/models/playlist_config.dart';
import 'package:xtremobile/core/theme/app_colors.dart';
import 'package:xtremobile/core/theme/app_decorations.dart';
import 'package:xtremobile/mobile/providers/mobile_settings_providers.dart';
import 'package:xtremobile/mobile/providers/mobile_xtream_providers.dart';
import 'package:xtremobile/core/models/iptv_models.dart' as model;
@@ -257,7 +257,7 @@ class _MobileMoviesTabState extends ConsumerState<MobileMoviesTab>
}
return Container(
decoration: const BoxDecoration(gradient: AppColors.appleTvGradient),
decoration: AppDecorations.background(context),
child: PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, _) async {
@@ -318,8 +318,8 @@ class _MobileMoviesTabState extends ConsumerState<MobileMoviesTab>
bottom: false,
child: RefreshIndicator(
onRefresh: _refresh,
color: AppColors.primary,
backgroundColor: AppColors.surface,
color: Theme.of(context).colorScheme.primary,
backgroundColor: Theme.of(context).colorScheme.surface,
child: CustomScrollView(
controller: _scrollController,
physics: const AlwaysScrollableScrollPhysics(),
@@ -371,30 +371,27 @@ class _MobileMoviesTabState extends ConsumerState<MobileMoviesTab>
borderRadius: BorderRadius.circular(12),
child: Container(
height: 40,
decoration: BoxDecoration(
color: AppColors.surface,
borderRadius: BorderRadius.circular(12),
),
decoration: AppDecorations.searchBar(context),
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
children: [
const Icon(
Icon(
Icons.search,
size: 20,
color: AppColors.textSecondary,
color: AppDecorations.textSecondary(context),
),
const SizedBox(width: 8),
Expanded(
child: ExcludeFocus(
excluding: !_isSearchEditing,
child: TextField(
cursorColor: Colors.white,
cursorColor: AppDecorations.textPrimary(context),
controller: _searchController,
focusNode: _searchFocusNode,
readOnly: !_isSearchEditing,
style: const TextStyle(
style: TextStyle(
fontSize: 14,
color: AppColors.textPrimary,
color: AppDecorations.textPrimary(context),
),
decoration: InputDecoration(
hintText: _selectedCategoryId != null
@@ -427,10 +424,10 @@ class _MobileMoviesTabState extends ConsumerState<MobileMoviesTab>
_searchController.clear();
_onSearchChanged('');
},
child: const Icon(
child: Icon(
Icons.close,
size: 16,
color: AppColors.textSecondary,
color: AppDecorations.textSecondary(context),
),
),
],
@@ -5,7 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:xtremobile/mobile/widgets/tv_focusable.dart';
import 'package:xtremobile/mobile/widgets/mobile_poster_card.dart';
import 'package:xtremobile/core/models/playlist_config.dart';
import 'package:xtremobile/core/theme/app_colors.dart';
import 'package:xtremobile/core/theme/app_decorations.dart';
import 'package:xtremobile/core/widgets/components/hero_carousel.dart';
import 'package:xtremobile/mobile/providers/mobile_settings_providers.dart';
import 'package:xtremobile/mobile/providers/mobile_xtream_providers.dart';
@@ -111,7 +111,7 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab>
// Add timeout to prevent infinite loading state
final newSeries = await service
.getSeriesPaginated()
.timeout(const Duration(seconds: 15));
.timeout(const Duration(seconds: 45));
if (mounted) {
setState(() {
@@ -214,7 +214,7 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab>
.toList();
return Container(
decoration: const BoxDecoration(gradient: AppColors.appleTvGradient),
decoration: AppDecorations.background(context),
child: PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, _) async {
@@ -268,8 +268,8 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab>
bottom: false,
child: RefreshIndicator(
onRefresh: _refresh,
color: AppColors.primary,
backgroundColor: AppColors.surface,
color: Theme.of(context).colorScheme.primary,
backgroundColor: Theme.of(context).colorScheme.surface,
child: CustomScrollView(
controller: _scrollController,
physics: const AlwaysScrollableScrollPhysics(),
@@ -315,31 +315,27 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab>
borderRadius: BorderRadius.circular(12),
child: Container(
height: 40,
decoration: BoxDecoration(
color: AppColors.surface,
borderRadius: BorderRadius.circular(12),
// Removed internal editing border here to prevent conflict and "inside frame" look
),
decoration: AppDecorations.searchBar(context),
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
children: [
const Icon(
Icon(
Icons.search,
size: 20,
color: AppColors.textSecondary,
color: AppDecorations.textSecondary(context),
),
const SizedBox(width: 8),
Expanded(
child: ExcludeFocus(
excluding: !_isSearchEditing,
child: TextField(
cursorColor: Colors.white, // Extra safety
cursorColor: AppDecorations.textPrimary(context),
controller: _searchController,
focusNode: _searchFocusNode,
readOnly: !_isSearchEditing,
style: const TextStyle(
style: TextStyle(
fontSize: 14,
color: AppColors.textPrimary,
color: AppDecorations.textPrimary(context),
),
decoration: const InputDecoration(
hintText: 'Rechercher une série...',
@@ -370,10 +366,10 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab>
_searchController.clear();
_onSearchChanged('');
},
child: const Icon(
child: Icon(
Icons.close,
size: 16,
color: AppColors.textSecondary,
color: AppDecorations.textSecondary(context),
),
),
],
@@ -419,6 +415,50 @@ class _MobileSeriesTabState extends ConsumerState<MobileSeriesTab>
child: Center(child: CircularProgressIndicator()),
),
),
if (!_isLoading && displaySeries.isEmpty)
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(48),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.video_library_outlined,
size: 64,
color: AppDecorations.textSecondary(context),
),
const SizedBox(height: 16),
Text(
'Aucune série chargée',
style: TextStyle(
color: AppDecorations.textPrimary(context),
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 8),
Text(
'Le chargement a pris trop de temps ou une erreur est survenue.',
textAlign: TextAlign.center,
style: TextStyle(
color: AppDecorations.textSecondary(context),
fontSize: 14,
),
),
const SizedBox(height: 24),
FilledButton.icon(
onPressed: () {
setState(() => _hasMore = true);
_loadMoreSeries();
},
icon: const Icon(Icons.refresh),
label: const Text('Réessayer'),
),
],
),
),
),
],
),
),
@@ -4,7 +4,8 @@ import 'package:google_fonts/google_fonts.dart';
// import 'package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_store.dart';
import 'package:xtremobile/mobile/providers/mobile_settings_providers.dart';
import 'package:xtremobile/mobile/widgets/tv_focusable.dart';
import 'package:xtremobile/core/theme/app_colors.dart';
import 'package:xtremobile/core/theme/app_decorations.dart';
import 'package:xtremobile/core/providers/theme_provider.dart';
import 'package:xtremobile/features/iptv/screens/mobile_playlist_selection_screen.dart';
/// Simplified mobile settings tab - optimized for TV remote control
@@ -79,9 +80,9 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
child: Image.asset(
'assets/images/logo_xtremobile.png',
fit: BoxFit.contain,
errorBuilder: (_, __, ___) => const Icon(
errorBuilder: (_, __, ___) => Icon(
Icons.play_circle_filled,
color: AppColors.primary,
color: Theme.of(context).colorScheme.primary,
size: 28,
),
),
@@ -95,14 +96,14 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
style: GoogleFonts.inter(
fontSize: 18,
fontWeight: FontWeight.bold,
color: AppColors.textPrimary,
color: AppDecorations.textPrimary(context),
),
),
Text(
'Version 1.5.1',
style: GoogleFonts.inter(
fontSize: 13,
color: AppColors.textSecondary,
color: AppDecorations.textSecondary(context),
),
),
],
@@ -113,6 +114,13 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
const SizedBox(height: 16),
// === APPARENCE ===
_buildSectionHeader('Apparence'),
_buildThemeSwitcher(),
const SizedBox(height: 8),
_buildSettingItem(
icon: Icons.access_time,
title: 'Afficher l\'heure',
@@ -304,6 +312,109 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
// === UI BUILDERS ===
Widget _buildThemeSwitcher() {
final themeState = ref.watch(themeProvider);
final notifier = ref.read(themeProvider.notifier);
final segments = [
(AppThemeMode.dark, Icons.dark_mode_rounded, 'Sombre'),
(AppThemeMode.light, Icons.light_mode_rounded, 'Clair'),
(AppThemeMode.system, Icons.brightness_auto_rounded, 'Système'),
];
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Icon(
Icons.brightness_6_rounded,
color: Theme.of(context).colorScheme.primary,
size: 24,
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Thème',
style: TextStyle(
color: AppDecorations.textPrimary(context),
fontWeight: FontWeight.w500,
fontSize: 15,
),
),
const SizedBox(height: 10),
// Segmented control
LayoutBuilder(
builder: (ctx, constraints) {
return Row(
children: segments.map((seg) {
final (mode, icon, label) = seg;
final selected = themeState.appThemeMode == mode;
final accentColor = Theme.of(context).colorScheme.primary;
return Expanded(
child: GestureDetector(
onTap: () => notifier.setThemeMode(mode),
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
margin: const EdgeInsets.symmetric(horizontal: 2),
padding: const EdgeInsets.symmetric(
vertical: 7,
),
decoration: BoxDecoration(
color: selected
? accentColor
: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
icon,
size: 16,
color: selected
? Colors.white
: AppDecorations.textSecondary(context),
),
const SizedBox(height: 3),
Text(
label,
style: TextStyle(
fontSize: 10,
fontWeight: selected
? FontWeight.w700
: FontWeight.w500,
color: selected
? Colors.white
: AppDecorations.textSecondary(context),
),
),
],
),
),
),
);
}).toList(),
);
},
),
],
),
),
],
),
),
);
}
Widget _buildSectionHeader(String title) {
return Padding(
padding: const EdgeInsets.only(left: 4, bottom: 8, top: 8),
@@ -312,7 +423,7 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
style: GoogleFonts.inter(
fontSize: 12,
fontWeight: FontWeight.w600,
color: AppColors.primary,
color: Theme.of(context).colorScheme.primary,
letterSpacing: 1.2,
),
),
@@ -334,12 +445,12 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
decoration: BoxDecoration(
color: AppColors.surface,
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Icon(icon, color: AppColors.primary, size: 24),
Icon(icon, color: Theme.of(context).colorScheme.primary, size: 24),
const SizedBox(width: 16),
Expanded(
child: Column(
@@ -347,8 +458,8 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
children: [
Text(
title,
style: const TextStyle(
color: AppColors.textPrimary,
style: TextStyle(
color: AppDecorations.textPrimary(context),
fontWeight: FontWeight.w500,
fontSize: 15,
),
@@ -356,8 +467,8 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
if (subtitle != null)
Text(
subtitle,
style: const TextStyle(
color: AppColors.textSecondary,
style: TextStyle(
color: AppDecorations.textSecondary(context),
fontSize: 12,
),
),
@@ -370,13 +481,13 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
vertical: 6,
),
decoration: BoxDecoration(
color: AppColors.primary.withOpacity(0.15),
color: Theme.of(context).colorScheme.primary.withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(8),
),
child: Text(
value,
style: const TextStyle(
color: AppColors.primary,
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
fontSize: 13,
),
@@ -413,12 +524,12 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
decoration: BoxDecoration(
color: AppColors.surface,
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Icon(icon, color: AppColors.primary, size: 24),
Icon(icon, color: Theme.of(context).colorScheme.primary, size: 24),
const SizedBox(width: 16),
Expanded(
child: Column(
@@ -426,8 +537,8 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
children: [
Text(
label,
style: const TextStyle(
color: AppColors.textPrimary,
style: TextStyle(
color: AppDecorations.textPrimary(context),
fontWeight: FontWeight.w500,
fontSize: 15,
),
@@ -436,8 +547,8 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
subtitle,
style: TextStyle(
color: hasFilters
? AppColors.primary
: AppColors.textSecondary,
? Theme.of(context).colorScheme.primary
: AppDecorations.textSecondary(context),
fontSize: 12,
fontWeight:
hasFilters ? FontWeight.w600 : FontWeight.normal,
@@ -448,7 +559,7 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
],
),
),
const Icon(Icons.edit, color: AppColors.textSecondary, size: 20),
Icon(Icons.edit, color: AppDecorations.textSecondary(context), size: 20),
],
),
),
@@ -466,20 +577,20 @@ class _MobileSettingsTabState extends ConsumerState<MobileSettingsTab> {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: AppColors.surface,
backgroundColor: Theme.of(ctx).colorScheme.surface,
title: Text(
'Filtres $label',
style: const TextStyle(color: AppColors.textPrimary),
style: TextStyle(color: AppDecorations.textPrimary(ctx)),
),
content: TextField(
controller: tempController,
autofocus: true,
style: const TextStyle(color: AppColors.textPrimary),
style: TextStyle(color: AppDecorations.textPrimary(ctx)),
decoration: InputDecoration(
hintText: 'Séparez par des virgules',
hintStyle: const TextStyle(color: AppColors.textSecondary),
hintStyle: TextStyle(color: AppDecorations.textSecondary(ctx)),
filled: true,
fillColor: AppColors.background,
fillColor: Theme.of(ctx).scaffoldBackgroundColor,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide.none,