stark

Creator: coderz1093

Last updated:

0 purchases

stark Image
stark Images

Languages

Categories

Add to Cart

Description:

stark

stark #

What is Stark?
Some info
Getting Started

Usage example
Modules definition
Initialize Stark
Getting a inject instance


Reference

Singleton definition
Factory definition
Named injections
Dynamic params
Scoped injections
Disposable Interface
Arch Components



What is Stark? #
A pragmatic lightweight dependency injection framework for Dart developers.
Some info #
This implementation does not rely on the dart reflection apis (mirrors) and favours a simple factory based approach.
This increases the performance and simplicity of this implementation.
Any help is appreciated! Comment, suggestions, issues, PR's!
Getting Started #
In your flutter or dart project add the dependency:
dependencies:
...
stark: 4.0.0
copied to clipboard
Usage example #
Import stark
import 'package:stark/stark.dart';
copied to clipboard
Modules definition #
import 'package:stark/stark.dart';

final appModule = {
single((i) => Api()),
single<Repository>((i) => MyRepository(i.get())),
factory((i) => UseCase(i.get())),
factoryWithParams((i, p) => ViewModel(i.get(), p["dynamicParam"])),
};
copied to clipboard
Initialize Stark #

//You can pass a list with many modules
Stark.init([
appModule,
domainModule,
presentationModule
]);

copied to clipboard
Initialize Stark with logger
Stark.init([...], logger: Logger());
copied to clipboard
Getting a inject instance #
class LoginScreen extends StatefulWidget{
@override
State<StatefulWidget> createState() => LoginScreenState();
}

class LoginScreenState extends State<LoginScreen>{

final _loginViewModel = Stark.get<LoginViewModel>();

@override
Widget build(BuildContext context) {

return Container(
...
);
}
}
copied to clipboard
Singleton definition: #
import 'package:stark/stark.dart';

final myModule = {
single((i) => Api(i.get())),
};
copied to clipboard
Single with dynamic param: #
import 'package:stark/stark.dart';

final myModule = {
singleWithParams((i,p) => Api(p["token"])),
};
copied to clipboard
Factory definition #
import 'package:stark/stark.dart';

final myModule = {
factory((i) => UseCase()),
};
copied to clipboard
Factory with dynamic param: #
import 'package:stark/stark.dart';

final myModule = {
factoryWithParams((i,p) => Api(p["token"])),
};
copied to clipboard
Named injections #
import 'package:stark/stark.dart';

final myModule = {
single((i) => Api(), named: "DEFAULT"),
single((i) => Api(), named: "EXTERNAL"),
};


// to get named injections
Stark.get<Api>(named: "DEFAULT");

copied to clipboard
Dynamic params #
import 'package:stark/stark.dart';

final myModule = {
singleWithParams((i,p) => Api(p["token"])),
factoryWithParams((i,p) => MyPresenter(p["view"])),
};


// to get with dynamic params
Stark.get<Api>(params: { "token" : "Bearer asdasdad"})
Stark.get<MyPresenter>(params: { "view" : this})

copied to clipboard
Scoped injections #

You can mix your class with Stark component to associate the injection life time to your widget:

class _MyHomePageState extends State<MyHomePage> with StarkComponent {
ViewModel _viewModel;

@override
void initState() {
super.initState();

//View model instance will destroyed when this widget state call dispose.
_viewModel = get<ViewModel>(
params: <String, dynamic>{'name': 'Custom dynamic param'});
}
...
copied to clipboard
Disposable Interface #
Stark provides a Disposable interface, when a injection that implements this interface is will be dispose the method dispose is called, is very nice to viewModels for example:

class LoginViewModel implements Disposable {
@override
dispose(){
//this method is called when the LoginViewModel is diposed, use to dispose your RX Subjects or Streams
}
}

copied to clipboard
Arch Components #
To support different types of architectures and state management we move these architecture components to new libraries.

stark_mvp: Stark library for MVP architecture
stark_bloc: Stark library for flutter_bloc projects


## License

Copyright 2020 The Stark Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.