Skip to content

Instantly share code, notes, and snippets.

View letsar's full-sized avatar
🦋
Flutter forever

Romain Rastel letsar

🦋
Flutter forever
View GitHub Profile
import 'package:kiwi/kiwi.dart';
part 'test01.g.dart';
abstract class Injector {
@Register.singleton(ServiceA)
@Register.factory(Service, from: ServiceB)
@Register.factory(ServiceB, name: 'factoryB')
@Register.factory(ServiceC, resolvers: {ServiceB: 'factoryB'})
void common();
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'test01.dart';
// **************************************************************************
// InjectorGenerator
// **************************************************************************
class _$Injector extends Injector {
void configure() {
import 'package:kiwi/kiwi.dart';
part 'test01.g.dart';
abstract class Injector {
@Register.singleton(ServiceA)
@Register.factory(Service, from: ServiceB)
@Register.factory(ServiceB, name: 'factoryB')
@Register.factory(ServiceC, resolvers: {ServiceB: 'factoryB'})
@Register.factory(ServiceC, constructorName: 'other')
class Service {}
class ServiceA extends Service {}
class ServiceB extends Service {
ServiceB(ServiceA serviceA);
}
...
// Registers a complex factory by resolving the dependency
// when the type is resolved.
// Gets the instance registered for the Sith type.
Sith theSith = container.resolve<Sith>();
// Gets the instance registered for the Sith type under 'DartVader' name.
Sith dartVader = container.resolve<Sith>('DartVader');
// Container is a callable class, so you can also resolve a type like this:
Sith sith = container<Sith>();
// Registers a new singleton.
container.registerSingleton((c) => Sith('Anakin', 'Skywalker'));
// Registers a new singleton with a specified name.
container.registerSingleton((c) => Sith('Anakin', 'Skywalker'), name: 'DartVader');
// Registers a new singleton, with a specified name, and under a supertype.
container.registerSingleton<Character, Sith>((c) => Sith('Anakin', 'Skywalker'), name: 'DartVader');
// Registers a new factory.
container.registerFactory((c) => Sith('Anakin', 'Skywalker'));
// Registers a new factory with a specified name.
container.registerFactory((c) => Sith('Anakin', 'Skywalker'), name: 'DartVader');
// Registers a new factory, with a specified name, and under a supertype.
container.registerFactory<Character, Sith>((c) => Sith('Anakin', 'Skywalker'), name: 'DartVader');
// Registers a new instance.
container.registerInstance(Sith('Anakin', 'Skywalker'));
// Registers a new instance with a specified name.
container.registerInstance(Sith('Anakin', 'Skywalker'), name: 'DartVader');
// Registers a new instance, with a specified name, and under a supertype.
container.registerInstance<Character, Sith>(Sith('Anakin', 'Skywalker'), name: 'DartVader');
Container container = Container();
const _kDuration = const Duration(milliseconds: 2000);
const _kAnimInterval03 = const Interval(.00, .90);
...
Widget _buildAnimation(BuildContext context, Widget child) {
return Container(
child: Container(
width: _kActionSize * 4,
height: 256.0,
color: Colors.black87,
child: Center(