准备借助release版本定位首帧阻塞的问题来源
This commit is contained in:
+17
-19
@@ -12,11 +12,15 @@ import 'widgets/global_mini_player.dart';
|
|||||||
|
|
||||||
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════
|
// ⏱️ 全局计时器
|
||||||
// main: 只做 runApp,不做任何初始化
|
final stopwatch = Stopwatch();
|
||||||
// ═══════════════════════════════════════════════════
|
|
||||||
void main() {
|
void main() {
|
||||||
|
stopwatch.start();
|
||||||
|
debugPrint('⏱️ T0 main: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
debugPrint('⏱️ T0.5 ensureInitialized: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
MultiProvider(
|
MultiProvider(
|
||||||
@@ -27,11 +31,10 @@ void main() {
|
|||||||
child: const QTPlayerApp(),
|
child: const QTPlayerApp(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
debugPrint('⏱️ T0.8 runApp 完成: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════
|
|
||||||
// RouteManager - 路由状态
|
|
||||||
// ═══════════════════════════════════════════════════
|
|
||||||
class RouteManager extends ChangeNotifier {
|
class RouteManager extends ChangeNotifier {
|
||||||
static final RouteManager _instance = RouteManager._internal();
|
static final RouteManager _instance = RouteManager._internal();
|
||||||
factory RouteManager() => _instance;
|
factory RouteManager() => _instance;
|
||||||
@@ -53,9 +56,6 @@ class RouteManager extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════
|
|
||||||
// MiniPlayerNavigatorObserver - 路由监听
|
|
||||||
// ═══════════════════════════════════════════════════
|
|
||||||
class MiniPlayerNavigatorObserver extends NavigatorObserver {
|
class MiniPlayerNavigatorObserver extends NavigatorObserver {
|
||||||
void _updateRoute(Route? route) {
|
void _updateRoute(Route? route) {
|
||||||
final name = route?.settings.name ?? '/';
|
final name = route?.settings.name ?? '/';
|
||||||
@@ -78,9 +78,6 @@ class MiniPlayerNavigatorObserver extends NavigatorObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════
|
|
||||||
// QTPlayerApp - 主应用
|
|
||||||
// ═══════════════════════════════════════════════════
|
|
||||||
class QTPlayerApp extends StatefulWidget {
|
class QTPlayerApp extends StatefulWidget {
|
||||||
const QTPlayerApp({super.key});
|
const QTPlayerApp({super.key});
|
||||||
|
|
||||||
@@ -92,17 +89,17 @@ class _QTPlayerAppState extends State<QTPlayerApp> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
debugPrint('⏱️ T1.5 initState: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
|
|
||||||
// 首帧完成后才开始初始化
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
debugPrint('🖼️ Flutter 首帧已完成');
|
debugPrint('⏱️ T2 首帧回调: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
_initializeServices();
|
_initializeServices();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
debugPrint('🎨 QTPlayerApp.build()');
|
debugPrint('⏱️ T1 build: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
|
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: '清听',
|
title: '清听',
|
||||||
@@ -148,23 +145,24 @@ class _QTPlayerAppState extends State<QTPlayerApp> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════
|
|
||||||
// 后台初始化 - 在首帧完成后执行
|
|
||||||
// ═══════════════════════════════════════════════════
|
|
||||||
void _initializeServices() async {
|
void _initializeServices() async {
|
||||||
|
debugPrint('⏱️ T3 开始初始化: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
final lifecycle = AppLifecycleService();
|
final lifecycle = AppLifecycleService();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lifecycle.updateStatus(AppStatus.mediaKitInitializing);
|
lifecycle.updateStatus(AppStatus.mediaKitInitializing);
|
||||||
MediaKit.ensureInitialized();
|
MediaKit.ensureInitialized();
|
||||||
|
debugPrint('⏱️ T4 MediaKit 完成: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
lifecycle.updateStatus(AppStatus.mediaKitReady);
|
lifecycle.updateStatus(AppStatus.mediaKitReady);
|
||||||
|
|
||||||
lifecycle.updateStatus(AppStatus.playerInitializing);
|
lifecycle.updateStatus(AppStatus.playerInitializing);
|
||||||
PlaybackService().init();
|
PlaybackService().init();
|
||||||
|
debugPrint('⏱️ T5 Player 完成: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
lifecycle.updateStatus(AppStatus.playerReady);
|
lifecycle.updateStatus(AppStatus.playerReady);
|
||||||
|
|
||||||
lifecycle.updateStatus(AppStatus.webdavChecking);
|
lifecycle.updateStatus(AppStatus.webdavChecking);
|
||||||
final hasCred = await WebDAVService.instance.loadCredentials();
|
final hasCred = await WebDAVService.instance.loadCredentials();
|
||||||
|
debugPrint('⏱️ T6 WebDAV 完成: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
if (hasCred) {
|
if (hasCred) {
|
||||||
lifecycle.updateStatus(AppStatus.webdavReady);
|
lifecycle.updateStatus(AppStatus.webdavReady);
|
||||||
} else {
|
} else {
|
||||||
@@ -172,7 +170,7 @@ void _initializeServices() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lifecycle.updateStatus(AppStatus.fullReady);
|
lifecycle.updateStatus(AppStatus.fullReady);
|
||||||
debugPrint('✅ 应用完全就绪');
|
debugPrint('✅ 应用完全就绪: ${stopwatch.elapsedMilliseconds}ms');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('❌ 初始化错误: $e');
|
debugPrint('❌ 初始化错误: $e');
|
||||||
lifecycle.updateStatus(AppStatus.error);
|
lifecycle.updateStatus(AppStatus.error);
|
||||||
|
|||||||
Reference in New Issue
Block a user