-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: added providers for the presentation layer (news feed feature)
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
lib/features/news_feed/presentation/providers/chosen_category_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class ChosenCategoryNotifier extends StateNotifier<String> { | ||
ChosenCategoryNotifier(super.state); | ||
|
||
void changeState(String value) { | ||
state = value; | ||
} | ||
} | ||
|
||
final chosenCategoryProvider = | ||
StateNotifierProvider<ChosenCategoryNotifier, String>((ref) { | ||
return ChosenCategoryNotifier("health"); | ||
}); |
58 changes: 58 additions & 0 deletions
58
lib/features/news_feed/presentation/providers/news_feed_providers.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:connectivity_plus/connectivity_plus.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:dio/dio.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:news_app/core/error/failures.dart'; | ||
import 'package:news_app/core/platform/network_info.dart'; | ||
import 'package:news_app/features/news_feed/data/data_sources/news_feed_remote_data_source.dart'; | ||
import 'package:news_app/features/news_feed/data/repositories/news_feed_repository_impl.dart'; | ||
import 'package:news_app/features/news_feed/domain/entities/news_feed_entity.dart'; | ||
import 'package:news_app/features/news_feed/domain/repositories/news_feed_repository.dart'; | ||
import 'package:news_app/features/news_feed/domain/use_cases/get_news_feed_for_a_category.dart'; | ||
import 'package:news_app/features/news_feed/presentation/providers/chosen_category_provider.dart'; | ||
|
||
// CORE - PLATFORM | ||
final connectivityProvider = Provider<Connectivity>((ref) { | ||
return Connectivity(); | ||
}); | ||
|
||
final networkInfoProvider = Provider<NetworkInfo>((ref) { | ||
final connectivity = ref.read(connectivityProvider); | ||
return NetworkInfoImplementation(connectivity); | ||
}); | ||
|
||
// DATA - DATA SOURCES | ||
final dioProvider = Provider<Dio>((ref) { | ||
return Dio(); | ||
}); | ||
|
||
final remoteDataSourceProvider = Provider<NewsFeedRemoteDataSource>((ref) { | ||
final dio = ref.read(dioProvider); | ||
return NewsFeedRemoteDataSourceImpl(dio); | ||
}); | ||
|
||
// DATA x DOMAIN - REPOSITORIES | ||
final repositoryProvider = Provider<NewsFeedRepository>((ref) { | ||
final remoteDataSource = ref.read(remoteDataSourceProvider); | ||
final networkInfo = ref.read(networkInfoProvider); | ||
return NewsFeedRepositoryImpl( | ||
networkInfo: networkInfo, | ||
remoteDataSource: remoteDataSource, | ||
); | ||
}); | ||
|
||
// DOMAIN - USE CASES | ||
final useCaseProvider = Provider<GetNewsFeedForACategory>((ref) { | ||
final repository = ref.read(repositoryProvider); | ||
return GetNewsFeedForACategory(repository); | ||
}); | ||
|
||
// PRESENTATION | ||
|
||
final newsFeedProvider = FutureProvider<Either<Failure, NewsFeedEntity>>((ref) { | ||
final category = ref.read(chosenCategoryProvider); | ||
final params = Params( | ||
category: category, | ||
); | ||
return ref.read(useCaseProvider).call(params); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters