扑动搜索模块未显示过滤器



我正在创建一个search模块,但它不工作。当我尝试搜索关键字时,用户没有显示。请看看我在我的代码中遗漏了什么。谢谢。

我的屏幕是这样的

输入图片描述

这是我这个页面的代码

class CategoryPage extends StatefulWidget {
final int categoryId;
List<Data> list = [];
CategoryPage({Key? key, required this.list, required this.categoryId}) : super(key: key);
@override
State<CategoryPage> createState() => _CategoryPageState();
}
class _CategoryPageState extends State<CategoryPage> {
late CategoryDetailService categoryDetailService;
final controller = TextEditingController();
List<UserData> user = [];
bool isCalled = false;
String categoryID = "";
@override
void initState() {
super.initState();
categoryID = widget.categoryId.toString();
}
void searchUser(String query) {
final suggestions = user.where((element) {
final userName = element.firstName!.toLowerCase();
final input = query.toLowerCase();
return userName.contains(input);
}).toList();
setState(() => user = suggestions);
}
@override
Widget build(BuildContext context) {
if (!isCalled) {
isCalled = true;
categoryDetailService = Provider.of<CategoryDetailService>(context);
categoryDetailService.offSet = 1;
(categoryDetailService.data ?? []).clear();
categoryDetailService.fetchData(context, categoryID);
}
return GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: SafeArea(
child: DefaultTabController(
length: widget.list.length,
child: Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_back_ios_rounded,
size: Dimensions.height30,
color: AppColors.fIconsAndTextColor,
),
),
actions: [
Padding(
padding: EdgeInsets.only(right: Dimensions.height15),
child: InkWell(
onTap: () => pushNewScreen(context, screen: const NotificationScreen()),
child: ImageIcon(
const AssetImage('assets/images/notif.png'),
size: Dimensions.height40,
color: AppColors.fIconsAndTextColor,
)),
),
],
elevation: 0.0,
backgroundColor: Colors.transparent),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: Dimensions.width15),
child: Container(
width: MediaQuery.of(context).size.width,
height: Dimensions.height45,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(Dimensions.radius10),
color: Colors.white,
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey,
blurRadius: Dimensions.radius10,
offset: const Offset(0.0, 6),
)
],
),
child: TextFormField(
controller: controller,
keyboardType: TextInputType.text,
onChanged: searchUser,
cursorColor: Colors.grey,
autocorrect: false,
decoration: InputDecoration(
hintText: LanguageStringKeys.instance.search.tr,
isDense: true,
contentPadding: EdgeInsets.fromLTRB(
Dimensions.width10,
Dimensions.height20,
Dimensions.width10,
0,
),
prefixIcon: const Icon(
Icons.search,
color: Colors.grey,
),
suffixIcon: InkWell(
onTap: () => pushNewScreen(context, screen: const FilterScreen()),
child: const Icon(
Icons.tune,
color: Colors.grey,
),
),
border: const OutlineInputBorder(
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
),
),
),
),
SizedBox(height: Dimensions.height10),
Padding(
padding: EdgeInsets.only(
left: Dimensions.width15,
top: Dimensions.height15,
right: Dimensions.width15,
),
child: SmallText(
text: LanguageStringKeys.instance.category.tr,
),
),
// SizedBox(height: Dimensions.height10),
SingleChildScrollView(
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: widget.list
.map((e) => InkWell(
onTap: () {
categoryDetailService.offSet = 1;
(categoryDetailService.data ?? []).clear();
categoryDetailService.fetchData(context, e.id.toString());
},
child: Padding(
padding: EdgeInsets.all(Dimensions.height10 - 2),
child: Tab(
height: Dimensions.height70,
child: TabsContainer(
image: e.photo ?? "",
tittle: Get.put(AppController()).isEnglish() ? e.enName ?? "" : e.arName ?? "",
),
),
),
))
.toList(),
),
),
UsersCategoryPage(categoryDetailService.usersByFilter?.data ?? []),
],
),
),
),
),
);
}
}

这是我的用户模型

UsersByFilter usersByFilterFromJson(String str) => UsersByFilter.fromJson(json.decode(str));
String usersByFilterToJson(UsersByFilter data) => json.encode(data.toJson());
class UsersByFilter {
UsersByFilter({
this.total,
this.perPage,
this.currentPage,
this.lastPage,
this.nextPageUrl,
this.prevPageUrl,
this.from,
this.to,
this.success,
this.enMessage,
this.arMessage,
this.data,
this.status,
});
UsersByFilter.fromJson(dynamic json) {
total = json['total'];
perPage = json['per_page'].toString();
currentPage = json['current_page'].toString();
lastPage = json['last_page'];
nextPageUrl = json['next_page_url'];
prevPageUrl = json['prev_page_url'];
from = json['from'].toString();
to = json['to'].toString();
success = json['success'];
enMessage = json['en_message'];
arMessage = json['ar_message'];
if (json['data'] != null) {
data = [];
json['data'].forEach((v) {
data?.add(UserData.fromJson(v));
});
}
status = json['status'];
}
int? total;
String? perPage;
String? currentPage;
int? lastPage;
String? nextPageUrl;
String? prevPageUrl;
String? from;
String? to;
bool? success;
String? enMessage;
String? arMessage;
List<UserData>? data;
int? status;
UsersByFilter copyWith({
int? total,
String? perPage,
String? currentPage,
int? lastPage,
String? nextPageUrl,
String? prevPageUrl,
String? from,
String? to,
bool? success,
String? enMessage,
String? arMessage,
List<UserData>? data,
int? status,
}) =>
UsersByFilter(
total: total ?? this.total,
perPage: perPage ?? this.perPage,
currentPage: currentPage ?? this.currentPage,
lastPage: lastPage ?? this.lastPage,
nextPageUrl: nextPageUrl ?? this.nextPageUrl,
prevPageUrl: prevPageUrl ?? this.prevPageUrl,
from: from ?? this.from,
to: to ?? this.to,
success: success ?? this.success,
enMessage: enMessage ?? this.enMessage,
arMessage: arMessage ?? this.arMessage,
data: data ?? this.data,
status: status ?? this.status,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['total'] = total;
map['per_page'] = perPage;
map['current_page'] = currentPage;
map['last_page'] = lastPage;
map['next_page_url'] = nextPageUrl;
map['prev_page_url'] = prevPageUrl;
map['from'] = from;
map['to'] = to;
map['success'] = success;
map['en_message'] = enMessage;
map['ar_message'] = arMessage;
if (data != null) {
map['data'] = data?.map((v) => v.toJson()).toList();
}
map['status'] = status;
return map;
}
}

UserData dataFromJson(String str) => UserData.fromJson(json.decode(str));
String dataToJson(UserData data) => json.encode(data.toJson());
class UserData {
UserData({
this.id,
this.username,
this.type,
this.customerId,
this.lang,
this.countryId,
this.email,
this.firstName,
this.lastName,
this.phone,
this.address,
this.location,
this.dob,
this.sex,
this.city,
this.createdAt,
this.updatedAt,
this.idPhoto,
this.accessToken,
this.accessTokenEnd,
this.roleId,
this.verified,
this.verificationCode,
this.passwordCode,
this.fcmToken,
this.mobile,
this.bio,
this.photo,
this.lat,
this.lon,
this.verifiedSponsor,
this.requests,
this.isActive,
this.categoryId,
this.companyName,
this.tradeLicense,
this.field,
this.workTime,
this.facebook,
this.linkedIn,
this.instagram,
this.whatsApp,
this.wishlisted,
this.fbId,
this.googleToken,
this.facebookToken,
this.facebookId,
this.googleId,
this.balance,
this.photos,
this.role,
});
UserData.fromJson(dynamic json) {
id = json['id'];
username = json['username'];
type = json['type'];
customerId = json['customer_id'];
lang = json['lang'];
countryId = json['country_id'];
email = json['email'];
firstName = json['first_name'];
lastName = json['last_name'];
phone = json['phone'];
address = json['address'];
location = json['location'];
dob = json['dob'];
sex = json['sex'];
city = json['city'];
createdAt = json['created_at'];
updatedAt = json['updated_at'];
idPhoto = json['id_photo'];
accessToken = json['access_token'];
accessTokenEnd = json['access_token_end'];
roleId = json['role_id'];
verified = json['verified'];
verificationCode = json['verification_code'];
passwordCode = json['password_code'];
fcmToken = json['fcm_token'];
mobile = json['mobile'];
bio = json['bio'];
photo = json['photo'];
lat = json['lat'];
lon = json['lon'];
verifiedSponsor = json['verified_sponsor'];
requests = json['requests'];
isActive = json['is_active'];
categoryId = json['category_id'];
companyName = json['company_name'];
tradeLicense = json['trade_license'];
field = json['field'];
workTime = json['work_time'];
facebook=
json["facebook"];
linkedIn=
json["linkedIn"];
instagram=
json["instagram"];
whatsApp=
json["whatsApp"];
wishlisted=
json["wishlisted"];
fbId=
json["fb_id"];
googleToken=
json["google_token"];
facebookToken=
json["facebook_token"];
facebookId=
json["facebook_id"];
googleId=
json["google_id"];
if (json['balance'] != null) {
balance = [];
json['balance'].forEach((v) {
balance?.add(Balance.fromJson(v));
});
}
if (json['photos'] != null) {
photos = [];
json['photos'].forEach((v) {
photos?.add(v);
});
}
role = json['role'] != null ? Role.fromJson(json['role']) : null;
}
int? id;
String? username;
int? type;
int? customerId;
int? lang;
int? countryId;
String? email;
String? firstName;
dynamic lastName;
String? phone;
String? address;
dynamic location;
dynamic dob;
dynamic sex;
dynamic city;
String? createdAt;
String? updatedAt;
dynamic idPhoto;
dynamic accessToken;
dynamic accessTokenEnd;
int? roleId;
int? verified;
String? verificationCode;
String? passwordCode;
String? fcmToken;
String? mobile;
String? bio;
String? photo;
String? lat;
String? lon;
int? verifiedSponsor;
int? requests;
int? isActive;
String? categoryId;
dynamic companyName;
dynamic tradeLicense;
dynamic field;
dynamic workTime;
String? facebook;
String? linkedIn;
String? instagram;
String? whatsApp;
bool? wishlisted;
dynamic fbId;
dynamic googleToken;
dynamic facebookToken;
dynamic facebookId;
dynamic googleId;
List<Balance>? balance;
List<dynamic>? photos;
Role? role;
UserData copyWith({
int? id,
String? username,
int? type,
int? customerId,
int? lang,
int? countryId,
String? email,
String? firstName,
dynamic lastName,
String? phone,
String? address,
dynamic location,
dynamic dob,
dynamic sex,
dynamic city,
String? createdAt,
String? updatedAt,
dynamic idPhoto,
dynamic accessToken,
dynamic accessTokenEnd,
int? roleId,
int? verified,
String? verificationCode,
String? passwordCode,
dynamic fcmToken,
String? mobile,
dynamic bio,
dynamic photo,
dynamic lat,
dynamic lon,
int? verifiedSponsor,
int? requests,
int? isActive,
String? categoryId,
dynamic companyName,
dynamic tradeLicense,
dynamic field,
dynamic workTime,
String? facebook,
String? linkedIn,
String? instagram,
String? whatsApp,
bool? wishlisted,
dynamic fbId,
dynamic googleToken,
dynamic facebookToken,
dynamic facebookId,
dynamic googleId,
List<Balance>? balance,
List<dynamic>? photos,
Role? role,
}) =>
UserData(
id: id ?? this.id,
username: username ?? this.username,
type: type ?? this.type,
customerId: customerId ?? this.customerId,
lang: lang ?? this.lang,
countryId: countryId ?? this.countryId,
email: email ?? this.email,
firstName: firstName ?? this.firstName,
lastName: lastName ?? this.lastName,
phone: phone ?? this.phone,
address: address ?? this.address,
location: location ?? this.location,
dob: dob ?? this.dob,
sex: sex ?? this.sex,
city: city ?? this.city,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
idPhoto: idPhoto ?? this.idPhoto,
accessToken: accessToken ?? this.accessToken,
accessTokenEnd: accessTokenEnd ?? this.accessTokenEnd,
roleId: roleId ?? this.roleId,
verified: verified ?? this.verified,
verificationCode: verificationCode ?? this.verificationCode,
passwordCode: passwordCode ?? this.passwordCode,
fcmToken: fcmToken ?? this.fcmToken,
mobile: mobile ?? this.mobile,
bio: bio ?? this.bio,
photo: photo ?? this.photo,
lat: lat ?? this.lat,
lon: lon ?? this.lon,
verifiedSponsor: verifiedSponsor ?? this.verifiedSponsor,
requests: requests ?? this.requests,
isActive: isActive ?? this.isActive,
categoryId: categoryId ?? this.categoryId,
companyName: companyName ?? this.companyName,
tradeLicense: tradeLicense ?? this.tradeLicense,
field: field ?? this.field,
workTime: workTime ?? this.workTime,
facebook: facebook ?? this.facebook,
linkedIn: linkedIn ?? this.linkedIn,
instagram: instagram ?? this.instagram,
whatsApp: whatsApp ?? this.whatsApp,
wishlisted: wishlisted ?? this.wishlisted,
fbId: fbId ?? this.fbId,
googleToken: googleToken ?? this.googleToken,
facebookToken: facebookToken ?? this.facebookToken,
facebookId: facebookId ?? this.facebookId,
googleId: googleId ?? this.googleId,
balance: balance ?? this.balance,
photos: photos ?? this.photos,
role: role ?? this.role,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['id'] = id;
map['username'] = username;
map['type'] = type;
map['customer_id'] = customerId;
map['lang'] = lang;
map['country_id'] = countryId;
map['email'] = email;
map['first_name'] = firstName;
map['last_name'] = lastName;
map['phone'] = phone;
map['address'] = address;
map['location'] = location;
map['dob'] = dob;
map['sex'] = sex;
map['city'] = city;
map['created_at'] = createdAt;
map['updated_at'] = updatedAt;
map['id_photo'] = idPhoto;
map['access_token'] = accessToken;
map['access_token_end'] = accessTokenEnd;
map['role_id'] = roleId;
map['verified'] = verified;
map['verification_code'] = verificationCode;
map['password_code'] = passwordCode;
map['fcm_token'] = fcmToken;
map['mobile'] = mobile;
map['bio'] = bio;
map['photo'] = photo;
map['lat'] = lat;
map['lon'] = lon;
map['verified_sponsor'] = verifiedSponsor;
map['requests'] = requests;
map['is_active'] = isActive;
map['category_id'] = categoryId;
map['company_name'] = companyName;
map['trade_license'] = tradeLicense;
map['field'] = field;
map['work_time'] = workTime;
map['facebook'] = facebook;
map['linkedIn'] = linkedIn;
map['instagram'] = instagram;
map['whatsApp'] = whatsApp;
map['fb_id'] = fbId;
map['google_token'] = googleToken;
map['facebook_token'] = facebookToken;
map['facebook_id'] = facebookId;
map['google_id'] = googleId;
if (balance != null) {
map['balance'] = balance?.map((v) => v.toJson()).toList();
}
if (photos != null) {
map['photos'] = photos?.map((v) => v.toJson()).toList();
}
if (role != null) {
map['role'] = role?.toJson();
}
return map;
}
}

如果您在屏幕中维护一个虚拟列表,那么您只会呈现一个从构造函数加载的列表,因为您已经提到过user

@override
void initState() {
user.addAll(widget.list)
super.initState();
categoryID = widget.categoryId.toString();
}

void searchUser(String query) {

if(query.isNotEmpty){

final suggestions = user.where((element) {
final userName = element.firstName!.toLowerCase();
final input = query.toLowerCase();
return userName.contains(input);
}).toList();
setState(() => user = suggestions);
}else{
user.clear()
user.addAll(widget.list)
}
}


SingleChildScrollView(
physics: const BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: user.toList()
.map((e) => InkWell(
onTap: () {
categoryDetailService.offSet = 1;
(categoryDetailService.data ?? []).clear();
categoryDetailService.fetchData(context, e.id.toString());
},
child: Padding(
padding: EdgeInsets.all(Dimensions.height10 - 2),
child: Tab(
height: Dimensions.height70,
child: TabsContainer(
image: e.photo ?? "",
tittle: Get.put(AppController()).isEnglish() ? e.enName ?? "" : e.arName ?? "",
),
),
),
))
.toList(),
),
),

相关内容

  • 没有找到相关文章

最新更新