提交 7726d3a0 authored 作者: yueweilu's avatar yueweilu

1、添加图标

2、课程接口
上级 a290cd06
part of apis;
abstract class CourseAPI {
/// 获取课程 内书籍列表
static Future <List<CourseModel>> list({
int page = 1,
int limit = 20,
}) async {
final result = await HttpService.to.post(
'/v1/members/Information/myCourse',
params: {
'currentPage': 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
...@@ -2,6 +2,7 @@ library apis; ...@@ -2,6 +2,7 @@ library apis;
import 'dart:io'; import 'dart:io';
import 'package:flutter_book/models/course.dart';
import 'package:flutter_book/store/index.dart'; import 'package:flutter_book/store/index.dart';
import '../models/user_model.dart'; import '../models/user_model.dart';
...@@ -9,3 +10,4 @@ import '../services/index.dart'; ...@@ -9,3 +10,4 @@ import '../services/index.dart';
part 'account.dart'; part 'account.dart';
part 'mine.dart'; part 'mine.dart';
part 'course.dart';
\ No newline at end of file
/// book_id : 2
/// book_name : "五禽戏"
/// authors : "华佗"
/// img : "https://resource.vning.net/book/img/vning_hEBkC8RG26_1646976647301.jpg"
/// progress : "0%"
class CourseModel {
CourseModel({
this.bookId,
this.bookName,
this.authors,
this.img,
this.progress,
});
CourseModel.fromJson(dynamic json) {
bookId = json['book_id'];
bookName = json['book_name'];
authors = json['authors'];
img = json['img'];
progress = json['progress'];
}
num? bookId;
String? bookName;
String? authors;
String? img;
String? progress;
int get type {
if (progress == '0.00%'){
return 0;
} else if (progress == '100.00%'){
return 1;
} else {
return 2;
}
}
String get typeName {
if (progress == '0.00%'){
return '未学习';
} else if (progress == '100.00%'){
return '已学完';
} else {
return '已学习$progress';
}
}
CourseModel copyWith({ num? bookId,
String? bookName,
String? authors,
String? img,
String? progress,
}) => CourseModel( bookId: bookId ?? this.bookId,
bookName: bookName ?? this.bookName,
authors: authors ?? this.authors,
img: img ?? this.img,
progress: progress ?? this.progress,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['book_id'] = bookId;
map['book_name'] = bookName;
map['authors'] = authors;
map['img'] = img;
map['progress'] = progress;
return map;
}
}
\ No newline at end of file
...@@ -3,7 +3,7 @@ part of course; ...@@ -3,7 +3,7 @@ part of course;
class CourseController extends GetxController { class CourseController extends GetxController {
late final List<String> courses; List<CourseModel> courses = [];
final EasyRefreshController refreshController = EasyRefreshController( final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true, controlFinishLoad: true,
...@@ -24,10 +24,13 @@ class CourseController extends GetxController { ...@@ -24,10 +24,13 @@ class CourseController extends GetxController {
Future<void> _getCourse([bool isRefresh = false]) async { Future<void> _getCourse([bool isRefresh = false]) async {
if (isRefresh) _page = 1; if (isRefresh) _page = 1;
/// 网路请求 /// 网路请求
List result = []; final result = await CourseAPI.list(
page: _page,
limit: _limit
);
/// 如果是刷新 清理数据 /// 如果是刷新 清理数据
if (isRefresh) courses.clear(); if (isRefresh) courses.clear();
courses.addAll([]); courses.addAll(result);
_page ++; _page ++;
_noMore = result.length < _limit; _noMore = result.length < _limit;
update(); update();
...@@ -47,6 +50,7 @@ class CourseController extends GetxController { ...@@ -47,6 +50,7 @@ class CourseController extends GetxController {
void onLoading() async { void onLoading() async {
if (_noMore) { if (_noMore) {
refreshController.finishLoad(IndicatorResult.noMore); refreshController.finishLoad(IndicatorResult.noMore);
return;
} }
try { try {
await _getCourse(); await _getCourse();
......
...@@ -5,6 +5,7 @@ import 'dart:math'; ...@@ -5,6 +5,7 @@ import 'dart:math';
import 'package:carousel_slider/carousel_slider.dart'; import 'package:carousel_slider/carousel_slider.dart';
import 'package:easy_refresh/easy_refresh.dart'; import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_book/models/course.dart';
import 'package:flutter_book/theme.dart'; import 'package:flutter_book/theme.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
......
...@@ -29,7 +29,9 @@ class _CoursePageState extends State<CoursePage> { ...@@ -29,7 +29,9 @@ class _CoursePageState extends State<CoursePage> {
CustomButton.icon( CustomButton.icon(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
icon: const Icon(Ionicons.timer), icon: Image.asset(
'assets/images/read_history.png',
),
onPressed: () => context.pushNamed(Routes.studyHistory), onPressed: () => context.pushNamed(Routes.studyHistory),
), ),
GestureDetector( GestureDetector(
...@@ -47,7 +49,9 @@ class _CoursePageState extends State<CoursePage> { ...@@ -47,7 +49,9 @@ class _CoursePageState extends State<CoursePage> {
child: CustomButton.icon( child: CustomButton.icon(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
icon: const Icon(Ionicons.notifications), icon: Image.asset(
'assets/images/msg_black.png',
),
// onPressed: () => context.pushNamed(Routes.msgs), // onPressed: () => context.pushNamed(Routes.msgs),
), ),
), ),
...@@ -84,13 +88,13 @@ class _CoursePageState extends State<CoursePage> { ...@@ -84,13 +88,13 @@ class _CoursePageState extends State<CoursePage> {
), ),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return GestureDetector( return GestureDetector(
child: const Book(), child: Book(model: controller.courses[index],),
onTap: (){ onTap: (){
context.pushNamed(Routes.bookDetail); context.pushNamed(Routes.bookDetail);
}, },
); );
}, },
itemCount: 10, itemCount: controller.courses.length,
), ),
), ),
), ),
......
part of course; part of course;
class Book extends StatelessWidget { class Book extends StatelessWidget {
const Book({Key? key}) : super(key: key); final CourseModel model;
const Book({
Key? key,
required this.model
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -26,31 +30,50 @@ class Book extends StatelessWidget { ...@@ -26,31 +30,50 @@ class Book extends StatelessWidget {
Expanded( Expanded(
child: AspectRatio( child: AspectRatio(
aspectRatio: 0.85, aspectRatio: 0.85,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: Colors.white,
boxShadow: [
BoxShadow(
color: const Color(0xFF707070).withOpacity(0.5),
offset: const Offset(0, 0),
blurRadius: 4.5.w,
spreadRadius: 0.w,
),
],
),
padding: EdgeInsets.all(1),
child: Container( child: Container(
// margin: const EdgeInsets.only(top: 16,bottom: 10), // margin: const EdgeInsets.only(top: 16,bottom: 10),
color: Colors.red, // color: Colors.red,
child: Image.network(model.img.toString()),
// width: 85, // width: 85,
), ),
), ),
), ),
),
Gaps.vGaps10, Gaps.vGaps10,
const Column( SizedBox(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text('从现在开始,为精彩活从现在开始,为精彩活',style: TextStyle(fontSize: 13,height: 1.5,color: Colours.c3),maxLines: 1,overflow: TextOverflow.ellipsis,), Text(model.bookName??'',style: const TextStyle(fontSize: 13,height: 1.5,color: Colours.c3),maxLines: 1,overflow: TextOverflow.ellipsis,),
Text('作者',style: TextStyle(fontSize:12,height: 1.3,color: Colours.c6,),textAlign: TextAlign.left,), Text(model.authors ??'',style: const TextStyle(fontSize:12,height: 1.3,color: Colours.c6,),textAlign: TextAlign.left,),
], ],
), ),
),
Gaps.vGaps5, Gaps.vGaps5,
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Container( Container(
color: Colors.cyan, color: model.type ==0||model.type ==1 ?Colours.cEF :AppTheme.primary.withOpacity(0.1),
padding: const EdgeInsets.symmetric(horizontal: 3.5), padding: const EdgeInsets.symmetric(horizontal: 3.5),
child: const Text('未学习',style: TextStyle(fontSize: 11,height: 1.3,color: Colours.c9),), child: Text(model.typeName,style: TextStyle(fontSize: 11,height: 1.3,color: model.type ==0||model.type ==1 ?Colours.c9:AppTheme.primary),),
), ),
const Text('继续学习',style: TextStyle(fontSize: 11,height: 1.3,color: AppTheme.primary),) model.type == 2? const Text('继续学习',style: TextStyle(fontSize: 11,height: 1.3,color: AppTheme.primary,fontWeight: Fonts.medium),):const SizedBox()
], ],
) )
], ],
......
...@@ -50,12 +50,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver{ ...@@ -50,12 +50,12 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver{
builder: (controller) => BottomNavigationBar( builder: (controller) => BottomNavigationBar(
currentIndex:controller.currentPage , currentIndex:controller.currentPage ,
onTap: (page){ onTap: (page){
// if (page != 1 && !UserStore.to.isLogin) { if (page != 1 && !UserStore.to.isLogin) {
// context.pushNamed(Routes.login); context.pushNamed(Routes.login);
// } else { } else {
// controller.pageController.jumpToPage(page);
// }
controller.pageController.jumpToPage(page); controller.pageController.jumpToPage(page);
}
// controller.pageController.jumpToPage(page);
}, },
items: [ items: [
BottomNavigationBarItem( BottomNavigationBarItem(
......
...@@ -20,19 +20,25 @@ class _MinePageState extends State<MinePage> { ...@@ -20,19 +20,25 @@ class _MinePageState extends State<MinePage> {
CustomButton.icon( CustomButton.icon(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
icon: const Icon(Ionicons.timer), icon: Image.asset(
onPressed: () => context.pushNamed(Routes.coin), 'assets/images/read_history.png',
),
onPressed: () => context.pushNamed(Routes.studyHistory),
), ),
CustomButton.icon( CustomButton.icon(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
icon: const Icon(Ionicons.settings), icon: Image.asset(
'assets/images/set.png',
),
onPressed: () => context.pushNamed(Routes.msgs), onPressed: () => context.pushNamed(Routes.msgs),
), ),
CustomButton.icon( CustomButton.icon(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
icon: const Icon(Ionicons.notifications), icon: Image.asset(
'assets/images/msg_black.png',
),
onPressed: () => context.pushNamed(Routes.msgs), onPressed: () => context.pushNamed(Routes.msgs),
), ),
], ],
......
...@@ -27,6 +27,7 @@ class Colours { ...@@ -27,6 +27,7 @@ class Colours {
static const cE2 = Color(0xFFE2E2E2); static const cE2 = Color(0xFFE2E2E2);
static const cE5 = Color(0xFFE5E5E5); static const cE5 = Color(0xFFE5E5E5);
static const cE7 = Color(0xFFE7E7E7); static const cE7 = Color(0xFFE7E7E7);
static const cEF = Color(0xFFEFEFEF);
static const cF0 = Color(0xFFF0F0F0); static const cF0 = Color(0xFFF0F0F0);
static const cF2 = Color(0xFFF2F2F2); static const cF2 = Color(0xFFF2F2F2);
static const cF4 = Color(0xFFF4F4F4); static const cF4 = Color(0xFFF4F4F4);
......
...@@ -34,7 +34,7 @@ class CustomButton extends StatelessWidget { ...@@ -34,7 +34,7 @@ class CustomButton extends StatelessWidget {
factory CustomButton.icon({ factory CustomButton.icon({
Key? key, Key? key,
required Icon icon, required Widget icon,
void Function()? onPressed, void Function()? onPressed,
Color? foregroundColor, Color? foregroundColor,
Color? backgroundColor, Color? backgroundColor,
...@@ -159,7 +159,7 @@ class CustomButton extends StatelessWidget { ...@@ -159,7 +159,7 @@ class CustomButton extends StatelessWidget {
} }
class _ButtonWithIcon extends CustomButton { class _ButtonWithIcon extends CustomButton {
final Icon icon; final Widget icon;
_ButtonWithIcon({ _ButtonWithIcon({
Key? key, Key? key,
...@@ -194,7 +194,7 @@ class _ButtonWithIcon extends CustomButton { ...@@ -194,7 +194,7 @@ class _ButtonWithIcon extends CustomButton {
} }
class _ButtonWithIconChild extends StatelessWidget { class _ButtonWithIconChild extends StatelessWidget {
final Icon icon; final Widget icon;
final CustomButtonSize size; final CustomButtonSize size;
final EdgeInsetsGeometry? padding; final EdgeInsetsGeometry? padding;
......
...@@ -21,7 +21,7 @@ class CustomPullScrollView extends StatelessWidget { ...@@ -21,7 +21,7 @@ class CustomPullScrollView extends StatelessWidget {
return EasyRefresh( return EasyRefresh(
header: const ClassicHeader(showText: false header: const ClassicHeader(showText: false
), ),
footer: const ClassicFooter(showText: false), footer: const ClassicFooter(showText: false,noMoreIcon: SizedBox()),
controller: controller, controller: controller,
onRefresh: onRefresh, onRefresh: onRefresh,
onLoad: onLoading, onLoad: onLoading,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论