https://github.com/surfstudio/flutter-surf-mwwm
https://github.com/surfstudio/flutter-surf-mwwm
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/surfstudio/flutter-surf-mwwm
- Owner: surfstudio
- License: apache-2.0
- Created: 2021-07-09T05:43:43.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-04-24T11:08:40.000Z (about 3 years ago)
- Last Synced: 2023-08-01T12:24:30.350Z (almost 3 years ago)
- Language: Dart
- Size: 80.1 KB
- Stars: 6
- Watchers: 6
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Surf MWWM
[](https://github.com/surfstudio/SurfGear/tree/main/packages/surf_mwwm)
[](https://codecov.io/gh/surfstudio/SurfGear)
[](https://pub.dev/packages/surf_mwwm)
[](https://pub.dev/packages/surf_mwwm)
[](https://pub.dev/packages/surf_mwwm/score)

This package made by [Surf](https://surf.ru/).
## Description
Reflection of widget in a single entity
## Installation
Add `surf_mwwm` to your `pubspec.yaml` file:
```yaml
dependencies:
surf_mwwm: ^1.0.0
```
You can use both `stable` and `dev` versions of the package listed above in the badges bar.
## Example
1. Create WM class
```dart
class CounterWidgetModel extends WidgetModel {
CounterWidgetModel(
WidgetModelDependencies dependencies,
this.navigator,
this._key,
) : super(dependencies);
final NavigatorState navigator;
final GlobalKey _key;
StreamedState counterState = StreamedState(0);
final incrementAction = VoidAction();
final showInit = StreamedAction();
@override
void onLoad() {
_listenToActions();
super.onLoad();
}
void _listenToActions() {
incrementAction.bind((_) {
counterState.accept(counterState.value + 1);
}).listenOn(
this,
onValue: (_) {},
);
showInit.bind((_) {
ScaffoldMessenger.of(_key.currentContext!).showSnackBar(
const SnackBar(
content: Text('init'),
),
);
}).listenOn(this, onValue: (_) {});
counterState.stream.where((c) => c.isEven).skip(1).listenOn(
this,
onValue: (c) {
navigator.push(
MaterialPageRoute(
builder: (ctx) => Scaffold(
body: Column(
children: [
TextField(
autofocus: true,
onChanged: (_) {},
),
],
),
),
),
);
},
);
}
}
```
2. Create Screen
```dart
class CounterScreen extends MwwmWidget {
CounterScreen({Key? key})
: super(
key: key,
dependenciesBuilder: (context) =>
CounterComponent(Navigator.of(context)),
widgetStateBuilder: () => _CounterScreenState(),
widgetModelBuilder: createCounterModel,
);
}
class _CounterScreenState extends OldWidgetState {
@override
Widget build(BuildContext context) {
return Scaffold(
key: context.getComponent().scaffoldKey,
appBar: AppBar(
title: const Text('Counter Demo'),
),
body: StreamBuilder(
stream: wm.counterState.stream,
initialData: 0,
builder: (context, snapshot) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('You have pushed the this many times:'),
Text(
'${snapshot.data}',
style: Theme.of(context).textTheme.caption,
),
TextField(
autofocus: true,
onChanged: (_) {},
),
],
),
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: wm.incrementAction,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
```
3. Create Route
```dart
class CounterScreenRoute extends MaterialPageRoute {
CounterScreenRoute() : super(builder: (ctx) => CounterScreen());
}
```
## Changelog
All notable changes to this project will be documented in [this file](./CHANGELOG.md).
## Issues
For issues, file directly in the Issues section.
## Contribute
If you would like to contribute to the package (e.g. by improving the documentation, solving a bug or adding a cool new feature), please review our [contribution guide](../../CONTRIBUTING.md) first and send us your pull request.
Your PRs are always welcome.
## How to reach us
Please feel free to ask any questions about this package. Join our community chat on Telegram. We speak English and Russian.
[](https://t.me/SurfGear)
## License
[Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)