solace_flowz 0.0.4
state management package built on top of InheritedWidget, that aims to simplify the state managementm work for flutter developers and perofrm the task using the minimal resources .
SolaceFlowz
SolaceFlowz is a simple state management package for Flutter based on the InheritedWidget and StatefulWidget classes.
Installation
Add the following line to your pubspec.yaml file:
dependencies: solace_flowz: ^1.0.0
Usage
- Wrap your widget tree with a SolaceFlowz widget:
SolaceFlowz(
value: myValue,
builder: (BuildContext context, int value, Widget child) {
// Return a widget that depends on the value.
},
child: MyChildWidget(),
)
-
Use the SolaceFlowz.of static method to access the value from any child widget:
int myValue = SolaceFlowz.of<int>(context); -
Update the value by calling the setState method on the SolaceFlowz widget:
SolaceFlowz.of<int>(context).setState(() { SolaceFlowz.of<int>(context).value = 42; });
- You can use this SolaceFlowzConsumer widget in a similar way to the Consumer widget provided by the provider package, by wrapping your widgets with the SolaceFlowz
widget, and using the SolaceFlowzConsumer widget to consume data from the SolaceFlowz instance. Here's an example usage:
SolaceFlowz<MyData>(
builder: (context, solaceFlowz) => SolaceFlowzConsumer<MyData>(
builder: (context, data) {
// Use the MyData object to build your widget tree
return Text(data.toString());
},
child: MyWidget(),
),
);
Example
Here's a simple example that shows how to use SolaceFlowz to manage the state of a counter:
import 'package:flutter/material.dart';
import 'package:solace_flowz/solace_flowz.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SolaceFlowz<int>(
value: 0,
builder: (BuildContext context, int value, Widget child) {
return Scaffold(
appBar: AppBar(
title: Text('SolaceFlowz Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Counter: $value'),
child,
],
),
),
);
},
child: ElevatedButton(
onPressed: () {
SolaceFlowz.of<int>(context).setState(() {
SolaceFlowz.of<int>(context).value += 1;
});
},
child: Text('Increment'),
),
),
);
}
}
GitHub Repository
The source code for My Package is available on GitHub at GitHub Repo.
You can clone the repository using the following command:
git clone https://github.com/AwaeshaHuss/Solace_FlowZ.git
License
In this example, we have created a section specifically for the GitHub repository, provided a brief description of the package, and included a link to the GitHub repository using markdown syntax. We have also mentioned the license and provided instructions on how to clone the repository and report issues.