This commit is contained in:
vipg
2025-11-19 17:13:25 +08:00
parent 30cfd98e92
commit e716663731

View File

@@ -3,27 +3,27 @@ import 'package:asset_assistant/utils/host_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
// 国家数据模型(新增flag字段 // 国家数据模型flag字段存储emoji
class Country { class Country {
final String countryId; final String countryId;
final String name; final String name;
final String code; final String code;
final String? flag; // 新增国旗字段 final String? flag; // 国旗字段存储emoji
Country({ Country({
required this.countryId, required this.countryId,
required this.name, required this.name,
required this.code, required this.code,
this.flag, // 新增参数 this.flag,
}); });
// 从JSON构建对象添加flag字段解析 // 从JSON构建对象
factory Country.fromJson(Map<String, dynamic> json) { factory Country.fromJson(Map<String, dynamic> json) {
return Country( return Country(
countryId: json['country_id'], countryId: json['country_id'],
name: json['name'], name: json['name'],
code: json['code'], code: json['code'],
flag: json['flag'], // 解析国旗字段 flag: json['flag'], // 解析emoji字段
); );
} }
} }
@@ -64,7 +64,6 @@ class CountryData {
}); });
factory CountryData.fromJson(Map<String, dynamic> json) { factory CountryData.fromJson(Map<String, dynamic> json) {
// 关键修复处理items为null的情况转为空列表
var itemsList = json['items'] as List? ?? []; var itemsList = json['items'] as List? ?? [];
List<Country> items = itemsList.map((i) => Country.fromJson(i)).toList(); List<Country> items = itemsList.map((i) => Country.fromJson(i)).toList();
@@ -376,26 +375,23 @@ class _CountryPageState extends State<CountryPage> {
padding: const EdgeInsets.symmetric(horizontal: 16), padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row( child: Row(
children: [ children: [
// 国旗Emoji展示区域
Container( Container(
width: 40, width: 40,
height: 40, height: 40,
decoration: BoxDecoration( decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHighest, color: theme.colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
image: country.flag != null && country.flag!.isNotEmpty
? DecorationImage(
image: NetworkImage(country.flag!),
fit: BoxFit.cover,
)
: null,
), ),
child: country.flag == null || country.flag!.isEmpty child: Center(
? Icon( child: Text(
Icons.flag, // 显示国旗emoji如果没有则显示默认图标
size: 24, country.flag != null && country.flag!.isNotEmpty
color: theme.colorScheme.secondary, ? country.flag!
) : '',
: null, style: const TextStyle(fontSize: 24), // 适当调整emoji大小
),
),
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
Expanded( Expanded(