From 69153e3256f74145fdfe44b2e5aad398927dfc79 Mon Sep 17 00:00:00 2001 From: "sanfan.hx" Date: Thu, 11 Jul 2019 16:37:39 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E8=BF=81=E7=A7=BB=E6=96=B0=E8=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E4=B8=8E=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file.js | 0 go-cli/config.json | 3 +- lib/components/widget_demo.dart | 30 ++++++------ lib/components/widget_item_container.dart | 46 ++++++++++++++++++- lib/model/collection.dart | 16 +++++-- lib/resources/widget_name_to_icon.dart | 2 + .../collection_page/collection_page.dart | 4 +- lib/views/web_page/web_view_page.dart | 28 +++++------ test.dart | 4 -- 9 files changed, 93 insertions(+), 40 deletions(-) delete mode 100644 file.js delete mode 100644 test.dart diff --git a/file.js b/file.js deleted file mode 100644 index e69de29b..00000000 diff --git a/go-cli/config.json b/go-cli/config.json index cee578dd..7490ec4d 100644 --- a/go-cli/config.json +++ b/go-cli/config.json @@ -1,4 +1,3 @@ { - "name": "sanfan", - + "name": "sanfan" } \ No newline at end of file diff --git a/lib/components/widget_demo.dart b/lib/components/widget_demo.dart index bbce9f51..bc52f498 100644 --- a/lib/components/widget_demo.dart +++ b/lib/components/widget_demo.dart @@ -64,25 +64,29 @@ class _WidgetDemoState extends State { @override void initState() { super.initState(); - _collectionControl.getRouterByName(widget.title).then((list) { - widgetDemosList.forEach((item) { - if (item.name == widget.title) { - _router = item.routerName; + // 这里不能直接 使用 ` ModalRoute.of(context)` 会产生报错 + Future.delayed(Duration.zero,() { + String currentPath = ModalRoute.of(context).settings.name; + _collectionControl.getRouterByUrl(currentPath).then((list) { + if (this.mounted) { + setState(() { + _hasCollected = list.length > 0; + }); } }); - if (this.mounted) { - setState(() { - _hasCollected = list.length > 0; - }); - } }); + } + // 点击收藏按钮 _getCollection() { + + String currentRouterPath = ModalRoute.of(context).settings.name; + if (_hasCollected) { // 删除操作 - _collectionControl.deleteByName(widget.title).then((result) { + _collectionControl.deleteByPath(currentRouterPath).then((result) { if (result > 0 && this.mounted) { setState(() { _hasCollected = false; @@ -91,7 +95,7 @@ class _WidgetDemoState extends State { .showSnackBar(SnackBar(content: Text('已取消收藏'))); if (ApplicationEvent.event != null) { ApplicationEvent.event - .fire(CollectionEvent(widget.title, _router, true)); + .fire(CollectionEvent(widget.title, currentRouterPath, true)); } return; } @@ -100,7 +104,7 @@ class _WidgetDemoState extends State { } else { // 插入操作 _collectionControl - .insert(Collection(name: widget.title, router: _router)) + .insert(Collection(name: widget.title, router: currentRouterPath)) .then((result) { if (this.mounted) { setState(() { @@ -109,7 +113,7 @@ class _WidgetDemoState extends State { if (ApplicationEvent.event != null) { ApplicationEvent.event - .fire(CollectionEvent(widget.title, _router, false)); + .fire(CollectionEvent(widget.title, currentRouterPath, false)); } _scaffoldKey.currentState diff --git a/lib/components/widget_item_container.dart b/lib/components/widget_item_container.dart index db0fa35c..5aa8b0cf 100644 --- a/lib/components/widget_item_container.dart +++ b/lib/components/widget_item_container.dart @@ -21,6 +21,31 @@ class WidgetItemContainer extends StatelessWidget { }) : super(key: key); + /// 跳转goup + void tapToGroup(CategoryComponent cate, BuildContext context) { + Application.router + .navigateTo(context, "/category/${cate.token}", transition: TransitionType.inFromRight); + } + + /// 跳转到老的widget界面 + void tapToOldWidget(WidgetLeaf leaf, BuildContext context) { + + String targetName = leaf.name; + String targetRouter = '/category/error/404'; + widgetDemosList.forEach((item) { + if (item.name == targetName) { + targetRouter = item.routerName; + } + }); + Application.router.navigateTo(context, targetRouter, transition: TransitionType.inFromRight); + } + + /// 跳转到新的标准页 + void tapToStandardPage(WidgetLeaf leaf, BuildContext context) { + String targetRouter = '/standard-page/${leaf.pageId}'; + Application.router.navigateTo(context, targetRouter, transition: TransitionType.inFromRight); + } + List _buildColumns(context) { List _listWidget = []; List _listRows = []; @@ -31,13 +56,30 @@ class WidgetItemContainer extends StatelessWidget { addI = innerI + i; if (addI < length) { CommonItem item = commonItems[addI]; + + _listRows.add( Expanded( flex: 1, child: WidgetItem( title: item.name, onTap: () { - if (item.type == 'widget') { + String type = item.type; + print("type>>>>$type"); + if (type == "category") { + return tapToGroup(item as CategoryComponent, context); + } + if (type == "widget") { + WidgetLeaf leaf = item as WidgetLeaf; + + if (leaf.display == "standard") { + return tapToStandardPage(leaf, context); + } else { + return tapToOldWidget(leaf, context); + } + } +// print("display $display"); + if (type == 'widget') { WidgetLeaf _item = item; String targetName = _item.name; String targetRouter = '/category/error/404'; @@ -48,7 +90,6 @@ class WidgetItemContainer extends StatelessWidget { }); print("targetRouter>>> $targetRouter"); - return Application.router.navigateTo(context, targetRouter, transition: TransitionType.inFromRight); } Application.router .navigateTo(context, "/category/${item.token}", transition: TransitionType.inFromRight); @@ -85,3 +126,4 @@ class WidgetItemContainer extends StatelessWidget { ); } } + diff --git a/lib/model/collection.dart b/lib/model/collection.dart index d0fb4901..49233bbe 100644 --- a/lib/model/collection.dart +++ b/lib/model/collection.dart @@ -55,9 +55,15 @@ class CollectionControlModel { return resultList; } - // 通过收藏名获取router - Future getRouterByName(String name) async { - List list = await sql.getByCondition(conditions: {'name': name}); + /// 通过收藏名获取router + /// 因为名称很容易重复. 所以这里使用path router做唯一判断 +// Future getRouterByName(String name) async { +// List list = await sql.getByCondition(conditions: {'name': name}); +// return list; +// } + + Future getRouterByUrl(String path) async { + List list = await sql.getByCondition(conditions: {'router': path}); return list; } @@ -65,4 +71,8 @@ class CollectionControlModel { Future deleteByName(String name) async{ return await sql.delete(name,'name'); } + // 通过path删除 + Future deleteByPath(String path) async{ + return await sql.delete(path,'router'); + } } diff --git a/lib/resources/widget_name_to_icon.dart b/lib/resources/widget_name_to_icon.dart index 0157a3e3..82f2593f 100644 --- a/lib/resources/widget_name_to_icon.dart +++ b/lib/resources/widget_name_to_icon.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; class WidgetName2Icon { static Map icons = { + "Developer": Icons.developer_mode, + "Standard": Icons.pages , "Element":Icons.explicit, "Components":Icons.extension, "Theme":Icons.filter_b_and_w, diff --git a/lib/views/collection_page/collection_page.dart b/lib/views/collection_page/collection_page.dart index bb2389ba..df3bf17f 100644 --- a/lib/views/collection_page/collection_page.dart +++ b/lib/views/collection_page/collection_page.dart @@ -48,7 +48,6 @@ class _CollectionPageState extends State { resultList.forEach((item) { _collectionList.add(item); }); - _collectionList.add(Collection(name:'test', router: '/standard-page/ee4feb8e_32ae_4241_9c8a_5c9e1f92b096')); print("_collectionList ${_collectionList}"); if (this.mounted) { setState(() { @@ -107,7 +106,8 @@ class _CollectionPageState extends State { color: Theme.of(context).primaryColor, ), title: Text( - Uri.decodeComponent(_collectionList[index - 1].name), + _collectionList[index - 1].name, +// Uri.decodeComponent(_collectionList[index - 1].name), overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 17.0), ), diff --git a/lib/views/web_page/web_view_page.dart b/lib/views/web_page/web_view_page.dart index df3793a5..83693522 100644 --- a/lib/views/web_page/web_view_page.dart +++ b/lib/views/web_page/web_view_page.dart @@ -30,20 +30,20 @@ class _WebViewPageState extends State { @override void initState() { super.initState(); - _collectionControl - .getRouterByName(Uri.encodeComponent(widget.title.trim())) - .then((list) { - list.forEach((item) { - if (widget.title.trim() == item['name']) { - _router = item['router']; - } - }); - if (mounted) { - setState(() { - _hasCollected = list.length > 0; - }); - } - }); +// _collectionControl +// .getRouterByName(Uri.encodeComponent(widget.title.trim())) +// .then((list) { +// list.forEach((item) { +// if (widget.title.trim() == item['name']) { +// _router = item['router']; +// } +// }); +// if (mounted) { +// setState(() { +// _hasCollected = list.length > 0; +// }); +// } +// }); } // 点击收藏按钮 diff --git a/test.dart b/test.dart deleted file mode 100644 index 167694b9..00000000 --- a/test.dart +++ /dev/null @@ -1,4 +0,0 @@ -List a = [1,2,3,4]; -main() { - print( a.firstWhere((int item) => item == 5 ,orElse: () => null)); -} \ No newline at end of file