|
|
|
@ -1,11 +1,19 @@
|
|
|
|
|
import 'dart:ui'; |
|
|
|
|
|
|
|
|
|
import 'package:dio/dio.dart'; |
|
|
|
|
import 'package:flutter/cupertino.dart'; |
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
|
|
|
|
|
|
import '../retrofit/data/base_data.dart'; |
|
|
|
|
import '../retrofit/data/im_user.dart'; |
|
|
|
|
import '../retrofit/retrofit_api.dart'; |
|
|
|
|
import '../utils/font_weight.dart'; |
|
|
|
|
import '../view_widget/my_appbar.dart'; |
|
|
|
|
import '../view_widget/settlement_tips_dialog.dart'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ImSearch extends StatefulWidget { |
|
|
|
@ -19,6 +27,10 @@ class _ImSearch extends State<ImSearch> {
|
|
|
|
|
ApiService apiService; |
|
|
|
|
final TextEditingController editingController = TextEditingController(); |
|
|
|
|
FocusNode _focusNode = FocusNode(); |
|
|
|
|
List<ImUser> searchUser = []; |
|
|
|
|
int searchState = 0; |
|
|
|
|
int textType = 0; |
|
|
|
|
int searchUserIndex = 0; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
void initState() { |
|
|
|
@ -32,6 +44,31 @@ class _ImSearch extends State<ImSearch> {
|
|
|
|
|
super.dispose(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///搜索列表 |
|
|
|
|
queryImSearch(keyword) async { |
|
|
|
|
if (apiService == null) { |
|
|
|
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
|
|
|
apiService = ApiService( |
|
|
|
|
Dio(), |
|
|
|
|
context: context, |
|
|
|
|
token: value.getString("token"), |
|
|
|
|
showLoading:false |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
BaseData<List<ImUser>> baseData = |
|
|
|
|
await apiService.memberSearch(keyword).catchError((onError) {}); |
|
|
|
|
if (baseData != null && baseData.isSuccess) { |
|
|
|
|
searchUser.clear(); |
|
|
|
|
searchUser.addAll(baseData.data); |
|
|
|
|
searchState = 1; |
|
|
|
|
|
|
|
|
|
if(baseData.data.length == 0){ |
|
|
|
|
searchState = 2; |
|
|
|
|
} |
|
|
|
|
setState(() {}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
return GestureDetector( |
|
|
|
@ -52,15 +89,54 @@ class _ImSearch extends State<ImSearch> {
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
imSearch(), |
|
|
|
|
// Expanded( |
|
|
|
|
// child: ListView.builder( |
|
|
|
|
// itemCount: 10, |
|
|
|
|
// physics: BouncingScrollPhysics(), |
|
|
|
|
// shrinkWrap: true, |
|
|
|
|
// itemBuilder: (context, position) { |
|
|
|
|
// return imSearch(); |
|
|
|
|
// }, |
|
|
|
|
// )), |
|
|
|
|
searchState == 2 ? |
|
|
|
|
Center( |
|
|
|
|
child: Text( |
|
|
|
|
"未找到该用户", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
color: Color(0xFFA29E9E), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
): |
|
|
|
|
Expanded(child: |
|
|
|
|
Row( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
if(searchState ==1) |
|
|
|
|
Padding(padding:EdgeInsets.only(left:16.w), |
|
|
|
|
child: Text( |
|
|
|
|
"搜索用户:", |
|
|
|
|
textAlign: TextAlign.center, |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Color(0xFF060606), |
|
|
|
|
fontSize:16.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
), |
|
|
|
|
),), |
|
|
|
|
if(searchState ==1) |
|
|
|
|
Expanded( |
|
|
|
|
child: ListView.builder( |
|
|
|
|
itemCount: searchUser?.length ?? 0, |
|
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
|
shrinkWrap: true, |
|
|
|
|
itemBuilder: (context, position) { |
|
|
|
|
return GestureDetector( |
|
|
|
|
behavior: HitTestBehavior.opaque, |
|
|
|
|
onTap:(){ |
|
|
|
|
setState(() { |
|
|
|
|
searchUserIndex = position; |
|
|
|
|
}); |
|
|
|
|
Navigator.of(context).pushNamed('/router/personal_page', arguments: { |
|
|
|
|
"memberId":searchUser[searchUserIndex].mid ?? "", |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
child: imSearchItem(searchUser[position]), |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
)) |
|
|
|
|
], |
|
|
|
|
)), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
@ -68,7 +144,7 @@ class _ImSearch extends State<ImSearch> {
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///搜索列表 |
|
|
|
|
///搜索 |
|
|
|
|
Widget imSearch() { |
|
|
|
|
return Container( |
|
|
|
|
margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w,29.h), |
|
|
|
@ -79,15 +155,39 @@ class _ImSearch extends State<ImSearch> {
|
|
|
|
|
), |
|
|
|
|
child: TextField( |
|
|
|
|
textInputAction: TextInputAction.search, |
|
|
|
|
onChanged: (value){ |
|
|
|
|
setState(() { |
|
|
|
|
searchState =3; |
|
|
|
|
}); |
|
|
|
|
if (isNumeric(value)) { |
|
|
|
|
textType = 1; |
|
|
|
|
} else { |
|
|
|
|
textType = 2; |
|
|
|
|
} |
|
|
|
|
if(editingController.text == null || editingController.text == ""){ |
|
|
|
|
return; |
|
|
|
|
}else{ |
|
|
|
|
queryImSearch(editingController.text ?? ""); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
onEditingComplete: () { |
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode()); |
|
|
|
|
if(editingController.text == null || editingController.text == ""){ |
|
|
|
|
SmartDialog.show( |
|
|
|
|
widget: SettlementTips( |
|
|
|
|
() {}, |
|
|
|
|
text: "请输入姓名或手机号搜索", |
|
|
|
|
)); |
|
|
|
|
}else{ |
|
|
|
|
queryImSearch(editingController.text ?? ""); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
controller: editingController, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
), |
|
|
|
|
decoration: InputDecoration( |
|
|
|
|
hintText: "搜索", |
|
|
|
|
hintText: "输入姓名或手机号搜索", |
|
|
|
|
hintStyle: TextStyle( |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
color: Color(0xFFA29E9E), |
|
|
|
@ -108,4 +208,24 @@ class _ImSearch extends State<ImSearch> {
|
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///搜索列表 |
|
|
|
|
Widget imSearchItem(ImUser searchUser) { |
|
|
|
|
return Container( |
|
|
|
|
padding: EdgeInsets.only(left:10.w,right:16.w,bottom:15.h), |
|
|
|
|
child: Text( |
|
|
|
|
textType == 1 ?(searchUser?.phone ?? searchUser?.nickname?? "") : (searchUser?.nickname ?? searchUser?.phone ?? ""), |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
color: Color(0xFF32A060), |
|
|
|
|
fontWeight:MyFontWeight.regular), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// 判断给的字符串是否全部由数字组成 |
|
|
|
|
bool isNumeric(String str) { |
|
|
|
|
RegExp regExp = RegExp(r'^\d+$'); |
|
|
|
|
return regExp.hasMatch(str); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|