111
This commit is contained in:
@@ -18,29 +18,34 @@ import 'data/services/trade_service.dart';
|
||||
import 'data/services/asset_service.dart';
|
||||
import 'data/services/fund_service.dart';
|
||||
import 'data/services/bonus_service.dart';
|
||||
import 'data/services/config_service.dart';
|
||||
import 'providers/auth_provider.dart';
|
||||
import 'providers/market_provider.dart';
|
||||
import 'providers/asset_provider.dart';
|
||||
import 'providers/trade_provider.dart';
|
||||
import 'providers/theme_provider.dart';
|
||||
import 'ui/pages/auth/login_page.dart';
|
||||
import 'ui/pages/main/main_page.dart';
|
||||
import 'ui/pages/onboarding/onboarding_page.dart';
|
||||
|
||||
/// 全局導航 Key,用於從任意位置跳轉到登錄頁
|
||||
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
void main() async {
|
||||
// 確保 Flutter 綁定初始化
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// 防截图:Android 端通过 FLAG_SECURE(在 MainActivity 中已设置)
|
||||
// Web 端通过 index.html 中的 JS/CSS 防护
|
||||
// iOS 端暂无原生防截图能力(Web 模式下同样由 JS 保护)
|
||||
|
||||
// 全局錯誤處理 - Flutter 框架錯誤
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
FlutterError.presentError(details);
|
||||
debugPrint('Flutter Error: ${details.exception}');
|
||||
debugPrint('Stack trace: ${details.stack}');
|
||||
};
|
||||
|
||||
// 全局錯誤處理 - 異步未捕獲錯誤
|
||||
PlatformDispatcher.instance.onError = (error, stack) {
|
||||
debugPrint('Uncaught error: $error');
|
||||
debugPrint('Stack: $stack');
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -54,12 +59,9 @@ void main() async {
|
||||
final resolvedUrl = await DomainNavigator.init();
|
||||
ApiEndpoints.init(resolvedUrl);
|
||||
|
||||
debugPrint('App initialized with domain: $resolvedUrl');
|
||||
} catch (e, stack) {
|
||||
// 域名解析失敗時使用兜底地址
|
||||
ApiEndpoints.init(DomainNavigator.activeUrl);
|
||||
debugPrint('Initialization error: $e');
|
||||
debugPrint('Stack: $stack');
|
||||
}
|
||||
|
||||
runApp(const MyApp());
|
||||
@@ -97,6 +99,7 @@ class MyApp extends StatelessWidget {
|
||||
Provider<AssetService>(create: (_) => AssetService(dioClient)),
|
||||
Provider<FundService>(create: (_) => FundService(dioClient)),
|
||||
Provider<BonusService>(create: (_) => BonusService(dioClient)),
|
||||
Provider<ConfigService>(create: (_) => ConfigService(dioClient)),
|
||||
// State Management
|
||||
ChangeNotifierProvider<AuthProvider>(
|
||||
create: (ctx) {
|
||||
@@ -113,14 +116,22 @@ class MyApp extends StatelessWidget {
|
||||
create: (ctx) => AssetProvider(
|
||||
ctx.read<AssetService>(),
|
||||
ctx.read<FundService>(),
|
||||
ctx.read<TradeService>(),
|
||||
ctx.read<AppEventBus>(),
|
||||
),
|
||||
),
|
||||
ChangeNotifierProvider<TradeProvider>(
|
||||
create: (ctx) => TradeProvider(
|
||||
ctx.read<MarketService>(),
|
||||
ctx.read<TradeService>(),
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Widget _buildMaterialApp(BuildContext context, ThemeMode themeMode) {
|
||||
return MaterialApp(
|
||||
navigatorKey: navigatorKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: AppTheme.lightTheme,
|
||||
darkTheme: AppTheme.darkTheme,
|
||||
|
||||
Reference in New Issue
Block a user