Created
March 9, 2021 15:04
-
-
Save kirimi/054a29311edb8206e47c891a99237021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart' hide Action; | |
import 'package:mwwm/mwwm.dart'; | |
import 'package:relation/relation.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold(body: MyHomePage()), | |
); | |
} | |
} | |
class MyHomePageWm extends WidgetModel { | |
MyHomePageWm() : super(WidgetModelDependencies()); | |
final myEntity = | |
EntityStreamedState<String>(EntityState.content('Initial content')); | |
final content = Action<void>(); | |
final loading = Action<void>(); | |
final loadingWithoutData = Action<void>(); | |
final error = Action<void>(); | |
@override | |
void onBind() { | |
super.onBind(); | |
subscribe( | |
content.stream, | |
(_) => myEntity.content('content data'), | |
); | |
subscribe( | |
loading.stream, | |
(_) => myEntity.loading('loading data'), | |
); | |
subscribe( | |
loadingWithoutData.stream, | |
(_) => myEntity.loading(), | |
); | |
subscribe( | |
error.stream, | |
(_) => myEntity.error(), | |
); | |
} | |
} | |
class MyHomePage extends CoreMwwmWidget { | |
MyHomePage() : super(widgetModelBuilder: (_) => MyHomePageWm()); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends WidgetState<MyHomePageWm> { | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
children: [ | |
Expanded( | |
child: Center( | |
child: EntityStateBuilder( | |
streamedState: wm.myEntity, | |
child: (context, data) => Text('Content: $data'), | |
// loadingChild: Text('loadingChild'), | |
loadingBuilder: (context, data) => Text('loadingBuilder: $data'), | |
// errorChild: Text('errorChild'), | |
errorBuilder: (context, data, e) => Text('errorBuilder'), | |
), | |
), | |
), | |
Wrap( | |
spacing: 10.0, | |
children: [ | |
ElevatedButton( | |
child: Text('content'), | |
onPressed: wm.content, | |
), | |
ElevatedButton( | |
child: Text('loading'), | |
onPressed: wm.loading, | |
), | |
ElevatedButton( | |
child: Text('loading without data'), | |
onPressed: wm.loadingWithoutData, | |
), | |
ElevatedButton( | |
child: Text('error'), | |
onPressed: wm.error, | |
), | |
], | |
) | |
], | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: loadingwmmw | |
description: A new Flutter project. | |
publish_to: 'none' | |
version: 1.0.0+1 | |
environment: | |
sdk: ">=2.7.0 <3.0.0" | |
dependencies: | |
flutter: | |
sdk: flutter | |
cupertino_icons: ^1.0.2 | |
mwwm: ^0.1.3-dev.3 | |
relation: ^0.0.4-dev.1 | |
dev_dependencies: | |
flutter_test: | |
sdk: flutter | |
flutter: | |
uses-material-design: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment