miodi 0.3.1 miodi: ^0.3.1 copied to clipboard
Dependency Injection tools for Dart.
import 'package:example/config_di.dart';
import 'package:example/widgets.dart';
import 'package:flutter/material.dart';
import 'package:miodi/miodi.dart';
import 'example_objects.dart';
void main() {
Miodi.init([AppComponent('miodi test')]);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Miodi',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage1(),
);
}
}
class MyHomePage1 extends StatefulWidget {
@override
_MyHomePageState1 createState() => _MyHomePageState1();
}
class _MyHomePageState1 extends State<MyHomePage1> {
final IExampleFactory factory = Miodi.inject();
final IExampleSingleton singleton = Miodi.inject();
@override
void initState() {
print('factory: ${factory.factoryCreatedCountObjects}');
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Screen 1'),
actions: <Widget>[
IconButton(icon: Icon(Icons.navigate_next), onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => MyHomePage2()));
})
],
),
body: Center(
child: InfoColumn(
factoryCount: factoryObjCount,
singletonCount: singletonObjCount,
usageFactory: true,
usageSingleton: true,
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class MyHomePage2 extends StatefulWidget {
@override
_MyHomePageState2 createState() => _MyHomePageState2();
}
class _MyHomePageState2 extends State<MyHomePage2> {
final IExampleFactory factory = Miodi.inject();
final IExampleSingleton singleton = Miodi.inject();
@override
void initState() {
print('factory: ${factory.factoryCreatedCountObjects}');
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Screen 2'),
actions: <Widget>[
IconButton(icon: Icon(Icons.navigate_next), onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => MyHomePage3()));
})
],
),
body: Center(
child: InfoColumn(
factoryCount: factoryObjCount,
singletonCount: singletonObjCount,
usageFactory: true,
usageSingleton: true,
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class MyHomePage3 extends StatefulWidget {
@override
_MyHomePageState3 createState() => _MyHomePageState3();
}
class _MyHomePageState3 extends State<MyHomePage3> {
final IExampleFactory factory = Miodi.inject();
final IExampleSingleton singleton = Miodi.inject();
@override
void initState() {
print('factory: ${factory.factoryCreatedCountObjects}');
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Screen 3'),
actions: <Widget>[
IconButton(icon: Icon(Icons.navigate_next), onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) => MyHomePage4()));
})
],
),
body: Center(
child: InfoColumn(
factoryCount: factoryObjCount,
singletonCount: singletonObjCount,
usageFactory: true,
usageSingleton: true,
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class MyHomePage4 extends StatefulWidget {
@override
_MyHomePageState4 createState() => _MyHomePageState4();
}
class _MyHomePageState4 extends State<MyHomePage4> {
final IExampleFactory factory = Miodi.inject();
final IExampleSingleton singleton = Miodi.inject();
@override
void initState() {
print('factory: ${factory.factoryCreatedCountObjects}');
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Screen 4'),
),
body: Center(
child: InfoColumn(
factoryCount: factoryObjCount,
singletonCount: singletonObjCount,
usageFactory: true,
usageSingleton: true,
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}