mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-05-17 12:55:57 +08:00
update: 迁移新老数据结构与收藏
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
{
|
||||
"name": "sanfan",
|
||||
|
||||
"name": "sanfan"
|
||||
}
|
@ -64,25 +64,29 @@ class _WidgetDemoState extends State<WidgetDemo> {
|
||||
@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<WidgetDemo> {
|
||||
.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<WidgetDemo> {
|
||||
} 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<WidgetDemo> {
|
||||
|
||||
if (ApplicationEvent.event != null) {
|
||||
ApplicationEvent.event
|
||||
.fire(CollectionEvent(widget.title, _router, false));
|
||||
.fire(CollectionEvent(widget.title, currentRouterPath, false));
|
||||
}
|
||||
|
||||
_scaffoldKey.currentState
|
||||
|
@ -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<Widget> _buildColumns(context) {
|
||||
List<Widget> _listWidget = [];
|
||||
List<Widget> _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 {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
class WidgetName2Icon {
|
||||
static Map<String,dynamic> icons = {
|
||||
"Developer": Icons.developer_mode,
|
||||
"Standard": Icons.pages ,
|
||||
"Element":Icons.explicit,
|
||||
"Components":Icons.extension,
|
||||
"Theme":Icons.filter_b_and_w,
|
||||
|
@ -48,7 +48,6 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
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<CollectionPage> {
|
||||
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),
|
||||
),
|
||||
|
@ -30,20 +30,20 @@ class _WebViewPageState extends State<WebViewPage> {
|
||||
@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;
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
// 点击收藏按钮
|
||||
|
Reference in New Issue
Block a user