lesnitsky / Inherited_builder
Licence: mit
🤖Autogenerated state management and dependency injection with inherited widgets
Stars: ✭ 17
Programming Languages
dart
5743 projects
Projects that are alternatives of or similar to Inherited builder
Reto
Flexible and efficient React Store with hooks.
Stars: ✭ 194 (+1041.18%)
Mutual labels: dependency-injection, state-management
Flutter Boilerplate Project
A boilerplate project created in flutter using MobX and Provider.
Stars: ✭ 1,194 (+6923.53%)
Mutual labels: dependency-injection, state-management
Momentum
MVC pattern for flutter. Works as state management, dependency injection and service locator.
Stars: ✭ 99 (+482.35%)
Mutual labels: dependency-injection, state-management
lamp-luwak
Service-oriented state management for React
Stars: ✭ 12 (-29.41%)
Mutual labels: state-management, dependency-injection
okito
Your best flutter coding friend. All in one; state management, navigation management(with dynamic routing), local storage, localization, dependency injection, cool extensions with best usages and with the support of best utilities!
Stars: ✭ 37 (+117.65%)
Mutual labels: state-management, dependency-injection
Getx
Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
Stars: ✭ 5,578 (+32711.76%)
Mutual labels: dependency-injection, state-management
wedi
[Deprecated] A lightweight dependency injection (DI) library for TypeScript, along with a binding for React.
Stars: ✭ 22 (+29.41%)
Mutual labels: state-management, dependency-injection
States rebuilder
a simple yet powerful state management technique for Flutter
Stars: ✭ 372 (+2088.24%)
Mutual labels: dependency-injection, state-management
Container
Small but powerful dependency injection container
Stars: ✭ 674 (+3864.71%)
Mutual labels: dependency-injection
Pullstate
Simple state stores using immer and React hooks - re-use parts of your state by pulling it anywhere you like!
Stars: ✭ 683 (+3917.65%)
Mutual labels: state-management
React Final Form
🏁 High performance subscription-based form state management for React
Stars: ✭ 6,781 (+39788.24%)
Mutual labels: state-management
Apk Dependency Graph
Android class dependency visualizer. This tool helps to visualize the current state of the project.
Stars: ✭ 675 (+3870.59%)
Mutual labels: dependency-injection
Di
Dependency Injection and IoC framework for PHP
Stars: ✭ 5 (-70.59%)
Mutual labels: dependency-injection
Little State Machine
📠 React custom hook for persist state management
Stars: ✭ 654 (+3747.06%)
Mutual labels: state-management
Injector
Python dependency injection framework, inspired by Guice
Stars: ✭ 651 (+3729.41%)
Mutual labels: dependency-injection
Marvelheroes
❤️ A sample Marvel heroes application based on MVVM (ViewModel, Coroutines, LiveData, Room, Repository, Koin) architecture.
Stars: ✭ 826 (+4758.82%)
Mutual labels: dependency-injection
Koin
Koin - a pragmatic lightweight dependency injection framework for Kotlin
Stars: ✭ 7,142 (+41911.76%)
Mutual labels: dependency-injection
Inherited Builder
Autogenerated state management and dependency inhection with inherited widgets
ToC
Motivation
InheritedWidget is a powerful concept which allows you to inject values and pass them down the widget tree as well as subscribe to updates, but it requires a lot of boilerplate
This package allows you to get advantage of this awesome concept w/o boilerplate, it will be autogenerated for you
App Reference Architecture
Check out app reference architecture
Example app
"flutter create" app built with inherited_builder
Installation
dev_dependencies:
build_runner: <version>
inherited_builder: ^1.0.0
Usage
Define your model
app_state.dart
import 'package:flutter/material.dart';
import 'package:inherited_builder/annotations.dart';
part 'app_state.g.dart'
@Inherited()
class AppState {
final int count;
const AppState({ this.count });
String toString() {
return 'Count is $count';
}
}
Execute build_runner
flutter packages pub run build_runner build --delete-conflicting-outputs
This will generate AppStateBuilder
and AppStateProvider
classes
Place Builder in your widget tree
import 'package:flutter/material.dart';
class ParentWidget extends StatelessWidget {
final Widget child;
const ParentWidget({Key key, this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
const initialValue = 0;
return AppStateBuilder(
count: initialValue,
child: child,
);
}
}
Access values using Provider
class ChildWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final appStateProvider = AppStateProvider.of(context);
return Scaffold(
body: Center(child: Text(appStateProvider.count.toString())),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
final count = appStateProvider.count;
appStateProvider.setcount(count + 1);
},
),
);
}
}
Access instance of your model using Provider
class ChildWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final appStateProvider = AppStateProvider.of(context);
+ final appState = appStateProvider.model;
return Scaffold(
- body: Center(child: Text(appStateProvider.count.toString())),
+ body: Center(child: Text(appState.toString())),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
final count = appStateProvider.count;
appStateProvider.setcount(count + 1);
},
),
);
}
}
React to changes
You can use didChangeDepencies()
to react to changes of your model (e.g. appStateProvider.setCount(newCount)
)
Example:
import 'package:flutter/material.dart';
class StatePersistance extends StatefulWidget {
final Widget child;
const StatePersistance({Key key, this.child}) : super(key: key);
@override
_StatePersistanceState createState() => _StatePersistanceState();
}
class _StatePersistanceState extends State<StatePersistance> {
@override
Widget build(BuildContext context) {
return widget.child;
}
@override
void didChangeDependencies() async {
final appStateProvider = AppStateProvider.of(context);
final currentState = appStateProvider.model;
final prevState = appStateProvider.oldModel;
if (currentState.count != prevState.count) {
persist(currentState);
}
super.didChangeDependencies();
}
}
Define actions on your model
requires dart >2.7.0
import 'package:flutter/material.dart';
import 'package:inherited_builder/annotations.dart';
@Inherited()
class AppState {
final int count;
const AppState({ this.count });
String toString() {
return 'Count is $count';
}
}
extension CounterActions on AppStateProvider {
increment() {
this.setCount(this.count + 1);
}
}
// somewhere in the widget tree:
final appStateProvider = AppStateProvider.of(context);
appStateProvider.increment();
License
MIT
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].