mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-07-03 23:00:26 +08:00
个人中心、收藏、搜索
This commit is contained in:
@ -1,2 +1,3 @@
|
||||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.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 "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 */; };
|
||||
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
|
||||
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 */; };
|
||||
FAD0116522F1B9DF0016E673 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAD0115F22F1B9DF0016E673 /* Flutter.framework */; };
|
||||
FAD0116622F1B9DF0016E673 /* Release.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = FAD0116022F1B9DF0016E673 /* Release.xcconfig */; };
|
||||
@ -47,6 +51,8 @@
|
||||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
FA240D7C22F28581003025F3 /* App.framework in Embed Frameworks */,
|
||||
FA240D7A22F2857D003025F3 /* Flutter.framework in Embed Frameworks */,
|
||||
);
|
||||
name = "Embed Frameworks";
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@ -102,6 +108,8 @@
|
||||
17DB4C25EDB98B3648015B9E /* libPods-Runner.a in Frameworks */,
|
||||
FAD0116722F1B9DF0016E673 /* App.framework in Frameworks */,
|
||||
FAD0116522F1B9DF0016E673 /* Flutter.framework in Frameworks */,
|
||||
FA240D7922F2857D003025F3 /* Flutter.framework in Frameworks */,
|
||||
FA240D7B22F28581003025F3 /* App.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -321,11 +329,11 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
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 */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
buildActionMask = 12;
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
|
@ -1,6 +1,7 @@
|
||||
class Api{
|
||||
// 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';//登陆
|
||||
|
||||
@ -23,11 +24,14 @@ class Api{
|
||||
|
||||
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 GET_THEMECOLOR = BASE_URL +'/getThemeColor';//获取主题颜色
|
||||
|
||||
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 'package:flutter/material.dart';
|
||||
import 'package:flutter_go/utils/data_utils.dart';
|
||||
|
||||
import '../routers/application.dart';
|
||||
import '../routers/routers.dart';
|
||||
@ -37,7 +38,7 @@ class _WidgetDemoState extends State<WidgetDemo> {
|
||||
CollectionControlModel _collectionControl = new CollectionControlModel();
|
||||
var _collectionIcons;
|
||||
List widgetDemosList = new WidgetDemoList().getDemos();
|
||||
String _router = '';
|
||||
String widgetType = 'old';
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
List<Widget> _buildContent() {
|
||||
@ -65,60 +66,66 @@ class _WidgetDemoState extends State<WidgetDemo> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 这里不能直接 使用 ` ModalRoute.of(context)` 会产生报错
|
||||
Future.delayed(Duration.zero,() {
|
||||
Future.delayed(Duration.zero, () {
|
||||
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) {
|
||||
setState(() {
|
||||
_hasCollected = list.length > 0;
|
||||
_hasCollected = result;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 点击收藏按钮
|
||||
_getCollection() {
|
||||
|
||||
String currentRouterPath = ModalRoute.of(context).settings.name;
|
||||
|
||||
Map<String, String> params = {
|
||||
"type": widgetType,
|
||||
"url": currentRouterPath,
|
||||
"name": widget.title
|
||||
};
|
||||
if (_hasCollected) {
|
||||
// 删除操作
|
||||
_collectionControl.deleteByPath(currentRouterPath).then((result) {
|
||||
if (result > 0 && this.mounted) {
|
||||
setState(() {
|
||||
_hasCollected = false;
|
||||
});
|
||||
DataUtils.removeCollected(params, context).then((result) {
|
||||
if (result) {
|
||||
_scaffoldKey.currentState
|
||||
.showSnackBar(SnackBar(content: Text('已取消收藏')));
|
||||
if (ApplicationEvent.event != null) {
|
||||
ApplicationEvent.event
|
||||
.fire(CollectionEvent(widget.title, currentRouterPath, true));
|
||||
}
|
||||
|
||||
return;
|
||||
if (this.mounted) {
|
||||
setState(() {
|
||||
_hasCollected = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
print('删除错误');
|
||||
});
|
||||
} else {
|
||||
// 插入操作
|
||||
_collectionControl
|
||||
.insert(Collection(name: widget.title, router: currentRouterPath))
|
||||
.then((result) {
|
||||
DataUtils.addCollected(params, context).then((result) {
|
||||
if (result) {
|
||||
if (this.mounted) {
|
||||
setState(() {
|
||||
_hasCollected = true;
|
||||
});
|
||||
|
||||
}
|
||||
_scaffoldKey.currentState
|
||||
.showSnackBar(SnackBar(content: Text('收藏成功')));
|
||||
if (ApplicationEvent.event != null) {
|
||||
ApplicationEvent.event
|
||||
.fire(CollectionEvent(widget.title, currentRouterPath, false));
|
||||
}
|
||||
|
||||
_scaffoldKey.currentState
|
||||
.showSnackBar(SnackBar(content: Text('收藏成功')));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -190,8 +190,8 @@ void main() async {
|
||||
sp = await SpUtil.getInstance();
|
||||
new SearchHistoryList(sp);
|
||||
await DataUtils.getWidgetTreeList().then((List json) {
|
||||
if (json == null) return;
|
||||
Application.widgetTree = WidgetTree.buildWidgetTree(json);
|
||||
|
||||
});
|
||||
db = Provider.db;
|
||||
runApp(new MyApp());
|
||||
|
@ -1,7 +1,9 @@
|
||||
import 'dart:async' show Future;
|
||||
|
||||
import 'package:fluro/fluro.dart';
|
||||
import 'package:flutter_go/model/collection.dart';
|
||||
import 'package:flutter_go/model/version.dart';
|
||||
import 'package:flutter_go/model/widget.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:flutter_go/model/responseData.dart';
|
||||
|
||||
@ -39,7 +41,6 @@ class DataUtils {
|
||||
var response = await NetUtils.get(Api.CHECK_LOGIN);
|
||||
print('response: $response');
|
||||
try {
|
||||
print('1111');
|
||||
if (response['success']) {
|
||||
print('${response['success']} ${response['data']} response[succes]');
|
||||
UserInformation userInfo = UserInformation.fromJson(response['data']);
|
||||
@ -104,15 +105,97 @@ class DataUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取widget列表处的树型数据
|
||||
static Future<List> getWidgetTreeList() async {
|
||||
try {
|
||||
var response = await NetUtils.get(Api.GET_WIDGET_TREE);
|
||||
|
||||
if (response['success']) {
|
||||
print('组件树:$response');
|
||||
if (response != null && response['success']) {
|
||||
return response['data'];
|
||||
} else {
|
||||
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
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:event_bus/event_bus.dart';
|
||||
import 'package:fluro/fluro.dart';
|
||||
|
||||
import 'package:flutter_go/model/collection.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_model.dart';
|
||||
import 'package:flutter_go/utils/data_utils.dart';
|
||||
|
||||
class CollectionFullPage extends StatefulWidget {
|
||||
final bool hasLogined;
|
||||
@ -41,13 +42,10 @@ class _CollectionFullPageState extends State<CollectionFullPage> {
|
||||
|
||||
void _getList() {
|
||||
_collectionList.clear();
|
||||
_collectionControl.getAllCollection().then((resultList) {
|
||||
resultList.forEach((item) {
|
||||
_collectionList.add(item);
|
||||
});
|
||||
DataUtils.getAllCollections(context).then((collectionList) {
|
||||
if (this.mounted) {
|
||||
setState(() {
|
||||
_collectionList = _collectionList;
|
||||
_collectionList = collectionList;
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -73,7 +71,7 @@ class _CollectionFullPageState extends State<CollectionFullPage> {
|
||||
SizedBox(
|
||||
width: 5.0,
|
||||
),
|
||||
Text('模拟器重新运行会丢失收藏'),
|
||||
Text('常用的组件都可以收藏在这里哦'),
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -115,21 +113,24 @@ class _CollectionFullPageState extends State<CollectionFullPage> {
|
||||
trailing:
|
||||
Icon(Icons.keyboard_arrow_right, color: Colors.grey, size: 30.0),
|
||||
onTap: () {
|
||||
if (_collectionList[index - 1].router.contains('http')) {
|
||||
// 注意这里title已经转义过了
|
||||
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}");
|
||||
}
|
||||
Application.router.navigateTo(
|
||||
context, _collectionList[index - 1].router,
|
||||
transition: TransitionType.inFromRight);
|
||||
|
||||
// if (_collectionList[index - 1].router.contains('http')) {
|
||||
// // 注意这里title已经转义过了
|
||||
// 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) {
|
||||
return ListView(
|
||||
children: <Widget>[
|
||||
|
@ -11,6 +11,7 @@ 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_model.dart';
|
||||
import 'package:flutter_go/utils/data_utils.dart';
|
||||
|
||||
class CollectionPage extends StatefulWidget {
|
||||
final bool hasLogined;
|
||||
@ -47,14 +48,10 @@ class _CollectionPageState extends State<CollectionPage> {
|
||||
|
||||
void _getList() {
|
||||
_collectionList.clear();
|
||||
_collectionControl.getAllCollection().then((resultList) {
|
||||
resultList.forEach((item) {
|
||||
_collectionList.add(item);
|
||||
});
|
||||
print("_collectionList ${_collectionList}");
|
||||
DataUtils.getAllCollections(context).then((collectionList) {
|
||||
if (this.mounted) {
|
||||
setState(() {
|
||||
_collectionList = _collectionList;
|
||||
_collectionList = collectionList;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -7,9 +7,11 @@
|
||||
|
||||
import 'package:flutter/material.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/views/first_page/first_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/welcome_page/fourth_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) {
|
||||
List widgetDemosList = new WidgetDemoList().getDemos();
|
||||
String targetName = widgetPoint.name;
|
||||
String targetRouter = '/category/error/404';
|
||||
widgetDemosList.forEach((item) {
|
||||
if (item.name == targetName) {
|
||||
targetRouter = item.routerName;
|
||||
}
|
||||
});
|
||||
searchHistoryList
|
||||
.add(SearchHistory(name: targetName, targetRouter: targetRouter));
|
||||
.add(SearchHistory(name: targetName, targetRouter: widgetPoint.routerName));
|
||||
print("searchHistoryList1 ${searchHistoryList.toString()}");
|
||||
print("searchHistoryList2 ${targetRouter}");
|
||||
print("searchHistoryList3 ${widgetPoint.name}");
|
||||
Application.router.navigateTo(context, "$targetRouter");
|
||||
Application.router.navigateTo(
|
||||
context, widgetPoint.routerName,
|
||||
transition: TransitionType.inFromRight);
|
||||
}
|
||||
|
||||
Widget buildSearchInput(BuildContext context) {
|
||||
return new SearchInput((value) async {
|
||||
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
|
||||
.map((item) => new MaterialSearchResult<String>(
|
||||
value: item.name,
|
||||
|
@ -27,7 +27,6 @@ class StandardView extends StatefulWidget {
|
||||
_StandardView createState() => _StandardView();
|
||||
}
|
||||
|
||||
|
||||
class _StandardView extends State<StandardView> {
|
||||
String markdownDesc = '# this is header';
|
||||
String pageTitle = "XXX";
|
||||
@ -37,15 +36,17 @@ class _StandardView extends State<StandardView> {
|
||||
StandardPages standardPage = new StandardPages();
|
||||
@override
|
||||
void initState() {
|
||||
|
||||
super.initState();
|
||||
this.getDetail();
|
||||
}
|
||||
|
||||
// 本地调用的获取基本信息
|
||||
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);
|
||||
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) {
|
||||
setState(() {
|
||||
pageTitle = pageDetail['title'] ?? '请加入title';
|
||||
@ -53,16 +54,14 @@ class _StandardView extends State<StandardView> {
|
||||
email = pageDetail['email'];
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
String _getContentFromLocal() {
|
||||
|
||||
String pageId = widget.id;
|
||||
Map<String, String> pagesList = standardPage.getPages();
|
||||
return pagesList[pageId];
|
||||
}
|
||||
|
||||
Future<String> _getContentOnline() async {
|
||||
String content = 'online content';
|
||||
|
||||
@ -79,12 +78,15 @@ class _StandardView extends State<StandardView> {
|
||||
getPagesInfo();
|
||||
conent = _getContentFromLocal();
|
||||
}
|
||||
if (this.mounted) {
|
||||
setState(() {
|
||||
markdownDesc = conent;
|
||||
});
|
||||
}
|
||||
return Future(() => conent);
|
||||
// this.rebuild();
|
||||
}
|
||||
|
||||
Widget buildMarkdown() {
|
||||
Map<String, String> contentList = new StandardPages().getPages();
|
||||
|
||||
@ -94,23 +96,19 @@ class _StandardView extends State<StandardView> {
|
||||
|
||||
return MarkdownBody(
|
||||
data: contentList[widget.id],
|
||||
syntaxHighlighter:new mdCopy.HighLight(),
|
||||
syntaxHighlighter: new mdCopy.HighLight(),
|
||||
demoBuilder: (Map<String, dynamic> attrs) {
|
||||
List<Widget> demo = demoObjects[attrs['id']];
|
||||
if (demo == null) {
|
||||
String errString = "not found ${attrs['id']} in demo packages";
|
||||
debugPrint(errString);
|
||||
demo = [
|
||||
Text(errString)
|
||||
];
|
||||
demo = [Text(errString)];
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: demo
|
||||
);
|
||||
}
|
||||
);
|
||||
return Column(children: demo);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new WidgetDemo(
|
||||
@ -123,7 +121,8 @@ class _StandardView extends State<StandardView> {
|
||||
'创建者: $email',
|
||||
'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> {
|
||||
final flutterWebviewPlugin = new FlutterWebviewPlugin();
|
||||
bool _hasCollected = false;
|
||||
String _router = '';
|
||||
var _collectionIcons;
|
||||
CollectionControlModel _collectionControl = new CollectionControlModel();
|
||||
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
@override
|
||||
@ -65,87 +61,14 @@ class _WebViewPageState extends State<WebViewPage> {
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
if (_hasCollected) {
|
||||
_collectionIcons = Icons.favorite;
|
||||
} else {
|
||||
_collectionIcons = Icons.favorite_border;
|
||||
}
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
appBar: AppBar(
|
||||
title: Text(widget.title),
|
||||
actions: <Widget>[
|
||||
new IconButton(
|
||||
tooltip: 'goBack home',
|
||||
onPressed: _getCollection,
|
||||
icon: Icon(
|
||||
_collectionIcons,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: WebviewScaffold(
|
||||
url: widget.url,
|
||||
|
@ -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));
|
||||
});
|
||||
|
Reference in New Issue
Block a user