mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-07-04 15:28:21 +08:00
个人中心、收藏、搜索
This commit is contained in:
@ -1,2 +1,3 @@
|
|||||||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
|
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
|
||||||
#include "Generated.xcconfig"
|
#include "Generated.xcconfig"
|
||||||
|
#include "../Pods/Target\ Support\ Files/Pods-Runner/Pods-Runner.debug.xcconfig"
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
|
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
|
||||||
#include "Generated.xcconfig"
|
#include "Generated.xcconfig"
|
||||||
|
#include "../Pods/Target\ Support\ Files/Pods-Runner/Pods-Runner.release.xcconfig"
|
||||||
|
@ -32,6 +32,10 @@
|
|||||||
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
||||||
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
|
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
|
||||||
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
|
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
|
||||||
|
FA240D7922F2857D003025F3 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAD0115F22F1B9DF0016E673 /* Flutter.framework */; };
|
||||||
|
FA240D7A22F2857D003025F3 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FAD0115F22F1B9DF0016E673 /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||||
|
FA240D7B22F28581003025F3 /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAD0116122F1B9DF0016E673 /* App.framework */; };
|
||||||
|
FA240D7C22F28581003025F3 /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FAD0116122F1B9DF0016E673 /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||||
FAD0116422F1B9DF0016E673 /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = FAD0115E22F1B9DF0016E673 /* Debug.xcconfig */; };
|
FAD0116422F1B9DF0016E673 /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = FAD0115E22F1B9DF0016E673 /* Debug.xcconfig */; };
|
||||||
FAD0116522F1B9DF0016E673 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAD0115F22F1B9DF0016E673 /* Flutter.framework */; };
|
FAD0116522F1B9DF0016E673 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAD0115F22F1B9DF0016E673 /* Flutter.framework */; };
|
||||||
FAD0116622F1B9DF0016E673 /* Release.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = FAD0116022F1B9DF0016E673 /* Release.xcconfig */; };
|
FAD0116622F1B9DF0016E673 /* Release.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = FAD0116022F1B9DF0016E673 /* Release.xcconfig */; };
|
||||||
@ -47,6 +51,8 @@
|
|||||||
dstPath = "";
|
dstPath = "";
|
||||||
dstSubfolderSpec = 10;
|
dstSubfolderSpec = 10;
|
||||||
files = (
|
files = (
|
||||||
|
FA240D7C22F28581003025F3 /* App.framework in Embed Frameworks */,
|
||||||
|
FA240D7A22F2857D003025F3 /* Flutter.framework in Embed Frameworks */,
|
||||||
);
|
);
|
||||||
name = "Embed Frameworks";
|
name = "Embed Frameworks";
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
@ -102,6 +108,8 @@
|
|||||||
17DB4C25EDB98B3648015B9E /* libPods-Runner.a in Frameworks */,
|
17DB4C25EDB98B3648015B9E /* libPods-Runner.a in Frameworks */,
|
||||||
FAD0116722F1B9DF0016E673 /* App.framework in Frameworks */,
|
FAD0116722F1B9DF0016E673 /* App.framework in Frameworks */,
|
||||||
FAD0116522F1B9DF0016E673 /* Flutter.framework in Frameworks */,
|
FAD0116522F1B9DF0016E673 /* Flutter.framework in Frameworks */,
|
||||||
|
FA240D7922F2857D003025F3 /* Flutter.framework in Frameworks */,
|
||||||
|
FA240D7B22F28581003025F3 /* App.framework in Frameworks */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@ -321,11 +329,11 @@
|
|||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
shellPath = /bin/sh;
|
shellPath = /bin/sh;
|
||||||
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin\n";
|
shellScript = "/bin/sh \"/Users/nealyang/development/flutter/packages/flutter_tools/bin/xcode_backend.sh\" thin\n";
|
||||||
};
|
};
|
||||||
9740EEB61CF901F6004384FC /* Run Script */ = {
|
9740EEB61CF901F6004384FC /* Run Script */ = {
|
||||||
isa = PBXShellScriptBuildPhase;
|
isa = PBXShellScriptBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 12;
|
||||||
files = (
|
files = (
|
||||||
);
|
);
|
||||||
inputPaths = (
|
inputPaths = (
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
class Api{
|
class Api{
|
||||||
// static const String BASE_URL = 'http://flutter-go.alibaba.net/';
|
// static const String BASE_URL = 'http://flutter-go.alibaba.net/';
|
||||||
static const String BASE_URL = 'https://flutter-go.pub/api/';
|
// static const String BASE_URL = 'https://flutter-go.pub/api/';
|
||||||
|
static const String BASE_URL = 'http://30.10.26.15:7001/';
|
||||||
|
|
||||||
static const String DO_LOGIN = BASE_URL+'doLogin';//登陆
|
static const String DO_LOGIN = BASE_URL+'doLogin';//登陆
|
||||||
|
|
||||||
@ -23,11 +24,14 @@ class Api{
|
|||||||
|
|
||||||
static const String ADD_COLLECTION = BASE_URL+'auth/addCollection';//添加收藏
|
static const String ADD_COLLECTION = BASE_URL+'auth/addCollection';//添加收藏
|
||||||
|
|
||||||
static const String CHECK_COLLECTED = BASE_URL+'auth/checkCollected';//校验收藏
|
static const String CHECK_COLLECTED = BASE_URL+'checkCollected';//校验收藏
|
||||||
|
|
||||||
static const String SET_THEMECOLOR = BASE_URL+'auth/setThemeColor';//设置主题颜色
|
static const String SET_THEMECOLOR = BASE_URL+'auth/setThemeColor';//设置主题颜色
|
||||||
|
|
||||||
static const String GET_THEMECOLOR = BASE_URL +'/getThemeColor';//获取主题颜色
|
static const String GET_THEMECOLOR = BASE_URL +'/getThemeColor';//获取主题颜色
|
||||||
|
|
||||||
static const String GET_WIDGET_TREE = 'http://flutter-go.alibaba.net/' + 'getCateList';//获取widget列表树
|
static const String GET_WIDGET_TREE = 'http://flutter-go.alibaba.net/' + 'getCateList';//获取widget列表树
|
||||||
|
|
||||||
|
static const String SEARCH_WIDGET = BASE_URL+'searchWidget';//搜索组件
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_go/utils/data_utils.dart';
|
||||||
|
|
||||||
import '../routers/application.dart';
|
import '../routers/application.dart';
|
||||||
import '../routers/routers.dart';
|
import '../routers/routers.dart';
|
||||||
@ -37,7 +38,7 @@ class _WidgetDemoState extends State<WidgetDemo> {
|
|||||||
CollectionControlModel _collectionControl = new CollectionControlModel();
|
CollectionControlModel _collectionControl = new CollectionControlModel();
|
||||||
var _collectionIcons;
|
var _collectionIcons;
|
||||||
List widgetDemosList = new WidgetDemoList().getDemos();
|
List widgetDemosList = new WidgetDemoList().getDemos();
|
||||||
String _router = '';
|
String widgetType = 'old';
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
|
|
||||||
List<Widget> _buildContent() {
|
List<Widget> _buildContent() {
|
||||||
@ -65,60 +66,66 @@ class _WidgetDemoState extends State<WidgetDemo> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
// 这里不能直接 使用 ` ModalRoute.of(context)` 会产生报错
|
// 这里不能直接 使用 ` ModalRoute.of(context)` 会产生报错
|
||||||
Future.delayed(Duration.zero,() {
|
Future.delayed(Duration.zero, () {
|
||||||
String currentPath = ModalRoute.of(context).settings.name;
|
String currentPath = ModalRoute.of(context).settings.name;
|
||||||
_collectionControl.getRouterByUrl(currentPath).then((list) {
|
if (currentPath.indexOf('/standard-page') == 0) {
|
||||||
|
widgetType = 'standard';
|
||||||
|
}
|
||||||
|
Map<String, String> params = {
|
||||||
|
'type': widgetType,
|
||||||
|
"url": currentPath,
|
||||||
|
"name": widget.title
|
||||||
|
};
|
||||||
|
DataUtils.checkCollected(params).then((result) {
|
||||||
if (this.mounted) {
|
if (this.mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_hasCollected = list.length > 0;
|
_hasCollected = result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 点击收藏按钮
|
// 点击收藏按钮
|
||||||
_getCollection() {
|
_getCollection() {
|
||||||
|
|
||||||
String currentRouterPath = ModalRoute.of(context).settings.name;
|
String currentRouterPath = ModalRoute.of(context).settings.name;
|
||||||
|
Map<String, String> params = {
|
||||||
|
"type": widgetType,
|
||||||
|
"url": currentRouterPath,
|
||||||
|
"name": widget.title
|
||||||
|
};
|
||||||
if (_hasCollected) {
|
if (_hasCollected) {
|
||||||
// 删除操作
|
// 删除操作
|
||||||
_collectionControl.deleteByPath(currentRouterPath).then((result) {
|
DataUtils.removeCollected(params, context).then((result) {
|
||||||
if (result > 0 && this.mounted) {
|
if (result) {
|
||||||
setState(() {
|
|
||||||
_hasCollected = false;
|
|
||||||
});
|
|
||||||
_scaffoldKey.currentState
|
_scaffoldKey.currentState
|
||||||
.showSnackBar(SnackBar(content: Text('已取消收藏')));
|
.showSnackBar(SnackBar(content: Text('已取消收藏')));
|
||||||
if (ApplicationEvent.event != null) {
|
if (ApplicationEvent.event != null) {
|
||||||
ApplicationEvent.event
|
ApplicationEvent.event
|
||||||
.fire(CollectionEvent(widget.title, currentRouterPath, true));
|
.fire(CollectionEvent(widget.title, currentRouterPath, true));
|
||||||
}
|
}
|
||||||
|
if (this.mounted) {
|
||||||
return;
|
setState(() {
|
||||||
|
_hasCollected = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print('删除错误');
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 插入操作
|
// 插入操作
|
||||||
_collectionControl
|
DataUtils.addCollected(params, context).then((result) {
|
||||||
.insert(Collection(name: widget.title, router: currentRouterPath))
|
if (result) {
|
||||||
.then((result) {
|
|
||||||
if (this.mounted) {
|
if (this.mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_hasCollected = true;
|
_hasCollected = true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
_scaffoldKey.currentState
|
||||||
|
.showSnackBar(SnackBar(content: Text('收藏成功')));
|
||||||
if (ApplicationEvent.event != null) {
|
if (ApplicationEvent.event != null) {
|
||||||
ApplicationEvent.event
|
ApplicationEvent.event
|
||||||
.fire(CollectionEvent(widget.title, currentRouterPath, false));
|
.fire(CollectionEvent(widget.title, currentRouterPath, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
_scaffoldKey.currentState
|
|
||||||
.showSnackBar(SnackBar(content: Text('收藏成功')));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -190,8 +190,8 @@ void main() async {
|
|||||||
sp = await SpUtil.getInstance();
|
sp = await SpUtil.getInstance();
|
||||||
new SearchHistoryList(sp);
|
new SearchHistoryList(sp);
|
||||||
await DataUtils.getWidgetTreeList().then((List json) {
|
await DataUtils.getWidgetTreeList().then((List json) {
|
||||||
|
if (json == null) return;
|
||||||
Application.widgetTree = WidgetTree.buildWidgetTree(json);
|
Application.widgetTree = WidgetTree.buildWidgetTree(json);
|
||||||
|
|
||||||
});
|
});
|
||||||
db = Provider.db;
|
db = Provider.db;
|
||||||
runApp(new MyApp());
|
runApp(new MyApp());
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import 'dart:async' show Future;
|
import 'dart:async' show Future;
|
||||||
|
|
||||||
import 'package:fluro/fluro.dart';
|
import 'package:fluro/fluro.dart';
|
||||||
|
import 'package:flutter_go/model/collection.dart';
|
||||||
import 'package:flutter_go/model/version.dart';
|
import 'package:flutter_go/model/version.dart';
|
||||||
|
import 'package:flutter_go/model/widget.dart';
|
||||||
import 'package:package_info/package_info.dart';
|
import 'package:package_info/package_info.dart';
|
||||||
import 'package:flutter_go/model/responseData.dart';
|
import 'package:flutter_go/model/responseData.dart';
|
||||||
|
|
||||||
@ -39,7 +41,6 @@ class DataUtils {
|
|||||||
var response = await NetUtils.get(Api.CHECK_LOGIN);
|
var response = await NetUtils.get(Api.CHECK_LOGIN);
|
||||||
print('response: $response');
|
print('response: $response');
|
||||||
try {
|
try {
|
||||||
print('1111');
|
|
||||||
if (response['success']) {
|
if (response['success']) {
|
||||||
print('${response['success']} ${response['data']} response[succes]');
|
print('${response['success']} ${response['data']} response[succes]');
|
||||||
UserInformation userInfo = UserInformation.fromJson(response['data']);
|
UserInformation userInfo = UserInformation.fromJson(response['data']);
|
||||||
@ -104,15 +105,97 @@ class DataUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 获取widget列表处的树型数据
|
/// 获取widget列表处的树型数据
|
||||||
static Future<List> getWidgetTreeList() async {
|
static Future<List> getWidgetTreeList() async {
|
||||||
|
try {
|
||||||
var response = await NetUtils.get(Api.GET_WIDGET_TREE);
|
var response = await NetUtils.get(Api.GET_WIDGET_TREE);
|
||||||
|
print('组件树:$response');
|
||||||
if (response['success']) {
|
if (response != null && response['success']) {
|
||||||
return response['data'];
|
return response['data'];
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
print('获取组件树 error $error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验是否收藏
|
||||||
|
static Future<bool> checkCollected(Map<String, String> params) async {
|
||||||
|
print('url 地址:${Api.CHECK_COLLECTED} $params');
|
||||||
|
try {
|
||||||
|
var response = await NetUtils.post(Api.CHECK_COLLECTED, params);
|
||||||
|
return response != null && response['hasCollected'];
|
||||||
|
} catch (error) {
|
||||||
|
print('校验收藏 error $error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加收藏
|
||||||
|
static Future addCollected(Map<String, String> params, context) async {
|
||||||
|
var response = await NetUtils.post(Api.ADD_COLLECTION, params);
|
||||||
|
if (response['status'] == 401 && response['message'] == '请先登录') {
|
||||||
|
Application.router.navigateTo(context, '${Routes.loginPage}',
|
||||||
|
transition: TransitionType.nativeModal);
|
||||||
|
}
|
||||||
|
return response != null && response['success'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移出收藏
|
||||||
|
static Future removeCollected(Map<String, String> params, context) async {
|
||||||
|
var response = await NetUtils.post(Api.REMOVE_COLLECTION, params);
|
||||||
|
if (response['status'] == 401 && response['message'] == '请先登录') {
|
||||||
|
Application.router.navigateTo(context, '${Routes.loginPage}',
|
||||||
|
transition: TransitionType.nativeModal);
|
||||||
|
}
|
||||||
|
return response != null && response['success'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取全部收藏
|
||||||
|
static Future getAllCollections(context) async {
|
||||||
|
var response = await NetUtils.get(Api.GET_ALL_COLLECTION);
|
||||||
|
List<Collection> responseList = [];
|
||||||
|
if (response['status'] == 401 && response['message'] == '请先登录') {
|
||||||
|
Application.router.navigateTo(context, '${Routes.loginPage}',
|
||||||
|
transition: TransitionType.nativeModal);
|
||||||
|
}
|
||||||
|
if (response != null && response['success'] == true) {
|
||||||
|
for (int i = 0; i < response['data'].length; i++) {
|
||||||
|
Map<String, dynamic> tempCo = response['data'][i];
|
||||||
|
responseList.add(Collection.fromJSON(
|
||||||
|
{"name": tempCo['name'], "router": tempCo['url']}));
|
||||||
|
}
|
||||||
|
return responseList;
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搜索组件
|
||||||
|
static Future searchWidget(String name) async {
|
||||||
|
var response = await NetUtils.get(Api.SEARCH_WIDGET, {"name": name});
|
||||||
|
List<WidgetPoint> list = [];
|
||||||
|
if (response != null && response['success'] == true) {
|
||||||
|
for (int i = 0; i < response['data'].length; i++) {
|
||||||
|
var json = response['data'][i];
|
||||||
|
String routerName;
|
||||||
|
if (json['display'] == 'old') {
|
||||||
|
routerName = json['path'];
|
||||||
|
} else {
|
||||||
|
routerName = json['pageId'];
|
||||||
|
}
|
||||||
|
Map<String, dynamic> tempMap = {
|
||||||
|
"name": json['name'],
|
||||||
|
"cnName": json['name'],
|
||||||
|
"routerName": routerName,
|
||||||
|
"catId": int.parse(json['parentId'])
|
||||||
|
};
|
||||||
|
list.add(WidgetPoint.fromJSON(tempMap));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,13 @@
|
|||||||
/// @Last Modified time: 2019-06-05 14:01:03
|
/// @Last Modified time: 2019-06-05 14:01:03
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:event_bus/event_bus.dart';
|
import 'package:event_bus/event_bus.dart';
|
||||||
|
import 'package:fluro/fluro.dart';
|
||||||
|
|
||||||
import 'package:flutter_go/model/collection.dart';
|
import 'package:flutter_go/model/collection.dart';
|
||||||
import 'package:flutter_go/routers/application.dart';
|
import 'package:flutter_go/routers/application.dart';
|
||||||
import 'package:flutter_go/routers/routers.dart';
|
|
||||||
import 'package:flutter_go/event/event_bus.dart';
|
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:flutter_go/utils/data_utils.dart';
|
||||||
|
|
||||||
class CollectionFullPage extends StatefulWidget {
|
class CollectionFullPage extends StatefulWidget {
|
||||||
final bool hasLogined;
|
final bool hasLogined;
|
||||||
@ -41,13 +42,10 @@ class _CollectionFullPageState extends State<CollectionFullPage> {
|
|||||||
|
|
||||||
void _getList() {
|
void _getList() {
|
||||||
_collectionList.clear();
|
_collectionList.clear();
|
||||||
_collectionControl.getAllCollection().then((resultList) {
|
DataUtils.getAllCollections(context).then((collectionList) {
|
||||||
resultList.forEach((item) {
|
|
||||||
_collectionList.add(item);
|
|
||||||
});
|
|
||||||
if (this.mounted) {
|
if (this.mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_collectionList = _collectionList;
|
_collectionList = collectionList;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -73,7 +71,7 @@ class _CollectionFullPageState extends State<CollectionFullPage> {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
width: 5.0,
|
width: 5.0,
|
||||||
),
|
),
|
||||||
Text('模拟器重新运行会丢失收藏'),
|
Text('常用的组件都可以收藏在这里哦'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -115,21 +113,24 @@ class _CollectionFullPageState extends State<CollectionFullPage> {
|
|||||||
trailing:
|
trailing:
|
||||||
Icon(Icons.keyboard_arrow_right, color: Colors.grey, size: 30.0),
|
Icon(Icons.keyboard_arrow_right, color: Colors.grey, size: 30.0),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (_collectionList[index - 1].router.contains('http')) {
|
Application.router.navigateTo(
|
||||||
// 注意这里title已经转义过了
|
context, _collectionList[index - 1].router,
|
||||||
Application.router.navigateTo(context,
|
transition: TransitionType.inFromRight);
|
||||||
'${Routes.webViewPage}?title=${_collectionList[index - 1].name}&url=${Uri.encodeComponent(_collectionList[index - 1].router)}');
|
|
||||||
} else {
|
// if (_collectionList[index - 1].router.contains('http')) {
|
||||||
Application.router
|
// // 注意这里title已经转义过了
|
||||||
.navigateTo(context, "${_collectionList[index - 1].router}");
|
// Application.router.navigateTo(context,
|
||||||
}
|
// '${Routes.webViewPage}?title=${_collectionList[index - 1].name}&url=${Uri.encodeComponent(_collectionList[index - 1].router)}');
|
||||||
|
// } else {
|
||||||
|
// Application.router
|
||||||
|
// .navigateTo(context, "${_collectionList[index - 1].router}");
|
||||||
|
// }
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListView buildContent() {
|
||||||
ListView buildContent(){
|
|
||||||
if (_collectionList.length == 0) {
|
if (_collectionList.length == 0) {
|
||||||
return ListView(
|
return ListView(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
|
@ -11,6 +11,7 @@ import 'package:flutter_go/routers/application.dart';
|
|||||||
import 'package:flutter_go/routers/routers.dart';
|
import 'package:flutter_go/routers/routers.dart';
|
||||||
import 'package:flutter_go/event/event_bus.dart';
|
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:flutter_go/utils/data_utils.dart';
|
||||||
|
|
||||||
class CollectionPage extends StatefulWidget {
|
class CollectionPage extends StatefulWidget {
|
||||||
final bool hasLogined;
|
final bool hasLogined;
|
||||||
@ -47,14 +48,10 @@ class _CollectionPageState extends State<CollectionPage> {
|
|||||||
|
|
||||||
void _getList() {
|
void _getList() {
|
||||||
_collectionList.clear();
|
_collectionList.clear();
|
||||||
_collectionControl.getAllCollection().then((resultList) {
|
DataUtils.getAllCollections(context).then((collectionList) {
|
||||||
resultList.forEach((item) {
|
|
||||||
_collectionList.add(item);
|
|
||||||
});
|
|
||||||
print("_collectionList ${_collectionList}");
|
|
||||||
if (this.mounted) {
|
if (this.mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_collectionList = _collectionList;
|
_collectionList = collectionList;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -7,9 +7,11 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:flutter_go/utils/data_utils.dart';
|
||||||
import 'package:flutter_go/utils/shared_preferences.dart';
|
import 'package:flutter_go/utils/shared_preferences.dart';
|
||||||
import 'package:flutter_go/views/first_page/first_page.dart';
|
import 'package:flutter_go/views/first_page/first_page.dart';
|
||||||
import 'package:flutter_go/views/first_page/main_page.dart';
|
import 'package:flutter_go/views/first_page/main_page.dart';
|
||||||
|
import 'package:fluro/fluro.dart';
|
||||||
import 'package:flutter_go/views/widget_page/widget_page.dart';
|
import 'package:flutter_go/views/widget_page/widget_page.dart';
|
||||||
import 'package:flutter_go/views/welcome_page/fourth_page.dart';
|
import 'package:flutter_go/views/welcome_page/fourth_page.dart';
|
||||||
import 'package:flutter_go/views/collection_page/collection_page.dart';
|
import 'package:flutter_go/views/collection_page/collection_page.dart';
|
||||||
@ -87,26 +89,21 @@ class _MyHomePageState extends State<AppPage>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onWidgetTap(WidgetPoint widgetPoint, BuildContext context) {
|
void onWidgetTap(WidgetPoint widgetPoint, BuildContext context) {
|
||||||
List widgetDemosList = new WidgetDemoList().getDemos();
|
|
||||||
String targetName = widgetPoint.name;
|
String targetName = widgetPoint.name;
|
||||||
String targetRouter = '/category/error/404';
|
|
||||||
widgetDemosList.forEach((item) {
|
|
||||||
if (item.name == targetName) {
|
|
||||||
targetRouter = item.routerName;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
searchHistoryList
|
searchHistoryList
|
||||||
.add(SearchHistory(name: targetName, targetRouter: targetRouter));
|
.add(SearchHistory(name: targetName, targetRouter: widgetPoint.routerName));
|
||||||
print("searchHistoryList1 ${searchHistoryList.toString()}");
|
print("searchHistoryList1 ${searchHistoryList.toString()}");
|
||||||
print("searchHistoryList2 ${targetRouter}");
|
Application.router.navigateTo(
|
||||||
print("searchHistoryList3 ${widgetPoint.name}");
|
context, widgetPoint.routerName,
|
||||||
Application.router.navigateTo(context, "$targetRouter");
|
transition: TransitionType.inFromRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildSearchInput(BuildContext context) {
|
Widget buildSearchInput(BuildContext context) {
|
||||||
return new SearchInput((value) async {
|
return new SearchInput((value) async {
|
||||||
if (value != '') {
|
if (value != '') {
|
||||||
List<WidgetPoint> list = await widgetControl.search(value);
|
print('value ::: $value');
|
||||||
|
// List<WidgetPoint> list = await widgetControl.search(value);
|
||||||
|
List<WidgetPoint> list = await DataUtils.searchWidget(value);
|
||||||
return list
|
return list
|
||||||
.map((item) => new MaterialSearchResult<String>(
|
.map((item) => new MaterialSearchResult<String>(
|
||||||
value: item.name,
|
value: item.name,
|
||||||
|
@ -27,7 +27,6 @@ class StandardView extends StatefulWidget {
|
|||||||
_StandardView createState() => _StandardView();
|
_StandardView createState() => _StandardView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _StandardView extends State<StandardView> {
|
class _StandardView extends State<StandardView> {
|
||||||
String markdownDesc = '# this is header';
|
String markdownDesc = '# this is header';
|
||||||
String pageTitle = "XXX";
|
String pageTitle = "XXX";
|
||||||
@ -37,15 +36,17 @@ class _StandardView extends State<StandardView> {
|
|||||||
StandardPages standardPage = new StandardPages();
|
StandardPages standardPage = new StandardPages();
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
this.getDetail();
|
this.getDetail();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 本地调用的获取基本信息
|
// 本地调用的获取基本信息
|
||||||
Future<void> getPagesInfo() async {
|
Future<void> getPagesInfo() 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';
|
||||||
@ -53,16 +54,14 @@ class _StandardView extends State<StandardView> {
|
|||||||
email = pageDetail['email'];
|
email = pageDetail['email'];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String _getContentFromLocal() {
|
String _getContentFromLocal() {
|
||||||
|
|
||||||
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';
|
||||||
|
|
||||||
@ -79,12 +78,15 @@ class _StandardView extends State<StandardView> {
|
|||||||
getPagesInfo();
|
getPagesInfo();
|
||||||
conent = _getContentFromLocal();
|
conent = _getContentFromLocal();
|
||||||
}
|
}
|
||||||
|
if (this.mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
markdownDesc = conent;
|
markdownDesc = conent;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return Future(() => conent);
|
return Future(() => conent);
|
||||||
// this.rebuild();
|
// this.rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildMarkdown() {
|
Widget buildMarkdown() {
|
||||||
Map<String, String> contentList = new StandardPages().getPages();
|
Map<String, String> contentList = new StandardPages().getPages();
|
||||||
|
|
||||||
@ -94,23 +96,19 @@ class _StandardView extends State<StandardView> {
|
|||||||
|
|
||||||
return MarkdownBody(
|
return MarkdownBody(
|
||||||
data: contentList[widget.id],
|
data: contentList[widget.id],
|
||||||
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']];
|
||||||
if (demo == null) {
|
if (demo == null) {
|
||||||
String errString = "not found ${attrs['id']} in demo packages";
|
String errString = "not found ${attrs['id']} in demo packages";
|
||||||
debugPrint(errString);
|
debugPrint(errString);
|
||||||
demo = [
|
demo = [Text(errString)];
|
||||||
Text(errString)
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Column(
|
return Column(children: demo);
|
||||||
children: demo
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new WidgetDemo(
|
return new WidgetDemo(
|
||||||
@ -123,7 +121,8 @@ class _StandardView extends State<StandardView> {
|
|||||||
'创建者: $email',
|
'创建者: $email',
|
||||||
'id: ${widget.id}',
|
'id: ${widget.id}',
|
||||||
],
|
],
|
||||||
docUrl: 'https://docs.flutter.io/flutter/material/DropdownButton-class.html',
|
docUrl:
|
||||||
|
'https://docs.flutter.io/flutter/material/DropdownButton-class.html',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,10 +23,6 @@ class WebViewPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _WebViewPageState extends State<WebViewPage> {
|
class _WebViewPageState extends State<WebViewPage> {
|
||||||
final flutterWebviewPlugin = new FlutterWebviewPlugin();
|
final flutterWebviewPlugin = new FlutterWebviewPlugin();
|
||||||
bool _hasCollected = false;
|
|
||||||
String _router = '';
|
|
||||||
var _collectionIcons;
|
|
||||||
CollectionControlModel _collectionControl = new CollectionControlModel();
|
|
||||||
|
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
@override
|
@override
|
||||||
@ -65,87 +61,14 @@ class _WebViewPageState extends State<WebViewPage> {
|
|||||||
flutterWebviewPlugin.close();
|
flutterWebviewPlugin.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 这里 存放不使用 name 改成 url. 确定唯一性
|
|
||||||
// _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;
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
|
|
||||||
// 点击收藏按钮
|
|
||||||
_getCollection() {
|
|
||||||
if (_hasCollected) {
|
|
||||||
// 删除操作
|
|
||||||
_collectionControl
|
|
||||||
.deleteByName(Uri.encodeComponent(widget.title.trim()))
|
|
||||||
.then((result) {
|
|
||||||
if (result > 0 && this.mounted) {
|
|
||||||
setState(() {
|
|
||||||
_hasCollected = false;
|
|
||||||
});
|
|
||||||
_scaffoldKey.currentState
|
|
||||||
.showSnackBar(SnackBar(content: Text('已取消收藏')));
|
|
||||||
if (ApplicationEvent.event != null) {
|
|
||||||
ApplicationEvent.event
|
|
||||||
.fire(CollectionEvent(widget.title, _router, true));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
print('删除错误');
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// 插入操作
|
|
||||||
_collectionControl
|
|
||||||
.insert(Collection(
|
|
||||||
name: Uri.encodeComponent(widget.title.trim()),
|
|
||||||
router: widget.url))
|
|
||||||
.then((result) {
|
|
||||||
if (this.mounted) {
|
|
||||||
setState(() {
|
|
||||||
_hasCollected = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ApplicationEvent.event != null) {
|
|
||||||
ApplicationEvent.event
|
|
||||||
.fire(CollectionEvent(widget.title, _router, false));
|
|
||||||
}
|
|
||||||
_scaffoldKey.currentState
|
|
||||||
.showSnackBar(SnackBar(content: Text('收藏成功')));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (_hasCollected) {
|
|
||||||
_collectionIcons = Icons.favorite;
|
|
||||||
} else {
|
|
||||||
_collectionIcons = Icons.favorite_border;
|
|
||||||
}
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _scaffoldKey,
|
key: _scaffoldKey,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
actions: <Widget>[
|
|
||||||
new IconButton(
|
|
||||||
tooltip: 'goBack home',
|
|
||||||
onPressed: _getCollection,
|
|
||||||
icon: Icon(
|
|
||||||
_collectionIcons,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
body: WebviewScaffold(
|
body: WebviewScaffold(
|
||||||
url: widget.url,
|
url: widget.url,
|
||||||
|
@ -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));
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user