diff --git a/lib/im/add_friend.dart b/lib/im/add_friend.dart index 3c01e717..780a92ec 100644 --- a/lib/im/add_friend.dart +++ b/lib/im/add_friend.dart @@ -252,7 +252,7 @@ class _AddFriend extends State { 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), diff --git a/lib/im/chat_friend_group.dart b/lib/im/chat_friend_group.dart index c4d54953..ccb49dc6 100644 --- a/lib/im/chat_friend_group.dart +++ b/lib/im/chat_friend_group.dart @@ -61,7 +61,7 @@ class _ChatFriendGroup extends State 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 baseData = await apiService.socialInfo().catchError((onError) {}); @@ -70,7 +70,6 @@ class _ChatFriendGroup extends State infoNumber = baseData.data; }); } - EasyLoading.dismiss(); } @override diff --git a/lib/im/im_search.dart b/lib/im/im_search.dart index 47205b71..5768f20d 100644 --- a/lib/im/im_search.dart +++ b/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 { ApiService apiService; final TextEditingController editingController = TextEditingController(); FocusNode _focusNode = FocusNode(); + List searchUser = []; + int searchState = 0; + int textType = 0; + int searchUserIndex = 0; @override void initState() { @@ -32,6 +44,31 @@ class _ImSearch extends State { 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> 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 { 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 { ); } - ///搜索列表 + ///搜索 Widget imSearch() { return Container( margin: EdgeInsets.fromLTRB(16.w, 8.h, 16.w,29.h), @@ -79,15 +155,39 @@ class _ImSearch extends State { ), 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 { ), ); } + + ///搜索列表 + 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); + } } diff --git a/lib/im/im_view/friend_groip_list.dart b/lib/im/im_view/friend_groip_list.dart index cb4b342f..06e3b291 100644 --- a/lib/im/im_view/friend_groip_list.dart +++ b/lib/im/im_view/friend_groip_list.dart @@ -176,7 +176,7 @@ class _FriendGroupList extends State { 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 { 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), diff --git a/lib/im/im_view/im_page.dart b/lib/im/im_view/im_page.dart index fe435583..663179b7 100644 --- a/lib/im/im_view/im_page.dart +++ b/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';