Files
iptv-ren/lib/screens/player_screen.dart
renato97 5351513619 v1.1.2: Channel name formatting and Live TV search optimization
## New Features

### lib/utils/channel_name_formatter.dart (NEW)
- Created new utility class for formatting channel names
- Removes quality tokens (SD, HD, FHD, UHD, 4K, 8K, HDR, HEVC, H264, H265, FULLHD)
- Strips prefixes before pipe character (e.g., "AR | Channel" → "Channel")
- Removes leading dashes, colons, and other separators
- Implements caching mechanism (max 50,000 entries) for performance
- Normalizes tokens by removing non-alphanumeric characters

## UI/UX Improvements

### lib/screens/home_screen.dart
- **Live TV Memory Optimization**: Live streams list now persists in memory while app is running
  - Prevents unnecessary reloads when navigating back to Live TV
  - Improves performance and reduces API calls
- **Search Bar Visibility**: Hidden search bar for Live TV content type
  - Search only shown for Movies and Series
  - Cleaner UI for Live TV browsing
- **Channel Name Display**: Applied ChannelNameFormatter to channel cards
  - Removes quality indicators from displayed names
  - Better text styling with centered alignment
  - Increased font weight (w500 → w600)
  - Improved line height (1.15) for better readability
  - Text alignment changed to center
  - Better overflow handling with ellipsis

### lib/screens/player_screen.dart
- Code cleanup and optimization
- Removed unused imports/statements (9 lines removed)

## Technical Details

### Performance
- Channel name caching reduces string processing overhead
- Live TV list persistence reduces API calls
- Memory-efficient cache with automatic cleanup

### Code Quality
- Separation of concerns with new utility class
- Consistent formatting across channel names
- Better memory management for large channel lists

## Statistics
- 3 files changed
- +141 insertions, -68 deletions
- Net: +73 lines
- New file: lib/utils/channel_name_formatter.dart

## Breaking Changes
None - all changes are additive or UI improvements
2026-02-26 00:28:03 -03:00

154 lines
4.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
import '../models/xtream_models.dart';
class PlayerScreen extends StatefulWidget {
final XtreamStream stream;
final bool isLive;
const PlayerScreen({super.key, required this.stream, this.isLive = true});
@override
State<PlayerScreen> createState() => _PlayerScreenState();
}
class _PlayerScreenState extends State<PlayerScreen> {
VideoPlayerController? _videoController;
ChewieController? _chewieController;
bool _isLoading = true;
String? _error;
@override
void initState() {
super.initState();
_initPlayer();
}
Future<void> _initPlayer() async {
try {
_chewieController?.dispose();
_chewieController = null;
await _videoController?.dispose();
_videoController = null;
final url = widget.stream.url;
if (url == null || url.isEmpty) {
throw Exception('No stream URL available');
}
final videoController = VideoPlayerController.networkUrl(
Uri.parse(url),
videoPlayerOptions: VideoPlayerOptions(
allowBackgroundPlayback: false,
mixWithOthers: false,
),
);
await videoController.initialize();
_videoController = videoController;
_chewieController = ChewieController(
videoPlayerController: videoController,
autoPlay: true,
looping: widget.isLive,
aspectRatio: videoController.value.aspectRatio,
allowFullScreen: true,
allowMuting: true,
showControls: true,
placeholder: Container(
color: Colors.black,
child: const Center(
child: CircularProgressIndicator(color: Colors.red),
),
),
errorBuilder: (context, errorMessage) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error, color: Colors.red, size: 48),
const SizedBox(height: 16),
Text(
errorMessage,
style: const TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
],
),
);
},
);
setState(() {
_isLoading = false;
});
} catch (e) {
setState(() {
_error = e.toString();
_isLoading = false;
});
}
}
@override
void dispose() {
_videoController?.dispose();
_chewieController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Center(
child: _isLoading
? const CircularProgressIndicator(color: Colors.red)
: _error != null
? _buildError()
: _chewieController != null
? Chewie(controller: _chewieController!)
: const Text(
'No video available',
style: TextStyle(color: Colors.white),
),
),
);
}
Widget _buildError() {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, color: Colors.red, size: 64),
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.all(16),
child: Text(
_error ?? 'Unknown error',
style: const TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
),
const SizedBox(height: 24),
ElevatedButton.icon(
onPressed: () {
setState(() {
_isLoading = true;
_error = null;
});
_initPlayer();
},
icon: const Icon(Icons.refresh),
label: const Text('Retry'),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
),
],
);
}
}