Skip to content

Commit

Permalink
Merge pull request #97 from yancechen/main
Browse files Browse the repository at this point in the history
添加布局动态化的example
  • Loading branch information
yancechen authored May 31, 2022
2 parents 8f69141 + c164711 commit 12074ef
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 5 deletions.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"className": "Scaffold",
"na": {
"appBar": {
"className": "AppBar",
"na": {
"title": {
"className": "Text",
"pa": [
"FairBinding 注解演示"
]
}
}
},
"body": {
"className": "Center",
"na": {
"child": {
"className": "Column",
"na": {
"mainAxisAlignment": "#(MainAxisAlignment.center)",
"children": [
{
"className": "Text",
"pa": [
"Hello World!"
]
},
{
"className": "FairBindingWidget"
}
]
}
}
}
}
},
"methodMap": {}
}
Binary file added example/assets/fair/lib_main.fair.bin
Binary file not shown.
Binary file added example/assets/fair/lib_page2page_page_one.fair.bin
Binary file not shown.
Binary file added example/assets/fair/lib_page2page_page_two.fair.bin
Binary file not shown.
29 changes: 29 additions & 0 deletions example/lib/fair_widget/fairbinding/fair_binding_sample.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:example/fair_widget/fairbinding/fair_binding_widget.dart';
import 'package:fair/fair.dart';
import 'package:flutter/material.dart';

@FairPatch()
class FairBindingSample extends StatelessWidget {
const FairBindingSample({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('FairBinding 注解演示'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Hello World!',
),
// 引用本地自定义的 FairBindingWidget
FairBindingWidget(),
],
),
)
);
}
}
22 changes: 22 additions & 0 deletions example/lib/fair_widget/fairbinding/fair_binding_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:fair/fair.dart';
import 'package:flutter/material.dart';

/// 本地自定义的 Widget。
class FairBindingWidget extends StatefulWidget {
const FairBindingWidget({Key? key}) : super(key: key);

@override
_FairBindingWidgetState createState() => _FairBindingWidgetState();
}

class _FairBindingWidgetState extends State<FairBindingWidget> {
@override
Widget build(BuildContext context) {
return Container(
child: Padding(
padding: EdgeInsets.all(15),
child: Text('我是一个本地自定义 Widget'),
),
);
}
}
17 changes: 12 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import 'package:flutter/material.dart';
import 'package:example/fair_widget/delegate/test_fair_delegate.dart';
import 'package:example/fair_widget/plugin/fair_basic_plugin.dart';
import 'package:example/home_page.dart';
import 'src/generated.fair.dart' as g;

/// 本 demo 演示 counting 的改造
@FairBinding(packages: [
'package:example/fair_widget/fairbinding/fair_binding_widget.dart',
])
void main() {
// runApp(MyApp());

Expand All @@ -21,6 +24,7 @@ void main() {
///TestFairDelegate只作用于相同名字的fairwidget
'assets/fair/lib_fair_widget_fair_delegate_widget.fair.json': (ctx, _) => TestFairDelegate(),
},
generated: g.AppGeneratedModule(),
),
///需要在此注册需要全局使用的plugin,key名可以随意不做要求
plugins: {
Expand Down Expand Up @@ -53,10 +57,13 @@ class MyApp extends StatelessWidget {
/// path 参数:需要加载的 bundle 资源文件路径
/// data 参数:需要传递给动态页面的参数
home: FairWidget(
/// path 可以是 assets 目录下的 bundle 资源,也可以是手机存储
/// 里的 bundle 资源,如果是手机存储里的 bundle 资源需要使用绝对路径
path: 'assets/fair/lib_page2page_page_one.fair.json',
)
/// path 可以是 assets 目录下的 bundle 资源,也可以是手机存储
/// 里的 bundle 资源,如果是手机存储里的 bundle 资源需要使用绝对路径
path: 'assets/fair/lib_main.fair.json',
data: {
'fairProps':jsonEncode({'title':'你好'})
},
)
// home: HomePage()
);
}
Expand Down
24 changes: 24 additions & 0 deletions example/lib/src/generated.fair.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Generated by Fair on 2022-05-31 13:02:55.553046.
import 'package:example/fair_widget/fairbinding/fair_binding_widget.dart';

import 'package:flutter/material.dart';
import 'package:fair/fair.dart';
import 'package:fair_version/fair_version.dart';

class AppGeneratedModule extends GeneratedModule {
@override
Map<String, dynamic> components() {
return {
'FairBindingWidget': (props) => FairBindingWidget(
key: props['key'],
),
};
}

@override
Map<String, bool> mapping() {
return const {
'FairBindingWidget': true,
};
}
}

0 comments on commit 12074ef

Please sign in to comment.