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

优化 笔记 错题 讨论 布局满足 UI 效果

上级 73519107
......@@ -69,7 +69,8 @@ abstract class MineAPI {
});
}
/// 紫金币记录
/// 4、紫金币记录
///
static Future <List<RecordModel>> coin({
int page = 1,
int limit = 10,
......@@ -87,7 +88,8 @@ abstract class MineAPI {
});
}
/// 积分记录
/// 5、积分记录
///
static Future <List<RecordModel>> point({
int page = 1,
int limit = 10,
......@@ -105,5 +107,24 @@ abstract class MineAPI {
});
}
/// 3、讨论
///
static Future <List<CourseModel>> discuss({
int page = 1,
int limit = 10,
}) async {
final result = await HttpService.to.post(
'/v1/members/Information/myComment',
params: {
'page': page,
'pageSize': limit,
},
);
if (result.data is! Map && result.data['list'] is! List) return [];
return List.generate(result.data['list'].length, (index){
return CourseModel.fromJson(result.data['list'][index]);
});
}
}
\ No newline at end of file
......@@ -41,6 +41,10 @@ class CourseModel {
this.wrongNum,
///
/// 笔记
this.commentNum,
///
});
CourseModel.fromJson(dynamic json) {
......@@ -72,6 +76,10 @@ class CourseModel {
/// 错题
wrongNum = json['wrong_num'];
///
/// 讨论
commentNum = json['comment_num'];
///
}
num? bookId;
String? bookName;
......@@ -103,6 +111,10 @@ class CourseModel {
num? wrongNum;
///
/// 讨论
num? commentNum;
///
......@@ -155,6 +167,10 @@ class CourseModel {
num? wrongNum,
///
/// 讨论
num? commentNum,
///
}) => CourseModel( bookId: bookId ?? this.bookId,
bookName: bookName ?? this.bookName,
authors: authors ?? this.authors,
......@@ -182,6 +198,10 @@ class CourseModel {
/// 错题
wrongNum: wrongNum ?? this.wrongNum,
///
/// 讨论
commentNum: commentNum ?? this.commentNum,
///
);
Map<String, dynamic> toJson() {
......@@ -204,7 +224,7 @@ class CourseModel {
map['cart_id'] = cartId;
map['notes_num'] = notesNum;
map['wrong_num'] = wrongNum;
map['comment_num'] = commentNum;
return map;
}
......
......@@ -43,7 +43,7 @@ class MineController extends GetxController {
userInfo = await MineAPI.userInfo();
reads = [
ReadModel(name: '笔记',value: userInfo['note_nums'].toString(),link: Routes.note),
ReadModel(name: '讨论',value: userInfo['comment_nums'].toString()),
ReadModel(name: '讨论',value: userInfo['comment_nums'].toString(),link: Routes.discuss),
ReadModel(name: '错题',value: userInfo['wrong_nums'].toString(),link: Routes.wrong),
ReadModel(name: '收藏',value: userInfo['collect_nums'].toString(),link: Routes.love)
];
......
part of user_discuss;
class UserDiscussController extends GetxController {
final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true,
controlFinishRefresh: true,
);
List<CourseModel> discuss = [];
final int _limit = 10;
int _page = 1;
bool _noMore = false;
@override
void onClose() {
refreshController.dispose();
super.onClose();
}
/// 获取讨论列表
Future<void> _getNotes([bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
final result = await MineAPI.discuss(
page: _page,
limit: _limit
);
// 如果是刷新 清理数据
if (isRefresh) discuss.clear();
discuss.addAll(result);
_page ++;
_noMore = result.length < _limit;
update();
}
void onRefresh() async {
try {
await _getNotes(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 _getNotes();
refreshController.finishLoad();
} catch (error) {
refreshController.finishLoad(IndicatorResult.fail);
}
}
}
\ No newline at end of file
library user_discuss;
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/widgets/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../models/index.dart';
import '../../utils/index.dart';
part 'view.dart';
part 'controller.dart';
part 'widgets/item.dart';
\ No newline at end of file
part of user_discuss;
class UserDiscussPage extends StatefulWidget {
const UserDiscussPage({Key? key}) : super(key: key);
@override
State<UserDiscussPage> createState() => _UserDiscussPageState();
}
class _UserDiscussPageState extends State<UserDiscussPage> {
@override
Widget build(BuildContext context) {
return GetBuilder<UserDiscussController>(
init: UserDiscussController(),
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.discuss[index],index: index,num: controller.discuss.length,);
},
itemCount: controller.discuss.length,
)
),
),
);
}
}
part of user_discuss;
class BuildItem extends StatelessWidget {
final CourseModel model;
final int index;
final int num;
const BuildItem({
Key? key,
required this.model,
required this.index,
required this.num
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 10),
padding: const EdgeInsets.symmetric(horizontal: 10),
// margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: Colors.white,
boxShadow: [
BoxShadow(
color: const Color(0xFFC7C7C7).withOpacity(0.5),
offset: const Offset(3, 0),
blurRadius: 10.w,
spreadRadius: 0.w,
),
],
),
child: Column(
children: [
index == 0 ? Container(
// padding: const EdgeInsets.only(left: 10),
height: 32,
width: double.infinity,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
),
color: Colors.white,
),
alignment: Alignment.centerLeft,
child: Text('共$num本书',style: const TextStyle(fontSize: 13,height: 1.5,color: Colours.c6),),
):const SizedBox(),
Container(
height: 0.5,
color: Colours.cF0,
),
Container(
padding: const EdgeInsets.only(top: 12,bottom: 15),
// color: Colors.red,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 87,
width: 73,
color: Colors.cyan,
),
Container(
height: 87,
margin: const EdgeInsets.only(left: 13),
// color: Colors.green,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(model.bookName??'',style: const TextStyle(fontSize: 14,height: 1.5,fontWeight: Fonts.medium,color: Colours.c3),),
Text(model.authors??'',style: const TextStyle(fontSize: 12,height: 1.5,color: Colours.c6),),
],
),
Text('${model.commentNum.toString()}讨论',style: const TextStyle(fontSize: 11,height: 1.5,color: AppTheme.primary)),
],
),
)
],
),
)
],
),
);
}
}
......@@ -19,7 +19,7 @@ class UserNoteController extends GetxController {
super.onClose();
}
/// 获取课程内图书列表
/// 获取笔记列表
Future<void> _getNotes([bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
......
......@@ -17,53 +17,16 @@ class _UserNotePageState extends State<UserNotePage> {
centerTitle: true,
title: const Text('笔记'),
),
body: Container(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
// color: Colors.yellow,
boxShadow: [
BoxShadow(
color: const Color(0xFFC7C7C7).withOpacity(0.5),
offset: const Offset(3, 0),
blurRadius: 10.w,
spreadRadius: 0.w,
),
],
),
child: CustomPullScrollView(
body: CustomPullScrollView(
controller: controller.refreshController,
onRefresh: controller.onRefresh,
onLoading: controller.onLoading,
child: SingleChildScrollView(
child: Column(
children: [
Container(
padding: const EdgeInsets.only(left: 10),
height: 32,
width: double.infinity,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
),
color: Colors.white,
),
alignment: Alignment.centerLeft,
child: Text('共${controller.notes.length}本书',style: const TextStyle(fontSize: 13,height: 1.5,color: Colours.c6),),
),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index){
return BuildItem(model: controller.notes[index],);
},
itemCount: controller.notes.length,
)
],
),
),
),
child:ListView.builder(
itemBuilder: (BuildContext context, int index){
return BuildItem(model: controller.notes[index],index: index,num: controller.notes.length,);
},
itemCount: controller.notes.length,
)
),
),
);
......
......@@ -2,9 +2,13 @@ part of user_notes;
class BuildItem extends StatelessWidget {
final CourseModel model;
final int index;
final int num;
const BuildItem({
Key? key,
required this.model
required this.model,
required this.index,
required this.num
}) : super(key: key);
@override
......
......@@ -19,7 +19,7 @@ class UserWrongController extends GetxController {
super.onClose();
}
/// 获取课程内图书列表
/// 获取错题列表
Future<void> _getWrongs([bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
......
......@@ -17,53 +17,16 @@ class _UserWrongPageState extends State<UserWrongPage> {
centerTitle: true,
title: const Text('错题'),
),
body: Container(
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
// color: Colors.yellow,
boxShadow: [
BoxShadow(
color: const Color(0xFFC7C7C7).withOpacity(0.5),
offset: const Offset(3, 0),
blurRadius: 10.w,
spreadRadius: 0.w,
),
],
),
child: CustomPullScrollView(
body: CustomPullScrollView(
controller: controller.refreshController,
onRefresh: controller.onRefresh,
onLoading: controller.onLoading,
child: SingleChildScrollView(
child: Column(
children: [
Container(
padding: const EdgeInsets.only(left: 10),
height: 32,
width: double.infinity,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
),
color: Colors.white,
),
alignment: Alignment.centerLeft,
child: Text('共${controller.wrongs.length}本书',style: const TextStyle(fontSize: 13,height: 1.5,color: Colours.c6),),
),
ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index){
return BuildItem(model: controller.wrongs[index],);
},
itemCount: controller.wrongs.length,
)
],
),
),
),
child:ListView.builder(
itemBuilder: (BuildContext context, int index){
return BuildItem(model: controller.wrongs[index],index: index,num: controller.wrongs.length,);
},
itemCount: controller.wrongs.length,
)
),
),
);
......
......@@ -2,9 +2,13 @@ part of user_wrong;
class BuildItem extends StatelessWidget {
final CourseModel model;
final int index;
final int num;
const BuildItem({
Key? key,
required this.model
required this.model,
required this.index,
required this.num
}) : super(key: key);
@override
......
......@@ -18,6 +18,7 @@ import 'package:flutter_book/pages/splash/index.dart';
import 'package:flutter_book/pages/study_history/index.dart';
import 'package:flutter_book/pages/study_report/index.dart';
import 'package:flutter_book/pages/user_coin/index.dart';
import 'package:flutter_book/pages/user_discuss/index.dart';
import 'package:flutter_book/pages/user_info/index.dart';
import 'package:flutter_book/pages/user_love/index.dart';
import 'package:flutter_book/pages/user_msg/index.dart';
......
......@@ -76,6 +76,8 @@ abstract class Routes {
static const note = 'note';
// 错题
static const wrong = 'wrong';
// 讨论
static const discuss = 'discuss';
static final GoRouter config = GoRouter(
......@@ -317,6 +319,15 @@ abstract class Routes {
child: const UserPointPage()
)
),
GoRoute(
path: '/$discuss',
name: discuss,
pageBuilder: (context, state) =>CupertinoPage(
name: state.uri.toString(),
key: state.pageKey,
child: const UserDiscussPage()
)
),
]
);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论