Giter Club home page Giter Club logo

kiwi's Introduction

Gabriel Tavares


GB-Flutter GB-Dart GB-C++ GB-Ts

kiwi's People

Contributors

dependabot[bot] avatar gbtb16 avatar hericles-koelher avatar ikomobi-apadol avatar kennethnym avatar letsar avatar miiite avatar simolus3 avatar vanlooverenkoen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kiwi's Issues

Version solving failed.

when i update flutter to 0.10.2, version solving failed.

Because every version of flutter_test from sdk depends on analyzer 0.33.0 and every version of kiwi_generator depends on analyzer ^0.32.2, flutter_test from sdk is incompatible with kiwi_generator.

Doesn't work with build_runner 2.0.4

Dart SDK version: 2.13.1 (stable) (Fri May 21 12:45:36 2021 +0200) on "macos_x64"
Flutter 2.2.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision d79295af24 (11 days ago) • 2021-06-11 08:56:01 -0700 Engine • revision 91c9fc8fe0 Tools • Dart 2.13.3

Using build_runner version: "2.0.4"

build.yml content:

targets:
  $default:
    builders:
      kiwi:

Running same script as before upgrade to new version is giving:

flutter packages pub run build_runner build

If you believe you have gotten this message in error, especially if using a new
feature, you may need to run `pub run build_runner clean` and then rebuild.

Invalid argument(s): line 4, column 7 of build.yaml: Unsupported value for "builders". Must not be null
  ╷
4 │       kiwi:
  │       ^^^^^

Null Safety

Since Null Safety is in beta, it is time to update Kiwi library to support null safety. Are there any timelines on this? Thanks!

Injecting multiple implementation in a constructor with base class in the signature

Hi, Thank you for the library.

I am currently using the generator to manage dependencies and I would like to know how to inject implementations for base class in the following example.

class SampleClass {
  final Repository repositoryA;
  final Repository repositoryB;

  FetchNewsUseCase({this.repositoryA, this.repositoryB});
}
  @Register.singleton(Repository, from: RepositoryA, name: 'repositoryA')
  @Register.singleton(Repository, from: RepositoryB, name: 'repositoryB')
  // Here I am not sure how to create a new singleton that accepts 'repositoryA' and 'repositoryB'.
  // I know there is the ability to use another constructor but I havent seen an example of how to 
  // pass arguments to that
  void configureData();

Thanks,

Use cascade operator in generated code

Currently the generated code produces something like this:

final KiwiContainer container = KiwiContainer();
container.registerSingleton();
container.registerSingleton();
container.registerSingleton();
container.registerSingleton();

Instead of repeating container over and over, the cascade operator can be used to chain method calls on container:

container
  ..registerSingleton()
  ..registerSingleton()
  ..registerSingleton()

kiwi_generator cannot be used with newer analyzers

Hi all,

I have problems when I try to use realm library with realm (and realm_generator) because of the version mismatch for the analyzer lib.

Because realm_generator >=1.6.1 depends on analyzer ^6.0.0 and kiwi_generator 4.1.0 depends on analyzer ^5.4.0, realm_generator >=1.6.1 is incompatible with kiwi_generator 4.1.0.
So, because shared_proj depends on both kiwi_generator 4.1.0 and realm_generator 3.0.0, version solving failed.

Cheers
Bummsa

Register Type from imported package

Hello!
How to register some Type from imported package, which doesn't have a constructor, but instead has a getInstance() method, witch return Future. As example SharedPreferences.

Dart 1 support

Thank you for creating this great library! The organization I work for has been looking for DI solutions in Dart, but have been disappointed by the existing options due to the reasons you outlined in your Medium post.

We have a lot of Dart code and as a result we are still at least a few months away from transitioning our entire codebase to Dart 2. I notice the README states this library requires Dart 2, but I was wondering if there were any limitations in Dart 1 that prevent this from working properly?

It seems that if I add the missing new keywords, the rest of the syntax passes the analyzer just fine. Is there anything else we should be concerned about? If not I'm thinking we might maintain a fork of this that works on Dart 1 until we have finished our codebase migration to Dart 2, at which point we will switch back to the mainline.

Thanks for the great work here!

Generator will succeed but not generate the .g.dart file. Because of method without annotations

Generator will succeed but not generate the .g.dart file. Because of method without annotations

abstract class Injector {
  @Register.singleton(NetworkLogInterceptor)
  @Register.singleton(NetworkAuthInterceptor)
  @Register.singleton(NetworkErrorInterceptor)
  @Register.singleton(NetworkRefreshInterceptor)
  void registerNetworkDependencies();

  @Register.singleton(TodoDaoStoring, from: TodoDaoStorage)
  void registerDatabase();

  @Register.singleton(LoggingBridging, from: LoggingBridge)
  void registerBridge();

  void registerWebservices();

  void registerDummyServices();
}

We cannot maintain the class objects, when application was terminated.

[ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The method 'getAllOrders' was called on null.
E/flutter ( 2544): Receiver: null
E/flutter ( 2544): Tried calling: getAllOrders("STY10")
E/flutter ( 2544): #      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter ( 2544): #      backgroundFetchHeadlessTask (package:courier_alliance/src/service/backgroundservice.dart:25:40)
E/flutter ( 2544): <asynchronous suspension>
E/flutter ( 2544): #      _headlessCallbackDispatcher.<anonymous closure> (package:background_fetch/background_fetch.dart:619:15)
E/flutter ( 2544): #      MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:432:55)
E/flutter ( 2544): #      MethodChannel.setMethodCallHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:385:33)
E/flutter ( 2544): #      _DefaultBinaryMessenger.handlePlatformMessage (package:flutter/src/services/binding.dart:267:33)
E/flutter ( 2544): #      _invoke3.<anonymous closure> (dart:ui/hooks.dart:282:15)
E/flutter ( 2544): #      _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 2544): #      _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 2544): #      _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 2544): #     _invoke3 (dart:ui/hooks.dart:281:10)
E/flutter ( 2544): #     _dispatchPlatformMessage (dart:ui/hooks.dart:156:5)

Add support for nullability

#49 does not yet support nullability.

With the testing/stable release closing for nullability, we need to make sure kiwi supports nullability as well

How can I create scoped container?

In your example you are creating a scoped container inside the screen itself, which makes such scoped DI worthless.
Can I somehow use scoped container to make the same logic as Dagger2 @Scoped and Koin scoped does?
I want to create a scoped container in the main class, for example, and then use it when I will open the screen related to that scoped container.

Maintenance?

The last update was a year ago, maybe it should be marked as discontinued on pub or new maintainers should be assigned?

kiwi generator incompatibility

Hello

thnak you for this amazing DI, This provide me a lot of functionality.
Now I update some packages to be compatible with mi unit tests. However, kiwi generator is not compatible with test package from sdk.

the error si the following

because kiwi_generator >=0.3.0 depends on analyzer >=0.32.4 <0.35.0 and paymobile_app depends on test ^1.3.0, flutter_test from sdk is incompatible with kiwi_generator >=0.3.0.

Please could you update the packages to fix this compatibility issue?

Thank you in advance

@override should be added to the generated file

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'injector.dart';

// **************************************************************************
// KiwiInjectorGenerator
// **************************************************************************

class _$Injector extends Injector {
  void registerWebservices() {
    final KiwiContainer container = KiwiContainer();
    container.registerSingleton<LoginService>((c) => LoginWebService(c<Dio>()));
  }

  void registerDummyServices() {
    final KiwiContainer container = KiwiContainer();
    container.registerSingleton<LoginService>((c) => LoginDummyService());
  }

  void registerViewModelFactories() {
    final KiwiContainer container = KiwiContainer();
    container.registerFactory((c) => LoginViewModel(c<LoginRepo>()));
  }
}

@override should be added

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'injector.dart';

// **************************************************************************
// KiwiInjectorGenerator
// **************************************************************************

class _$Injector extends Injector {
  @override
  void registerWebservices() {
    final KiwiContainer container = KiwiContainer();
    container.registerSingleton<LoginService>((c) => LoginWebService(c<Dio>()));
  }

  @override
  void registerDummyServices() {
    final KiwiContainer container = KiwiContainer();
    container.registerSingleton<LoginService>((c) => LoginDummyService());
  }

  @override
  void registerViewModelFactories() {
    final KiwiContainer container = KiwiContainer();
    container.registerFactory((c) => LoginViewModel(c<LoginRepo>()));
  }
}

The name 'Container' is not very user-friendly when used in flutter Widgets

When using the Container in a file that imports package:flutter/material.dart, using the kiwi Container becomes a challenge.

An easy solution is to use a named import e.g. import 'package:kiwi/kiwi.dart' as kiwi; and then use kiwi.Container(). But I still think that, since Flutter is a big use case for Dart, choosing a different name would be a valid decision.

Usage of generics is wrong

Looking at the implementation, e.g.:

  void registerInstance<S, T extends S>(
    S instance, {
    String name,
  }) {
    _setProvider(name, _Provider<S>.instance(instance));
  }

The use of generics here is not really correct. There are 2 type parameters, but the T type parameter is not actually used in the code. Shouldn't the T type parameter just be removed?

So if you have class B that extends class A and I want to register an instance of class B but using type A, I have to say:

container.resgisterInstance<A, B>( bInstance);

which doesn't seem that onerous with single letter class names, but with generic types this is ridiculously verbose.

If the T parameter is removed, I should be able to do that simply as:

container.resgisterInstance<A>(bInstance);

Generate custom Stateless widget and State

Don't know if other people doing it or not, but to minimize usage of service locator I often find myself adding custom classes that fake method injection. Something like:

abstract class StatelessWidgetInjected<TDependency> extends StatelessWidget {
  TDependency _resolve() => KiwiContainer().resolve<TDependency>();

  @override
  Widget build(BuildContext context) {
    return buildInjected(context, _resolve());
  }

  Widget buildInjected(BuildContext context, TDependency dependency);
}

abstract class StateInjectedInitAndBuild<TWidget extends StatefulWidget, TDependency>
    extends State<TWidget> {
  TDependency _resolve() => KiwiContainer().resolve<TDependency>();

  @override
  void initState() {
    super.initState();
    initStateInjected(_resolve());
  }

  @override
  Widget build(BuildContext context) {
    return buildInjected(context, _resolve());
  }

  void initStateInjected(TDependency dependency);

  Widget buildInjected(BuildContext context, TDependency dependency);
}

So that you can simply use

class MyWidget extends StatelessWidgetInjected<IServiceA> {
  @override
  Widget buildInjected(BuildContext context, IServiceA dependency) {
    // use dependency
    // ...
  }
}

It's just an example of course.

Maybe you can add something like this to the generated output, so that the option to use it is there right out of the box.

Registered objects life cycle.

What is the registered object life cycle? If on a screen I retrieve an object what happens when I go out of this screen?

Reading the code, i saw the object has been created only when I retrieve it. So what is the moment it is destroyed and go out of memory, or the objects stay on memory all the time app's live?

That is not clear to me, anyone can helpme?

Thanks

unregister should not throw error if class does not exist

I want my widget to register some class in kiwi and after widget is disposed to unregister that class. The problem I experience is following:

User opens page A;
page A register class B in kiwi;
User leaves page A;
User enters page A before dispose A is called;
User gets error for registering class in kiwi that is already registered;
dispose A gets called and class B gets unregistered;

Obvious solution is to call unregister always before register but that throws error if class doesn't exist.

[kiwi_generator] Registering singleton in module with dependencies from another module

It's possible to register a singleton in a file that has a dependency a singleton of another file?
Ex.:

// ModuleA.dart
abstract class ModuleA {
    @Register.signleton(SingletonA)
     void configure();
}

// SingletonA.dart
class SingletonA {
    SingletonA(SingletonB singletonB)
}
// ModuleB.dart
abstract class ModuleB {
    @Register.signleton(SingletonB)
     void configure();
}

// SingletonB.dart
class SingletonB {
    SingletonB()
}

I tried it and the generated file wont have the imports of the missing clases that are not imported in the file of ModuleA.
I have to go to the generated file and import those missing dependencies. Don't know if is possible to reference another files inside the generated file.

Thanks!

Can I create `kiwi_generator` record for a string?

Something like

@Register.singleton('localhost', name: 'websiteUrl' )

So that I can easily change it for dev/staging/prod. Often it is useful for other classes created via DIC to have these string parameters. And I cannot come up with any other way than to create a class for each environment and register the class instead.

Improve Error handling when resolving, unregistering a dependency

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building MyHomePage(dirty, dependencies:
flutter: [_LocalizationsScope-[GlobalKey#6687f], _InheritedTheme], state: _MyHomePageState#b91a6):
flutter: Failed to resolve `String`:
flutter: The type `String` was not registered
flutter: Make sure `String` is added to your KiwiContainer and rerun flutter build
flutter: 'package:kiwi/src/kiwi_container.dart':
flutter: Failed assertion: line 95 pos 7: 'silent || (providers?.containsKey(T) ?? false)'
flutter:
flutter: The relevant error-causing widget was:
flutter:   MyHomePage file:///Users/vanlooverenkoen/Documents/projects/kiwi/flutter_example/lib/main.dart:18:13
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #2      KiwiContainer.resolve (package:kiwi/src/kiwi_container.dart:95:7)
flutter: #3      _MyHomePageState.build (package:flutter_example/main.dart:59:33)
flutter: #4      StatefulElement.build (package:flutter/src/widgets/framework.dart:4619:28)
flutter: #5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15)
flutter: #6      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
flutter: #7      Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
flutter: #8      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
flutter: #9      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4666:11)
flutter: #10     ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
flutter: ...     Normal element mounting (24 frames)
flutter: #34     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
flutter: #35     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5947:32)
flutter: ...     Normal element mounting (119 frames)
flutter: #154    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
flutter: #155    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5947:32)
flutter: ...     Normal element mounting (253 frames)
flutter: #408    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
flutter: #409    Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
flutter: #410    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1148:16)
flutter: #411    RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1119:5)
flutter: #412    RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1061:17)
flutter: #413    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2607:19)
flutter: #414    RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1060:13)
flutter: #415    WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:941:7)
flutter: #416    WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:922:7)
flutter: (elided 13 frames from class _AssertionError, class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)
flutter:
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building MyHomePage(dirty, dependencies: [_LocalizationsScope-[GlobalKey#6687f], _InheritedTheme], state: _MyHomePageState#b91a6):
Failed to resolve `String`:
The type `String` was not registered
Make sure `String` is added to your KiwiContainer and rerun flutter build
'package:kiwi/src/kiwi_container.dart':
Failed assertion: line 95 pos 7: 'silent || (providers?.containsKey(T) ?? false)'

When the exception was thrown, this was the stack: 
#2      KiwiContainer.resolve (package:kiwi/src/kiwi_container.dart:95:7)
#3      _MyHomePageState.build (package:flutter_example/main.dart:59:33)
#4      StatefulElement.build (package:flutter/src/widgets/framework.dart:4619:28)
#5      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15)
#6      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

Resolve object by specific type: resolveAs<S, T extends S>

During testing we want to be using a moc implementation of a specific class. But in our tests we want to setup,seed, configure our mocks.

That is why we need a method that can give us an Object from a specific type. That was previously registered.

Something like this:

static T resolveAs<S, T extends S>() => kiwi.Container().resolve<S>() as T;

The type String was not registered

The type String was not registered
'package:kiwi/src/container.dart':
Failed assertion: line 92 pos 12: 'silent || (providers?.containsKey(T) ?? false)'
hello how can i resolve this problem?

Kiwi uses outdated analyzer dependencies


And because json_serializable >=3.2.3 depends on analyzer >=0.37.1 <0.39.0, kiwi_generator ^0.4.0 is incompatible with json_serializable >=3.2.3.

So, because my_app depends on both json_serializable ^3.2.3 and kiwi_generator ^0.4.0, version solving failed.
pub get failed (1; So, because my_app depends on both json_serializable ^3.2.3 and kiwi_generator ^0.4.0, version solving failed.)

This should be fixed

Class could not be registered correctly even when defaults are specified

Failed to resolve `IOSOptions`:
The type `IOSOptions` was not registered
Make sure `IOSOptions` is added to your KiwiContainer and rerun build_runner build
(If you are using the kiwi_generator)
When using Flutter, most of the time a hot restart is required to setup the KiwiContainer again.

There is probably an issue with default values

const FlutterSecureStorage({
  this.iOptions = IOSOptions.defaultOptions,
  this.aOptions = AndroidOptions.defaultOptions,
  this.lOptions = LinuxOptions.defaultOptions,
  this.wOptions = WindowsOptions.defaultOptions,
  this.webOptions = WebOptions.defaultOptions,
  this.mOptions = MacOsOptions.defaultOptions,
});

It is not generating anything

I am using

  build_runner: ^2.4.7
  kiwi_generator: ^4.1.0

and do run
flutter packages pub run build_runner build

My /lib/di/core/injector.dart is

import 'package:dl_mobile_flutter/app/app_config.dart';
import 'package:kiwi/kiwi.dart';

part 'injector.g.dart';

const keyApiUrl = 'apiUrl';

abstract class Injector {
  void configure();

  void production();

  void development();

  static void inject(AppConfig config) {
    var injector = _$Injector()..configure();

    if (config.isProduction) {
      injector.production();
    } else if (config.isDevelopment) {
      injector.development();
    }
    KiwiContainer().registerInstance(config.baseUrl, name: keyApiUrl);
  }
}

T inject<T>([String? name]) => KiwiContainer().resolve<T>(name);

After running build_runner no injector.g.dart is created

Generated Injector is private

After generating the injector.g.dart the class name is _$Injector and therefore cant by referenced in another dart file. I have to manually remove the underline

The type `Object` was not registered

What is the correct way to register KiwiContainer as I'm getting below error:

KiwiError:

Failed to resolve `SearchBloc`:

The type `SearchBloc` was not registered

Make sure `SearchBloc` is added to your KiwiContainer and rerun build_runner build
(If you are using the kiwi_generator)

When using Flutter, most of the time a hot restart is required to setup the KiwiContainer again.

Here I registered:

class SearchPage extends StatefulWidget {
  _SearchPageState createState() => _SearchPageState();
}

  KiwiContainer container = KiwiContainer(); 
  
class _SearchPageState extends State<SearchPage> {

  final _searchBloc = container.resolve<SearchBloc>();
  final _scrollController = ScrollController();

  @override
  void initState() {
    super.initState();
    container.registerInstance(SearchBloc(null)); //register
  }

   . . .

}

P.S: I'm using kiwi: ^2.1.1

kiwi generator should provide creating scoped container.

abstract class Injector {
  @Register.singleton(ServiceA)
  @Register.factory(Service, from: ServiceB)
  @Register.factory(ServiceB, name: 'factoryB')
  @Register.factory(ServiceC, resolvers: {ServiceB: 'factoryB'})
  void configure();
}

class Service {}

class ServiceA extends Service {}

class ServiceB extends Service {
  ServiceB(ServiceA serviceA);
}

class ServiceC extends Service {
  ServiceC(ServiceA serviceA, ServiceB serviceB);
  ServiceC.other(ServiceB serviceA);
}

void setup() {
  var injector = _$Injector();
  injector.configure();
}
class _$Injector extends Injector {
  void configure() {
    final Container container = Container();
    container.registerSingleton((c) => ServiceA());
    container
        .registerFactory<Service, ServiceB>((c) => ServiceB(c<ServiceA>()));
    container.registerFactory((c) => ServiceB(c<ServiceA>()), name: 'factoryB');
    container.registerFactory(
        (c) => ServiceC(c<ServiceA>(), c<ServiceB>('factoryB')));
  }
}

above we can't create scoped container, all our dependency will be store in Container class.someone knows how to create scoped container in generator package please provide information.

Kiwi injection not working in background/app killed state.

[√] Flutter (Channel stable, 2.5.0, on Microsoft Windows [Version 10.0.17763.1577], locale en-IN)
• Flutter version 2.5.0 at C:\Flutter_SDK\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4cc385b4b8 (7 months ago), 2021-09-07 23:01:49 -0700
• Engine revision f0826da7ef
• Dart version 2.14.0

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at D:\Sdk
• Platform android-31, build-tools 30.0.3
• ANDROID_HOME = D:\Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 2020.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[√] IntelliJ IDEA Community Edition (version 2021.3)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.3
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart

[√] Connected device (3 available)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.127
• Edge (web) • edge • web-javascript • Microsoft Edge 100.0.1185.44

Code generator does not play nice with mockito

Consider the following code:

  @Register.singleton(DeepLinkViewModel, from: MockDeepLinkViewModel)
  void registerViewModelFactories();

In this case MockDeepLinkViewModel is generated by mockito using @GenerateMocks. This results in the following generated kiwi code:

   ..registerSingleton<DeepLinkViewModel>((c) => DeepLinkViewModel());

Kiwi generator crash boolean expression must not be null

Failed assertion: boolean expression must not be null
#0      ElementDisplayStringBuilder._writeNullability (package:analyzer/src/dart/element/display_string_builder.dart:252:9)
#1      ElementDisplayStringBuilder.writeInterfaceType (package:analyzer/src/dart/element/display_string_builder.dart:152:5)
#2      InterfaceTypeImpl.appendTo (package:analyzer/src/dart/element/type.dart:840:13)
#3      TypeImpl.getDisplayString (package:analyzer/src/dart/element/type.dart:1696:5)
#4      KiwiInjectorGenerator._generateRegister (package:kiwi_generator/src/kiwi_injector_generator.dart:135:43)
#5      KiwiInjectorGenerator._generateRegisters.<anonymous closure> (package:kiwi_generator/src/kiwi_injector_generator.dart:122:13)
#6      MappedIterator.moveNext (dart:_internal/iterable.dart:392:20)
#7      new List.from (dart:core-patch/array_patch.dart:50:19)
#8      new List.of (dart:core-patch/array_patch.dart:68:17)
#9      Iterable.toList (dart:core/iterable.dart:404:12)
#10     KiwiInjectorGenerator._generateRegisters (package:kiwi_generator/src/kiwi_injector_generator.dart:123:10)
#11     KiwiInjectorGenerator._generateInjectorMethod.<anonymous closure>.<anonymous closure> (package:kiwi_generator/src/kiwi_injector_generator.dart:114:31)
#12     _$BlockBuilder.update (package:code_builder/src/specs/code.g.dart:82:33)
#13     new _$Block (package:code_builder/src/specs/code.g.dart:14:28)
#14     KiwiInjectorGenerator._generateInjectorMethod.<anonymous closure> (package:kiwi_generator/src/kiwi_injector_generator.dart:111:18)
#15     new Method.returnsVoid.<anonymous closure> (package:code_builder/src/specs/method.dart:31:18)
#16     _$MethodBuilder.update (package:code_builder/src/specs/method.g.dart:345:33)
#17     new _$Method (package:code_builder/src/specs/method.g.dart:38:29)
#18     new Method.returnsVoid (package:code_builder/src/specs/method.dart:29:7)
#19     KiwiInjectorGenerator._generateInjectorMethod (package:kiwi_generator/src/kiwi_injector_generator.dart:84:19)
#20     KiwiInjectorGenerator._generateInjectorMethods.<anonymous closure> (package:kiwi_generator/src/kiwi_injector_generator.dart:69:21)
#21     MappedIterator.moveNext (dart:_internal/iterable.dart:392:20)
#22     new List.from (dart:core-patch/array_patch.dart:50:19)
#23     new List.of (dart:core-patch/array_patch.dart:68:17)
#24     Iterable.toList (dart:core/iterable.dart:404:12)
#25     KiwiInjectorGenerator._generateInjectorMethods (package:kiwi_generator/src/kiwi_injector_generator.dart:70:10)
#26     KiwiInjectorGenerator._generateInjector.<anonymous closure> (package:kiwi_generator/src/kiwi_injector_generator.dart:63:24)
#27     _$ClassBuilder.update (package:code_builder/src/specs/class.g.dart:312:33)
#28     new _$Class (package:code_builder/src/specs/class.g.dart:34:28)
#29     KiwiInjectorGenerator._generateInjector (package:kiwi_generator/src/kiwi_injector_generator.dart:60:12)
#30     KiwiInjectorGenerator.generate.<anonymous closure>.<anonymous closure> (package:kiwi_generator/src/kiwi_injector_generator.dart:43:34)
#31     MappedListIterable.elementAt (dart:_internal/iterable.dart:417:31)
#32     ListIterator.moveNext (dart:_internal/iterable.dart:343:26)
#33     List.addAll (dart:core-patch/growable_array.dart:226:13)
#34     ListBuilder.addAll (package:built_collection/src/list/list_builder.dart:106:14)
#35     KiwiInjectorGenerator.generate.<anonymous closure> (package:kiwi_generator/src/kiwi_injector_generator.dart:42:16)
#36     _$LibraryBuilder.update (package:code_builder/src/specs/library.g.dart:104:33)
#37     new _$Library (package:code_builder/src/specs/library.g.dart:16:30)
#38     KiwiInjectorGenerator.generate (package:kiwi_generator/src/kiwi_injector_generator.dart:41:20)
#39     _generate (package:source_gen/src/builder.dart:303:33)
<asynchronous suspension>
#40     _Builder._generateForLibrary (package:source_gen/src/builder.dart:79:15)
#41     _Builder.build (package:source_gen/src/builder.dart:71:11)
<asynchronous suspension>
#42     runBuilder.buildForInput (package:build/src/generate/run_builder.dart:55:21)
#43     MappedListIterable.elementAt (dart:_internal/iterable.dart:417:31)
#44     ListIterator.moveNext (dart:_internal/iterable.dart:343:26)
#45     Future.wait (dart:async/future.dart:406:26)
#46     runBuilder.<anonymous closure> (package:build/src/generate/run_builder.dart:61:36)
#47     _rootRun (dart:async/zone.dart:1190:13)
#48     _CustomZone.run (dart:async/zone.dart:1093:19)
#49     _runZoned (dart:async/zone.dart:1630:10)
#50     runZonedGuarded (dart:async/zone.dart:1618:12)
#51     runZoned (dart:async/zone.dart:1547:12)
#52     scopeLogAsync (package:build/src/builder/logging.dart:26:3)
#53     runBuilder (package:build/src/generate/run_builder.dart:61:9)
#54     _SingleBuild._runForInput.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:485:19)
#55     _NoOpBuilderActionTracker.trackStage (package:build_runner_core/src/generate/performance_tracker.dart:302:15)
#56     _SingleBuild._runForInput.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:483:23)
<asynchronous suspension>
#57     _SingleBuild._runForInput.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart)
#58     NoOpTimeTracker.track (package:timing/src/timing.dart:222:44)
#59     _SingleBuild._runForInput.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:440:22)
#60     Pool.withResource (package:pool/pool.dart:127:28)
<asynchronous suspension>
#61     _SingleBuild._runForInput (package:build_runner_core/src/generate/build_impl.dart:436:17)
#62     _SingleBuild._runBuilder.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:374:38)
#63     MappedIterator.moveNext (dart:_internal/iterable.dart:392:20)
#64     Future.wait (dart:async/future.dart:406:26)
#65     _SingleBuild._runBuilder (package:build_runner_core/src/generate/build_impl.dart:373:36)
#66     _SingleBuild._runPhases.<anonymous closure>.<anonymous closure> (package:build_runner_core/src/generate/build_impl.dart:319:20)
#67     _rootRunUnary (dart:async/zone.dart:1198:47)
#68     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#69     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#70     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#71     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#72     Future._completeWithValue (dart:async/future_impl.dart:529:5)
#73     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
#74     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
#75     _SingleBuild._matchingPrimaryInputs (package:build_runner_core/src/generate/build_impl.dart)
#76     _rootRunUnary (dart:async/zone.dart:1198:47)
#77     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#78     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#79     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#80     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#81     Future._completeWithValue (dart:async/future_impl.dart:529:5)
#82     Future.wait.<anonymous closure> (dart:async/future.dart:414:23)
#83     _rootRunUnary (dart:async/zone.dart:1198:47)
#84     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
#85     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
#86     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
#87     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
#88     Future._completeWithValue (dart:async/future_impl.dart:529:5)
#89     Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)
#90     _rootRun (dart:async/zone.dart:1190:13)
#91     _CustomZone.run (dart:async/zone.dart:1093:19)
#92     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
#93     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
#94     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#95     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#96     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#97     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:404:11)
#98     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

Kiwi DI for abstract classes

Hello, First of all Thank you very much for making job really easy for DI in flutter for the beginners like me, Really appreciate this work. I want to ask that How can I create DI for abstract classes?

I am using Floor package for local database storage in flutter, which requires to create abstract classes for DAO like following. can you let me know how to DI for abstract classes?


import 'package:CookingApp/models/cooks.dart';
import 'package:floor/floor.dart';

@dao
abstract class CookDAO{

  @Insert(onConflict : OnConflictStrategy.replace)
  Future<void> insertCooks(List<Cook> cook);

  @Query('Select * from Cook')
  Future<List<Cook>> fetchAllCooks();
}

Scopes and Modules

What about scopes and modules for dependencies?

I what to clear few dependencies by calling one method. How can I do it?

Can I create module for some features? Example: AppModule(only app dependencies), ShopListModule, WaletModule...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.