mentionTextFiled method

FlutterMentions mentionTextFiled({
  1. required Rx<GlobalKey<FlutterMentionsState>> key,
  2. int? minLines = 1,
  3. Timer? searchTimer,
})

Implementation

FlutterMentions mentionTextFiled({
  required Rx<GlobalKey<FlutterMentionsState>> key,
  int? minLines = 1,
  Timer? searchTimer,
}) {
  return FlutterMentions(
    key: key.value,
    suggestionPosition: SuggestionPosition.Top,
    maxLines: 20,
    minLines: minLines,
    suggestionListDecoration: BoxDecoration(color: Get.theme.cardColor),
    suggestionListHeight: ARMOYU.screenHeight / 3,
    onChanged: (value) {
      List<String> words = value.split(' ');
      final String lastWord = words.isNotEmpty ? words.last : "";

      if (lastWord.isEmpty) {
        // Eğer son kelime boşsa, mevcut sorguyu iptal eder
        searchTimer?.cancel();
        return;
      }

      //Oyuncu listesi bomboşsa
      if (WidgetMention.peopleList.isEmpty) {
        searchTimer = Timer(const Duration(milliseconds: 500), () async {
          SearchListResponse response =
              await service.searchServices.onlyusers(searchword: "", page: 1);
          if (!response.result.status) {
            log(response.result.description);
            return;
          }

          for (var element in response.response!.search) {
            WidgetMention.addpeopleList({
              'id': element.id.toString(),
              'display': element.username,
              'full_name': element.value.toString(),
              'photo': element.avatar.toString()
            });
          }
          key.refresh();
        });
      }
      //Hashtag listesi bomboşsa
      if (WidgetMention.hashtagList.isEmpty) {
        searchTimer = Timer(const Duration(milliseconds: 500), () async {
          SearchHashtagListResponse response =
              await service.searchServices.hashtag(hashtag: "", page: 1);
          if (!response.result.status) {
            log(response.result.description);
            return;
          }

          for (var element in response.response!.search) {
            WidgetMention.addhashtagList({
              'id': element.hashtagID.toString(),
              'display': element.value.toString(),
              'numberofuses': element.numberofuses,
            });
          }
          key.refresh();
        });
      }

      if (lastWord.length <= 3) {
        return;
      }

      if (lastWord[0] != "@" && lastWord[0] != "#") {
        // Eğer son kelime @ veya # ile başlamıyorsa, mevcut sorguyu iptal eder
        searchTimer?.cancel();
        return;
      }

      // Eğer buraya kadar gelindi ise, yeni bir kelime girilmiştir, mevcut sorguyu iptal eder
      searchTimer?.cancel();
      searchTimer = Timer(const Duration(milliseconds: 500), () async {
        if (lastWord[0] == "@") {
          SearchListResponse response = await service.searchServices
              .onlyusers(searchword: lastWord.substring(1), page: 1);

          if (!response.result.status) {
            log(response.result.description);
            return;
          }

          for (var element in response.response!.search) {
            if (lastWord[0] == "@") {
              WidgetMention.addpeopleList({
                'id': element.id.toString(),
                'display': element.username.toString(),
                'full_name': element.value.toString(),
                'photo': element.avatar.toString()
              });
            }
          }
        } else if (lastWord[0] == "#") {
          SearchHashtagListResponse response = await service.searchServices
              .hashtag(hashtag: lastWord.substring(1), page: 1);

          if (!response.result.status) {
            log(response.result.description);
            return;
          }
          for (var element in response.response!.search) {
            if (lastWord[0] == "#") {
              WidgetMention.addhashtagList({
                'id': element.hashtagID.toString(),
                'display': element.value.toString(),
                'numberofuses': element.numberofuses,
              });
            }
          }
        } else {
          return;
        }

        key.refresh();
      });
    },
    decoration: InputDecoration(hintText: SocialKeys.socialwritesomething.tr),
    mentions: [
      WidgetMention.poplementions(),
      WidgetMention.hashtag(),
    ],
  );
}