feat(mobile-next): 导入官方 openim-flutter-demo 固定基线 3.8.3-patch.3 并完成双构建
- 上游: github.com/OpenIMSDK/openim-flutter-demo tag 3.8.3-patch.3 commit b3dfdb1e8aaeaaf6f0793e10cadd20d5c184a31f - 并行目录 mobile-next/ 原样导入(含 LICENSE),不覆盖现网 mobile/ - 锁定 Flutter 3.24.5 / Dart 3.5.4 / JDK 17 / Gradle 7.6.3 / AGP 7.3.1 - 实测 Android debug 与 release 构建均成功(见 docs/mobile-next-baseline-import.md) - 本提交可单独回退:git revert 1db1229(重写前) Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'add_by_search_logic.dart';
|
||||
|
||||
class AddContactsBySearchBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut(() => AddContactsBySearchLogic());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:openim/pages/contacts/group_profile_panel/group_profile_panel_logic.dart';
|
||||
import 'package:openim/routes/app_navigator.dart';
|
||||
import 'package:openim_common/openim_common.dart';
|
||||
import 'package:pull_to_refresh_new/pull_to_refresh.dart';
|
||||
import 'package:sprintf/sprintf.dart';
|
||||
|
||||
enum SearchType {
|
||||
user,
|
||||
group,
|
||||
}
|
||||
|
||||
class AddContactsBySearchLogic extends GetxController {
|
||||
final refreshCtrl = RefreshController();
|
||||
final searchCtrl = TextEditingController();
|
||||
final focusNode = FocusNode();
|
||||
final userInfoList = <UserFullInfo>[].obs;
|
||||
final groupInfoList = <GroupInfo>[].obs;
|
||||
late SearchType searchType;
|
||||
int pageNo = 0;
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
searchCtrl.dispose();
|
||||
focusNode.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
searchType = Get.arguments['searchType'] ?? SearchType.user;
|
||||
searchCtrl.addListener(() {
|
||||
if (searchKey.isEmpty) {
|
||||
focusNode.requestFocus();
|
||||
userInfoList.clear();
|
||||
groupInfoList.clear();
|
||||
}
|
||||
});
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
bool get isSearchUser => searchType == SearchType.user;
|
||||
|
||||
String get searchKey => searchCtrl.text.trim();
|
||||
|
||||
bool get isNotFoundUser => userInfoList.isEmpty && searchKey.isNotEmpty;
|
||||
|
||||
bool get isNotFoundGroup => groupInfoList.isEmpty && searchKey.isNotEmpty;
|
||||
|
||||
void search() {
|
||||
if (searchKey.isEmpty) return;
|
||||
if (isSearchUser) {
|
||||
searchUser();
|
||||
} else {
|
||||
searchGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void searchUser() async {
|
||||
var list = await LoadingView.singleton.wrap(
|
||||
asyncFunction: () => Apis.searchUserFullInfo(
|
||||
content: searchKey,
|
||||
pageNumber: pageNo = 1,
|
||||
showNumber: 20,
|
||||
),
|
||||
);
|
||||
userInfoList.assignAll(list ?? []);
|
||||
refreshCtrl.refreshCompleted();
|
||||
if (null == list || list.isEmpty || list.length < 20) {
|
||||
refreshCtrl.loadNoData();
|
||||
} else {
|
||||
refreshCtrl.loadComplete();
|
||||
}
|
||||
}
|
||||
|
||||
void loadMoreUser() async {
|
||||
var list = await LoadingView.singleton.wrap(
|
||||
asyncFunction: () => Apis.searchUserFullInfo(
|
||||
content: searchKey,
|
||||
pageNumber: ++pageNo,
|
||||
showNumber: 20,
|
||||
),
|
||||
);
|
||||
userInfoList.addAll(list ?? []);
|
||||
refreshCtrl.refreshCompleted();
|
||||
if (null == list || list.isEmpty || list.length < 20) {
|
||||
refreshCtrl.loadNoData();
|
||||
} else {
|
||||
refreshCtrl.loadComplete();
|
||||
}
|
||||
}
|
||||
|
||||
void searchGroup() async {
|
||||
var list = await OpenIM.iMManager.groupManager.getGroupsInfo(
|
||||
groupIDList: [searchKey],
|
||||
);
|
||||
groupInfoList.assignAll(list);
|
||||
}
|
||||
|
||||
String getMatchContent(UserFullInfo userInfo) {
|
||||
final keyword = searchCtrl.text;
|
||||
|
||||
return sprintf(StrRes.searchNicknameIs, [userInfo.nickname]);
|
||||
}
|
||||
|
||||
String? getShowName(dynamic info) {
|
||||
if (info is UserFullInfo) {
|
||||
return info.nickname;
|
||||
} else if (info is GroupInfo) {
|
||||
return info.groupName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void viewInfo(dynamic info) {
|
||||
if (info is UserFullInfo) {
|
||||
AppNavigator.startUserProfilePane(
|
||||
userID: info.userID!,
|
||||
nickname: info.nickname,
|
||||
faceURL: info.faceURL,
|
||||
);
|
||||
} else if (info is GroupInfo) {
|
||||
AppNavigator.startGroupProfilePanel(
|
||||
groupID: info.groupID,
|
||||
joinGroupMethod: JoinGroupMethod.search,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String getShowTitle(info) {
|
||||
if (!isSearchUser) {
|
||||
return sprintf(StrRes.searchGroupNicknameIs, [getShowName(info)]);
|
||||
}
|
||||
|
||||
UserFullInfo userFullInfo = info;
|
||||
String? tips, content;
|
||||
if (int.tryParse(searchKey) != null) {
|
||||
if (searchKey.length == 11) {
|
||||
tips = StrRes.phoneNumber;
|
||||
content = userFullInfo.phoneNumber ?? searchKey;
|
||||
} else {
|
||||
tips = StrRes.userID;
|
||||
content = userFullInfo.userID;
|
||||
}
|
||||
} else {
|
||||
tips = StrRes.searchNicknameIs;
|
||||
content = getShowName(info);
|
||||
}
|
||||
return "$tips:$content";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:openim/routes/app_navigator.dart';
|
||||
import 'package:openim_common/openim_common.dart';
|
||||
import 'package:pull_to_refresh_new/pull_to_refresh.dart';
|
||||
import 'package:sprintf/sprintf.dart';
|
||||
|
||||
import 'add_by_search_logic.dart';
|
||||
|
||||
class AddContactsBySearchPage extends StatelessWidget {
|
||||
final logic = Get.find<AddContactsBySearchLogic>();
|
||||
|
||||
AddContactsBySearchPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: TitleBar.back(
|
||||
title: logic.isSearchUser ? StrRes.addFriend : StrRes.addGroup,
|
||||
),
|
||||
backgroundColor: Styles.c_FFFFFF,
|
||||
body: Column(
|
||||
children: [
|
||||
SearchBox(
|
||||
focusNode: logic.focusNode,
|
||||
controller: logic.searchCtrl,
|
||||
hintText: logic.isSearchUser ? StrRes.searchByPhoneAndUid : StrRes.searchIDAddGroup,
|
||||
enabled: true,
|
||||
autofocus: true,
|
||||
margin: EdgeInsets.symmetric(horizontal: 17.w, vertical: 10.h),
|
||||
onSubmitted: (_) => logic.search(),
|
||||
),
|
||||
Divider(color: Styles.c_E8EAEF, height: 1.h),
|
||||
if (logic.isSearchUser)
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onTap: AppNavigator.startScan,
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(top: 22.h),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.w),
|
||||
child: Row(
|
||||
children: [
|
||||
ImageRes.scanBlue.toImage
|
||||
..width = 40.w
|
||||
..height = 40.h,
|
||||
8.horizontalSpace,
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
StrRes.scan.toText..style = Styles.ts_0C1C33_17sp_medium,
|
||||
8.verticalSpace,
|
||||
StrRes.scanHint.toText..style = Styles.ts_8E9AB0_12sp,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Obx(() => Expanded(
|
||||
child: logic.isSearchUser
|
||||
? (logic.isNotFoundUser ? _buildNotFoundView() : _buildUserListView())
|
||||
: (logic.isNotFoundGroup
|
||||
? _buildNotFoundView()
|
||||
: (Column(
|
||||
children: logic.groupInfoList.map((e) => _buildItemView(e)).toList(),
|
||||
))),
|
||||
))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUserListView() => SmartRefresher(
|
||||
controller: logic.refreshCtrl,
|
||||
enablePullDown: false,
|
||||
enablePullUp: true,
|
||||
footer: IMViews.buildFooter(),
|
||||
onLoading: logic.loadMoreUser,
|
||||
child: ListView.builder(
|
||||
itemCount: logic.userInfoList.length,
|
||||
itemBuilder: (_, index) {
|
||||
final userInfo = logic.userInfoList.elementAt(index);
|
||||
return _buildItemView(userInfo);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildItemView(dynamic info) => InkWell(
|
||||
onTap: () => logic.viewInfo(info),
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.w),
|
||||
decoration: BoxDecoration(
|
||||
border: BorderDirectional(
|
||||
bottom: BorderSide(color: Styles.c_E8EAEF, width: 1.h),
|
||||
),
|
||||
),
|
||||
height: 49.h,
|
||||
child: Row(
|
||||
children: [
|
||||
(logic.isSearchUser ? ImageRes.searchPersonIcon : ImageRes.searchGroupIcon).toImage
|
||||
..width = 24.w
|
||||
..height = 24.h,
|
||||
12.horizontalSpace,
|
||||
logic.getShowTitle(info).toText
|
||||
..style = Styles.ts_0089FF_17sp
|
||||
..maxLines = 1
|
||||
..overflow = TextOverflow.ellipsis,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildNotFoundView() => Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 12.h),
|
||||
child: (logic.isSearchUser ? StrRes.noFoundUser : StrRes.noFoundGroup).toText..style = Styles.ts_8E9AB0_17sp,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user