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

图书馆列表

上级 29447b04
...@@ -5,7 +5,7 @@ abstract class LibraryAPI { ...@@ -5,7 +5,7 @@ abstract class LibraryAPI {
/// 1、图书分类 /// 1、图书分类
/// ///
static Future <List<CategoryModel>> categoryList() async { static Future <List<CategoryModel>> categories() async {
final result = await HttpService.to.post( final result = await HttpService.to.post(
'/v1/book/category/getCategoryListAll', '/v1/book/category/getCategoryListAll',
params: {}, params: {},
...@@ -18,7 +18,7 @@ abstract class LibraryAPI { ...@@ -18,7 +18,7 @@ abstract class LibraryAPI {
/// 2、图书标签 /// 2、图书标签
/// ///
static Future <List<LabelModel>> labelList() async { static Future <List<LabelModel>> labels() async {
final result = await HttpService.to.post( final result = await HttpService.to.post(
'/v1/book/category/getLabelListAll', '/v1/book/category/getLabelListAll',
params: {}, params: {},
...@@ -31,7 +31,7 @@ abstract class LibraryAPI { ...@@ -31,7 +31,7 @@ abstract class LibraryAPI {
/// 3、书籍列表 /// 3、书籍列表
/// ///
static Future <List<CourseModel>> bookList({ static Future <List<CourseModel>> books({
int page = 1, int page = 1,
int limit = 20, int limit = 20,
}) async { }) async {
...@@ -48,23 +48,6 @@ abstract class LibraryAPI { ...@@ -48,23 +48,6 @@ abstract class LibraryAPI {
}); });
} }
/// 4、收藏、取消收藏
static Future <bool> love({
required String bookId,
required String isSelect
}) async {
final result = await HttpService.to.post(
'/v1/book/Information/serachDel',
params: {
'book_id':bookId,
'is_select': isSelect
},
);
if (result.data is Map && result.data['is_success'] == 1){
return true;
}
return false;
}
......
part of library; part of library;
class LibraryController extends GetxController with GetSingleTickerProviderStateMixin{ class LibraryController extends GetxController with GetTickerProviderStateMixin{
final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true,
controlFinishRefresh: true,
);
late TabController tabController = TabController(length:7, vsync: this); // 分类数据
List<CategoryModel> categories = [];
// 标签数据
List<LabelModel> labels = [];
// 图书列表数据
List<CourseModel> books = [];
// 广告数组
List<AdModel> ads = [];
late TabController tabController = TabController(length:categories.length, vsync: this);
final int _limit = 20;
int _page = 1;
bool _noMore = false;
@override @override
void onInit() { void onInit() {
// 获取分类数据
_getTabs();
super.onInit(); super.onInit();
} }
@override
void onReady() {
// 获取标签数据
_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 _getAds() async {
ads = await CommonAPI.list(type: '1');
update();
}
/// 获取tab分类数据
void _getTabs() async {
categories = await LibraryAPI.categories();
tabController.dispose();
tabController = TabController(length:categories.length, vsync: this);
update();
}
/// 获取标签数据
void _getLabels() async {
labels = await LibraryAPI.labels();
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);
}
}
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; library library;
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_book/apis/index.dart';
import 'package:flutter_book/theme.dart'; import 'package:flutter_book/theme.dart';
import 'package:flutter_book/utils/index.dart'; import 'package:flutter_book/utils/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
...@@ -8,6 +10,7 @@ import 'package:get/get.dart'; ...@@ -8,6 +10,7 @@ import 'package:get/get.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:ionicons/ionicons.dart'; import 'package:ionicons/ionicons.dart';
import '../../models/index.dart';
import '../../routes/index.dart'; import '../../routes/index.dart';
import '../../widgets/index.dart'; import '../../widgets/index.dart';
import '../course/index.dart'; import '../course/index.dart';
......
...@@ -7,9 +7,9 @@ class LibraryPage extends StatefulWidget { ...@@ -7,9 +7,9 @@ class LibraryPage extends StatefulWidget {
State<LibraryPage> createState() => _LibraryPageState(); State<LibraryPage> createState() => _LibraryPageState();
} }
class _LibraryPageState extends State<LibraryPage> with AutomaticKeepAliveClientMixin,SingleTickerProviderStateMixin{ class _LibraryPageState extends State<LibraryPage> with SingleTickerProviderStateMixin{
//AutomaticKeepAliveClientMixin
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GetBuilder<LibraryController>( return GetBuilder<LibraryController>(
...@@ -48,15 +48,18 @@ class _LibraryPageState extends State<LibraryPage> with AutomaticKeepAliveClient ...@@ -48,15 +48,18 @@ class _LibraryPageState extends State<LibraryPage> with AutomaticKeepAliveClient
unselectedLabelStyle: TextStyle(color: Colours.c9,fontSize: 14,height: 1.5), unselectedLabelStyle: TextStyle(color: Colours.c9,fontSize: 14,height: 1.5),
controller: controller.tabController, controller: controller.tabController,
isScrollable: true, isScrollable: true,
tabs: [ tabs: controller.categories.map((model){
Tab(text: '全部'), return Tab(text: model.name);
Tab(text: '职业证书'), }).toList(),
Tab(text: '人文艺术'), // [
Tab(text: '财经管理'), // Tab(text: '全部'),
Tab(text: '待评价'), // Tab(text: '职业证书'),
Tab(text: '待评价1'), // Tab(text: '人文艺术'),
Tab(text: '待评价2'), // Tab(text: '财经管理'),
], // Tab(text: '待评价'),
// Tab(text: '待评价1'),
// Tab(text: '待评价2'),
// ],
), ),
), ),
GestureDetector( GestureDetector(
...@@ -93,25 +96,25 @@ class _LibraryPageState extends State<LibraryPage> with AutomaticKeepAliveClient ...@@ -93,25 +96,25 @@ class _LibraryPageState extends State<LibraryPage> with AutomaticKeepAliveClient
body: TabBarView( body: TabBarView(
controller: controller.tabController, controller: controller.tabController,
children: List.generate(7, (index){ children: List.generate(controller.categories.length, (index){
return LibraryContentPage(); return LibraryContentPage(controller: controller,);
}) })
), ),
), ),
); );
} }
/// 列表 // /// 列表
Widget createListView(){ // Widget createListView(){
return ListView.builder( // return ListView.builder(
itemBuilder: (BuildContext context, int index){ // itemBuilder: (BuildContext context, int index){
return LibraryCell(); // return LibraryCell();
}, // },
itemCount: 2, // itemCount: 2,
); // );
} // }
@override // @override
// TODO: implement wantKeepAlive // // TODO: implement wantKeepAlive
bool get wantKeepAlive => true; // bool get wantKeepAlive => true;
} }
part of library; part of library;
class LibraryCell extends StatefulWidget { class LibraryCell extends StatelessWidget {
const LibraryCell({Key? key}) : super(key: key); final CourseModel model;
final void Function() onTap;
const LibraryCell({
Key? key,
required this.model,
required this.onTap
}) : super(key: key);
@override
State<LibraryCell> createState() => _LibraryCellState();
}
class _LibraryCellState extends State<LibraryCell> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: const EdgeInsets.only(top: 10), padding: const EdgeInsets.only(top: 10),
height: 150,
// color: Colors.red, // color: Colors.red,
child: Stack( child: Stack(
children: [ children: [
Container( Container(
padding: EdgeInsets.only(left: 10,top: 10,bottom: 20), padding: const EdgeInsets.only(left: 10,top: 10,bottom: 20),
margin: EdgeInsets.only(top:15,left: 10,right: 10), margin: const EdgeInsets.only(top:15,left: 10,right: 10),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
...@@ -26,59 +28,49 @@ class _LibraryCellState extends State<LibraryCell> { ...@@ -26,59 +28,49 @@ class _LibraryCellState extends State<LibraryCell> {
color: Colours.cC7.withOpacity(0.5), // 阴影颜色 color: Colours.cC7.withOpacity(0.5), // 阴影颜色
spreadRadius: 2, // 阴影扩散半径 spreadRadius: 2, // 阴影扩散半径
blurRadius: 5, // 阴影模糊半径 blurRadius: 5, // 阴影模糊半径
offset: Offset(0, 2), // 阴影偏移 offset: const Offset(0, 2), // 阴影偏移
), ),
], ],
), ),
// height: 200,
// color: Colors.cyanAccent,
child: Row( child: Row(
children: [ children: [
/// 左侧 /// 左侧
Container( Container(
width: 100, width: 100,
height: 105, height: 120,
color: Colors.red, color: Colors.red,
), ),
/// 右侧 /// 右侧
Expanded( Expanded(
child: Container( child: Container(
margin: const EdgeInsets.only(left: 10,right: 10), margin: const EdgeInsets.only(left: 10,right: 10),
// color: Colors.red,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: [ children: [
// SizedBox(height: 10,), // SizedBox(height: 10,),
Text('标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题',overflow: TextOverflow.ellipsis,maxLines: 2,style: TextStyle(fontSize: 14,fontWeight: Fonts.medium,height: 1.5,color: Colours.c3),), Text(model.bookName??'',overflow: TextOverflow.ellipsis,maxLines: 2,style: const TextStyle(fontSize: 14,fontWeight: Fonts.medium,height: 1.5,color: Colours.c3),),
SizedBox(height: 4,), // const SizedBox(height: 4,),
Text('威廉·莎士比亚',style: TextStyle(fontSize: 11,color: Colours.c9,height: 1.5),),
Gaps.vGaps15,
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
children: [ children: [
Text('¥88',style: TextStyle(fontSize: 14,height: 1.5,color: AppTheme.primary,fontWeight: Fonts.medium),), Text(model.authors??'',style: TextStyle(fontSize: 11,color: Colours.c9,height: 1.5),),
SizedBox(width: 10,),
Text('108',style: TextStyle(
decoration: TextDecoration.combine([
TextDecoration.lineThrough
]),
decorationColor: Colors.red,fontSize: 12,height: 1.5,color: Colours.c9
),),
],
),
Row( Row(
children: [ children: [
Text('103万人读过',style:TextStyle(fontSize: 11,height: 1.5,color: Colours.cC7)), Text('${model.readNum.toString()}人读过',style:TextStyle(fontSize: 11,height: 1.5,color: Colours.cC7)),
Gaps.hGaps5, Gaps.hGaps5,
Container( GestureDetector(
onTap: onTap,
child: SizedBox(
width: 20, width: 20,
height: 20, height: 20,
// color: Colors.yellow, // color: Colors.yellow,
child: Image.asset( child: Image.asset(
'assets/images/unlove.png', model.isCollection == 0? 'assets/images/unlove.png':'assets/images/love.png',
),
), ),
) )
], ],
...@@ -100,9 +92,9 @@ class _LibraryCellState extends State<LibraryCell> { ...@@ -100,9 +92,9 @@ class _LibraryCellState extends State<LibraryCell> {
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3), borderRadius: BorderRadius.circular(3),
color: Colors.cyan, color: Colors.cyan,
), ),
width: 100, width: 100,
child: CustomImage.network(url: model.img??''),
), ),
), ),
], ],
......
part of library; part of library;
class LibraryContentPage extends StatefulWidget { class LibraryContentPage extends StatefulWidget {
const LibraryContentPage({Key? key}) : super(key: key); final LibraryController controller;
// final CategoryModel categoryModel;
const LibraryContentPage({
Key? key,
required this.controller,
// required this.categoryModel
}) : super(key: key);
@override @override
State<LibraryContentPage> createState() => _LibraryContentPageState(); State<LibraryContentPage> createState() => _LibraryContentPageState();
...@@ -19,16 +25,20 @@ class _LibraryContentPageState extends State<LibraryContentPage> { ...@@ -19,16 +25,20 @@ class _LibraryContentPageState extends State<LibraryContentPage> {
scrollDirection:Axis.horizontal , scrollDirection:Axis.horizontal ,
itemBuilder: (BuildContext context, int index){ itemBuilder: (BuildContext context, int index){
return GestureDetector( return GestureDetector(
child: BookLibrarySubjectTypeWidget(), child: BuildLabelWidget(model: widget.controller.labels[index],),
onTap: (){ onTap: (){
}, },
); );
}, },
itemCount: 10, itemCount: widget.controller.labels.length,
), ),
), ),
Expanded( Expanded(
child: CustomPullScrollView(
controller: widget.controller.refreshController,
onRefresh: widget.controller.onRefresh,
onLoading: widget.controller.onLoading,
child: NestedScrollView( child: NestedScrollView(
headerSliverBuilder: (BuildContext context ,bool innerBoxIsScrolled){ headerSliverBuilder: (BuildContext context ,bool innerBoxIsScrolled){
return [ return [
...@@ -37,20 +47,24 @@ class _LibraryContentPageState extends State<LibraryContentPage> { ...@@ -37,20 +47,24 @@ class _LibraryContentPageState extends State<LibraryContentPage> {
Container( Container(
color: Colors.transparent, color: Colors.transparent,
padding: const EdgeInsets.symmetric(horizontal: 10), padding: const EdgeInsets.symmetric(horizontal: 10),
// child: const BuildBanner(items: ['111','222','333'],), child: BuildBanner(items: widget.controller.ads,),
), ),
]) ])
) )
]; ];
}, },
body: ListView.builder( body: ListView.builder(
itemCount: 50, itemCount: widget.controller.books.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return LibraryCell(); CourseModel model = widget.controller.books[index];
return LibraryCell(model: model,onTap: (){
widget.controller.love(bookId: model.bookId.toString(), isCollection: model.isCollection!);
},);
}, },
), ),
), ),
), ),
),
], ],
); );
} }
......
part of library; part of library;
class BookLibrarySubjectTypeWidget extends StatefulWidget {
const BookLibrarySubjectTypeWidget({super.key});
// late BookSubjectTypeEntity model; class BuildLabelWidget extends StatelessWidget {
@override final LabelModel model;
_BookLibrarySubjectTypeWidgetState createState() => _BookLibrarySubjectTypeWidgetState(); const BuildLabelWidget({
Key? key,
// BookLibrarySubjectTypeWidget(this.model); required this.model
} }) : super(key: key);
class _BookLibrarySubjectTypeWidgetState extends State<BookLibrarySubjectTypeWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
margin: EdgeInsets.only(left: 10), margin: const EdgeInsets.only(left: 10),
color: Colors.white, color: Colors.white,
width: 65, width: 65,
padding: const EdgeInsets.only(top: 10,bottom: 10), padding: const EdgeInsets.only(top: 10,bottom: 10),
child: Container( child: Container(
// padding: EdgeInsets.all(8), // padding: EdgeInsets.all(8),
alignment: Alignment.center, alignment: Alignment.center,
padding: EdgeInsets.only(left: 8,right:8 ), padding: const EdgeInsets.only(left: 8,right:8 ),
height: 23, height: 23,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(12.5)), borderRadius: const BorderRadius.all(Radius.circular(12.5)),
border: Border.all(color:AppTheme.primary,width: 0.5,style: BorderStyle.solid), border: Border.all(color:AppTheme.primary,width: 0.5,style: BorderStyle.solid),
// color: widget.model.selected == true?Colours.book_app_main:Colors.white, // color: widget.model.selected == true?Colours.book_app_main:Colors.white,
), ),
child: Text('最新',style: TextStyle(fontSize: 13,height: 1.5,color: AppTheme.primary,fontWeight: Fonts.medium),) child: Text(model.name??'',style: const TextStyle(fontSize: 13,height: 1.5,color: AppTheme.primary,fontWeight: Fonts.medium),)
), ),
); );
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论