update: 完成markdown动态更新

This commit is contained in:
sanfan.hx
2019-08-07 14:33:40 +08:00
parent bc10e99823
commit 8f835fec3a
23 changed files with 660 additions and 193 deletions

View File

@ -96,18 +96,14 @@ class StandardPages {
var template = new Template(source, name: 'template-filename.html'); var template = new Template(source, name: 'template-filename.html');
// print(prettyJson(data[0]));
// 自定义前缀 避免出现数字非法字符等 // 自定义前缀 避免出现数字非法字符等
String pre = "StandardPage";
Map<String, List> formatData = { Map<String, List> formatData = {
"pages": data "pages": data
}; };
var output = template.renderString(formatData); String output = template.renderString(formatData);
print(output);
// }
return output; return output;
} }

View File

@ -18,6 +18,7 @@ class _CommandRunner extends CommandRunner<int> {
negatable: false, help: 'Prints the version of goCi.'); negatable: false, help: 'Prints the version of goCi.');
addCommand(CreateDemoCommand()); addCommand(CreateDemoCommand());
addCommand(CreatePageCommand()); addCommand(CreatePageCommand());
addCommand(WatchCommand());
addCommand(Build()); addCommand(Build());
} }

View File

@ -0,0 +1,94 @@
//
// Created with Android Studio.
// User: 三帆
// Date: 07/08/2019
// Time: 08:40
// email: sanfan.hx@alibaba-inc.com
// tartget: 代码获取自: https://blog.csdn.net/O_time/article/details/86496537
//
import 'dart:async';
import 'package:flutter/material.dart';
// ignore: must_be_immutable
class NetLoadingDialog extends StatefulWidget {
String loadingText;
bool outsideDismiss;
bool loading;
Function dismissCallback;
Future<dynamic> requestCallBack;
NetLoadingDialog(
{Key key,
this.loadingText = "loading...",
this.outsideDismiss = true,
this.dismissCallback,
this.loading,
this.requestCallBack})
: super(key: key);
@override
State<NetLoadingDialog> createState() => _LoadingDialog();
}
class _LoadingDialog extends State<NetLoadingDialog> {
_dismissDialog() {
if (widget.dismissCallback != null) {
widget.dismissCallback();
}
Navigator.of(context).pop();
}
@override
void initState() {
super.initState();
if (widget.requestCallBack != null) {
widget.requestCallBack.then((_) {
Navigator.pop(context);
});
}
}
@override
Widget build(BuildContext context) {
if (!widget.loading) {
return Container();
}
return new GestureDetector(
onTap: widget.outsideDismiss ? _dismissDialog : null,
child: Material(
type: MaterialType.transparency,
child: new Center(
child: new SizedBox(
width: 120.0,
height: 120.0,
child: new Container(
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
),
),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new CircularProgressIndicator(),
new Padding(
padding: const EdgeInsets.only(
top: 20.0,
),
child: new Text(
widget.loadingText,
style: new TextStyle(fontSize: 12.0),
),
),
],
),
),
),
),
),
);
}
}

View File

@ -24,8 +24,8 @@ class WidgetDemo extends StatefulWidget {
{Key key, {Key key,
@required this.title, @required this.title,
@required this.contentList, @required this.contentList,
@required this.codeUrl, this.codeUrl,
@required this.docUrl, this.docUrl,
this.bottomNaviBar}) this.bottomNaviBar})
: super(key: key); : super(key: key);
@ -134,7 +134,38 @@ class _WidgetDemoState extends State<WidgetDemo> {
'${Routes.codeView}?filePath=${Uri.encodeComponent(widget.codeUrl)}'); '${Routes.codeView}?filePath=${Uri.encodeComponent(widget.codeUrl)}');
} }
} }
List<PopupMenuEntry<String>> buildPopupMenu() {
List<PopupMenuEntry<String>> comps = [];
if (widget.docUrl != null) {
comps.add(
PopupMenuItem<String>(
value: 'doc',
child: ListTile(
leading: Icon(
Icons.library_books,
size: 22.0,
),
title: Text('查看文档'),
),
)
);
}
if (widget.codeUrl != null) {
comps.add(
PopupMenuItem<String>(
value: 'code',
child: ListTile(
leading: Icon(
Icons.code,
size: 22.0,
),
title: Text('查看Demo'),
),
)
);
}
return comps;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (_hasCollected) { if (_hasCollected) {
@ -142,50 +173,34 @@ class _WidgetDemoState extends State<WidgetDemo> {
} else { } else {
_collectionIcons = Icons.favorite_border; _collectionIcons = Icons.favorite_border;
} }
List<PopupMenuEntry<String>> menus = buildPopupMenu();
List<Widget> actions = [
new IconButton(
tooltip: 'goBack home',
onPressed: () {
Navigator.popUntil(context, ModalRoute.withName('/'));
},
icon: Icon(Icons.home),
),
new IconButton(
tooltip: 'collection',
onPressed: _getCollection,
icon: Icon(_collectionIcons),
),
];
if (menus.length > 0) {
actions.add(
PopupMenuButton<String>(
onSelected: _selectValue,
itemBuilder: (BuildContext context) => menus,
)
);
}
return Scaffold( return Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
appBar: AppBar( appBar: AppBar(
title: Text(widget.title), title: Text(widget.title),
actions: <Widget>[ actions: actions,
new IconButton(
tooltip: 'goBack home',
onPressed: () {
Navigator.popUntil(context, ModalRoute.withName('/'));
},
icon: Icon(Icons.home),
),
new IconButton(
tooltip: 'collection',
onPressed: _getCollection,
icon: Icon(_collectionIcons),
),
PopupMenuButton<String>(
onSelected: _selectValue,
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'doc',
child: ListTile(
leading: Icon(
Icons.library_books,
size: 22.0,
),
title: Text('查看文档'),
),
),
const PopupMenuDivider(),
const PopupMenuItem<String>(
value: 'code',
child: ListTile(
leading: Icon(
Icons.code,
size: 22.0,
),
title: Text('查看Demo'),
),
),
],
),
],
), ),
body: Container( body: Container(
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0), padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0),

View File

@ -17,7 +17,7 @@ import 'package:flutter_go/event/event_bus.dart';
import 'package:flutter_go/event/event_model.dart'; import 'package:flutter_go/event/event_model.dart';
import 'package:event_bus/event_bus.dart'; import 'package:event_bus/event_bus.dart';
import 'package:flutter_go/model/widget.dart'; import 'package:flutter_go/model/widget.dart';
import 'package:flutter_go/standard_pages/index.dart';
//import 'views/welcome_page/index.dart'; //import 'views/welcome_page/index.dart';
SpUtil sp; SpUtil sp;
@ -28,7 +28,6 @@ class MyApp extends StatefulWidget {
final router = new Router(); final router = new Router();
Routes.configureRoutes(router); Routes.configureRoutes(router);
// 这里设置项目环境 // 这里设置项目环境
Application.env = ENV.PRODUCTION;
Application.router = router; Application.router = router;
} }
@ -189,13 +188,13 @@ void main() async {
await provider.init(true); await provider.init(true);
sp = await SpUtil.getInstance(); sp = await SpUtil.getInstance();
new SearchHistoryList(sp); new SearchHistoryList(sp);
await DataUtils.getWidgetTreeList().then((List json) {
Application.widgetTree = WidgetTree.buildWidgetTree(json);
if (Application.env == ENV.DEV) {
} await DataUtils.getWidgetTreeList().then((List json) {
List data = WidgetTree.insertDevPagesToList(json, StandardPages().getLocalList());
Application.widgetTree = WidgetTree.buildWidgetTree(data);
print("Application.widgetTree>>>> ${Application.widgetTree}"); print("Application.widgetTree>>>> ${Application.widgetTree}");
}); });
db = Provider.db; db = Provider.db;
runApp(new MyApp()); runApp(new MyApp());
} }

View File

@ -1,107 +1,107 @@
//
import 'dart:async'; //import 'dart:async';
//
import 'package:flutter_go/utils/sql.dart'; //import 'package:flutter_go/utils/sql.dart';
//
abstract class CatInterface{ //abstract class CatInterface{
int get id; // int get id;
//类目名称 // //类目名称
String get name; // String get name;
//描述 // //描述
String get desc; // String get desc;
//第几级类目,默认 1 // //第几级类目,默认 1
int get depth; // int get depth;
//父类目id没有为 0 // //父类目id没有为 0
int get parentId; // int get parentId;
} //}
//
class Cat implements CatInterface { //class Cat implements CatInterface {
int id; // int id;
String name; // String name;
String desc; // String desc;
int depth; // int depth;
int parentId; // int parentId;
//
Cat({this.id, this.name, this.desc, this.depth, this.parentId}); // Cat({this.id, this.name, this.desc, this.depth, this.parentId});
//
Cat.fromJSON(Map json) // Cat.fromJSON(Map json)
: id = json['id'], // : id = json['id'],
name = json['name'], // name = json['name'],
desc = json['desc'], // desc = json['desc'],
depth = json['depth'], // depth = json['depth'],
parentId = json['parentId']; // parentId = json['parentId'];
//
String toString() { // String toString() {
return '(Cat $name)'; // return '(Cat $name)';
} // }
//
Map toMap() { // Map toMap() {
return { // return {
'id': id, // 'id': id,
'name': name, // 'name': name,
'desc': desc, // 'desc': desc,
'depth': depth, // 'depth': depth,
'parentId': parentId // 'parentId': parentId
}; // };
} // }
Map toSqlCondition() { // Map toSqlCondition() {
Map _map = this.toMap(); // Map _map = this.toMap();
Map condition = {}; // Map condition = {};
_map.forEach((k, value) { // _map.forEach((k, value) {
//
if (value != null) { // if (value != null) {
//
condition[k] = value; // condition[k] = value;
} // }
}); // });
//
if (condition.isEmpty) { // if (condition.isEmpty) {
return {}; // return {};
} // }
//
return condition; // return condition;
} // }
} //}
//
//
class CatControlModel{ //class CatControlModel{
final String table = 'cat'; // final String table = 'cat';
Sql sql; // Sql sql;
CatControlModel() { // CatControlModel() {
sql = Sql.setTable(table); // sql = Sql.setTable(table);
} // }
//
/// 获取一级类目 // /// 获取一级类目
Future<List> mainList() async{ // Future<List> mainList() async{
List listJson = await sql.getByCondition(conditions: {'parentId': 0}); // List listJson = await sql.getByCondition(conditions: {'parentId': 0});
List<Cat> cats = listJson.map((json) { // List<Cat> cats = listJson.map((json) {
return new Cat.fromJSON(json); // return new Cat.fromJSON(json);
}).toList(); // }).toList();
return cats; // return cats;
} // }
//
// 获取Cat不同深度与parent的列表 // // 获取Cat不同深度与parent的列表
Future<List<Cat>> getList([Cat cat]) async{ // Future<List<Cat>> getList([Cat cat]) async{
//
//
if (cat == null) { // if (cat == null) {
cat = new Cat(depth: 1, parentId: 0); // cat = new Cat(depth: 1, parentId: 0);
} // }
// print("cat in getList ${cat.toMap()}"); // // print("cat in getList ${cat.toMap()}");
List listJson = await sql.getByCondition(conditions: cat.toSqlCondition()); // List listJson = await sql.getByCondition(conditions: cat.toSqlCondition());
List<Cat> cats = listJson.map((json) { // List<Cat> cats = listJson.map((json) {
return new Cat.fromJSON(json); // return new Cat.fromJSON(json);
}).toList(); // }).toList();
return cats; // return cats;
} // }
//
// 通过name获取Cat对象信息 // // 通过name获取Cat对象信息
Future<Cat> getCatByName(String name) async { // Future<Cat> getCatByName(String name) async {
List json = await sql.getByCondition(conditions: {'name': name}); // List json = await sql.getByCondition(conditions: {'name': name});
if (json.isEmpty) { // if (json.isEmpty) {
return null; // return null;
} // }
return new Cat.fromJSON(json.first); // return new Cat.fromJSON(json.first);
} // }
//
} //}

View File

@ -2,7 +2,7 @@
import 'dart:async'; import 'dart:async';
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_go/routers/application.dart";
import 'package:flutter_go/utils/sql.dart'; import 'package:flutter_go/utils/sql.dart';
enum treeNode { enum treeNode {
@ -188,6 +188,7 @@ class CategoryComponent extends CommonItem {
@required this.id, @required this.id,
@required this.name, @required this.name,
@required this.parentId, @required this.parentId,
this.type = 'categoryw',
this.children, this.children,
this.parent this.parent
}); });
@ -289,6 +290,7 @@ class WidgetLeaf extends CommonItem {
} }
class WidgetTree { class WidgetTree {
// 构建树型结构
static CategoryComponent buildWidgetTree(List json, [parent]){ static CategoryComponent buildWidgetTree(List json, [parent]){
CategoryComponent current; CategoryComponent current;
if (parent != null) { if (parent != null) {
@ -312,6 +314,41 @@ class WidgetTree {
}); });
return current; return current;
} }
static insertDevPagesToList(List list, List devPages) {
List devChildren = [];
int index = 9999999;
if (Application.env == ENV.PRODUCTION) {
return list;
}
devPages.forEach((item) {
index++;
if (item['id'] != null) {
devChildren.add({
"id": index.toString(),
"name": item['name'],
"parentId": "99999999999",
"type": "widget",
"display": "standard",
"author": item['author'],
"pageId": item['id']
});
}
});
list.forEach((item) {
if (item['name'].toString().toUpperCase() == 'DEVELOPER') {
List children = item['children'];
children.insert(0, {
"id": "99999999999",
"name": "本地代码",
"parentId": int.parse(item['id']),
"type": "category",
"children": devChildren
});
}
});
return list;
}
static CategoryComponent getCommonItemById(List<int> path, CategoryComponent root) { static CategoryComponent getCommonItemById(List<int> path, CategoryComponent root) {
print("getCommonItemByPath $path"); print("getCommonItemByPath $path");
print("root $root"); print("root $root");

View File

@ -1 +1 @@
[{"name":"demoName","screenShot":"","author":"yourName","email":"yourEmail","desc":"这是一个测试的标准demo","id":"1a29aa8e_32ae_4241_9c8a_5c9e1f92b096"}] [{"name":"demoName","screenShot":"","author":"yourName","email":"yourEmail","desc":"这是一个测试的标准demo","id":"1a29aa8e_32ae_4241_9c8a_5c9e1f92b096"},{"name":"local","screenShot":"","author":"ab","email":"email","desc":"ags","id":"2c1d57d0_42ae_4241_9c8a_5c9e1f92b096"}]

View File

@ -1,4 +1,6 @@
import 'demoName_yourName_1a29aa8e_32ae_4241_9c8a_5c9e1f92b096/index.dart' as StandardDemo_demoName_1a29aa8e_32ae_4241_9c8a_5c9e1f92b096; import 'demoName_yourName_1a29aa8e_32ae_4241_9c8a_5c9e1f92b096/index.dart' as StandardDemo_demoName_1a29aa8e_32ae_4241_9c8a_5c9e1f92b096;
import 'local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/index.dart' as StandardDemo_local_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096;
var demoObjects = { var demoObjects = {
'1a29aa8e_32ae_4241_9c8a_5c9e1f92b096': StandardDemo_demoName_1a29aa8e_32ae_4241_9c8a_5c9e1f92b096.demoWidgets '1a29aa8e_32ae_4241_9c8a_5c9e1f92b096': StandardDemo_demoName_1a29aa8e_32ae_4241_9c8a_5c9e1f92b096.demoWidgets,
'2c1d57d0_42ae_4241_9c8a_5c9e1f92b096': StandardDemo_local_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096.demoWidgets
}; };

View File

@ -0,0 +1,9 @@
{
"name": "local",
"screenShot": "",
"author":"ab",
"email": "email",
"desc": "ags",
"id": "2c1d57d0_42ae_4241_9c8a_5c9e1f92b096"
}

View File

@ -0,0 +1,15 @@
//
// Created with flutter go cli
// User: ab
// Time: 2019-08-06 17:26:02.905889
// email: email
// desc: ags
//
import 'src/index.dart';
var demoWidgets = [
new Demo()
];

View File

@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
class Demo extends StatefulWidget {
@override
_State createState() => _State();
}
class _State extends State<Demo> {
@override
Widget build(BuildContext context) {
return Container(
child: Text("this is flutter go init demo"),
);
}
}

View File

@ -1 +1 @@
[{"name":"standard","screenShot":"","author":"sanfan","title":"介绍页","email":"hanxu317@qq.com","desc":"desc","id":"ee4feb8e_32ae_4241_9c8a_5c9e1f92b096"}] [{"name":"local","screenShot":"","author":"hnaxu","title":"本地","email":"hanxu@qq.com","desc":"desc","id":"5d7178d0_42ae_4241_9c8a_5c9e1f92b096"},{"name":"test","screenShot":"","author":"abc","title":"ya","email":"adsf.com","desc":"desc","id":"84f38e00_42ae_4241_9c8a_5c9e1f92b096"},{"name":"standard","screenShot":"","author":"sanfan","title":"介绍页","email":"hanxu317@qq.com","desc":"desc","id":"ee4feb8e_32ae_4241_9c8a_5c9e1f92b096"}]

View File

@ -1,16 +1,26 @@
import 'local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/index.dart' as StandardPage_local_5d7178d0_42ae_4241_9c8a_5c9e1f92b096;
import 'test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/index.dart' as StandardPage_test_84f38e00_42ae_4241_9c8a_5c9e1f92b096;
import 'standard_sanfan_ee4feb8e_32ae_4241_9c8a_5c9e1f92b096/index.dart' as StandardPage_standard_ee4feb8e_32ae_4241_9c8a_5c9e1f92b096; import 'standard_sanfan_ee4feb8e_32ae_4241_9c8a_5c9e1f92b096/index.dart' as StandardPage_standard_ee4feb8e_32ae_4241_9c8a_5c9e1f92b096;
class StandardPages { class StandardPages {
Map<String, String> standardPages; Map<String, String> standardPages;
Map<String, String> getPages() { Map<String, String> getPages() {
return { return {
"0": "0" , "0": "0" ,
"5d7178d0_42ae_4241_9c8a_5c9e1f92b096" : StandardPage_local_5d7178d0_42ae_4241_9c8a_5c9e1f92b096.getMd()
,
"84f38e00_42ae_4241_9c8a_5c9e1f92b096" : StandardPage_test_84f38e00_42ae_4241_9c8a_5c9e1f92b096.getMd()
,
"ee4feb8e_32ae_4241_9c8a_5c9e1f92b096" : StandardPage_standard_ee4feb8e_32ae_4241_9c8a_5c9e1f92b096.getMd() "ee4feb8e_32ae_4241_9c8a_5c9e1f92b096" : StandardPage_standard_ee4feb8e_32ae_4241_9c8a_5c9e1f92b096.getMd()
}; };
} }
List<Map<String, String>> getLocalList() { List<Map<String, String>> getLocalList() {
return [ return [
{}, {},
{ "id": "5d7178d0_42ae_4241_9c8a_5c9e1f92b096", "name": "local", "email": "hanxu@qq.com", "author": "hnaxu"}
,
{ "id": "84f38e00_42ae_4241_9c8a_5c9e1f92b096", "name": "test", "email": "adsf.com", "author": "abc"}
,
{ "id": "ee4feb8e_32ae_4241_9c8a_5c9e1f92b096", "name": "standard", "email": "hanxu317@qq.com", "author": "sanfan"} { "id": "ee4feb8e_32ae_4241_9c8a_5c9e1f92b096", "name": "standard", "email": "hanxu317@qq.com", "author": "sanfan"}
]; ];
} }

View File

@ -0,0 +1,10 @@
{
"name": "local",
"screenShot": "",
"author":"hnaxu",
"title":"本地",
"email": "hanxu@qq.com",
"desc": "desc",
"id": "5d7178d0_42ae_4241_9c8a_5c9e1f92b096"
}

View File

@ -0,0 +1,52 @@
String getMd() {
return """
# 标准的详情页
您可以在这个界面中, 编写大多数的markdown文案, 他会在 **goCli watch** 下同步被编译成 **dart** 文件
您可以通过goCli创建详情页所需要的demo
```
goCLi createDemo
```
在flutter go 根文件下通过命令行输入以上命令可以进行以下操作
[✓] 请输入新增加的demo名称? demoName
[✓] 请输入您的姓名(使用英文) yourName
[✓] 请输入您的github的email地址 yourEmail
[✓] 请输入您demo的描述 这是一个测试的标准demo
在完成以上操作后, 可以得到这样的输出:
```
------------------
您新增的组件信息如下
==================
{
name : demoName
author : yourName
email : yourEmail
desc : 这是一个测试的标准demo
}
==================
[✓] Is this the config you want ? (Y/n) y
{
新建的demo文件位于 : /flutter go/lib/page_demo_package/demoName_yourName_1a29aa8e_32ae_4241_9c8a_5c9e1f92b096
demoId为 : 1a29aa8e_32ae_4241_9c8a_5c9e1f92b096
markdown中调用方式 : [demo:1a29aa8e_32ae_4241_9c8a_5c9e1f92b096]
}
```
您可以在任意详情页中, 通过以下方式调用
```
[demo: 1a29aa8e_32ae_4241_9c8a_5c9e1f92b096]
```""";
}

View File

@ -0,0 +1,48 @@
# 标准的详情页
您可以在这个界面中, 编写大多数的markdown文案, 他会在 **goCli watch** 下同步被编译成 **dart** 文件
您可以通过goCli创建详情页所需要的demo
```
goCLi createDemo
```
在flutter go 根文件下通过命令行输入以上命令可以进行以下操作
[✓] 请输入新增加的demo名称? demoName
[✓] 请输入您的姓名(使用英文) yourName
[✓] 请输入您的github的email地址 yourEmail
[✓] 请输入您demo的描述 这是一个测试的标准demo
在完成以上操作后, 可以得到这样的输出:
```
------------------
您新增的组件信息如下
==================
{
name : demoName
author : yourName
email : yourEmail
desc : 这是一个测试的标准demo
}
==================
[✓] Is this the config you want ? (Y/n) y
{
新建的demo文件位于 : /flutter go/lib/page_demo_package/demoName_yourName_1a29aa8e_32ae_4241_9c8a_5c9e1f92b096
demoId为 : 1a29aa8e_32ae_4241_9c8a_5c9e1f92b096
markdown中调用方式 : [demo:1a29aa8e_32ae_4241_9c8a_5c9e1f92b096]
}
```
您可以在任意详情页中, 通过以下方式调用
```
[demo: 1a29aa8e_32ae_4241_9c8a_5c9e1f92b096]
```

View File

@ -0,0 +1,10 @@
{
"name": "test",
"screenShot": "",
"author":"abc",
"title":"ya",
"email": "adsf.com",
"desc": "desc",
"id": "84f38e00_42ae_4241_9c8a_5c9e1f92b096"
}

View File

@ -0,0 +1,52 @@
String getMd() {
return """
# 标准的详情页
您可以在这个界面中, 编写大多数的markdown文案, 他会在 **goCli watch** 下同步被编译成 **dart** 文件
您可以通过goCli创建详情页所需要的demo
```
goCLi createDemo
```
在flutter go 根文件下通过命令行输入以上命令可以进行以下操作
[✓] 请输入新增加的demo名称? demoName
[✓] 请输入您的姓名(使用英文) yourName
[✓] 请输入您的github的email地址 yourEmail
[✓] 请输入您demo的描述 这是一个测试的标准demo
在完成以上操作后, 可以得到这样的输出:
```
------------------
您新增的组件信息如下
==================
{
name : demoName
author : yourName
email : yourEmail
desc : 这是一个测试的标准demo
}
==================
[✓] Is this the config you want ? (Y/n) y
{
新建的demo文件位于 : /flutter go/lib/page_demo_package/demoName_yourName_1a29aa8e_32ae_4241_9c8a_5c9e1f92b096
demoId为 : 1a29aa8e_32ae_4241_9c8a_5c9e1f92b096
markdown中调用方式 : [demo:1a29aa8e_32ae_4241_9c8a_5c9e1f92b096]
}
```
您可以在任意详情页中, 通过以下方式调用
```
[demo: 1a29aa8e_32ae_4241_9c8a_5c9e1f92b096]
```""";
}

View File

@ -0,0 +1,48 @@
# 标准的详情页
您可以在这个界面中, 编写大多数的markdown文案, 他会在 **goCli watch** 下同步被编译成 **dart** 文件
您可以通过goCli创建详情页所需要的demo
```
goCLi createDemo
```
在flutter go 根文件下通过命令行输入以上命令可以进行以下操作
[✓] 请输入新增加的demo名称? demoName
[✓] 请输入您的姓名(使用英文) yourName
[✓] 请输入您的github的email地址 yourEmail
[✓] 请输入您demo的描述 这是一个测试的标准demo
在完成以上操作后, 可以得到这样的输出:
```
------------------
您新增的组件信息如下
==================
{
name : demoName
author : yourName
email : yourEmail
desc : 这是一个测试的标准demo
}
==================
[✓] Is this the config you want ? (Y/n) y
{
新建的demo文件位于 : /flutter go/lib/page_demo_package/demoName_yourName_1a29aa8e_32ae_4241_9c8a_5c9e1f92b096
demoId为 : 1a29aa8e_32ae_4241_9c8a_5c9e1f92b096
markdown中调用方式 : [demo:1a29aa8e_32ae_4241_9c8a_5c9e1f92b096]
}
```
您可以在任意详情页中, 通过以下方式调用
```
[demo: 1a29aa8e_32ae_4241_9c8a_5c9e1f92b096]
```

View File

@ -15,6 +15,13 @@ import '../../components/flutter_markdown/lib/flutter_markdown.dart';
import '../../standard_pages/index.dart'; import '../../standard_pages/index.dart';
import '../../page_demo_package/index.dart'; import '../../page_demo_package/index.dart';
import 'package:flutter_go/routers/application.dart'; import 'package:flutter_go/routers/application.dart';
import 'package:flutter_go/utils/net_utils.dart';
import 'package:flutter_go/components/loading.dart';
const githubUrl = 'https://raw.githubusercontent.com/alibaba/flutter-go/beta/lib/standard_pages/';
const PagesUrl = 'https://raw.githubusercontent.com/alibaba/flutter-go/beta/lib/standard_pages/.pages.json';
const DemosUrl = 'https://raw.githubusercontent.com/alibaba/flutter-go/beta/lib/page_demo_package/.demo.json';
// ONLINE || LOCAL // ONLINE || LOCAL
ENV env = Application.env; ENV env = Application.env;
@ -29,9 +36,9 @@ class StandardView extends StatefulWidget {
class _StandardView extends State<StandardView> { class _StandardView extends State<StandardView> {
String markdownDesc = '# this is header'; String markdownDesc = '';
String pageTitle = "XXX"; String pageTitle = '';
bool isLoading = false;
String author = ''; String author = '';
String email = ''; String email = '';
StandardPages standardPage = new StandardPages(); StandardPages standardPage = new StandardPages();
@ -39,13 +46,15 @@ class _StandardView extends State<StandardView> {
void initState() { void initState() {
super.initState(); super.initState();
this.getDetail(); this.getPageInfo();
} }
// 本地调用的获取基本信息
Future<void> getPagesInfo() async { /// 本地调用的获取文章属性的基本信息
Future<void> localGetPagesAttrsInfo() async {
String jsonString = await DefaultAssetBundle.of(context).loadString('lib/standard_pages/.pages.json'); String jsonString = await DefaultAssetBundle.of(context).loadString('lib/standard_pages/.pages.json');
List jsonList = json.decode(jsonString); List jsonList = json.decode(jsonString);
Map<String, dynamic> pageDetail = jsonList.firstWhere((item) => item['id'] == widget.id); Map<String, dynamic> pageDetail = jsonList.firstWhere((item) => item['id'] == widget.id);
if (pageDetail != null) { if (pageDetail != null) {
setState(() { setState(() {
pageTitle = pageDetail['title'] ?? '请加入title'; pageTitle = pageDetail['title'] ?? '请加入title';
@ -56,44 +65,85 @@ class _StandardView extends State<StandardView> {
} }
/// 从本地获取基本文章信息
String _getContentFromLocal() { String localGetPagesMarkdown() {
String pageId = widget.id; String pageId = widget.id;
Map<String, String> pagesList = standardPage.getPages(); Map<String, String> pagesList = standardPage.getPages();
return pagesList[pageId]; return pagesList[pageId];
} }
Future<String> _getContentOnline() async { Future<String> getContentOnline() async {
String content = 'online content'; String content = 'online content';
this.setState(() {
isLoading = true;
});
return Future(() => content); List response = jsonDecode(await NetUtils.get(PagesUrl));
Map targetPage = response.firstWhere((page) => page['id'] == widget.id);
if (targetPage == null) {
setState(() {
isLoading = false;
});
return Future(() => '未获取界面相当信息');
}
setState(() {
pageTitle = targetPage['title'] ?? 'xxx';
author = targetPage['author'];
email = targetPage['email'];
});
String pageName = targetPage['name'] + "_" +targetPage['author']+ "_" +targetPage['id'];
String pageContent = await NetUtils.get(githubUrl + pageName + "/index.md");
setState(() {
isLoading = false;
});
return Future(() => pageContent);
} }
/// 获取当面界面的相关信息. 需要区分环境
Future<String> getDetail() async { /// 本地环境下, 从本地获取 standard_pages的目录中互殴
/// 线上环境. 从github的api中获取
Future<String> getPageInfo() async {
String conent = ''; String conent = '';
print("env:::: $env"); print("env:::: $env");
if (env == ENV.PRODUCTION) { if (env == ENV.PRODUCTION) {
conent = await _getContentOnline(); conent = await getContentOnline();
} else { } else {
getPagesInfo(); conent = localGetPagesMarkdown();
conent = _getContentFromLocal(); localGetPagesAttrsInfo();
} }
setState(() { setState(() {
markdownDesc = conent; markdownDesc = conent;
}); });
return Future(() => conent); return Future(() => conent);
// this.rebuild(); }
Widget buildFootInfo() {
if (!isLoading) {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('创建者: $author'),
Text('邮箱: $email'),
Text('界面id: ${widget.id}')
],
),
);
}
return Container();
} }
Widget buildMarkdown() { Widget buildMarkdown() {
Map<String, String> contentList = new StandardPages().getPages();
if (contentList[widget.id] == null) {
contentList[widget.id] = ''; if (markdownDesc == null) {
return null;
} }
return MarkdownBody( return MarkdownBody(
data: contentList[widget.id], data: markdownDesc,
syntaxHighlighter:new mdCopy.HighLight(), syntaxHighlighter:new mdCopy.HighLight(),
demoBuilder: (Map<String, dynamic> attrs) { demoBuilder: (Map<String, dynamic> attrs) {
List<Widget> demo = demoObjects[attrs['id']]; List<Widget> demo = demoObjects[attrs['id']];
@ -111,19 +161,24 @@ class _StandardView extends State<StandardView> {
} }
); );
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new WidgetDemo( return new WidgetDemo(
title: pageTitle, title: pageTitle,
codeUrl: 'elements/Form/Button/DropdownButton/demo.dart', // codeUrl: 'elements/Form/Button/DropdownButton/demo.dart',
contentList: [ contentList: [
NetLoadingDialog(
loading: isLoading,
outsideDismiss: false,
),
buildMarkdown(), buildMarkdown(),
SizedBox(height: 30), SizedBox(height: 30),
'创建者: $author', buildFootInfo(),
'创建者: $email', SizedBox(height: 30)
'id: ${widget.id}',
], ],
docUrl: 'https://docs.flutter.io/flutter/material/DropdownButton-class.html',
); );
} }
} }

View File

@ -42,7 +42,6 @@ class SecondPageState extends State<WidgetPage> with AutomaticKeepAliveClientMix
Widget buildGrid() { Widget buildGrid() {
// 存放最后的widget // 存放最后的widget
List<Widget> tiles = []; List<Widget> tiles = [];
print("Application.widgetTree>>> ${Application.widgetTree}");
Application.widgetTree.children.forEach((dynamic item) { Application.widgetTree.children.forEach((dynamic item) {
tiles.add(new CateCard(category: item)); tiles.add(new CateCard(category: item));
}); });
@ -54,7 +53,6 @@ class SecondPageState extends State<WidgetPage> with AutomaticKeepAliveClientMix
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context); super.build(context);
print("build in widget page");
return Container( return Container(
color: Theme.of(context).backgroundColor, color: Theme.of(context).backgroundColor,
child: this.buildGrid(), child: this.buildGrid(),

View File

@ -21,7 +21,7 @@ dependencies:
cupertino_icons: ^0.1.2 cupertino_icons: ^0.1.2
event_bus: ^1.0.1 event_bus: ^1.0.1
fluro: ^1.3.4 fluro: ^1.3.4
image_picker: ^0.5.0 image_picker: ^0.6.0
sqflite: ^1.1.5 sqflite: ^1.1.5
url_launcher: ^5.0.2 url_launcher: ^5.0.2
# 本地存储、收藏功能 # 本地存储、收藏功能