Skip to content

Commit

Permalink
feature: added providers for the presentation layer (news feed feature)
Browse files Browse the repository at this point in the history
  • Loading branch information
BasakK6 committed Sep 28, 2023
1 parent 71807dd commit 6fb3a01
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
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");
});
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);
});
24 changes: 24 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.3"
flutter_riverpod:
dependency: "direct main"
description:
name: flutter_riverpod
sha256: fcea39b84b666649280f6f678bc0bb479253bf865abc0387a8b11dac6477bf92
url: "https://pub.dev"
source: hosted
version: "2.4.1"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -464,6 +472,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.3"
riverpod:
dependency: transitive
description:
name: riverpod
sha256: ff676bd8a715c7085692fe4919564f78fb90d33b10a1c5c14e740581857cc914
url: "https://pub.dev"
source: hosted
version: "2.4.1"
shelf:
dependency: transitive
description:
Expand Down Expand Up @@ -509,6 +525,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.11.0"
state_notifier:
dependency: transitive
description:
name: state_notifier
sha256: b8677376aa54f2d7c58280d5a007f9e8774f1968d1fb1c096adcb4792fba29bb
url: "https://pub.dev"
source: hosted
version: "1.0.0"
stream_channel:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ dependencies:
connectivity_plus: ^4.0.2
# network requests
dio: ^5.3.3
# state management
flutter_riverpod: ^2.4.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 6fb3a01

Please sign in to comment.