Skip to content

Instantly share code, notes, and snippets.

@esarbanis
Last active March 23, 2020 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esarbanis/c4eaadd389570640adb56b53bb5ce582 to your computer and use it in GitHub Desktop.
Save esarbanis/c4eaadd389570640adb56b53bb5ce582 to your computer and use it in GitHub Desktop.
IoC
final getIt = GetIt.instance;
void configure() {
getIt
..registerSingleton(Repository())
..registerFactory(
() => Bloc(getIt<Repository>()));
}
import 'app_context.dart';
void main() {
configure();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyPage(),
);
}
}
class MyPage extends StatefulWidget {
@override
_MyPageState createState() => _MyPageState();
}
class _MyPageState extends State<MyPage> {
final bloc = getIt<DebtorBloc>();
@override
void dispose() {
bloc.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
// Presentanional Components Composition
}
}
class Repository {}
class Bloc {
final Repository repository;
ServiceB(this.repository);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment