Last active
March 23, 2020 17:10
-
-
Save esarbanis/c4eaadd389570640adb56b53bb5ce582 to your computer and use it in GitHub Desktop.
IoC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final getIt = GetIt.instance; | |
void configure() { | |
getIt | |
..registerSingleton(Repository()) | |
..registerFactory( | |
() => Bloc(getIt<Repository>())); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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