add
This commit is contained in:
@@ -11,9 +11,10 @@ class AddCountryPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AddCountryPageState extends State<AddCountryPage> {
|
||||
// 输入控制器
|
||||
// 输入控制器 - 新增国旗控制器
|
||||
final TextEditingController _nameController = TextEditingController();
|
||||
final TextEditingController _codeController = TextEditingController();
|
||||
final TextEditingController _flagController = TextEditingController(); // 新增
|
||||
|
||||
// 加载状态
|
||||
bool _isLoading = false;
|
||||
@@ -21,7 +22,7 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
||||
// 表单验证键
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
// 创建国家
|
||||
// 创建国家 - 调整请求数据
|
||||
Future<void> _createCountry() async {
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
return;
|
||||
@@ -32,7 +33,7 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
||||
});
|
||||
|
||||
try {
|
||||
// 获取用户ID
|
||||
// 获取用户ID(保持不变)
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final userId = prefs.getString('user_id');
|
||||
if (userId == null) {
|
||||
@@ -43,7 +44,7 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
||||
return;
|
||||
}
|
||||
|
||||
// 准备请求数据
|
||||
// 准备请求数据 - 新增flag字段
|
||||
final baseUrl = HostUtils().currentHost;
|
||||
const path = '/country/create';
|
||||
final url = '$baseUrl$path';
|
||||
@@ -51,9 +52,10 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
||||
final requestData = {
|
||||
'name': _nameController.text.trim(),
|
||||
'code': _codeController.text.trim(),
|
||||
'flag': _flagController.text.trim(), // 新增国旗参数
|
||||
};
|
||||
|
||||
// 发送请求
|
||||
// 发送请求(保持不变)
|
||||
final dio = Dio();
|
||||
final response = await dio.post(
|
||||
url,
|
||||
@@ -61,7 +63,7 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
||||
options: Options(headers: {'Content-Type': 'application/json'}),
|
||||
);
|
||||
|
||||
// 处理响应
|
||||
// 处理响应(保持不变)
|
||||
if (response.statusCode == 200) {
|
||||
final result = response.data;
|
||||
if (result['success'] == true) {
|
||||
@@ -81,6 +83,7 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
||||
}
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
// 异常处理(保持不变)
|
||||
String errorMessage = '网络请求失败';
|
||||
if (e.response != null) {
|
||||
errorMessage = '请求失败: ${e.response?.statusCode}';
|
||||
@@ -106,7 +109,7 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
||||
}
|
||||
}
|
||||
|
||||
// 显示对话框
|
||||
// 显示对话框(保持不变)
|
||||
void _showDialog(String title, String content, [VoidCallback? onConfirm]) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -159,7 +162,7 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
// 国家名称输入框
|
||||
// 国家名称输入框(保持不变)
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
style: TextStyle(color: theme.colorScheme.onSurface),
|
||||
@@ -180,7 +183,7 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 国家代码输入框
|
||||
// 国家代码输入框(保持不变)
|
||||
TextFormField(
|
||||
controller: _codeController,
|
||||
style: TextStyle(color: theme.colorScheme.onSurface),
|
||||
@@ -199,6 +202,22 @@ class _AddCountryPageState extends State<AddCountryPage> {
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 新增国旗输入框
|
||||
TextFormField(
|
||||
controller: _flagController,
|
||||
style: TextStyle(color: theme.colorScheme.onSurface),
|
||||
decoration: InputDecoration(
|
||||
labelText: '国旗URL',
|
||||
hintText: '请输入国旗图片URL(可选)',
|
||||
prefixIcon: Icon(
|
||||
Icons.flag,
|
||||
color: theme.colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
// 国旗为可选字段,不添加验证器
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user