Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated provider, injectable and get_it versions #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions lib/domain/i_counter_repository.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import 'package:injectable/injectable.dart';
import 'package:injectable_tutorial/infrastructure/counter_repository.dart';
import 'package:injectable_tutorial/infrastructure/dev_counter_repository.dart';
import 'package:injectable_tutorial/infrastructure/mock_counter_repository.dart';
import 'package:injectable_tutorial/injection.dart';

@Bind.toType(MockCounterRepository, env: Env.test)
@Bind.toType(DevCounterRepository, env: Env.dev)
@Bind.toType(CounterRepository, env: Env.prod)
@injectable
abstract class ICounterRepository {
int getIncrement();
}
4 changes: 3 additions & 1 deletion lib/infrastructure/counter_repository.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:injectable/injectable.dart';
import 'package:injectable_tutorial/domain/i_counter_repository.dart';

@injectable

@Environment("prod")
@Injectable(as: ICounterRepository)
class CounterRepository implements ICounterRepository {
@override
int getIncrement() => 1;
Expand Down
6 changes: 4 additions & 2 deletions lib/infrastructure/dev_counter_repository.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:injectable/injectable.dart';
import 'package:injectable_tutorial/domain/i_counter_repository.dart';

@injectable

@Environment("dev")
@Injectable(as: ICounterRepository)
class DevCounterRepository implements ICounterRepository {
@override
int getIncrement() => 2;
int getIncrement() => 5;
}
3 changes: 2 additions & 1 deletion lib/infrastructure/mock_counter_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import 'package:injectable/injectable.dart';
import 'package:injectable_tutorial/domain/i_counter_repository.dart';
import 'package:mockito/mockito.dart';

@injectable
@Environment("test")
@Injectable(as: ICounterRepository)
class MockCounterRepository extends Mock implements ICounterRepository {}
39 changes: 39 additions & 0 deletions lib/injection.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/injection.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
import 'package:injectable_tutorial/injection.iconfig.dart';
import 'package:injectable_tutorial/injection.config.dart';

final getIt = GetIt.instance;

@injectableInit
void configureInjection(String environment) =>
$initGetIt(environment: environment);
$initGetIt(getIt, environment: environment);

abstract class Env {
static const test = 'test';
Expand Down
43 changes: 0 additions & 43 deletions lib/injection.iconfig.dart

This file was deleted.

7 changes: 3 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import 'package:flutter/material.dart';
import 'package:injectable_tutorial/infrastructure/counter_repository.dart';
import 'package:injectable_tutorial/infrastructure/dev_counter_repository.dart';
import 'package:injectable_tutorial/injection.dart';
import 'package:injectable_tutorial/injection.iconfig.dart';
import 'package:injectable_tutorial/presentation/counter_change_notifier.dart';
import 'package:injectable_tutorial/presentation/counter_page.dart';

import 'package:provider/provider.dart';

void main() {
configureInjection(Env.dev);
configureInjection(Env.prod);
runApp(MyApp());
}

Expand All @@ -18,6 +16,7 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Material App',
home: ChangeNotifierProvider(
// Manually passing in the production repository
create: (_) => getIt<CounterChangeNotifier>(),
child: CounterPage(),
),
Expand Down
1 change: 1 addition & 0 deletions lib/presentation/counter_change_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';
import 'package:injectable_tutorial/domain/i_counter_repository.dart';


@injectable
class CounterChangeNotifier extends ChangeNotifier {
final ICounterRepository _counterRepository;
Expand Down
Loading