add
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:asset_assistant/pages/home_page.dart';
|
||||
import 'package:asset_assistant/utils/host_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -40,7 +41,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
try {
|
||||
// 构建请求URL
|
||||
const baseUrl = 'https://api.fishestlife.com';
|
||||
final baseUrl = HostUtils().currentHost;
|
||||
const path = '/user/login';
|
||||
final url = '$baseUrl$path';
|
||||
debugPrint('请求URL: $url');
|
||||
|
||||
22
frontend/asset_assistant/lib/utils/host_utils.dart
Normal file
22
frontend/asset_assistant/lib/utils/host_utils.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
// Host
|
||||
class HostUtils {
|
||||
// 单例实例
|
||||
static final HostUtils _instance = HostUtils._internal();
|
||||
|
||||
// 工厂构造函数,确保全局唯一实例
|
||||
factory HostUtils() => _instance;
|
||||
|
||||
// 私有构造函数
|
||||
HostUtils._internal();
|
||||
|
||||
// 根据运行环境获取当前Host
|
||||
String get currentHost {
|
||||
// 区分debug和release环境
|
||||
bool isDebug = false;
|
||||
assert(() {
|
||||
isDebug = true;
|
||||
return true;
|
||||
}());
|
||||
return isDebug ? 'http://127.0.0.1:20000' : 'https://api.fishestlife.com';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user