sc2bat / my_flutter_image_searching_app_cleanarch

2 stars 2 forks source link

topSearches 화면 연결 #28

Closed yoonjikimkr closed 8 months ago

yoonjikimkr commented 8 months ago

Clean Architecture

1. TagRepository

  • abstract interface class TagRepository{Future getTagCounts();}

2. TagRepositoryImpl

  • getTagCounts() async { supabase.rpc('get_tag_counts'); return Result.success(data);}

3. dependency injection

final getIt = GetIt.instance; void registerDependencies() { // repositories /..registerSingleton( TagRepositoryImpl(), );/ // usecases / // topsearch ..registerSingleton( TopsearchUseCase( tagRepository: getIt(), ), );/ // view models /..registerFactory( () => HomeViewModel( topsearchUseCase: getIt(), ), )/

4. TopsearchUseCase

  • await _tagRepository.getTagCounts();
  • return topTagsResult.when(success: (topTags) { return Result.success(topTags);},

5. HomeViewModel

getToptags() /_homeState = homeState.copyWith( isLoading: true, topTags: topTagsList); notifyListeners();/

6. HomeState

  • @freezed List<Map<String, dynamic>> topTags

7. HomeScreen

'${homeState.topTags[index]['tag']}',