Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/istornz/flutter_hermep
A very simple & lightweight MVC flutter state managment 📚
https://github.com/istornz/flutter_hermep
animation dart flutter mvc mvvm
Last synced: 4 months ago
JSON representation
A very simple & lightweight MVC flutter state managment 📚
- Host: GitHub
- URL: https://github.com/istornz/flutter_hermep
- Owner: istornz
- License: mit
- Created: 2021-06-12T10:45:17.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-06-28T08:49:52.000Z (7 months ago)
- Last Synced: 2024-08-22T23:29:24.467Z (6 months ago)
- Topics: animation, dart, flutter, mvc, mvvm
- Language: Dart
- Homepage: https://dimitridessus.fr
- Size: 597 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
An **MVVM state** management library which let **full access** to widget state.
## 🧐 What is it ?
Hermep provide a way to create an **MVVM** page structure and let you **full access** to the widget state. Coding & testing will be easier 😇
To summarize It's just a **very simple wrapper** to split your code logic 😎
## 👻 Getting started
- Create a **model** file ```_viewmodel.dart```
```dart
class YourClassModel with HermepModel {
late int counter;
}
```- Create the **presenter** file ```_presenter.dart```.
```dart
class YourClassPresenter with HermepPresenter {
YourClassPresenter(
YourClassView viewInterface,
) {
this.viewModel = YourClassModel();
this.viewInterface = viewInterface;
}@override
void dispose() { }@override
void init() { }
}
```- Create the **page** file ```.dart```.
```dart
mixin YourClassView {}class YourClassPage extends StatefulWidget {
YourClassPage({Key? key}) : super(key: key);@override
_YourClassPageState createState() => _YourClassPageState();
}class _YourClassPageState extends HermepPage with YourClassView {
@override
void createAnimations() { }@override
void afterViewInit() { }@override
HermepPresenter createPresenter() => YourClassPresenter(this);@override
Widget build(BuildContext context) {
return Text('Your Page');
}
}
```## 💫 Animations
Yes you can use **animations** with Hermep and it's very easy !
- In your ```model.dart``` file, create the **animation** & **value notifier** (used to trigger animation)
```dart
class YourClassModel with HermepModel {
late ValueNotifier triggerAnimation;
late Animation animation;YourClassModel();
}
```- In your ```presenter.dart``` file, init the animation **value notifier**.
```dart
// [...]
@override
void init() {
this.viewModel.triggerAnimation = new ValueNotifier(false);
}
// [...]
```- In your page, override the ```createAnimations()``` method to init the animation controller & assign animation tween.
```dart
// [...]
@override
void createAnimations() {
this.animationControllers = {
this.viewModel.triggerAnimation: AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
)
};this.viewModel.animation = Tween(
begin: 50,
end: 300,
).animate(this.animationControllers.values.first)
..addListener(() => this.refreshView());
}
// [..]
```- To trigger ```on``` or ```off``` your animation, just **set the value notifier** in your presenter 🎉.
```dart
// launch the animation
this.viewModel.triggerAnimation.value = true;// stop the animation
this.viewModel.triggerAnimation.value = false;
```## ✅ Testing
Hermep can be **fully tested** by getting the **presenter** & **model** instances directly from your tests. This can be achieved with only *3 lines* of code 😎.
```dart
final dynamic yourClassPageState = tester.state(find.byType(YourClassPage));
final YourClassPresenter presenter = yourClassPageState.presenter;
final YourClassModel model = yourClassPageState.viewModel;
```You can now check all your **model data** & **trigger** some functions from your presenter in your test 🚀.
## Psst 🤫 !
You can use Hermep with [Koby for VSCode](https://marketplace.visualstudio.com/items?itemName=istornz.koby) to generate **all needed files** (presenter, model & page) with 2 clicks 🤩.
## 👥 Contributions
Contributions are welcome. Contribute by creating a PR or create an issue 🎉.