Skip to content

Commit

Permalink
code for documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
escamoteur committed Feb 12, 2020
1 parent 13139b7 commit eb97742
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions example/lib/code_for_documentation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:get_it/get_it.dart';
import 'package:get_it_example/app_model.dart';

class AppModel {}

class AppModelImplmentation extends AppModel {
AppModelImplmentation(initiData);
}

class AppModelMock extends AppModel {}

class DbService {}

GetIt getIt = GetIt.instance;

class UserManager {
AppModel appModel;
DbService dbService;

UserManager({AppModel appModel, DbService dbService}) {
this.appModel = appModel ?? getIt.get<AppModel>();
this.dbService = dbService ?? getIt.get<DbService>();
}
}

Future restCall()async{}

void init() {
bool testing;
// ambient variable to access the service locator
GetIt sl = GetIt.instance;

void setup() {
sl.registerFactoryAsync<AppModel>(() async => AppModelImplmentation(await restCall()));

sl.registerSingletonAsync<AppModel>(() async => AppModelImplmentation(await restCall()));

sl.registerFactoryAsync<AppModel>(() async => AppModelImplmentation(await restCall()));

// sl.registerFactory<AppModel>(() => AppModelImplmentation());

// sl.registerSingleton<AppModel>(AppModelImplmentation());

// sl.registerLazySingleton<AppModel>(() => AppModelImplmentation());

if (testing) {
sl.registerSingleton<AppModel>(AppModelMock());
} else {
sl.registerSingleton<AppModel>(AppModelImplmentation());
}
}
}

// /// instead of
// MaterialButton(
// child: Text("Update"),
// onPressed: TheViewModel.of(context).update
// ),

// /// do
// MaterialButton(
// child: Text("Update"),
// onPressed: sl.get<AppModel>().update
// ),

// /// or even shorter
// MaterialButton(
// child: Text("Update"),
// onPressed: sl.<AppModel>().update
// ),

0 comments on commit eb97742

Please sign in to comment.