fix: 修复 Flutter Web 白屏问题
- main.dart: 添加全局错误处理和 FlutterError.onError - index.html: 添加加载指示器,vconsole 仅在开发环境启用 - dio_client.dart: 添加详细错误日志,优化超时配置 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
@@ -21,13 +22,37 @@ import 'ui/pages/auth/login_page.dart';
|
||||
import 'ui/pages/main/main_page.dart';
|
||||
|
||||
void main() async {
|
||||
// 确保 Flutter 绑定初始化
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
Provider.debugCheckInvalidValueType = null;
|
||||
|
||||
await SharedPreferences.getInstance();
|
||||
await LocalStorage.init();
|
||||
// 全局错误处理
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
FlutterError.presentError(details);
|
||||
debugPrint('Flutter Error: ${details.exception}');
|
||||
debugPrint('Stack trace: ${details.stack}');
|
||||
};
|
||||
|
||||
runApp(const MyApp());
|
||||
// 捕获异步错误
|
||||
runZonedGuarded<Future<void>>(
|
||||
() async {
|
||||
Provider.debugCheckInvalidValueType = null;
|
||||
|
||||
try {
|
||||
await SharedPreferences.getInstance();
|
||||
await LocalStorage.init();
|
||||
debugPrint('App initialized successfully');
|
||||
} catch (e, stack) {
|
||||
debugPrint('Initialization error: $e');
|
||||
debugPrint('Stack: $stack');
|
||||
}
|
||||
|
||||
runApp(const MyApp());
|
||||
},
|
||||
(error, stack) {
|
||||
debugPrint('Uncaught error: $error');
|
||||
debugPrint('Stack: $stack');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user