diff --git a/analysis_options.yaml b/analysis_options.yaml index 61b6c4d..93fe27a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -7,23 +7,22 @@ # The following line activates a set of recommended lints for Flutter apps, # packages, and plugins designed to encourage good coding practices. -include: package:flutter_lints/flutter.yaml +include: package:lint/analysis_options.yaml linter: - # The lint rules applied to this project can be customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at - # https://dart-lang.github.io/linter/lints/index.html. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + always_declare_return_types: true -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options +analyzer: + exclude: + - "**/*.freezed.dart" + - "**/*.config.dart" + - "**/*.g.dart" + + strong-mode: + implicit-casts: true + + errors: + missing_required_param: error + must_be_immutable: error + always_declare_return_types: warning diff --git a/lib/application/auth/sign_in_form/sign_in_form_bloc.dart b/lib/application/auth/sign_in_form/sign_in_form_bloc.dart index 1d4473e..7c04ea7 100644 --- a/lib/application/auth/sign_in_form/sign_in_form_bloc.dart +++ b/lib/application/auth/sign_in_form/sign_in_form_bloc.dart @@ -6,10 +6,12 @@ import 'package:flutter_firebase_ddd_bloc/domain/auth/i_auth_facade.dart'; import 'package:flutter_firebase_ddd_bloc/domain/auth/value_objects.dart'; import 'package:fpdart/fpdart.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:injectable/injectable.dart'; part 'sign_in_form_event.dart'; part 'sign_in_form_bloc.freezed.dart'; +@injectable class SignInFormBloc extends Bloc { SignInFormBloc(this._authFacade) : super(SignInFormState.initial()) { on( diff --git a/lib/domain/core/firebase_injectable.module.dart b/lib/domain/core/firebase_injectable.module.dart new file mode 100644 index 0000000..33add52 --- /dev/null +++ b/lib/domain/core/firebase_injectable.module.dart @@ -0,0 +1,12 @@ +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:google_sign_in/google_sign_in.dart'; +import 'package:injectable/injectable.dart'; + +@module +abstract class FirebaseInjectableModule { + @lazySingleton + GoogleSignIn get googleSignIn => GoogleSignIn(); + + @lazySingleton + FirebaseAuth get firebaseAuth => FirebaseAuth.instance; +} diff --git a/lib/infrastructure/auth/firebase_auth_facade.dart b/lib/infrastructure/auth/firebase_auth_facade.dart index 1d23472..f81e409 100644 --- a/lib/infrastructure/auth/firebase_auth_facade.dart +++ b/lib/infrastructure/auth/firebase_auth_facade.dart @@ -6,7 +6,9 @@ import 'package:flutter_firebase_ddd_bloc/domain/auth/value_objects.dart'; import 'package:fpdart/fpdart.dart'; import 'package:google_sign_in/google_sign_in.dart'; +import 'package:injectable/injectable.dart'; +@LazySingleton(as: IAuthFacade) class FirebaseAuthFacade implements IAuthFacade { FirebaseAuthFacade(this._firebaseAuth, this._googleSignIn); diff --git a/lib/injection.config.dart b/lib/injection.config.dart new file mode 100644 index 0000000..7927462 --- /dev/null +++ b/lib/injection.config.dart @@ -0,0 +1,45 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ************************************************************************** +// InjectableConfigGenerator +// ************************************************************************** + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:firebase_auth/firebase_auth.dart' as _i3; +import 'package:get_it/get_it.dart' as _i1; +import 'package:google_sign_in/google_sign_in.dart' as _i4; +import 'package:injectable/injectable.dart' as _i2; + +import 'application/auth/sign_in_form/sign_in_form_bloc.dart' as _i7; +import 'domain/auth/i_auth_facade.dart' as _i5; +import 'domain/core/firebase_injectable.module.dart' as _i8; +import 'infrastructure/auth/firebase_auth_facade.dart' + as _i6; // ignore_for_file: unnecessary_lambdas + +// ignore_for_file: lines_longer_than_80_chars +/// initializes the registration of provided dependencies inside of [GetIt] +_i1.GetIt $initGetIt( + _i1.GetIt get, { + String? environment, + _i2.EnvironmentFilter? environmentFilter, +}) { + final gh = _i2.GetItHelper( + get, + environment, + environmentFilter, + ); + final firebaseInjectableModule = _$FirebaseInjectableModule(); + gh.lazySingleton<_i3.FirebaseAuth>( + () => firebaseInjectableModule.firebaseAuth); + gh.lazySingleton<_i4.GoogleSignIn>( + () => firebaseInjectableModule.googleSignIn); + gh.lazySingleton<_i5.IAuthFacade>(() => _i6.FirebaseAuthFacade( + get<_i3.FirebaseAuth>(), + get<_i4.GoogleSignIn>(), + )); + gh.factory<_i7.SignInFormBloc>( + () => _i7.SignInFormBloc(get<_i5.IAuthFacade>())); + return get; +} + +class _$FirebaseInjectableModule extends _i8.FirebaseInjectableModule {} diff --git a/lib/injection.dart b/lib/injection.dart new file mode 100644 index 0000000..a57eff6 --- /dev/null +++ b/lib/injection.dart @@ -0,0 +1,10 @@ +import 'package:flutter_firebase_ddd_bloc/injection.config.dart'; +import 'package:get_it/get_it.dart'; +import 'package:injectable/injectable.dart'; + +final getIt = GetIt.instance; + +@injectableInit +void configureInjection(String env) { + $initGetIt(getIt, environment: env); +} diff --git a/lib/main.dart b/lib/main.dart index 9e24ab3..ec85f06 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,9 +1,12 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:flutter_firebase_ddd_bloc/firebase_options.dart'; +import 'package:flutter_firebase_ddd_bloc/injection.dart'; +import 'package:injectable/injectable.dart'; void main() async { await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); + configureInjection(Environment.prod); runApp(const AppWidget()); } diff --git a/pubspec.yaml b/pubspec.yaml index 523efcc..58041d0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,7 +37,8 @@ dependencies: flutter_bloc: ^8.1.1 google_sign_in: ^5.4.2 firebase_auth: ^4.0.1 - rename: ^2.0.1 + injectable: ^1.5.3 + get_it: ^7.2.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 @@ -47,11 +48,13 @@ dev_dependencies: sdk: flutter freezed: ^2.2.0 build_runner: ^2.3.0 + injectable_generator: ^1.5.4 # The "flutter_lints" package below contains a set of recommended lints to # encourage good coding practices. The lint set provided by the package is # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. + lint: ^1.10.0 flutter_lints: ^2.0.0 # For information on the generic Dart part of this file, see the