Skip to content

Commit fb706cf

Browse files
committed
adding dependency injection framework
1 parent d1dce2c commit fb706cf

24 files changed

+217
-75
lines changed

android/app/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ android {
3737
}
3838

3939
defaultConfig {
40-
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
41-
applicationId "com.ruben.fun_box"
40+
applicationId "com.ruben.funbox"
4241
minSdkVersion 16
43-
targetSdkVersion 29
42+
targetSdkVersion 30
4443
versionCode flutterVersionCode.toInteger()
4544
versionName flutterVersionName
4645
}

data/lib/di/di.config.dart

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data/lib/di/di.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:data/di/di.config.dart';
2+
import 'package:injectable/injectable.dart';
3+
4+
@InjectableInit(
5+
initializerName: r'$initDataGetIt'
6+
)
7+
Future configureDataInjection(final getIt) async => $initDataGetIt(getIt);

data/lib/repository/repository_impl.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import 'package:domain/repository/repository.dart';
2-
import 'package:remote/datasource/movies_shows_data_source_impl.dart';
2+
import 'package:injectable/injectable.dart';
3+
import 'package:remote/datasource/movies_shows_data_source.dart';
34
import 'package:remote/model/request/movies_shows_request.dart';
45

6+
@Singleton(as: Repository)
57
class RepositoryImpl implements Repository {
68

7-
var moviesShowsDataSource = MoviesShowsDataSourceImpl();
9+
final MoviesShowsDataSource moviesShowsDataSource;
10+
11+
RepositoryImpl(this.moviesShowsDataSource);
812

913
@override
1014
Future<dynamic> getTrendingMoviesShows(String type) {

data/pubspec.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
publish_to: none
12
name: data
23
description: A new flutter module project.
34

@@ -18,7 +19,7 @@ description: A new flutter module project.
1819
version: 1.0.0+1
1920

2021
environment:
21-
sdk: ">=2.1.0 <3.0.0"
22+
sdk: ">=2.12.0 <3.0.0"
2223

2324
dependencies:
2425
flutter:
@@ -27,6 +28,8 @@ dependencies:
2728
# The following adds the Cupertino Icons font to your application.
2829
# Use with the CupertinoIcons class for iOS style icons.
2930
cupertino_icons: ^1.0.0
31+
injectable: ^1.2.2
32+
get_it: ^6.0.0
3033

3134
domain:
3235
path: ../domain
@@ -37,6 +40,8 @@ dependencies:
3740
dev_dependencies:
3841
flutter_test:
3942
sdk: flutter
43+
injectable_generator: 1.2.2
44+
build_runner: 1.12.2
4045

4146
# For information on the generic Dart part of this file, see the
4247
# following page: https://dart.dev/tools/pub/pubspec
@@ -88,5 +93,5 @@ flutter:
8893
# identifiers, which may be completely independent or the same as these.
8994
module:
9095
androidX: true
91-
androidPackage: com.example.data
92-
iosBundleIdentifier: com.example.data
96+
androidPackage: com.ruben.funbox.data
97+
iosBundleIdentifier: com.ruben.funbox.data

domain/lib/di/di.config.dart

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

domain/lib/di/di.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'package:domain/di/di.config.dart';
2+
import 'package:injectable/injectable.dart';
3+
4+
@InjectableInit(
5+
initializerName: r'$initDomainGetIt'
6+
)
7+
Future configureDomainInjection(final getIt) async => $initDomainGetIt(getIt);

domain/lib/model/movies_shows.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
11
class MoviesShows{
22

3-
String title;
4-
int id;
5-
String posterPath;
6-
String backDropPath;
7-
8-
MoviesShows({this.title, this.id, this.posterPath, this.backDropPath});
9-
103
}

domain/lib/model/movies_shows_record.dart

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
class MoviesShowsRecord {
2-
int page;
3-
List<Results> results;
4-
int totalPages;
5-
int totalResults;
2+
int? page;
3+
List<Results>? results;
4+
int? totalPages;
5+
int? totalResults;
66

77
MoviesShowsRecord(
88
{this.page, this.results, this.totalPages, this.totalResults});
99

1010
MoviesShowsRecord.fromJson(Map<String, dynamic> json) {
1111
page = json['page'];
1212
if (json['results'] != null) {
13-
results = new List<Results>();
13+
results = <Results>[];
1414
json['results'].forEach((v) {
15-
results.add(new Results.fromJson(v));
15+
results?.add(new Results.fromJson(v));
1616
});
1717
}
1818
totalPages = json['total_pages'];
@@ -23,7 +23,7 @@ class MoviesShowsRecord {
2323
final Map<String, dynamic> data = new Map<String, dynamic>();
2424
data['page'] = this.page;
2525
if (this.results != null) {
26-
data['results'] = this.results.map((v) => v.toJson()).toList();
26+
data['results'] = this.results?.map((v) => v.toJson()).toList();
2727
}
2828
data['total_pages'] = this.totalPages;
2929
data['total_results'] = this.totalResults;
@@ -32,25 +32,25 @@ class MoviesShowsRecord {
3232
}
3333

3434
class Results {
35-
String title;
36-
String originalLanguage;
37-
String originalTitle;
38-
String posterPath;
39-
bool video;
40-
double voteAverage;
41-
String overview;
42-
int id;
43-
int voteCount;
44-
bool adult;
45-
String backdropPath;
46-
String releaseDate;
47-
List<int> genreIds;
48-
double popularity;
49-
String mediaType;
50-
String firstAirDate;
51-
List<String> originCountry;
52-
String name;
53-
String originalName;
35+
String? title;
36+
String? originalLanguage;
37+
String? originalTitle;
38+
String? posterPath;
39+
bool? video;
40+
double? voteAverage;
41+
String? overview;
42+
int? id;
43+
int? voteCount;
44+
bool? adult;
45+
String? backdropPath;
46+
String? releaseDate;
47+
List<int>? genreIds;
48+
double? popularity;
49+
String? mediaType;
50+
String? firstAirDate;
51+
List<String>? originCountry;
52+
String? name;
53+
String? originalName;
5454

5555
Results(
5656
{this.title,

domain/lib/usecase/trending_movies_shows_use_case.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import 'package:domain/repository/repository.dart';
2+
import 'package:injectable/injectable.dart';
23

4+
@injectable
35
class TrendingMoviesShowsUseCase {
46

57
final Repository repository;
68

7-
TrendingMoviesShowsUseCase({this.repository});
9+
TrendingMoviesShowsUseCase(this.repository);
810

9-
Future<dynamic> getTrendingMoviesShows({String type}) async {
11+
Future<dynamic> getTrendingMoviesShows({required String type}) async {
1012
return repository.getTrendingMoviesShows(type);
1113
}
1214

0 commit comments

Comments
 (0)