Files
xtremobile/lib/features/iptv/screens/mobile_dashboard_screen.dart
T
GitHub CopilotandClaude Haiku 4.5 93b8e5b337 perf(critical): Implement P0 optimization fixes - TiviMate parity
CRITICAL FIXES:
- P0-1: Fix EPG N+1 query storm with batch loading
  * Implement XtreamServiceMobile with getBatchEPG() method
  * Batch load EPG data instead of per-channel requests
  * Reduce 50-200 concurrent requests to 1 request per category
  * Add EPG cache with 1-hour TTL to prevent redundant calls

- P0-2: Remove destructive cache clearing on startup
  * Implement TTL-based cache invalidation
  * Preserve cache between app launches (6h channels, 1h EPG, 30m search)
  * Add HiveService.invalidateExpiredCache() method
  * Expected: -80% startup time on cold launches

- P0-3: Preserve tab state with IndexedStack
  * Replace switch statement with IndexedStack
  * Keep all tabs alive in widget tree
  * Preserve scroll position, search state, filters across tab switches
  * Expected: instant tab switching (<100ms)

HIGH PRIORITY FIXES:
- P1-1: Debounce search input (500ms)
  * Prevent per-keystroke full rebuilds
  * Add search debounce timer

- P1-3: Fix double FocusNode disposal crash
  * Remove duplicate focus node disposal in native_player_screen.dart
  * Prevents StateError on player exit

Expected impact: -75-80% perceived latency, instant tab switching, no OOM on startup.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-25 22:31:36 +01:00

70 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/models/playlist_config.dart';
import '../../../widgets/mobile_scaffold.dart';
import '../../../theme/mobile_theme.dart';
import '../widgets/mobile_live_tv_tab.dart';
import '../widgets/mobile_movies_tab.dart';
import '../widgets/mobile_series_tab.dart';
import '../widgets/mobile_settings_tab.dart';
import '../../../providers/mobile_xtream_providers.dart';
class MobileDashboardScreen extends ConsumerStatefulWidget {
final PlaylistConfig playlist;
const MobileDashboardScreen({
super.key,
required this.playlist,
});
@override
ConsumerState<MobileDashboardScreen> createState() =>
_MobileDashboardScreenState();
}
class _MobileDashboardScreenState extends ConsumerState<MobileDashboardScreen> {
@override
Widget build(BuildContext context) {
final currentIndex = ref.watch(mobileDashboardIndexProvider);
// [P0-3 FIX] Use IndexedStack to preserve tab state and scroll position
// Instead of destroying/recreating tabs on each switch, keep all tabs alive in memory
// 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,
child: MobileScaffold(
currentIndex: currentIndex,
onIndexChanged: (index) {
ref.read(mobileDashboardIndexProvider.notifier).state = index;
},
child: IndexedStack(
index: currentIndex,
children: [
// Tab 0: Live TV - stays alive to preserve channel list scroll position
MobileLiveTVTab(
key: const PageStorageKey('live_tv_tab'),
playlist: widget.playlist,
),
// Tab 1: Movies - stays alive to preserve search and filter state
MobileMoviesTab(
key: const PageStorageKey('movies_tab'),
playlist: widget.playlist,
),
// Tab 2: Series - stays alive to preserve series browsing state
MobileSeriesTab(
key: const PageStorageKey('series_tab'),
playlist: widget.playlist,
),
// Tab 3: Settings - stays alive to preserve settings scroll position
const MobileSettingsTab(
key: PageStorageKey('settings_tab'),
),
],
),
),
);
}
}