Browse Source

搜索页面处理

wr_202303
wurong 4 months ago
parent
commit
2ceab5a1de
  1. 2
      lib/im/add_friend.dart
  2. 3
      lib/im/chat_friend_group.dart
  3. 142
      lib/im/im_search.dart
  4. 4
      lib/im/im_view/friend_groip_list.dart
  5. 8
      lib/im/im_view/im_page.dart

2
lib/im/add_friend.dart

@ -252,7 +252,7 @@ class _AddFriend extends State<AddFriend> {
behavior: HitTestBehavior.opaque,
onTap:(){Navigator.of(context).pushNamed('/router/im_search');},
child: Container(
margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0),
margin: EdgeInsets.fromLTRB(16.w,22.h, 16.w, 24.h),
padding: EdgeInsets.symmetric(vertical: 13.h),
decoration: BoxDecoration(
color: Color(0xFFFDFCFC),

3
lib/im/chat_friend_group.dart

@ -61,7 +61,7 @@ class _ChatFriendGroup extends State<ChatFriendGroup>
querySocialInfo() async {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(Dio(),
context: context, token: value.getString("token"), showLoading: true);
context: context, token: value.getString("token"), showLoading: false);
BaseData<SocialInfo> baseData =
await apiService.socialInfo().catchError((onError) {});
@ -70,7 +70,6 @@ class _ChatFriendGroup extends State<ChatFriendGroup>
infoNumber = baseData.data;
});
}
EasyLoading.dismiss();
}
@override

142
lib/im/im_search.dart

@ -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);
}
}

4
lib/im/im_view/friend_groip_list.dart

@ -176,7 +176,7 @@ class _FriendGroupList extends State<FriendGroupList> {
child: Row(children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(26.5.r),
borderRadius: BorderRadius.circular(100),
),
child: MImage(
list?.avatar ?? "",
@ -208,7 +208,7 @@ class _FriendGroupList extends State<FriendGroupList> {
behavior: HitTestBehavior.opaque,
onTap:(){Navigator.of(context).pushNamed('/router/im_search');},
child: Container(
margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0),
margin: EdgeInsets.fromLTRB(16.w, 0, 16.w, 24.h),
padding: EdgeInsets.symmetric(vertical: 13.h),
decoration: BoxDecoration(
color: Color(0xFFFDFCFC),

8
lib/im/im_view/im_page.dart

@ -1,25 +1,17 @@
import 'dart:async';
import 'dart:collection';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/constant.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/im/database/message.dart';
import 'package:huixiang/im/im_view/time_formatter.dart';
import 'package:huixiang/im/out/message.pb.dart';
import 'package:huixiang/main.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/msg_stats.dart';
import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:huixiang/view_widget/round_button.dart';
import 'package:intl/intl.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

Loading…
Cancel
Save