界面部分阶段性达成效果
This commit is contained in:
+43
-4
@@ -8,11 +8,50 @@ import 'pages/home_page.dart';
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// ✅ 关键:必须在调用任何 media_kit API 之前执行
|
||||
MediaKit.ensureInitialized();
|
||||
// 捕获初始化阶段的所有异常,避免引擎崩溃
|
||||
try {
|
||||
// 必须先初始化 media_kit
|
||||
MediaKit.ensureInitialized();
|
||||
// 然后初始化播放服务
|
||||
PlaybackService().init();
|
||||
} catch (e, stack) {
|
||||
print('❌ 初始化失败: $e');
|
||||
print(stack);
|
||||
// 显示错误页面,而不是白屏
|
||||
runApp(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
backgroundColor: const Color(0xFF0E1211),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 64, color: Colors.red[300]),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'应用初始化失败',
|
||||
style: TextStyle(color: Colors.white, fontSize: 20),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'$e',
|
||||
style: TextStyle(color: Colors.grey[400], fontSize: 14),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 现在可以安全地初始化 PlaybackService
|
||||
PlaybackService().init();
|
||||
// 运行时错误捕获
|
||||
FlutterError.onError = (details) {
|
||||
print('❌ Flutter Error: ${details.exception}');
|
||||
print('Stack: ${details.stack}');
|
||||
};
|
||||
|
||||
runApp(
|
||||
ChangeNotifierProvider(
|
||||
|
||||
Reference in New Issue
Block a user