Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M3-337 그룹 검색 기능 개발 #95

Merged
merged 14 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/constants/app_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ class AppColors {
static const Color boxColorThird = Color(0xFF292929);
static const Color buttonColor = Colors.white;
static const Color navigationBarColor = Color(0xFF1D1D1D);
static const Color subLineColor = Color(0xFF262626);
}
65 changes: 65 additions & 0 deletions lib/controllers/search_community_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../service/community_service.dart';

class SearchCommunityController extends GetxController {
RxList<dynamic> searchResult = <dynamic>[].obs;
FocusNode searchFocusNode = FocusNode();
late final TextEditingController textEditingController;

RxString searchKeyword = "".obs;
RxString imageUrl = "".obs;
RxString communityName = "".obs;
RxInt communityId = 0.obs;

CommunityService communityService = CommunityService();
tkdals802 marked this conversation as resolved.
Show resolved Hide resolved

@override
void onInit() {
super.onInit();
textEditingController = TextEditingController(text: searchKeyword.value);
searchFocusNode.addListener(
() {
if (searchFocusNode.hasFocus) {
textEditingController.selection = TextSelection(
baseOffset: 0,
extentOffset: textEditingController.text.length,
);
}
},
);
}

@override
Future<void> onClose() async {
await textDispose();
super.onClose();
}

Future<void> textDispose() async {
textEditingController.dispose();
searchFocusNode.dispose();
}

void getSearchedGroup(keyword) async {
List<dynamic> getInstance =
await communityService.getSearchCommunities(searchKeyword: keyword);
searchResult.assignAll(getInstance);
}

void updateKeyword(String value) {
searchKeyword.value = value;
if (textEditingController.text.isNotEmpty) {
getSearchedGroup(value);
}else{
searchResult.clear();
}
}

void updateCommunityInfo(dynamic communityInfo){
imageUrl.value = communityInfo.backgroundImageUrl;
communityName.value = communityInfo.name;
communityId.value = communityInfo.id;
}
}
37 changes: 0 additions & 37 deletions lib/controllers/search_group_controller.dart

This file was deleted.

27 changes: 24 additions & 3 deletions lib/models/search_group.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
class SearchGroupResult {
String name;
String backgroundImageUrl;
String communityColor;
int id;

SearchGroupResult({required this.name});
SearchGroupResult(
{required this.name,
required this.backgroundImageUrl,
required this.communityColor,
required this.id,});
tkdals802 marked this conversation as resolved.
Show resolved Hide resolved

factory SearchGroupResult.fromJson(Map<String, dynamic> json) {
return switch (json) {
{'name': var name} => SearchGroupResult(name: name),
{
'name': var name,
'backgroundImageUrl': var backgroundImageUrl,
'communityColor': var communityColor,
'id': var id
} =>
SearchGroupResult(
name: name,
backgroundImageUrl: backgroundImageUrl,
communityColor: communityColor,
id: id,
),
_ => throw const FormatException('Failed to load group')
};
}

static List<SearchGroupResult> listFromJson(List<dynamic> jsonList) {
return [for (var element in jsonList) SearchGroupResult.fromJson(element)];
return [
for (var element in jsonList)
if (element != null) SearchGroupResult.fromJson(element),
];
}
}
Loading