state_holder

Creator: coderz1093

Last updated:

0 purchases

state_holder Image
state_holder Images

Languages

Categories

Add to Cart

Description:

state holder

StateHolder #

StateHolder #
StateHolder is A wrapper around InheritedWidget to make them easier to use and more reusable.
By using StateHolder instead of manually writing InheritedWidget, you get:


simplified allocation of resources
lazy-loading
a vastly reduced boilerplate over making a new class every time
friendly to devtools
increased scalability for classes with a listening mechanism that grows >exponentially in complexity (such as ChangeNotifier, which is O(N) for dispatching notifications).



Add Dependencie #
update in pubspec.ymal
dependencies:
state_holder:
git:
url: https://github.com/mishrabroshan/state_holder.git
copied to clipboard

Compoenents #




State Components
Access Components




SimpleStateHolder
SateHolder


ChangeNotifierStateHolder
StateConsumer


MultiStateHolder
StateHolderContext





State Components #
SimpleStateHolder Component #
Description
: Use This Component To initialize [SimpleStateHolder] Which Will Just Hold The State Without Providing Any Change Updates
How To Use

Just Wrap This Component To the Widget And It is Ready To Roll

import 'package:state_holder/state_holder.dart';

SimpleStateHolder(
builder : (context) => "[State]",
lazy : true/false // Lazy-Loading,
child : SomeWidget(),
),
copied to clipboard
ChangeNotifierStateHolder Component #
Description
: Use This Component To initialize [ChangeNotifierStateHolder] Which Will Hold The State And Providing Any Change Updates
[Note] : ChangeNotifierStateHolder can be only Used With Listnable Components
How To Use

Just Wrap This Component To the Widget And It is Ready To Roll

import 'package:state_holder/state_holder.dart';

ChangeNotifierStateHolder(
builder : (context) => "[State]",
lazy : true/false // Lazy-Loading,
child : SomeWidget(),
),
copied to clipboard
MultiStateHolder Component #
Description
: A [StateHolder] that merges multiple StateHolders into a single linear widget tree.
It is used to improve readability and reduce boilerplate code of having to nest multiple layers of StateHolders.
As such, we're going from:
import 'package:state_holder/state_holder.dart';

StateHolder<Something>(
builder : (context) => Something(),
child : StateHolder<SomethingElse>(
builder : (context) => SomethingElse(),
child StateHolder<AnotherThing>(
builder : (context) => AnotherThing(),
child : App(),
),
),
),
copied to clipboard
To:
import 'package:state_holder/state_holder.dart';

MultiStateHolder(
stateHolders : [
StateHolder<Something>(
builder : (context) => Something()
),
StateHolder<SomethingElse>(
builder : (context) => SomethingElse(),
),
StateHolder<AnotherThing>(
builder : (context) => AnotherThing(),
),
],
child : App(),
),
copied to clipboard
Access Components #
StateHolder Component #
Description
: Provides Simple Interface To Access State Components From Any Where in Widget
StateHolder.of<T>(BuildContext context, [bool listen = false])
Use This Method To Obtain The Nearest StateHolder Where [T] is The Type of StateHolder Required And Context of Widget Requesting The State
Making [Listen] True
Will Add This State To Dependant of The Context.
Then Whenever The Value Inside State is Changed The Dependant is Rebuild.
By Default The Parameter is False;
[Note] : Only [ChangeNotifierStateHolder] Has The Ablity To Rebuild Its Dependants.
Example :
import 'package:state_holder/state_holder.dart';

// Somewhere in Widget Tree

MultiStateHolder(
stateHolders : [
StateHolder(
builder : (context) => "HelloWorld",
),
ChangeNotifierStateHolder(
builder : (context) => ValueNotifier(10),
),
],
child : SomeWidget(),
),
copied to clipboard
class SomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
var nonListnableDaa = StateHolder.of<String>(context);
var listnableData = StateHolder.of<ValueNotifier<int>>(context, true);
return AnotherWidget();
}
}
copied to clipboard
StateConsumer Component #
Description
Obtains [StateHolder
Example :
import 'package:state_holder/state_holder.dart';

// Somewhere in Widget Tree

StateHolder(
builder : (context) => "HelloWorld",
child : SomeWidget(),
)
copied to clipboard
Widget foo() {
return StateConsumer<String>(
builder : (context, state, child) {
return SomeWidget();
},
);
}
copied to clipboard
StateHolderContext Component #
Description
: [StateHolderContext] is an Extension on [BuildContext]
Which Provides Two Methods To Read And Watch State of [StateHolder]
context.readStateHolder<T>();
Use This Method To Read The State of StateHolde Without Listinig To Updates.
It Is Similer to :
StateHolder.of<T>(context, false);
copied to clipboard
context.watchStateHolder<T>();
Use This Method To Watch The State of StateHolde and Listinig To Updates
It Is Similer to :
StateHolder.of<T>(context, true);
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.