tuiBuild method

  1. @override
Widget tuiBuild(
  1. BuildContext context,
  2. TUIKitBuildValue value
)
override

Implementation

@override
Widget tuiBuild(BuildContext context, TUIKitBuildValue value) {
  if (PlatformUtils().isWeb) {
    return TIMUIKitSearchNotSupport();
  }
  return MultiProvider(
    providers: [
      ChangeNotifierProvider.value(
          value: serviceLocator<TUISearchViewModel>())
    ],
    builder: (context, w) {
      List<V2TimFriendInfoResult> friendResultList =
          Provider.of<TUISearchViewModel>(context).friendList ?? [];
      List<V2TimMessageSearchResultItem> msgList =
          Provider.of<TUISearchViewModel>(context).msgList ?? [];
      List<V2TimGroupInfo> groupList =
          Provider.of<TUISearchViewModel>(context).groupList ?? [];
      int totalMsgCount =
          Provider.of<TUISearchViewModel>(context).totalMsgCount;
      return GestureDetector(
        onTap: () {
          FocusScopeNode currentFocus = FocusScope.of(context);
          if (!currentFocus.hasPrimaryFocus) {
            currentFocus.unfocus();
          }
        },
        child: Scaffold(
          body: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              TIMUIKitSearchInput(
                focusNode: focusNode,
                key: inputTextField,
                isAutoFocus: widget.isAutoFocus,
                onChange: (String value) {
                  model.searchByKey(value);
                },
                controller: textEditingController,
                prefixIcon: Icon(
                  Icons.search,
                  size: 16,
                  color: hexToColor("979797"),
                ),
              ),
              Expanded(
                  child: GestureDetector(
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      if ((friendResultList.isEmpty ||
                          !(searchTypes.contains(SearchType.contact))) &&
                              (groupList.isEmpty ||
                                  !(searchTypes
                                      .contains(SearchType.group))) &&
                              (totalMsgCount == 0 ||
                                  !(searchTypes
                                      .contains(SearchType.history))))
                        TIMUIKitSearchIndicator(
                          typeList: searchTypes,
                          onChange: (list) {
                            setState(() {
                              searchTypes = list;
                            });
                          },
                        ),
                      if (searchTypes.contains(SearchType.contact))
                        TIMUIKitSearchFriend(
                            onTapConversation: (conversation, message) {
                              focusNode.unfocus();
                              Future.delayed(
                                  const Duration(milliseconds: 100), () {
                                widget.onTapConversation(
                                    conversation, message);
                              });
                            },
                            friendResultList: friendResultList),
                      if (searchTypes.contains(SearchType.group))
                        TIMUIKitSearchGroup(
                          groupList: groupList,
                          onTapConversation: (conversation, message) {
                            focusNode.unfocus();
                            Future.delayed(const Duration(milliseconds: 100),
                                () {
                              widget.onTapConversation(conversation, message);
                            });
                          },
                        ),
                      if (searchTypes.contains(SearchType.history))
                        TIMUIKitSearchMsg(
                          onTapConversation: widget.onTapConversation,
                          keyword: textEditingController.text,
                          totalMsgCount: totalMsgCount,
                          msgList: msgList,
                          onEnterConversation:
                              (V2TimConversation conversation,
                                  String keyword) {
                            if (widget.onEnterSearchInConversation != null) {
                              widget.onEnterSearchInConversation!(
                                  conversation, keyword);
                            } else if (widget.onEnterConversation != null) {
                              widget.onEnterConversation!(
                                  conversation, keyword);
                            }
                          },
                        ),
                    ],
                  ),
                ),
                onTap: () {
                  if (widget.onBack != null) {
                    widget.onBack!();
                  }
                },
              ))
            ],
          ),
        ),
      );
    },
  );
}