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

图书馆列表

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