add
This commit is contained in:
@@ -3,27 +3,27 @@ import 'package:asset_assistant/utils/host_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
// 国家数据模型(新增flag字段)
|
||||
// 国家数据模型(flag字段存储emoji)
|
||||
class Country {
|
||||
final String countryId;
|
||||
final String name;
|
||||
final String code;
|
||||
final String? flag; // 新增国旗字段
|
||||
final String? flag; // 国旗字段,存储emoji
|
||||
|
||||
Country({
|
||||
required this.countryId,
|
||||
required this.name,
|
||||
required this.code,
|
||||
this.flag, // 新增参数
|
||||
this.flag,
|
||||
});
|
||||
|
||||
// 从JSON构建对象(添加flag字段解析)
|
||||
// 从JSON构建对象
|
||||
factory Country.fromJson(Map<String, dynamic> json) {
|
||||
return Country(
|
||||
countryId: json['country_id'],
|
||||
name: json['name'],
|
||||
code: json['code'],
|
||||
flag: json['flag'], // 解析国旗字段
|
||||
flag: json['flag'], // 解析emoji字段
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,6 @@ class CountryData {
|
||||
});
|
||||
|
||||
factory CountryData.fromJson(Map<String, dynamic> json) {
|
||||
// 关键修复:处理items为null的情况,转为空列表
|
||||
var itemsList = json['items'] as List? ?? [];
|
||||
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),
|
||||
child: Row(
|
||||
children: [
|
||||
// 国旗Emoji展示区域
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest,
|
||||
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
|
||||
? Icon(
|
||||
Icons.flag,
|
||||
size: 24,
|
||||
color: theme.colorScheme.secondary,
|
||||
)
|
||||
: null,
|
||||
child: Center(
|
||||
child: Text(
|
||||
// 显示国旗emoji,如果没有则显示默认图标
|
||||
country.flag != null && country.flag!.isNotEmpty
|
||||
? country.flag!
|
||||
: '',
|
||||
style: const TextStyle(fontSize: 24), // 适当调整emoji大小
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
|
||||
Reference in New Issue
Block a user