Merge pull request #249 from Nealyang/beta

feat:收藏
This commit is contained in:
一凨
2019-06-10 16:35:43 +08:00
committed by GitHub
8 changed files with 255 additions and 24 deletions

View File

@ -16,4 +16,12 @@ class Api{
static const String FEEDBACK = BASE_URL+'auth/feedback';//建议反馈
static const String LOTOUT = BASE_URL+'logout';//退出登陆
static const String GET_ALL_COLLECTION = BASE_URL+'auth/getAllUserCollection';//获取全部收藏
static const String REMOVE_COLLECTION = BASE_URL+'auth/removeCollection';//移除收藏
static const String ADD_COLLECTION = BASE_URL+'auth/addCollection';//添加收藏
static const String CHECK_COLLECTED = BASE_URL+'auth/checkCollected';//校验收藏
}

View File

@ -8,6 +8,9 @@ import 'package:flutter_go/views/web_page/web_view_page.dart';
import 'package:flutter_go/views/home.dart';
import 'package:flutter_go/views/login_page/login_page.dart';
import 'package:flutter_go/model/user_info.dart';
import 'package:flutter_go/views/collection_page/collection_page.dart';
import 'package:flutter_go/views/collection_page/collection_full_page.dart';
// app的首页
var homeHandler = new Handler(
@ -16,6 +19,20 @@ var homeHandler = new Handler(
},
);
var collectionFullHandler = new Handler(
handlerFunc: (BuildContext context,Map<String,List<String>> params){
bool hasLogined = params['hasLogin']?.first == 'true';
return CollectionFullPage(hasLogined: hasLogined);
}
);
var collectionHandler = new Handler(
handlerFunc: (BuildContext context,Map<String,List<String>> params){
bool hasLogined = params['hasLogin']?.first == 'true';
return CollectionPage(hasLogined: hasLogined);
}
);
var categoryHandler = new Handler(
handlerFunc: (BuildContext context, Map<String, List<String>> params) {
String name = params["type"]?.first;

View File

@ -13,6 +13,8 @@ class Routes {
static String codeView = '/code-view';
static String webViewPage = '/web-view-page';
static String loginPage = '/loginpage';
static String collectionPage = '/collection-page';
static String collectionFullPage = '/collection-full-page';
static void configureRoutes(Router router) {
List widgetDemosList = new WidgetDemoList().getDemos();
@ -20,7 +22,8 @@ class Routes {
handlerFunc: (BuildContext context, Map<String, List<String>> params) {
});
router.define(home, handler: homeHandler);
router.define(collectionPage,handler:collectionHandler);
router.define(collectionFullPage,handler:collectionFullHandler);
router.define('/category/:type', handler: categoryHandler);
router.define('/category/error/404', handler: widgetNotFoundHandler);
router.define(loginPage, handler: loginPageHandler);

View File

@ -1,11 +1,14 @@
import 'dart:async' show Future;
import 'package:fluro/fluro.dart';
import 'package:flutter_go/model/version.dart';
import 'package:package_info/package_info.dart';
import './net_utils.dart';
import '../model/user_info.dart';
import 'package:flutter_go/api/api.dart';
import 'package:flutter_go/routers/application.dart';
import 'package:flutter_go/routers/routers.dart';
class DataUtils {
// 登陆获取用户信息
@ -46,9 +49,12 @@ class DataUtils {
}
// 一键反馈
static Future feedback(Map<String, String> params) async {
static Future feedback(Map<String, String> params, context) async {
var response = await NetUtils.post(Api.FEEDBACK, params);
print(response);
// print(response);
if(response['status'] == 401 && response['message']=='请先登录'){
Application.router.navigateTo(context, '${Routes.loginPage}',transition:TransitionType.nativeModal);
}
return response;
}

View File

@ -0,0 +1,167 @@
/// @Author: 一凨
/// @Date: 2019-06-05 14:01:03
/// @Last Modified by: 一凨
/// @Last Modified time: 2019-06-05 14:01:03
import 'package:flutter/material.dart';
import 'package:event_bus/event_bus.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';
class CollectionFullPage extends StatefulWidget {
final bool hasLogined;
CollectionFullPage({Key key, this.hasLogined}) : super(key: key);
@override
_CollectionFullPageState createState() => _CollectionFullPageState();
}
class _CollectionFullPageState extends State<CollectionFullPage> {
_CollectionFullPageState() {
final eventBus = new EventBus();
ApplicationEvent.event = eventBus;
}
CollectionControlModel _collectionControl = new CollectionControlModel();
List<Collection> _collectionList = [];
ScrollController _scrollController = new ScrollController();
var _icons;
@override
void initState() {
super.initState();
_getList();
ApplicationEvent.event.on<CollectionEvent>().listen((event) {
_getList();
});
}
void _getList() {
_collectionList.clear();
_collectionControl.getAllCollection().then((resultList) {
resultList.forEach((item) {
_collectionList.add(item);
});
if (this.mounted) {
setState(() {
_collectionList = _collectionList;
});
}
});
}
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
Widget _renderList(context, index) {
if (index == 0) {
return Container(
height: 40.0,
padding: const EdgeInsets.only(left: 10.0),
child: Row(
children: <Widget>[
Icon(
Icons.warning,
size: 22.0,
),
SizedBox(
width: 5.0,
),
Text('模拟器重新运行会丢失收藏'),
],
),
);
}
if (_collectionList[index - 1].router.contains('http')) {
if (_collectionList[index - 1].name.endsWith('Doc')) {
_icons = Icons.library_books;
} else {
_icons = Icons.language;
}
} else {
_icons = Icons.extension;
}
return Container(
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 5.0),
margin: const EdgeInsets.only(bottom: 7.0),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
new BoxShadow(
color: const Color(0xFFd0d0d0),
blurRadius: 1.0,
spreadRadius: 2.0,
offset: Offset(3.0, 2.0),
),
],
),
child: ListTile(
leading: Icon(
_icons,
size: 30.0,
color: Theme.of(context).primaryColor,
),
title: Text(
Uri.decodeComponent(_collectionList[index - 1].name),
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 17.0),
),
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}");
}
},
),
);
}
ListView buildContent(){
if (_collectionList.length == 0) {
return ListView(
children: <Widget>[
Column(
children: <Widget>[
Image.asset(
'assets/images/nothing.png',
fit: BoxFit.contain,
width: MediaQuery.of(context).size.width / 2,
),
Text('暂无收藏,赶紧去收藏一个吧!'),
],
),
],
);
}
return ListView.builder(
itemBuilder: _renderList,
itemCount: _collectionList.length + 1,
controller: _scrollController,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('我的收藏'),
),
body: Container(
child: buildContent(),
),
);
}
}

View File

@ -1,5 +1,5 @@
/// @Author: 一凨
/// @Date: 2019-01-08 17:12:58
/// @Author: 一凨
/// @Date: 2019-01-08 17:12:58
/// @Last Modified by: 一凨
/// @Last Modified time: 2019-01-14 20:13:28
@ -12,8 +12,11 @@ import 'package:flutter_go/routers/routers.dart';
import 'package:flutter_go/event/event_bus.dart';
import 'package:flutter_go/event/event_model.dart';
class CollectionPage extends StatefulWidget {
final bool hasLogined;
CollectionPage({Key key, this.hasLogined}) : super(key: key);
_CollectionPageState createState() => _CollectionPageState();
}

View File

@ -1,3 +1,4 @@
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_go/model/user_info.dart';
import 'package:share/share.dart';
@ -25,6 +26,44 @@ class _DrawerPageState extends State<DrawerPage> {
hasLogin = this.widget.userInfo.id != 0;
}
void showLogoutDialog() {
if (hasLogin) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('确认退出登陆?'),
// content: Text('退出登陆后将没法进行'),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
// 退出登陆
DataUtils.logout().then((result) {
if (result) {
setState(() {
hasLogin = false;
});
Application.router.navigateTo(context, '${Routes.loginPage}',transition:TransitionType.nativeModal,clearStack: true);
}
});
},
child: Text('确认',style: TextStyle(color: Colors.red),),
),
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('取消'),
)
],
);
});
} else {
Application.router.navigateTo(context, '${Routes.loginPage}',transition:TransitionType.native,clearStack: true);
}
}
@override
Widget build(BuildContext context) {
print(hasLogin);
@ -59,7 +98,9 @@ class _DrawerPageState extends State<DrawerPage> {
'我的收藏',
style: textStyle,
),
onTap: () {},
onTap: () {
Application.router.navigateTo(context, '${Routes.collectionFullPage}?hasLogin=${hasLogin.toString()}',transition: TransitionType.fadeIn);
},
),
// new Divider(),
ListTile(
@ -88,7 +129,7 @@ class _DrawerPageState extends State<DrawerPage> {
DataUtils.feedback({
'title': "这是客户端 FeedBack title",
"body": "这是客户端 FeedBack body"
}).then((result) {
},context).then((result) {
print(result);
});
},
@ -127,21 +168,7 @@ class _DrawerPageState extends State<DrawerPage> {
hasLogin ? '退出登陆' : '点击登录',
style: textStyle,
),
onTap: () {
if (hasLogin) {
// 退出登陆
DataUtils.logout().then((result) {
if (result) {
setState(() {
hasLogin = false;
});
Application.router.navigateTo(context, '${Routes.loginPage}');
}
});
} else {
Application.router.navigateTo(context, '${Routes.loginPage}');
}
},
onTap: showLogoutDialog,
),
],
);

View File

@ -70,7 +70,7 @@ class _MyHomePageState extends State<AppPage>
// ..add(FirstPage())
..add(MainPage(userInfo: widget.userInfo))
..add(WidgetPage(Provider.db))
..add(CollectionPage())
..add(CollectionPage(hasLogined: widget.userInfo.id != 0))
..add(FourthPage());
}