更新样式
This commit is contained in:
@@ -221,6 +221,39 @@ class CityModelController extends GetControllerEx<CityModel> {
|
||||
// 检查是否已加载数据
|
||||
bool get isDataLoaded => cityList.isNotEmpty;
|
||||
|
||||
// void searchCities(String keyword) {
|
||||
// model.keyword = keyword;
|
||||
// searchResults?.clear();
|
||||
|
||||
// if (keyword.isEmpty) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// final keywordLower = keyword.toLowerCase();
|
||||
|
||||
// // 遍历所有城市数据
|
||||
// for (var country in cityList) {
|
||||
// final countryName = country.value ?? country.country ?? '';
|
||||
|
||||
// for (var province in country.children ?? []) {
|
||||
// final provinceName = province.value ?? province.province ?? '';
|
||||
|
||||
// for (var city in province.children ?? []) {
|
||||
// final cityName = city.value ?? city.city ?? '';
|
||||
// final displayName = '$countryName-$provinceName-$cityName';
|
||||
|
||||
// // 模糊匹配
|
||||
// if (countryName.toLowerCase().contains(keywordLower) ||
|
||||
// provinceName.toLowerCase().contains(keywordLower) ||
|
||||
// cityName.toLowerCase().contains(keywordLower) ||
|
||||
// displayName.toLowerCase().contains(keywordLower)) {
|
||||
// searchResults?.add(displayName);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
void searchCities(String keyword) {
|
||||
model.keyword = keyword;
|
||||
searchResults?.clear();
|
||||
@@ -231,23 +264,43 @@ class CityModelController extends GetControllerEx<CityModel> {
|
||||
|
||||
final keywordLower = keyword.toLowerCase();
|
||||
|
||||
// 遍历所有城市数据
|
||||
for (var country in cityList) {
|
||||
final countryName = country.value ?? country.country ?? '';
|
||||
|
||||
for (var province in country.children ?? []) {
|
||||
// 如果该国家没有 children(一级结构)
|
||||
if (country.children == null || country.children!.isEmpty) {
|
||||
final name = countryName;
|
||||
if (name.toLowerCase().contains(keywordLower)) {
|
||||
searchResults?.add(name);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// 二层循环:省份或城市
|
||||
for (var province in country.children!) {
|
||||
final provinceName = province.value ?? province.province ?? '';
|
||||
final level2Name = '$countryName-$provinceName';
|
||||
|
||||
for (var city in province.children ?? []) {
|
||||
// 省本身是否匹配(适用于 国家→省 二级结构)
|
||||
if (province.children == null || province.children!.isEmpty) {
|
||||
if (countryName.toLowerCase().contains(keywordLower) ||
|
||||
provinceName.toLowerCase().contains(keywordLower) ||
|
||||
level2Name.toLowerCase().contains(keywordLower)) {
|
||||
searchResults?.add(level2Name);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// 有第三级城市 → 遍历城市
|
||||
for (var city in province.children!) {
|
||||
final cityName = city.value ?? city.city ?? '';
|
||||
final displayName = '$countryName-$provinceName-$cityName';
|
||||
final level3Name = '$countryName-$provinceName-$cityName';
|
||||
|
||||
// 模糊匹配
|
||||
if (countryName.toLowerCase().contains(keywordLower) ||
|
||||
provinceName.toLowerCase().contains(keywordLower) ||
|
||||
cityName.toLowerCase().contains(keywordLower) ||
|
||||
displayName.toLowerCase().contains(keywordLower)) {
|
||||
searchResults?.add(displayName);
|
||||
level3Name.toLowerCase().contains(keywordLower)) {
|
||||
searchResults?.add(level3Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,27 +308,77 @@ class CityModelController extends GetControllerEx<CityModel> {
|
||||
}
|
||||
|
||||
// 根据显示名称获取对应的 CityModel
|
||||
// CityModel? getCityByDisplayName(String displayName) {
|
||||
// final parts = displayName.split('-');
|
||||
// if (parts.length != 3) return null;
|
||||
|
||||
// final countryName = parts[0];
|
||||
// final provinceName = parts[1];
|
||||
// final cityName = parts[2];
|
||||
|
||||
// for (var country in cityList) {
|
||||
// if ((country.value ?? country.country ?? '') == countryName) {
|
||||
// for (var province in country.children ?? []) {
|
||||
// if ((province.value ?? province.province ?? '') == provinceName) {
|
||||
// for (var city in province.children ?? []) {
|
||||
// if ((city.value ?? city.city ?? '') == cityName) {
|
||||
// return city;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
CityModel? getCityByDisplayName(String displayName) {
|
||||
final parts = displayName.split('-');
|
||||
if (parts.length != 3) return null;
|
||||
|
||||
if (parts.isEmpty) return null;
|
||||
|
||||
final countryName = parts[0];
|
||||
final provinceName = parts[1];
|
||||
final cityName = parts[2];
|
||||
final provinceName = parts.length >= 2 ? parts[1] : null;
|
||||
final cityName = parts.length >= 3 ? parts[2] : null;
|
||||
|
||||
for (var country in cityList) {
|
||||
if ((country.value ?? country.country ?? '') == countryName) {
|
||||
for (var province in country.children ?? []) {
|
||||
if ((province.value ?? province.province ?? '') == provinceName) {
|
||||
for (var city in province.children ?? []) {
|
||||
if ((city.value ?? city.city ?? '') == cityName) {
|
||||
return city;
|
||||
}
|
||||
}
|
||||
final cName = country.value ?? country.country ?? '';
|
||||
if (cName != countryName) continue;
|
||||
|
||||
// 一级结构:直接 return 国家
|
||||
if (provinceName == null) {
|
||||
return country;
|
||||
}
|
||||
|
||||
// 如果没有 children,就不可能有省或市
|
||||
if (country.children == null || country.children!.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 二级匹配:省或城市
|
||||
for (var province in country.children!) {
|
||||
final pName = province.value ?? province.province ?? '';
|
||||
if (pName != provinceName) continue;
|
||||
|
||||
// 二级结构:国家-省
|
||||
if (cityName == null) {
|
||||
return province;
|
||||
}
|
||||
|
||||
// 有城市才继续
|
||||
if (province.children == null || province.children!.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 三级结构:国家-省-市
|
||||
for (var city in province.children!) {
|
||||
final ciName = city.value ?? city.city ?? '';
|
||||
if (ciName == cityName) {
|
||||
return city;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||||
import '../../common/util/MyUtils.dart';
|
||||
|
||||
class ListSearchWidget extends GetView {
|
||||
@@ -38,7 +39,8 @@ class ListSearchWidget extends GetView {
|
||||
children: [
|
||||
// 搜索框部分
|
||||
Padding(
|
||||
padding: padding ?? EdgeInsetsDirectional.fromSTEB(30.rpx, 0, 30.rpx, 0),
|
||||
padding:
|
||||
padding ?? EdgeInsetsDirectional.fromSTEB(30.rpx, 0, 30.rpx, 0),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
@@ -46,7 +48,7 @@ class ListSearchWidget extends GetView {
|
||||
borderRadius: BorderRadius.circular(16.rpx),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(35.rpx, 0, 35.rpx, 0),
|
||||
padding: EdgeInsetsDirectional.fromSTEB(35.rpx, 0, 0.rpx, 0),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -139,7 +141,9 @@ class ListSearchWidget extends GetView {
|
||||
},
|
||||
onTap: () {
|
||||
// 点击输入框时显示结果列表(如果开启了显示功能且有搜索结果)
|
||||
if (showResultList && searchResults != null && searchResults!.isNotEmpty) {
|
||||
if (showResultList &&
|
||||
searchResults != null &&
|
||||
searchResults!.isNotEmpty) {
|
||||
_showResults.value = true;
|
||||
}
|
||||
},
|
||||
@@ -151,8 +155,12 @@ class ListSearchWidget extends GetView {
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(26.rpx, 0, 0, 0),
|
||||
child: InkWell(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 0, 0, 0),
|
||||
child: ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor:
|
||||
themeController.currentColor.sc4.withOpacity(0.8),
|
||||
padding: EdgeInsets.fromLTRB(0, 0, 35.rpx, 0),
|
||||
onTap: () {
|
||||
findCallback?.call();
|
||||
// 点击搜索按钮后显示结果列表(如果开启了显示功能)
|
||||
@@ -192,7 +200,9 @@ class ListSearchWidget extends GetView {
|
||||
// 搜索结果列表(可选显示)
|
||||
if (showResultList) ...[
|
||||
Obx(() {
|
||||
if (!_showResults.value || searchResults == null || searchResults!.isEmpty) {
|
||||
if (!_showResults.value ||
|
||||
searchResults == null ||
|
||||
searchResults!.isEmpty) {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
|
||||
@@ -244,4 +254,4 @@ class ListSearchWidget extends GetView {
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user