fix(app): Flutter Web 开发模式默认连接 localhost:3000 API
- app.dart: kDebugMode 下使用 AppConfig.dev (localhost:3000) - dev.mjs: flutter run 传入 --dart-define API_BASE_URL/SSE_BASE_URL
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
// └─ BlocProvider<AuthBloc>
|
||||
// └─ MaterialApp.router
|
||||
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:flutter/foundation.dart' show kIsWeb, kDebugMode;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -37,7 +37,8 @@ class NuanjiApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 创建全局依赖(App 生命周期内单例)
|
||||
final config = AppConfig.fromEnvironment();
|
||||
// 开发模式默认使用 localhost,可通过 --dart-define 覆盖
|
||||
final config = kDebugMode ? AppConfig.dev : AppConfig.fromEnvironment();
|
||||
final apiClient = ApiClient(baseUrl: config.apiBaseUrl);
|
||||
final tokenStore = createSecureTokenStore();
|
||||
final authRepository = AuthRepository(apiClient: apiClient, tokenStore: tokenStore);
|
||||
|
||||
@@ -308,7 +308,7 @@ async function startApp() {
|
||||
const appDir = resolve(ROOT, "app");
|
||||
const flutterBin = IS_WIN ? "D:\\flutter\\bin\\flutter.bat" : "flutter";
|
||||
|
||||
const child = spawn(`${flutterBin} run -d chrome --web-port=${PORTS.app}`, {
|
||||
const child = spawn(`${flutterBin} run -d chrome --web-port=${PORTS.app} --dart-define=API_BASE_URL=http://localhost:${PORTS.backend}/api/v1 --dart-define=SSE_BASE_URL=http://localhost:${PORTS.backend}/api/v1`, {
|
||||
cwd: appDir,
|
||||
shell: true,
|
||||
stdio: "pipe",
|
||||
|
||||
Reference in New Issue
Block a user