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

@ -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,
@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<WidgetDemo> {
'${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
Widget build(BuildContext context) {
if (_hasCollected) {
@ -142,50 +173,34 @@ class _WidgetDemoState extends State<WidgetDemo> {
} else {
_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(
key: _scaffoldKey,
appBar: AppBar(
title: Text(widget.title),
actions: <Widget>[
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'),
),
),
],
),
],
actions: actions,
),
body: Container(
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: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());
}

View File

@ -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<List> mainList() async{
List listJson = await sql.getByCondition(conditions: {'parentId': 0});
List<Cat> cats = listJson.map((json) {
return new Cat.fromJSON(json);
}).toList();
return cats;
}
// 获取Cat不同深度与parent的列表
Future<List<Cat>> 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<Cat> cats = listJson.map((json) {
return new Cat.fromJSON(json);
}).toList();
return cats;
}
// 通过name获取Cat对象信息
Future<Cat> 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<List> mainList() async{
// List listJson = await sql.getByCondition(conditions: {'parentId': 0});
// List<Cat> cats = listJson.map((json) {
// return new Cat.fromJSON(json);
// }).toList();
// return cats;
// }
//
// // 获取Cat不同深度与parent的列表
// Future<List<Cat>> 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<Cat> cats = listJson.map((json) {
// return new Cat.fromJSON(json);
// }).toList();
// return cats;
// }
//
// // 通过name获取Cat对象信息
// Future<Cat> getCatByName(String name) async {
// List json = await sql.getByCondition(conditions: {'name': name});
// if (json.isEmpty) {
// return null;
// }
// return new Cat.fromJSON(json.first);
// }
//
//}

View File

@ -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<int> path, CategoryComponent root) {
print("getCommonItemByPath $path");
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 '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
};

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;
class StandardPages {
Map<String, String> standardPages;
Map<String, String> 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<Map<String, String>> 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"}
];
}

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 '../../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<StandardView> {
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<StandardView> {
void 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');
List jsonList = json.decode(jsonString);
Map<String, dynamic> pageDetail = jsonList.firstWhere((item) => item['id'] == widget.id);
if (pageDetail != null) {
setState(() {
pageTitle = pageDetail['title'] ?? '请加入title';
@ -56,44 +65,85 @@ class _StandardView extends State<StandardView> {
}
String _getContentFromLocal() {
/// 从本地获取基本文章信息
String localGetPagesMarkdown() {
String pageId = widget.id;
Map<String, String> pagesList = standardPage.getPages();
return pagesList[pageId];
}
Future<String> _getContentOnline() async {
Future<String> 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<String> getDetail() async {
/// 获取当面界面的相关信息. 需要区分环境
/// 本地环境下, 从本地获取 standard_pages的目录中互殴
/// 线上环境. 从github的api中获取
Future<String> 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: <Widget>[
Text('创建者: $author'),
Text('邮箱: $email'),
Text('界面id: ${widget.id}')
],
),
);
}
return Container();
}
Widget buildMarkdown() {
Map<String, String> 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<String, dynamic> attrs) {
List<Widget> demo = demoObjects[attrs['id']];
@ -111,19 +161,24 @@ class _StandardView extends State<StandardView> {
}
);
}
@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',
);
}
}

View File

@ -42,7 +42,6 @@ class SecondPageState extends State<WidgetPage> with AutomaticKeepAliveClientMix
Widget buildGrid() {
// 存放最后的widget
List<Widget> 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<WidgetPage> 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(),