From 8f835fec3ad8f9d9f95047f2024cecc8d145325c Mon Sep 17 00:00:00 2001 From: "sanfan.hx" Date: Wed, 7 Aug 2019 14:33:40 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E5=AE=8C=E6=88=90markdown=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go-cli/src/build/build_page_list.dart | 6 +- go-cli/src/cli_command_runder.dart | 1 + lib/components/loading.dart | 94 ++++++++ lib/components/widget_demo.dart | 101 +++++---- lib/main.dart | 11 +- lib/model/cat.dart | 214 +++++++++--------- lib/model/widget.dart | 39 +++- lib/page_demo_package/.demo.json | 2 +- lib/page_demo_package/index.dart | 4 +- .../.demo.json | 9 + .../index.dart | 15 ++ .../src/index.dart | 16 ++ lib/standard_pages/.pages.json | 2 +- lib/standard_pages/index.dart | 10 + .../.page.json | 10 + .../index.dart | 52 +++++ .../index.md | 48 ++++ .../.page.json | 10 + .../index.dart | 52 +++++ .../index.md | 48 ++++ lib/views/standard_demo_page/index.dart | 105 +++++++-- lib/views/widget_page/widget_page.dart | 2 - pubspec.yaml | 2 +- 23 files changed, 660 insertions(+), 193 deletions(-) create mode 100644 lib/components/loading.dart create mode 100644 lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/.demo.json create mode 100644 lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/index.dart create mode 100644 lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/src/index.dart create mode 100644 lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/.page.json create mode 100644 lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/index.dart create mode 100644 lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/index.md create mode 100644 lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/.page.json create mode 100644 lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/index.dart create mode 100644 lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/index.md diff --git a/go-cli/src/build/build_page_list.dart b/go-cli/src/build/build_page_list.dart index 1b89413a..a8757444 100644 --- a/go-cli/src/build/build_page_list.dart +++ b/go-cli/src/build/build_page_list.dart @@ -96,18 +96,14 @@ class StandardPages { var template = new Template(source, name: 'template-filename.html'); -// print(prettyJson(data[0])); // 自定义前缀 避免出现数字非法字符等 - String pre = "StandardPage"; Map formatData = { "pages": data }; - var output = template.renderString(formatData); - print(output); + String output = template.renderString(formatData); -// } return output; } diff --git a/go-cli/src/cli_command_runder.dart b/go-cli/src/cli_command_runder.dart index 76105449..d9581573 100644 --- a/go-cli/src/cli_command_runder.dart +++ b/go-cli/src/cli_command_runder.dart @@ -18,6 +18,7 @@ class _CommandRunner extends CommandRunner { negatable: false, help: 'Prints the version of goCi.'); addCommand(CreateDemoCommand()); addCommand(CreatePageCommand()); + addCommand(WatchCommand()); addCommand(Build()); } diff --git a/lib/components/loading.dart b/lib/components/loading.dart new file mode 100644 index 00000000..659b2ff8 --- /dev/null +++ b/lib/components/loading.dart @@ -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 requestCallBack; + + NetLoadingDialog( + {Key key, + this.loadingText = "loading...", + this.outsideDismiss = true, + this.dismissCallback, + this.loading, + this.requestCallBack}) + : super(key: key); + + @override + State createState() => _LoadingDialog(); +} + +class _LoadingDialog extends State { + _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: [ + new CircularProgressIndicator(), + new Padding( + padding: const EdgeInsets.only( + top: 20.0, + ), + child: new Text( + widget.loadingText, + style: new TextStyle(fontSize: 12.0), + ), + ), + ], + ), + ), + ), + ), + ), + ); + } +} diff --git a/lib/components/widget_demo.dart b/lib/components/widget_demo.dart index 045c3620..d2ef6ddf 100644 --- a/lib/components/widget_demo.dart +++ b/lib/components/widget_demo.dart @@ -24,8 +24,8 @@ class WidgetDemo extends StatefulWidget { {Key key, @required this.title, @required this.contentList, - @required this.codeUrl, - @required this.docUrl, + this.codeUrl, + this.docUrl, this.bottomNaviBar}) : super(key: key); @@ -134,7 +134,38 @@ class _WidgetDemoState extends State { '${Routes.codeView}?filePath=${Uri.encodeComponent(widget.codeUrl)}'); } } - + List> buildPopupMenu() { + List> comps = []; + if (widget.docUrl != null) { + comps.add( + PopupMenuItem( + value: 'doc', + child: ListTile( + leading: Icon( + Icons.library_books, + size: 22.0, + ), + title: Text('查看文档'), + ), + ) + ); + } + if (widget.codeUrl != null) { + comps.add( + PopupMenuItem( + value: 'code', + child: ListTile( + leading: Icon( + Icons.code, + size: 22.0, + ), + title: Text('查看Demo'), + ), + ) + ); + } + return comps; + } @override Widget build(BuildContext context) { if (_hasCollected) { @@ -142,50 +173,34 @@ class _WidgetDemoState extends State { } else { _collectionIcons = Icons.favorite_border; } + List> menus = buildPopupMenu(); + List 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( + onSelected: _selectValue, + itemBuilder: (BuildContext context) => menus, + ) + ); + } return Scaffold( key: _scaffoldKey, appBar: AppBar( title: Text(widget.title), - 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( - onSelected: _selectValue, - itemBuilder: (BuildContext context) => >[ - const PopupMenuItem( - value: 'doc', - child: ListTile( - leading: Icon( - Icons.library_books, - size: 22.0, - ), - title: Text('查看文档'), - ), - ), - const PopupMenuDivider(), - const PopupMenuItem( - value: 'code', - child: ListTile( - leading: Icon( - Icons.code, - size: 22.0, - ), - title: Text('查看Demo'), - ), - ), - ], - ), - ], + actions: actions, ), body: Container( padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0), diff --git a/lib/main.dart b/lib/main.dart index d1cc0eb2..52082f22 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,7 +17,7 @@ import 'package:flutter_go/event/event_bus.dart'; import 'package:flutter_go/event/event_model.dart'; import 'package:event_bus/event_bus.dart'; import 'package:flutter_go/model/widget.dart'; - +import 'package:flutter_go/standard_pages/index.dart'; //import 'views/welcome_page/index.dart'; SpUtil sp; @@ -28,7 +28,6 @@ class MyApp extends StatefulWidget { final router = new Router(); Routes.configureRoutes(router); // 这里设置项目环境 - Application.env = ENV.PRODUCTION; Application.router = router; } @@ -189,13 +188,13 @@ void main() async { await provider.init(true); sp = await SpUtil.getInstance(); 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}"); }); db = Provider.db; runApp(new MyApp()); } + diff --git a/lib/model/cat.dart b/lib/model/cat.dart index e9ecae7b..5ac493f4 100644 --- a/lib/model/cat.dart +++ b/lib/model/cat.dart @@ -1,107 +1,107 @@ - -import 'dart:async'; - -import 'package:flutter_go/utils/sql.dart'; - -abstract class CatInterface{ - int get id; - //类目名称 - String get name; - //描述 - String get desc; - //第几级类目,默认 1 - int get depth; - //父类目id,没有为 0 - int get parentId; -} - -class Cat implements CatInterface { - int id; - String name; - String desc; - int depth; - int parentId; - - Cat({this.id, this.name, this.desc, this.depth, this.parentId}); - - Cat.fromJSON(Map json) - : id = json['id'], - name = json['name'], - desc = json['desc'], - depth = json['depth'], - parentId = json['parentId']; - - String toString() { - return '(Cat $name)'; - } - - Map toMap() { - return { - 'id': id, - 'name': name, - 'desc': desc, - 'depth': depth, - 'parentId': parentId - }; - } - Map toSqlCondition() { - Map _map = this.toMap(); - Map condition = {}; - _map.forEach((k, value) { - - if (value != null) { - - condition[k] = value; - } - }); - - if (condition.isEmpty) { - return {}; - } - - return condition; - } -} - - -class CatControlModel{ - final String table = 'cat'; - Sql sql; - CatControlModel() { - sql = Sql.setTable(table); - } - - /// 获取一级类目 - Future mainList() async{ - List listJson = await sql.getByCondition(conditions: {'parentId': 0}); - List cats = listJson.map((json) { - return new Cat.fromJSON(json); - }).toList(); - return cats; - } - - // 获取Cat不同深度与parent的列表 - Future> getList([Cat cat]) async{ - - - if (cat == null) { - cat = new Cat(depth: 1, parentId: 0); - } - // print("cat in getList ${cat.toMap()}"); - List listJson = await sql.getByCondition(conditions: cat.toSqlCondition()); - List cats = listJson.map((json) { - return new Cat.fromJSON(json); - }).toList(); - return cats; - } - - // 通过name获取Cat对象信息 - Future getCatByName(String name) async { - List json = await sql.getByCondition(conditions: {'name': name}); - if (json.isEmpty) { - return null; - } - return new Cat.fromJSON(json.first); - } - -} +// +//import 'dart:async'; +// +//import 'package:flutter_go/utils/sql.dart'; +// +//abstract class CatInterface{ +// int get id; +// //类目名称 +// String get name; +// //描述 +// String get desc; +// //第几级类目,默认 1 +// int get depth; +// //父类目id,没有为 0 +// int get parentId; +//} +// +//class Cat implements CatInterface { +// int id; +// String name; +// String desc; +// int depth; +// int parentId; +// +// Cat({this.id, this.name, this.desc, this.depth, this.parentId}); +// +// Cat.fromJSON(Map json) +// : id = json['id'], +// name = json['name'], +// desc = json['desc'], +// depth = json['depth'], +// parentId = json['parentId']; +// +// String toString() { +// return '(Cat $name)'; +// } +// +// Map toMap() { +// return { +// 'id': id, +// 'name': name, +// 'desc': desc, +// 'depth': depth, +// 'parentId': parentId +// }; +// } +// Map toSqlCondition() { +// Map _map = this.toMap(); +// Map condition = {}; +// _map.forEach((k, value) { +// +// if (value != null) { +// +// condition[k] = value; +// } +// }); +// +// if (condition.isEmpty) { +// return {}; +// } +// +// return condition; +// } +//} +// +// +//class CatControlModel{ +// final String table = 'cat'; +// Sql sql; +// CatControlModel() { +// sql = Sql.setTable(table); +// } +// +// /// 获取一级类目 +// Future mainList() async{ +// List listJson = await sql.getByCondition(conditions: {'parentId': 0}); +// List cats = listJson.map((json) { +// return new Cat.fromJSON(json); +// }).toList(); +// return cats; +// } +// +// // 获取Cat不同深度与parent的列表 +// Future> getList([Cat cat]) async{ +// +// +// if (cat == null) { +// cat = new Cat(depth: 1, parentId: 0); +// } +// // print("cat in getList ${cat.toMap()}"); +// List listJson = await sql.getByCondition(conditions: cat.toSqlCondition()); +// List cats = listJson.map((json) { +// return new Cat.fromJSON(json); +// }).toList(); +// return cats; +// } +// +// // 通过name获取Cat对象信息 +// Future getCatByName(String name) async { +// List json = await sql.getByCondition(conditions: {'name': name}); +// if (json.isEmpty) { +// return null; +// } +// return new Cat.fromJSON(json.first); +// } +// +//} diff --git a/lib/model/widget.dart b/lib/model/widget.dart index 59605e86..8d8c243e 100644 --- a/lib/model/widget.dart +++ b/lib/model/widget.dart @@ -2,7 +2,7 @@ import 'dart:async'; import "package:flutter/material.dart"; - +import "package:flutter_go/routers/application.dart"; import 'package:flutter_go/utils/sql.dart'; enum treeNode { @@ -188,6 +188,7 @@ class CategoryComponent extends CommonItem { @required this.id, @required this.name, @required this.parentId, + this.type = 'categoryw', this.children, this.parent }); @@ -289,6 +290,7 @@ class WidgetLeaf extends CommonItem { } class WidgetTree { + // 构建树型结构 static CategoryComponent buildWidgetTree(List json, [parent]){ CategoryComponent current; if (parent != null) { @@ -312,6 +314,41 @@ class WidgetTree { }); 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 path, CategoryComponent root) { print("getCommonItemByPath $path"); print("root $root"); diff --git a/lib/page_demo_package/.demo.json b/lib/page_demo_package/.demo.json index 0e45bee1..1967c339 100644 --- a/lib/page_demo_package/.demo.json +++ b/lib/page_demo_package/.demo.json @@ -1 +1 @@ -[{"name":"demoName","screenShot":"","author":"yourName","email":"yourEmail","desc":"这是一个测试的标准demo","id":"1a29aa8e_32ae_4241_9c8a_5c9e1f92b096"}] \ No newline at end of file +[{"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"}] \ No newline at end of file diff --git a/lib/page_demo_package/index.dart b/lib/page_demo_package/index.dart index 3a4a6f72..1e6a4966 100644 --- a/lib/page_demo_package/index.dart +++ b/lib/page_demo_package/index.dart @@ -1,4 +1,6 @@ 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 = { - '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 }; \ No newline at end of file diff --git a/lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/.demo.json b/lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/.demo.json new file mode 100644 index 00000000..e6e8114d --- /dev/null +++ b/lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/.demo.json @@ -0,0 +1,9 @@ +{ + "name": "local", + "screenShot": "", + "author":"ab", + "email": "email", + "desc": "ags", + "id": "2c1d57d0_42ae_4241_9c8a_5c9e1f92b096" +} + \ No newline at end of file diff --git a/lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/index.dart b/lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/index.dart new file mode 100644 index 00000000..4e315373 --- /dev/null +++ b/lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/index.dart @@ -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() +]; + + \ No newline at end of file diff --git a/lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/src/index.dart b/lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/src/index.dart new file mode 100644 index 00000000..d0d3921e --- /dev/null +++ b/lib/page_demo_package/local_ab_2c1d57d0_42ae_4241_9c8a_5c9e1f92b096/src/index.dart @@ -0,0 +1,16 @@ +import 'package:flutter/material.dart'; + +class Demo extends StatefulWidget { + @override + _State createState() => _State(); +} + +class _State extends State { + @override + Widget build(BuildContext context) { + return Container( + child: Text("this is flutter go init demo"), + ); + } +} + \ No newline at end of file diff --git a/lib/standard_pages/.pages.json b/lib/standard_pages/.pages.json index ee0bce1f..18e4f686 100644 --- a/lib/standard_pages/.pages.json +++ b/lib/standard_pages/.pages.json @@ -1 +1 @@ -[{"name":"standard","screenShot":"","author":"sanfan","title":"介绍页","email":"hanxu317@qq.com","desc":"desc","id":"ee4feb8e_32ae_4241_9c8a_5c9e1f92b096"}] \ No newline at end of file +[{"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"}] \ No newline at end of file diff --git a/lib/standard_pages/index.dart b/lib/standard_pages/index.dart index bf6a71bd..eb5ac663 100644 --- a/lib/standard_pages/index.dart +++ b/lib/standard_pages/index.dart @@ -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; class StandardPages { Map standardPages; Map getPages() { return { "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() }; } List> getLocalList() { 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"} ]; } diff --git a/lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/.page.json b/lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/.page.json new file mode 100644 index 00000000..d6a9e3d0 --- /dev/null +++ b/lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/.page.json @@ -0,0 +1,10 @@ +{ + "name": "local", + "screenShot": "", + "author":"hnaxu", + "title":"本地", + "email": "hanxu@qq.com", + "desc": "desc", + "id": "5d7178d0_42ae_4241_9c8a_5c9e1f92b096" +} + \ No newline at end of file diff --git a/lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/index.dart b/lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/index.dart new file mode 100644 index 00000000..6e506d10 --- /dev/null +++ b/lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/index.dart @@ -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] +```"""; + +} diff --git a/lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/index.md b/lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/index.md new file mode 100644 index 00000000..61a5f516 --- /dev/null +++ b/lib/standard_pages/local_hnaxu_5d7178d0_42ae_4241_9c8a_5c9e1f92b096/index.md @@ -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] +``` \ No newline at end of file diff --git a/lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/.page.json b/lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/.page.json new file mode 100644 index 00000000..297b026e --- /dev/null +++ b/lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/.page.json @@ -0,0 +1,10 @@ +{ + "name": "test", + "screenShot": "", + "author":"abc", + "title":"ya", + "email": "adsf.com", + "desc": "desc", + "id": "84f38e00_42ae_4241_9c8a_5c9e1f92b096" +} + \ No newline at end of file diff --git a/lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/index.dart b/lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/index.dart new file mode 100644 index 00000000..6e506d10 --- /dev/null +++ b/lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/index.dart @@ -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] +```"""; + +} diff --git a/lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/index.md b/lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/index.md new file mode 100644 index 00000000..61a5f516 --- /dev/null +++ b/lib/standard_pages/test_abc_84f38e00_42ae_4241_9c8a_5c9e1f92b096/index.md @@ -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] +``` \ No newline at end of file diff --git a/lib/views/standard_demo_page/index.dart b/lib/views/standard_demo_page/index.dart index 74b415a6..e2907513 100644 --- a/lib/views/standard_demo_page/index.dart +++ b/lib/views/standard_demo_page/index.dart @@ -15,6 +15,13 @@ import '../../components/flutter_markdown/lib/flutter_markdown.dart'; import '../../standard_pages/index.dart'; import '../../page_demo_package/index.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 ENV env = Application.env; @@ -29,9 +36,9 @@ class StandardView extends StatefulWidget { class _StandardView extends State { - String markdownDesc = '# this is header'; - String pageTitle = "XXX"; - + String markdownDesc = ''; + String pageTitle = ''; + bool isLoading = false; String author = ''; String email = ''; StandardPages standardPage = new StandardPages(); @@ -39,13 +46,15 @@ class _StandardView extends State { void initState() { super.initState(); - this.getDetail(); + this.getPageInfo(); } - // 本地调用的获取基本信息 - Future getPagesInfo() async { + + /// 本地调用的获取文章属性的基本信息 + Future localGetPagesAttrsInfo() async { String jsonString = await DefaultAssetBundle.of(context).loadString('lib/standard_pages/.pages.json'); List jsonList = json.decode(jsonString); Map pageDetail = jsonList.firstWhere((item) => item['id'] == widget.id); + if (pageDetail != null) { setState(() { pageTitle = pageDetail['title'] ?? '请加入title'; @@ -56,44 +65,85 @@ class _StandardView extends State { } - - String _getContentFromLocal() { + /// 从本地获取基本文章信息 + String localGetPagesMarkdown() { String pageId = widget.id; Map pagesList = standardPage.getPages(); return pagesList[pageId]; } - Future _getContentOnline() async { + Future getContentOnline() async { 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 getDetail() async { + /// 获取当面界面的相关信息. 需要区分环境 + /// 本地环境下, 从本地获取 standard_pages的目录中互殴 + /// 线上环境. 从github的api中获取 + Future getPageInfo() async { String conent = ''; print("env:::: $env"); if (env == ENV.PRODUCTION) { - conent = await _getContentOnline(); + conent = await getContentOnline(); } else { - getPagesInfo(); - conent = _getContentFromLocal(); + conent = localGetPagesMarkdown(); + localGetPagesAttrsInfo(); } setState(() { markdownDesc = conent; }); return Future(() => conent); -// this.rebuild(); + } + Widget buildFootInfo() { + if (!isLoading) { + return Container( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('创建者: $author'), + Text('邮箱: $email'), + Text('界面id: ${widget.id}') + ], + ), + ); + } + return Container(); } Widget buildMarkdown() { - Map contentList = new StandardPages().getPages(); - if (contentList[widget.id] == null) { - contentList[widget.id] = ''; + + if (markdownDesc == null) { + return null; } return MarkdownBody( - data: contentList[widget.id], + data: markdownDesc, syntaxHighlighter:new mdCopy.HighLight(), demoBuilder: (Map attrs) { List demo = demoObjects[attrs['id']]; @@ -111,19 +161,24 @@ class _StandardView extends State { } ); } + + + @override Widget build(BuildContext context) { return new WidgetDemo( title: pageTitle, - codeUrl: 'elements/Form/Button/DropdownButton/demo.dart', +// codeUrl: 'elements/Form/Button/DropdownButton/demo.dart', contentList: [ + NetLoadingDialog( + loading: isLoading, + outsideDismiss: false, + ), buildMarkdown(), SizedBox(height: 30), - '创建者: $author', - '创建者: $email', - 'id: ${widget.id}', + buildFootInfo(), + SizedBox(height: 30) ], - docUrl: 'https://docs.flutter.io/flutter/material/DropdownButton-class.html', ); } } \ No newline at end of file diff --git a/lib/views/widget_page/widget_page.dart b/lib/views/widget_page/widget_page.dart index 9e613ba3..5df042cb 100644 --- a/lib/views/widget_page/widget_page.dart +++ b/lib/views/widget_page/widget_page.dart @@ -42,7 +42,6 @@ class SecondPageState extends State with AutomaticKeepAliveClientMix Widget buildGrid() { // 存放最后的widget List tiles = []; - print("Application.widgetTree>>> ${Application.widgetTree}"); Application.widgetTree.children.forEach((dynamic item) { tiles.add(new CateCard(category: item)); }); @@ -54,7 +53,6 @@ class SecondPageState extends State with AutomaticKeepAliveClientMix @override Widget build(BuildContext context) { super.build(context); - print("build in widget page"); return Container( color: Theme.of(context).backgroundColor, child: this.buildGrid(), diff --git a/pubspec.yaml b/pubspec.yaml index b2cd154f..dfe43579 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: cupertino_icons: ^0.1.2 event_bus: ^1.0.1 fluro: ^1.3.4 - image_picker: ^0.5.0 + image_picker: ^0.6.0 sqflite: ^1.1.5 url_launcher: ^5.0.2 # 本地存储、收藏功能