add
This commit is contained in:
@@ -109,14 +109,17 @@ class _CountryPageState extends State<CountryPage> {
|
||||
final baseUrl = HostUtils().currentHost;
|
||||
final path = '/country/read';
|
||||
final url = '$baseUrl$path';
|
||||
// 打印请求基本信息
|
||||
debugPrint('====== 开始请求国家列表 ======');
|
||||
debugPrint('请求URL: $url');
|
||||
debugPrint('请求参数: page=$_currentPage, page_size=$_pageSize');
|
||||
|
||||
final dio = Dio();
|
||||
final response = await dio.get(
|
||||
final response = await dio.post(
|
||||
url,
|
||||
queryParameters: {
|
||||
'page': _currentPage,
|
||||
'page_size': _pageSize,
|
||||
// 为空时查询所有国家
|
||||
'name': '',
|
||||
'code': '',
|
||||
'country_id': '',
|
||||
@@ -124,6 +127,10 @@ class _CountryPageState extends State<CountryPage> {
|
||||
options: Options(headers: {'Content-Type': 'application/json'}),
|
||||
);
|
||||
|
||||
// 打印响应状态
|
||||
debugPrint('请求成功,状态码: ${response.statusCode}');
|
||||
debugPrint('响应数据: ${response.data}');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final CountryResponse countryResponse = CountryResponse.fromJson(
|
||||
response.data,
|
||||
@@ -142,24 +149,36 @@ class _CountryPageState extends State<CountryPage> {
|
||||
_currentPage++;
|
||||
_errorMessage = null;
|
||||
});
|
||||
// 打印数据处理结果
|
||||
debugPrint('数据解析成功,当前列表总数: ${_countries.length}');
|
||||
debugPrint('是否还有更多数据: $_hasMoreData,下一页: $_currentPage');
|
||||
} else {
|
||||
setState(() {
|
||||
_errorMessage = countryResponse.message;
|
||||
});
|
||||
debugPrint('接口返回失败: ${countryResponse.message}');
|
||||
}
|
||||
} else {
|
||||
setState(() {
|
||||
_errorMessage = '服务器响应异常: ${response.statusCode}';
|
||||
});
|
||||
debugPrint('服务器响应异常: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
String errorMsg = '网络请求失败';
|
||||
if (e.response != null) {
|
||||
errorMsg = '请求失败: ${e.response?.statusCode}';
|
||||
debugPrint(
|
||||
'请求错误,状态码: ${e.response?.statusCode},响应数据: ${e.response?.data}',
|
||||
);
|
||||
} else if (e.type == DioExceptionType.connectionTimeout) {
|
||||
errorMsg = '连接超时,请检查网络';
|
||||
debugPrint('连接超时: ${e.message}');
|
||||
} else if (e.type == DioExceptionType.connectionError) {
|
||||
errorMsg = '网络连接错误';
|
||||
debugPrint('网络连接错误: ${e.message}');
|
||||
} else {
|
||||
debugPrint('Dio异常: ${e.type},消息: ${e.message}');
|
||||
}
|
||||
setState(() {
|
||||
_errorMessage = errorMsg;
|
||||
@@ -168,21 +187,25 @@ class _CountryPageState extends State<CountryPage> {
|
||||
setState(() {
|
||||
_errorMessage = '发生未知错误: $e';
|
||||
});
|
||||
debugPrint('未知错误: $e');
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
debugPrint('====== 请求结束 ======\n');
|
||||
}
|
||||
}
|
||||
|
||||
// 下拉刷新
|
||||
Future<void> _refresh() async {
|
||||
debugPrint('触发下拉刷新');
|
||||
await _fetchCountries(isRefresh: true);
|
||||
}
|
||||
|
||||
// 加载更多
|
||||
void _loadMore() {
|
||||
if (!_isLoading && _hasMoreData) {
|
||||
debugPrint('触发加载更多,当前页: $_currentPage');
|
||||
_fetchCountries();
|
||||
}
|
||||
}
|
||||
@@ -208,12 +231,14 @@ class _CountryPageState extends State<CountryPage> {
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () async {
|
||||
debugPrint('点击新增按钮,跳转到新增页面');
|
||||
// 跳转到新增页面,返回时刷新列表
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const AddCountryPage()),
|
||||
);
|
||||
if (result == true) {
|
||||
debugPrint('从新增页面返回,刷新列表数据');
|
||||
_fetchCountries(isRefresh: true);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:asset_assistant/pages/exchange_page.dart';
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
// 功能列表数据 - 为交易所项添加路由信息
|
||||
@@ -117,7 +116,7 @@ class HomePage extends StatelessWidget {
|
||||
// 点击事件处理 - 如果有路由信息则导航
|
||||
if (route != null && context.mounted) {
|
||||
// 使用路由路径进行导航
|
||||
Navigator.pushNamed(context, route!);
|
||||
Navigator.pushNamed(context, route);
|
||||
}
|
||||
},
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
|
||||
Reference in New Issue
Block a user