Skip to content

Commit

Permalink
Merge pull request #3 from SandroMaglione/3_dependency_injection
Browse files Browse the repository at this point in the history
Dependency injection (`injectable`) [3]
  • Loading branch information
SandroMaglione authored Sep 24, 2022
2 parents 5ab4a61 + cdc5d19 commit dbdd86e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ app.*.map.json
# Generated files
lib/**/*.g.dart
lib/**/*.gr.dart
lib/**/*.freezed.dart
lib/**/*.freezed.dart
lib/**/*.config.dart
3 changes: 3 additions & 0 deletions lib/app/repository/auth_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract class AuthRepository {
Future<String> signIn();
}
11 changes: 11 additions & 0 deletions lib/app/services/supabase_auth_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter_supabase_complete/app/repository/auth_repository.dart';
import 'package:injectable/injectable.dart';

@Injectable(as: AuthRepository)
class SupabaseAuthRepository implements AuthRepository {
@override
Future<String> signIn() {
// TODO: implement signIn
throw UnimplementedError();
}
}
8 changes: 8 additions & 0 deletions lib/injectable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:flutter_supabase_complete/injectable.config.dart';
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';

final getIt = GetIt.instance;

@InjectableInit()
void configureDependencies() => $initGetIt(getIt);
5 changes: 5 additions & 0 deletions lib/main_common.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import 'package:flutter/material.dart';
import 'package:flutter_supabase_complete/app.dart';
import 'package:flutter_supabase_complete/constants.dart';
import 'package:flutter_supabase_complete/injectable.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

/// Shared `runApp` configuration.
///
/// Used to initialize all required dependencies, packages, and constants.
Future<void> mainCommon() async {
WidgetsFlutterBinding.ensureInitialized();

// Dependency injection (injectable)
configureDependencies();

await Supabase.initialize(
url: Constants.supabaseUrl,
anonKey: Constants.supabaseAnnonKey,
Expand Down
21 changes: 21 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0-dev.1"
get_it:
dependency: "direct main"
description:
name: get_it
url: "https://pub.dartlang.org"
source: hosted
version: "7.2.0"
glob:
dependency: transitive
description:
Expand Down Expand Up @@ -338,6 +345,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.1"
injectable:
dependency: "direct main"
description:
name: injectable
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.3"
injectable_generator:
dependency: "direct dev"
description:
name: injectable_generator
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.4"
io:
dependency: transitive
description:
Expand Down
7 changes: 7 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ dependencies:
sdk: flutter

supabase_flutter: ^1.0.0-dev.2

# Routing
auto_route: ^4.2.1

# Dependency injection
injectable: ^1.5.3
get_it: ^7.2.0

dev_dependencies:
flutter_test:
sdk: flutter

build_runner: ^2.2.0
flutter_lints: ^2.0.0
auto_route_generator: ^4.2.1
injectable_generator: ^1.5.4

flutter:

0 comments on commit dbdd86e

Please sign in to comment.