Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] optimize example #368

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fair_provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ class CounterModel extends FairChangeNotifier {
注意read函数的泛型即是状态管理类的类型,参数需要手动输入该类的字符串
```dart
void _incrementCounter(FairContext context) {
//通过FairContext获取状态对象
var counterModel = context.read<CounterModel>("CounterModel");
//修改对象中的value
counterModel.count++;
//调用notify通知观察者
counterModel.notify();
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,5 @@
"CounterModel"
],
"methodMap": {},
"digest": "2a50f76be88274617782a4aaf287fae5"
"digest": "9a57f6332184336987ce97b19ff50c9d"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Fair on 2023-11-07 10:58:27.291068.
# Generated by Fair on 2023-11-15 20:13:27.284796.

source: example|lib/ui/counter_page.dart
md5: d2e3f3306a431e152fa405978c7ff341
md5: 819e54e126cf41cbf9f2d9b7b8bd1042
json: example|build/fair/lib_ui_counter_page.fair.json
bin: example|build/fair/lib_ui_counter_page.fair.bin
date: 2023-11-07 10:58:27.291284
date: 2023-11-15 20:13:27.285044
Original file line number Diff line number Diff line change
Expand Up @@ -863,5 +863,5 @@
"ExampleModel"
],
"methodMap": {},
"digest": "e892fd0f6f5e2dd8e7bf13ebf6525b34"
"digest": "4822d9ccf383c2962f94493efc6197ac"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Fair on 2023-11-07 10:58:27.258829.
# Generated by Fair on 2023-11-15 20:13:27.343253.

source: example|lib/ui/example_page.dart
md5: df9a174788a4cad9b1e55169ba5e5dcf
md5: 1985fff1986e3c121d13b7b1aab62b59
json: example|build/fair/lib_ui_example_page.fair.json
bin: example|build/fair/lib_ui_example_page.fair.bin
date: 2023-11-07 10:58:27.259251
date: 2023-11-15 20:13:27.343627
93 changes: 62 additions & 31 deletions fair_provider/example/assets/fair/lib_ui_example_page2.fair.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"title": {
"className": "Text",
"pa": [
"跨组件共享状态"
"状态共享-页面1"
]
}
}
Expand All @@ -21,42 +21,73 @@
"mainAxisAlignment": "#(MainAxisAlignment.center)",
"children": [
{
"className": "Text",
"pa": [
"监听TopModel中的intFiled:"
]
},
{
"className": "FairConsumer",
"className": "Row",
"na": {
"builder": {
"className": "SugarProvider.consumerBuilder",
"pa": [
{
"className": "Text",
"pa": [
{
"className": "SugarProvider.readAsString",
"pa": [
"^(value)",
"intField"
]
}
],
"functionParameters": {
"mainAxisAlignment": "#(MainAxisAlignment.center)",
"children": [
{
"className": "Text",
"pa": [
"监听TopModel中的intFiled:"
]
},
{
"className": "FairConsumer",
"na": {
"builder": {
"className": "SugarProvider.consumerBuilder",
"pa": [
"context",
"value",
"child"
{
"className": "Text",
"pa": [
{
"className": "SugarProvider.readAsString",
"pa": [
"^(value)",
"intField"
]
}
],
"functionParameters": {
"pa": [
"context",
"value",
"child"
]
}
}
]
}
},
"typeArgumentList": [
"TopModel"
]
}
]
}
},
{
"className": "ElevatedButton",
"na": {
"onPressed": {
"className": "Navigator.pushNamed",
"pa": [
"^(context)",
"fair_page_two"
],
"na": {
"arguments": {
"path": "assets/fair/lib_ui_second_page.fair.json"
}
}
},
"child": {
"className": "Text",
"pa": [
"点击跳转二级页面"
]
}
},
"typeArgumentList": [
"TopModel"
]
}
}
]
}
Expand Down Expand Up @@ -93,5 +124,5 @@
}
},
"methodMap": {},
"digest": "2411e8da388fc4af26fa00d0278de484"
"digest": "fa93eea4a8aed0095b7cd960eb827e9e"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Fair on 2023-11-07 10:58:27.306859.
# Generated by Fair on 2023-11-15 20:13:27.329194.

source: example|lib/ui/example_page2.dart
md5: 7e0452e2e8e8d84789b198debd6035da
md5: cf9cb059b5cb15a1f911fbd4dc02e0a5
json: example|build/fair/lib_ui_example_page2.fair.json
bin: example|build/fair/lib_ui_example_page2.fair.bin
date: 2023-11-07 10:58:27.307047
date: 2023-11-15 20:13:27.329383

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

111 changes: 111 additions & 0 deletions fair_provider/example/assets/fair/lib_ui_second_page.fair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"className": "Scaffold",
"na": {
"appBar": {
"className": "AppBar",
"na": {
"title": {
"className": "Text",
"pa": [
"状态共享-页面2"
]
}
}
},
"body": {
"className": "Container",
"na": {
"color": "#(Colors.white)",
"child": {
"className": "Center",
"na": {
"child": {
"className": "Column",
"na": {
"mainAxisAlignment": "#(MainAxisAlignment.center)",
"children": [
{
"className": "Row",
"na": {
"mainAxisAlignment": "#(MainAxisAlignment.center)",
"children": [
{
"className": "Text",
"pa": [
"监听TopModel中的intFiled:"
]
},
{
"className": "FairConsumer",
"na": {
"builder": {
"className": "SugarProvider.consumerBuilder",
"pa": [
{
"className": "Text",
"pa": [
{
"className": "SugarProvider.readAsString",
"pa": [
"^(value)",
"intField"
]
}
],
"functionParameters": {
"pa": [
"context",
"value",
"child"
]
}
}
]
}
},
"typeArgumentList": [
"TopModel"
]
}
]
}
}
]
}
}
}
}
}
},
"floatingActionButton": {
"className": "FairContextBuilder",
"na": {
"builder": {
"className": "SugarProvider.widgetBuilder",
"pa": [
{
"className": "FloatingActionButton",
"na": {
"onPressed": "@(_incrementCounter(^(context)))",
"tooltip": "Increment",
"child": {
"className": "Icon",
"pa": [
"#(Icons.add)"
]
}
},
"functionParameters": {
"pa": [
"context"
]
}
}
]
}
}
}
},
"methodMap": {},
"digest": "5e7cd6297fd4cca54ff47dc3369bc035"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by Fair on 2023-11-15 20:13:27.313370.

source: example|lib/ui/second_page.dart
md5: e011b307244623677adc6f1adfde4c0b
json: example|build/fair/lib_ui_second_page.fair.json
bin: example|build/fair/lib_ui_second_page.fair.bin
date: 2023-11-15 20:13:27.313553
1 change: 0 additions & 1 deletion fair_provider/example/lib/entity/top_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import 'package:fair_provider/fair_provider.dart';

class TopModel extends FairChangeNotifier {
int intField = 1;
double doubleFiled = 0.0;
}
Loading
Loading