提交 ea5b1d3f authored 作者: yueweilu's avatar yueweilu

图书馆界面还是有问题

上级 47cdef08
......@@ -145,10 +145,10 @@ abstract class CommonAPI {
'is_select':love
},
);
if (result.data is! Map && result.data['is_success'] == 1){
return true;
if (result.data is! Map || result.data['is_success'] == 0){
return false;
}
return false;
return true;
}
/// 10、上传文件
......
......@@ -37,16 +37,34 @@ abstract class LibraryAPI {
String sortField = '',
String sort = '',
String isFree = '',
String labelId = '',
required String categoryId
}) async {
Map<String,dynamic> params = {
'page' : page,
'limit' : limit,
'category_id':categoryId
};
if (sortField.isNotEmpty){
params['sort_field'] = sortField;
}
if (sort.isNotEmpty){
params['sort'] = sort;
}
if (isFree.isNotEmpty){
params['is_free'] = isFree;
}
if (sort.isNotEmpty){
params['sort'] = sort;
}
if (labelId.isNotEmpty){
params['label_id'] = labelId;
}
final result = await HttpService.to.post(
'/v1/book/category/getBookList',
params: {
'page': page,
'page_size': limit,
// 'sort_field':sortField,
// 'sort':sort,
// 'is_free':isFree
},
params: params
);
if (result.data is! Map && result.data['list'] is! List) return [];
return List.generate(result.data['list'].length, (index){
......
......@@ -24,7 +24,7 @@ class _BuildItemState extends State<BuildItem> {
});
},
child: Container(
margin: EdgeInsets.symmetric(horizontal: 15.w),
padding: EdgeInsets.symmetric(horizontal: 15.w),
height: 30.w,
color: Colors.white,
child: Row(
......@@ -74,7 +74,8 @@ class _BuildItemState extends State<BuildItem> {
Widget _buildSection(ChapterModel model){
return Container(
margin: const EdgeInsets.only(left: 60),
color: Colors.white,
padding: const EdgeInsets.only(left: 60),
child: Text(model.name??'',style:TextStyle(fontSize: 12,color: model.seen ==0? Colours.c3:Colours.c9,height: 1.6),),
);
}
......
......@@ -63,6 +63,7 @@ class BookDetailController extends GetxController with GetSingleTickerProviderSt
}
bool result = await CommonAPI.love(
bookId: bookId, love: isCollection.toString());
print('================================$result');
if (result) {
_getBookDetails();
}
......
......@@ -56,17 +56,20 @@ class _BookDetailPageState extends State<BookDetailPage> with SingleTickerProvid
height: 2,
color: const Color(0xFFF9F9F9),
),
TabBar(
labelColor: AppTheme.primary,
// isScrollable: true,
labelStyle: TextStyle(fontSize: 15.w,height: 1.4,fontWeight: Fonts.medium),
unselectedLabelColor: Colours.c9,
unselectedLabelStyle: TextStyle(fontSize: 15.w,height: 1.4),
indicatorSize: TabBarIndicatorSize.label,
indicatorColor: AppTheme.primary,
tabs:controller.tabs,
physics: const NeverScrollableScrollPhysics(),
controller: controller.tabController,
Container(
color: Colors.white,
child: TabBar(
labelColor: AppTheme.primary,
// isScrollable: true,
labelStyle: TextStyle(fontSize: 15.w,height: 1.4,fontWeight: Fonts.medium),
unselectedLabelColor: Colours.c9,
unselectedLabelStyle: TextStyle(fontSize: 15.w,height: 1.4),
indicatorSize: TabBarIndicatorSize.label,
indicatorColor: AppTheme.primary,
tabs:controller.tabs,
physics: const NeverScrollableScrollPhysics(),
controller: controller.tabController,
),
),
Expanded(
child: TabBarView(
......@@ -74,8 +77,8 @@ class _BookDetailPageState extends State<BookDetailPage> with SingleTickerProvid
children: [
BookCategoryPage(chapters: controller.chapters,),
Container(
margin: EdgeInsets.only(left: 15.w,right: 15.w,top:12.w),
// color: Colors.lightBlue,
padding: EdgeInsets.only(left: 15.w,right: 15.w,top:12.w),
color: Colors.white,
child: Text(controller.bookDetails.content??'',style: TextStyle(fontSize: 12.w,height: 1.5,color: Colours.c3),),
),
BookInfoPage(model:controller.bookDetails,)
......@@ -87,7 +90,8 @@ class _BookDetailPageState extends State<BookDetailPage> with SingleTickerProvid
),
bottomNavigationBar: SafeArea(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 15.w),
color: Colors.white,
padding: EdgeInsets.symmetric(horizontal: 15.w,vertical: 10.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
......
......@@ -10,7 +10,8 @@ class BookInfoPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 15.w,vertical: 18.w),
color: Colors.white,
padding: EdgeInsets.symmetric(horizontal: 15.w,vertical: 18.w),
child: Column(
children: [
// 评分容器
......
part of library;
class LibraryContentController extends GetxController {
final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true,
controlFinishRefresh: true,
);
// 图书列表数据
List<CourseModel> books = [];
final int _limit = 20;
int _page = 1;
bool _noMore = false;
@override
void onClose() {
refreshController.dispose();
super.onClose();
}
/// 收藏 与 取消收藏
void love({
required String bookId,
required num isCollection
}) async {
if (isCollection == 0){
isCollection = 1;
}
else{
isCollection = 0;
}
bool result = await CommonAPI.love(bookId: bookId, love: isCollection.toString());
if (result) {
onRefresh();
}
}
/// 获取图书列表数据
Future<void> _getBooks([bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
final result = await LibraryAPI.books(
page: _page,
limit: _limit, categoryId: '',
);
// 如果是刷新 清理数据
if (isRefresh) books.clear();
books.addAll(result);
_page ++;
_noMore = result.length < _limit;
update();
}
void onRefresh() async {
try {
await _getBooks(true);
refreshController.finishRefresh(IndicatorResult.success);
refreshController.resetFooter();
} catch (error) {
refreshController.finishRefresh(IndicatorResult.fail);
}
}
void onLoading() async {
if (_noMore) {
refreshController.finishLoad(IndicatorResult.noMore);
return;
}
try {
await _getBooks();
refreshController.finishLoad();
} catch (error) {
refreshController.finishLoad(IndicatorResult.fail);
}
}
}
\ No newline at end of file
part of library;
class LibraryController extends GetxController with GetTickerProviderStateMixin{
final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true,
controlFinishRefresh: true,
);
// 分类数据
List<CategoryModel> categories = [];
// 标签数据
List<LabelModel> labels = [];
// 图书列表数据
List<CourseModel> books = [];
// 广告数组
List<AdModel> ads = [];
......@@ -20,9 +14,7 @@ class LibraryController extends GetxController with GetTickerProviderStateMixin{
late TabController tabController = TabController(length:categories.length, vsync: this);
final int _limit = 20;
int _page = 1;
bool _noMore = false;
late AnimationController _controller;
bool _show = false;
......@@ -62,33 +54,15 @@ class LibraryController extends GetxController with GetTickerProviderStateMixin{
// 获取标签数据
_getLabels();
_getAds();
onRefresh();
super.onReady();
}
@override
void onClose() {
tabController.dispose();
refreshController.dispose();
super.onClose();
}
/// 收藏 与 取消收藏
void love({
required String bookId,
required num isCollection
}) async {
if (isCollection == 0){
isCollection = 1;
}
else{
isCollection = 0;
}
bool result = await CommonAPI.love(bookId: bookId, love: isCollection.toString());
if (result) {
onRefresh();
}
}
//
void selectLabel(LabelModel model){
for (LabelModel m in labels){
......@@ -118,52 +92,9 @@ class LibraryController extends GetxController with GetTickerProviderStateMixin{
labels = await LibraryAPI.labels();
selectedLabel = labels.first;
selectedLabel.selected = true;
update();
}
/// 获取图书列表数据
Future<void> _getBooks([bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
final result = await LibraryAPI.books(
page: _page,
limit: _limit
);
// 如果是刷新 清理数据
if (isRefresh) books.clear();
books.addAll(result);
_page ++;
_noMore = result.length < _limit;
update();
}
void onRefresh() async {
try {
await _getBooks(true);
refreshController.finishRefresh(IndicatorResult.success);
refreshController.resetFooter();
} catch (error) {
refreshController.finishRefresh(IndicatorResult.fail);
}
update(['label']);
}
void onLoading() async {
if (_noMore) {
refreshController.finishLoad(IndicatorResult.noMore);
return;
}
try {
await _getBooks();
refreshController.finishLoad();
} catch (error) {
refreshController.finishLoad(IndicatorResult.fail);
}
}
}
\ No newline at end of file
......@@ -24,4 +24,6 @@ part 'controller.dart';
part 'widgets/cell.dart';
part 'widgets/content.dart';
part 'widgets/subject.dart';
part 'widgets/filter.dart';
\ No newline at end of file
part 'widgets/filter.dart';
part 'test.dart';
part 'content_controller.dart';
\ No newline at end of file
part of library;
class TestPage extends StatefulWidget {
const TestPage({Key? key}) : super(key: key);
@override
State<LibraryPage> createState() => _LibraryPageState();
}
class _TestPageState extends State<TestPage> with AutomaticKeepAliveClientMixin {
//AutomaticKeepAliveClientMixin
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('分类'),
bottom: PreferredSize(
preferredSize: Size.fromHeight(48.w),
child: Container(
child: Row(
children: [
// TabBar放在左侧
Expanded(
child: TabBar(
tabs: [
Tab(text: 'Tab 1'),
Tab(text: 'Tab 2'),
Tab(text: 'Tab 3'),
Tab(text: 'Tab 4'),
Tab(text: 'Tab 5'),
],
),
),
// 筛选按钮放在右侧
IconButton(
icon: Icon(Icons.filter_list),
onPressed: () {
// 处理筛选按钮点击事件
},
),
],
),
),
)
),
body: Column(
children: [
Container(
height: 43, // 设置标签栏的高度
color: Colors.cyan, // 设置标签栏的颜色
// child: // 添加你的横向滑动标签组件
),
Expanded(
child: CustomScrollView(
slivers: [
// // 横向滑动的标签
// SliverToBoxAdapter(
// child: Container(
// height: 43, // 设置标签栏的高度
// color: Colors.grey, // 设置标签栏的颜色
// // child: // 添加你的横向滑动标签组件
// ),
// ),
// 广告位
SliverToBoxAdapter(
child: Container(
height: 100, // 设置广告位的高度
color: Colors.grey, // 设置广告位的颜色
)
),
SliverFillRemaining(
child: TabBarView(
children: [
// Tab 1 对应的内容
Container(
color: Colors.red,
),
// Tab 2 对应的内容
Container(
color: Colors.green,
),
// Tab 3 对应的内容
Container(
color: Colors.blue,
),
Container(
color: Colors.blue,
),
Container(
color: Colors.blue,
),
],
),
),
],
),
),
],
),
);
}
@override
bool get wantKeepAlive => true;
}
part of library;
class LibraryContentPage extends StatefulWidget {
final LibraryController controller;
final LibraryContentController controller;
// final CategoryModel categoryModel;
const LibraryContentPage({
Key? key,
......@@ -16,36 +16,21 @@ class LibraryContentPage extends StatefulWidget {
class _LibraryContentPageState extends State<LibraryContentPage> with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
return CustomPullScrollView(
controller: widget.controller.refreshController,
onRefresh: widget.controller.onRefresh,
onLoading: widget.controller.onLoading,
child: ListView.builder(
// shrinkWrap: true,
// physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
itemCount: widget.controller.books.length,
itemBuilder: (BuildContext context, int index) {
// if (index == 0){
// return Container(
// color: Colors.transparent,
// padding: const EdgeInsets.symmetric(horizontal: 10),
// child: BuildBanner(items: widget.controller.ads,),
// );
// }
// else {
CourseModel model = widget.controller.books[index];
return GestureDetector(
onTap: (){
context.pushNamed(Routes.bookDetail,queryParameters: {'book_id':model.bookId.toString()});
},
child: LibraryCell(model: model,onTap: (){
widget.controller.love(bookId: model.bookId.toString(), isCollection: model.isCollection!);
},),
);
}
// },
),
return ListView.builder(
// shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: widget.controller.books.length,
itemBuilder: (BuildContext context, int index) {
CourseModel model = widget.controller.books[index];
return GestureDetector(
onTap: (){
context.pushNamed(Routes.bookDetail,queryParameters: {'book_id':model.bookId.toString()});
},
child: LibraryCell(model: model,onTap: (){
widget.controller.love(bookId: model.bookId.toString(), isCollection: model.isCollection!);
},),
);
}
);
}
@override
......
part of library_content;
class LibraryContentController extends GetxController {
final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true,
controlFinishRefresh: true,
);
final int _limit = 10;
int _page = 1;
bool _noMore = false;
// 图书列表数据
List<CourseModel> books = [];
@override
void onReady() {
super.onReady();
}
@override
void onClose() {
refreshController.dispose();
super.onClose();
}
/// 收藏 与 取消收藏
void love({
required String bookId,
required num isCollection
}) async {
if (isCollection == 0){
isCollection = 1;
}
else{
isCollection = 0;
}
bool result = await CommonAPI.love(bookId: bookId, love: isCollection.toString());
if (result) {
onRefresh();
}
}
/// 获取图书列表数据
Future<void> _getBooks([bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
final result = await LibraryAPI.books(
page: _page,
limit: _limit
);
// 如果是刷新 清理数据
if (isRefresh) books.clear();
books.addAll(result);
_page ++;
_noMore = result.length < _limit;
update();
}
void onRefresh() async {
try {
await _getBooks(true);
refreshController.finishRefresh(IndicatorResult.success);
refreshController.resetFooter();
} catch (error) {
refreshController.finishRefresh(IndicatorResult.fail);
}
}
void onLoading() async {
if (_noMore) {
refreshController.finishLoad(IndicatorResult.noMore);
return;
}
try {
await _getBooks();
refreshController.finishLoad();
} catch (error) {
refreshController.finishLoad(IndicatorResult.fail);
}
}
}
\ No newline at end of file
// part of library_content;
//
// class LibraryContentController extends GetxController {
//
// final CategoryModel categoryModel;
// late LabelModel labelModel;
// LibraryContentController(this.categoryModel, this.labelModel);
//
// final EasyRefreshController refreshController = EasyRefreshController(
// controlFinishLoad: true,
// controlFinishRefresh: true,
// );
//
// // 广告数组
// List<AdModel> ads = [];
//
// final int _limit = 10;
// int _page = 1;
// bool _noMore = false;
//
//
// // 图书列表数据
// List<CourseModel> books = [];
//
//
// @override
// void onReady() {
//
// super.onReady();
// }
//
//
// @override
// void onClose() {
// refreshController.dispose();
// super.onClose();
// }
//
//
// /// 收藏 与 取消收藏
// void love({
// required String bookId,
// required num isCollection
// }) async {
// if (isCollection == 0){
// isCollection = 1;
// }
// else{
// isCollection = 0;
// }
// bool result = await CommonAPI.love(bookId: bookId, love: isCollection.toString());
// if (result) {
// onRefresh();
// }
// }
//
// /// 获取图书列表数据
// Future<void> _getBooks([bool isRefresh = false]) async {
// if (isRefresh) _page = 1;
// // 网路请求
// final result = await LibraryAPI.books(
// page: _page,
// limit: _limit,
// categoryId: categoryModel.categoryId.toString(),
// labelId: labelModel.labelId.toString()
// );
// // 如果是刷新 清理数据
// if (isRefresh) books.clear();
// books.addAll(result);
// _page ++;
// _noMore = result.length < _limit;
// update();
//
// }
//
// void onRefresh() async {
// try {
// await _getBooks(true);
// refreshController.finishRefresh(IndicatorResult.success);
// refreshController.resetFooter();
// } catch (error) {
// refreshController.finishRefresh(IndicatorResult.fail);
// }
// }
//
// void onLoading() async {
// if (_noMore) {
// refreshController.finishLoad(IndicatorResult.noMore);
// return;
// }
// try {
// await _getBooks();
// refreshController.finishLoad();
// } catch (error) {
// refreshController.finishLoad(IndicatorResult.fail);
// }
// }
//
// }
\ No newline at end of file
library library_content;
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/src/simple/get_controllers.dart';
import 'package:go_router/go_router.dart';
import '../../apis/index.dart';
import '../../models/index.dart';
import '../../routes/index.dart';
import '../../widgets/index.dart';
import '../course/index.dart';
import '../library/index.dart';
part 'view.dart';
part 'controller.dart';
\ No newline at end of file
// library library_content;
//
// import 'package:easy_refresh/easy_refresh.dart';
// import 'package:flutter/material.dart';
// import 'package:get/get.dart';
// import 'package:get/get_state_manager/src/simple/get_controllers.dart';
// import 'package:go_router/go_router.dart';
//
// import '../../apis/index.dart';
// import '../../models/index.dart';
// import '../../routes/index.dart';
// import '../../widgets/index.dart';
// import '../course/index.dart';
// import '../library/index.dart';
//
// part 'view.dart';
// part 'controller.dart';
\ No newline at end of file
part of library_content;
class LibraryContentPage extends StatefulWidget {
final CategoryModel categoryModel;
final LabelModel labelModel;
const LibraryContentPage({
Key? key,
required this.categoryModel,
required this.labelModel
}) : super(key: key);
@override
State<LibraryContentPage> createState() => _LibraryContentPageState();
}
class _LibraryContentPageState extends State<LibraryContentPage> with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
return GetBuilder<LibraryContentController>(
init: LibraryContentController(),
builder: (controller) => CustomPullScrollView(
controller: controller.refreshController,
onRefresh: controller.onRefresh,
onLoading: controller.onLoading,
child: ListView.builder(
itemCount: controller.books.length,
itemBuilder: (BuildContext context, int index) {
// if (index == 0){
// return Container(
// color: Colors.transparent,
// padding: const EdgeInsets.symmetric(horizontal: 10),
// child: BuildBanner(items: controller.ads,),
// );
// }
// else {
CourseModel model = controller.books[index];
return GestureDetector(
onTap: (){
context.pushNamed(Routes.bookDetail,queryParameters: {'book_id':model.bookId.toString()});
},
child: LibraryCell(model: model,onTap: (){
controller.love(bookId: model.bookId.toString(), isCollection: model.isCollection!);
},),
);
}
// },
),
),
);
}
@override
bool get wantKeepAlive => true;
}
// part of library_content;
//
// class LibraryContentPage extends StatefulWidget {
// final CategoryModel categoryModel;
// final LabelModel labelModel;
// final String tag;
// const LibraryContentPage({
// Key? key,
// required this.categoryModel,
// required this.labelModel,
// required this.tag
// }) : super(key: key);
//
// @override
// State<LibraryContentPage> createState() => _LibraryContentPageState();
// }
//
// class _LibraryContentPageState extends State<LibraryContentPage> {
// @override
// Widget build(BuildContext context) {
// return GetBuilder<LibraryContentController>(
// // tag: widget.tag,
// init: LibraryContentController(widget.categoryModel,widget.labelModel),
// builder: (controller) => CustomPullScrollView(
// controller: controller.refreshController,
// onRefresh: controller.onRefresh,
// onLoading: controller.onLoading,
// child: ListView.builder(
// itemCount: controller.books.length+1,
// itemBuilder: (BuildContext context, int index) {
// if (index == 0){
// return Container(
// color: Colors.red,
// padding: const EdgeInsets.symmetric(horizontal: 10),
// child: BuildBanner(items: controller.ads,),
// );
// }
// else {
// CourseModel model = controller.books[index-1];
// return GestureDetector(
// onTap: (){
// context.pushNamed(Routes.bookDetail,queryParameters: {'book_id':model.bookId.toString()});
// },
// child: LibraryCell(model: model,onTap: (){
// controller.love(bookId: model.bookId.toString(), isCollection: model.isCollection!);
// },),
// );
// }
// },
// ),
// ),
// );
// }
// // @override
// // bool get wantKeepAlive => true;
// }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论