提交 811b4ba5 authored 作者: yueweilu's avatar yueweilu

评分及书评界面 接口调试与数据绑定

上级 c2ab2006
......@@ -33,7 +33,7 @@ abstract class LibraryAPI {
///
static Future <List<CourseModel>> books({
int page = 1,
int limit = 20,
int limit = 10,
}) async {
final result = await HttpService.to.post(
'/v1/book/category/getBookList',
......@@ -48,8 +48,26 @@ abstract class LibraryAPI {
});
}
/// 4、评分及书评
///
static Future <List<ScoreModel>> scores({
int page = 1,
int limit = 10,
required String bookId
}) async {
final result = await HttpService.to.post(
'/v1/book/Information/getBookCommentList',
params: {
'page': page,
'pageSize': limit,
'book_id':bookId
},
);
if (result.data is! Map && result.data['list'] is! List) return [];
return List.generate(result.data['list'].length, (index){
return ScoreModel.fromJson(result.data['list'][index]);
});
}
}
\ No newline at end of file
......@@ -52,5 +52,73 @@ class LabelModel {
map['name'] = name;
return map;
}
}
/// 3、书籍评价模型
///
/// book_comment_id : 4
/// comments : "bbbbbbb"
/// rating : 4.5
/// create_time : "2021-09-01 18:38:27"
/// members_id : 385
/// users : "王多余5"
/// users_img : ""
class ScoreModel {
ScoreModel({
this.bookCommentId,
this.comments,
this.rating,
this.createTime,
this.membersId,
this.users,
this.usersImg,});
ScoreModel.fromJson(dynamic json) {
bookCommentId = json['book_comment_id'];
comments = json['comments'];
rating = json['rating'];
createTime = json['create_time'];
membersId = json['members_id'];
users = json['users'];
usersImg = json['users_img'];
}
num? bookCommentId;
String? comments;
num? rating;
String? createTime;
num? membersId;
String? users;
String? usersImg;
ScoreModel copyWith({ num? bookCommentId,
String? comments,
num? rating,
String? createTime,
num? membersId,
String? users,
String? usersImg,
}) => ScoreModel( bookCommentId: bookCommentId ?? this.bookCommentId,
comments: comments ?? this.comments,
rating: rating ?? this.rating,
createTime: createTime ?? this.createTime,
membersId: membersId ?? this.membersId,
users: users ?? this.users,
usersImg: usersImg ?? this.usersImg,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['book_comment_id'] = bookCommentId;
map['comments'] = comments;
map['rating'] = rating;
map['create_time'] = createTime;
map['members_id'] = membersId;
map['users'] = users;
map['users_img'] = usersImg;
return map;
}
}
......@@ -29,7 +29,7 @@ class _BookInfoPageState extends State<BookInfoPage> {
GestureDetector(
child: const Text('查看全部',style: TextStyle(fontSize: 11,color: Colours.c9),),
onTap: (){
context.pushNamed(Routes.bookScore);
context.pushNamed(Routes.bookScore,queryParameters: {'book_id':'110'});
},
),
Gaps.hGaps5,
......
part of book_score;
class BookScoreController extends GetxController {
final String bookId ;
BookScoreController(this.bookId);
final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true,
controlFinishRefresh: true,
);
// 评价列表
List <ScoreModel> scores = [];
@override
void onClose() {
refreshController.dispose();
super.onClose();
}
final int _limit = 10;
int _page = 1;
bool _noMore = false;
/// 获取课程内图书列表
Future<void> _getScores(String bookId,[bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
final result = await LibraryAPI.scores(
page: _page,
limit: _limit,
bookId: bookId
);
// 如果是刷新 清理数据
if (isRefresh) scores.clear();
scores.addAll(result);
_page ++;
_noMore = result.length < _limit;
update();
}
void onRefresh() async {
try {
await _getScores(bookId,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 _getScores(bookId);
refreshController.finishLoad();
} catch (error) {
refreshController.finishLoad(IndicatorResult.fail);
}
}
}
\ No newline at end of file
library book_score;
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_book/theme.dart';
import 'package:flutter_book/utils/index.dart';
import 'package:flutter_book/widgets/index.dart';
import 'package:flutter_star/flutter_star.dart';
import 'package:get/get.dart';
import '../../apis/index.dart';
import '../../models/index.dart';
part 'view.dart';
part 'widgets/item.dart';
\ No newline at end of file
part 'widgets/item.dart';
part 'controller.dart';
\ No newline at end of file
......@@ -3,7 +3,11 @@ part of book_score;
class BookScorePage extends StatefulWidget {
const BookScorePage({Key? key}) : super(key: key);
final String bookId;
const BookScorePage({
Key? key,
required this.bookId
}) : super(key: key);
@override
State<BookScorePage> createState() => _BookScorePageState();
......@@ -12,16 +16,24 @@ class BookScorePage extends StatefulWidget {
class _BookScorePageState extends State<BookScorePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('评分及书评'),
),
body: ListView.builder(
itemBuilder: (BuildContext context, int index){
return BuildItem();
},
itemCount: 5,
return GetBuilder<BookScoreController>(
init: BookScoreController(widget.bookId),
builder:(controller) => Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('评分及书评'),
),
body: CustomPullScrollView(
controller: controller.refreshController,
onRefresh: controller.onRefresh,
onLoading: controller.onLoading,
child: ListView.builder(
itemBuilder: (BuildContext context, int index){
return BuildItem(model: controller.scores[index],);
},
itemCount: controller.scores.length,
),
),
),
);
}
......
part of book_score;
class BuildItem extends StatelessWidget {
const BuildItem({Key? key}) : super(key: key);
final ScoreModel model;
const BuildItem({
Key? key,
required this.model
}) : super(key: key);
@override
Widget build(BuildContext context) {
......@@ -22,6 +26,7 @@ class BuildItem extends StatelessWidget {
borderRadius: BorderRadius.circular(8)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
......@@ -32,6 +37,7 @@ class BuildItem extends StatelessWidget {
color: Colors.cyan,
borderRadius: BorderRadius.circular(17.5)
),
child: CustomImage.network(url: model.usersImg??''),
),
Gaps.hGaps10,
Expanded(
......@@ -41,18 +47,18 @@ class BuildItem extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('张三',style: TextStyle(fontSize: 12,height: 1.3,color: Colours.c9),),
Text(model.users??'',style: const TextStyle(fontSize: 12,height: 1.3,color: Colours.c9),),
// Spacer(),
Text('2023-12-07',style: TextStyle(fontSize: 12,height: 1.3,color: Colours.c9),)
Text(model.createTime??'',style: const TextStyle(fontSize: 12,height: 1.3,color: Colours.c9),)
],
),
AbsorbPointer(
absorbing: true,
child: CustomRating(
max: 5,
score: 4.5,
score:model.rating!.toDouble() ,
star: const Star(
progress: 4,
progress: 7,
fillColor: AppTheme.primary,
size: 12,
emptyColor: Colours.cE2,
......@@ -65,7 +71,7 @@ class BuildItem extends StatelessWidget {
],
),
Gaps.vGaps15,
const Text('这本书里有很多我比较喜欢的内容,总体来说真的很不错,很喜欢。',style: TextStyle(fontSize: 14,height: 1.5,color: Colours.c3),)
Text(model.comments??'',style: const TextStyle(fontSize: 14,height: 1.5,color: Colours.c3),)
],
),
),
......
......@@ -222,7 +222,9 @@ abstract class Routes {
pageBuilder: (context, state) =>CupertinoPage(
name: state.uri.toString(),
key: state.pageKey,
child: const BookScorePage()
child: BookScorePage(
bookId: state.uri.queryParameters['book_id'].toString(),
)
)
),
GoRoute(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论