提交 74e379ca authored 作者: yueweilu's avatar yueweilu

调试接口

上级 7726d3a0
...@@ -2,7 +2,8 @@ part of apis; ...@@ -2,7 +2,8 @@ part of apis;
abstract class AccountAPI { abstract class AccountAPI {
/// 登录 /// 1、登录
///
static Future <UserModel> login({ static Future <UserModel> login({
required String phone, required String phone,
required String type, required String type,
...@@ -37,7 +38,8 @@ abstract class AccountAPI { ...@@ -37,7 +38,8 @@ abstract class AccountAPI {
return UserModel.fromJson(result.data); return UserModel.fromJson(result.data);
} }
/// 退出登录 /// 2、退出登录
///
static Future logout() async{ static Future logout() async{
final result = await HttpService.to.post( final result = await HttpService.to.post(
'/v1/members/login/logout', '/v1/members/login/logout',
...@@ -49,7 +51,8 @@ abstract class AccountAPI { ...@@ -49,7 +51,8 @@ abstract class AccountAPI {
return false; return false;
} }
/// 注销 /// 3、注销
///
static Future delete() async{ static Future delete() async{
final result = await HttpService.to.post( final result = await HttpService.to.post(
'/v1/members/login/del', '/v1/members/login/del',
...@@ -61,7 +64,8 @@ abstract class AccountAPI { ...@@ -61,7 +64,8 @@ abstract class AccountAPI {
return false; return false;
} }
/// 发送验证码 /// 4、发送验证码
///
static Future sendCode({ static Future sendCode({
required String phone, required String phone,
required String type, required String type,
...@@ -81,7 +85,8 @@ abstract class AccountAPI { ...@@ -81,7 +85,8 @@ abstract class AccountAPI {
return false; return false;
} }
/// 重置密码 /// 5、重置密码
///
static Future resetPassword({ static Future resetPassword({
required String phone, required String phone,
required String code, required String code,
......
part of apis;
abstract class CommonAPI {
/// 1、广告位接口
///
static Future <List<AdModel>> list({
required String type,
}) async {
final result = await HttpService.to.post(
'/v1/ad/ad/getListAll',
params: {
'type': type,
},
);
if (result.data is! Map && result.data['list'] is! List) return [];
return List.generate(result.data['list'].length, (index){
return AdModel.fromJson(result.data['list'][index]);
});
}
/// 2、消息接口
///
static Future <List<MsgModel>> msgs({
int page = 1,
int limit = 10,
}) async {
final result = await HttpService.to.post(
'/v1/message/Message/getList',
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 MsgModel.fromJson(result.data['list'][index]);
});
}
/// 3、消息未读数
///
static Future <int> num() async {
final result = await HttpService.to.post(
'/v1/message/Message/getMessageNums',
params: {},
);
if (result.data is! Map ) return 0;
return result.data['num'];
}
/// 4、最近学习
///
static Future <List<StudyHistoryModel>> history({
int page = 1,
int limit = 10,
}) async {
final result = await HttpService.to.post(
'/v1/members/Information/myReadRecord',
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 StudyHistoryModel.fromJson(result.data['list'][index]);
});
}
/// 5、消息未读变已读
///
static Future <bool> read({
required String id
}) async {
final result = await HttpService.to.post(
'/v1/message/Message/editOneStatus',
params: {
'id':id
},
);
if (result.data is Map && result.data['is_success'] == 1){
return true;
}
return false;
}
}
\ No newline at end of file
...@@ -2,7 +2,8 @@ part of apis; ...@@ -2,7 +2,8 @@ part of apis;
abstract class CourseAPI { abstract class CourseAPI {
/// 获取课程 内书籍列表 /// 1、获取课程 内书籍列表
///
static Future <List<CourseModel>> list({ static Future <List<CourseModel>> list({
int page = 1, int page = 1,
int limit = 20, int limit = 20,
......
library apis; library apis;
import 'dart:io';
import 'package:flutter_book/models/course.dart'; import '../models/index.dart';
import 'package:flutter_book/store/index.dart';
import '../models/user_model.dart';
import '../services/index.dart'; import '../services/index.dart';
part 'account.dart'; part 'account.dart';
part 'mine.dart'; part 'mine.dart';
part 'course.dart'; part 'course.dart';
part 'common.dart';
part 'library.dart';
part 'shop.dart';
\ No newline at end of file
part of apis;
\ No newline at end of file
part of apis;
\ No newline at end of file
part of models;
/// pic : "1.jpg"
/// url : "http://www.baidu.com"
class AdModel {
AdModel({
this.pic,
this.url,});
AdModel.fromJson(dynamic json) {
pic = json['pic'];
url = json['url'];
}
String? pic;
String? url;
AdModel copyWith({ String? pic,
String? url,
}) => AdModel( pic: pic ?? this.pic,
url: url ?? this.url,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['pic'] = pic;
map['url'] = url;
return map;
}
}
\ No newline at end of file
part of models;
/// book_id : 2 /// book_id : 2
/// book_name : "五禽戏" /// book_name : "五禽戏"
/// authors : "华佗" /// authors : "华佗"
...@@ -11,6 +13,9 @@ class CourseModel { ...@@ -11,6 +13,9 @@ class CourseModel {
this.authors, this.authors,
this.img, this.img,
this.progress, this.progress,
this.lastChapter,
this.createTime,
this.days
}); });
CourseModel.fromJson(dynamic json) { CourseModel.fromJson(dynamic json) {
...@@ -19,12 +24,18 @@ class CourseModel { ...@@ -19,12 +24,18 @@ class CourseModel {
authors = json['authors']; authors = json['authors'];
img = json['img']; img = json['img'];
progress = json['progress']; progress = json['progress'];
lastChapter = json['lastChapter'];
createTime = json['create_time'];
days = json['days'];
} }
num? bookId; num? bookId;
String? bookName; String? bookName;
String? authors; String? authors;
String? img; String? img;
String? progress; String? progress;
String? lastChapter;
String? createTime;
String? days;
int get type { int get type {
if (progress == '0.00%'){ if (progress == '0.00%'){
...@@ -51,11 +62,17 @@ class CourseModel { ...@@ -51,11 +62,17 @@ class CourseModel {
String? authors, String? authors,
String? img, String? img,
String? progress, String? progress,
String? lastChapter,
String? createTime,
String? days,
}) => CourseModel( bookId: bookId ?? this.bookId, }) => CourseModel( bookId: bookId ?? this.bookId,
bookName: bookName ?? this.bookName, bookName: bookName ?? this.bookName,
authors: authors ?? this.authors, authors: authors ?? this.authors,
img: img ?? this.img, img: img ?? this.img,
progress: progress ?? this.progress, progress: progress ?? this.progress,
lastChapter: lastChapter ?? this.lastChapter,
createTime: createTime ?? this.createTime,
days: days ?? this.days,
); );
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
...@@ -65,6 +82,9 @@ class CourseModel { ...@@ -65,6 +82,9 @@ class CourseModel {
map['authors'] = authors; map['authors'] = authors;
map['img'] = img; map['img'] = img;
map['progress'] = progress; map['progress'] = progress;
map['lastChapter'] = lastChapter;
map['create_time'] = createTime;
map['days'] = days;
return map; return map;
} }
......
library models; library models;
part 'response.dart'; part 'response.dart';
part 'course.dart';
part 'ad_model.dart';
part 'user_model.dart';
part 'msg.dart';
part 'study_history.dart';
\ No newline at end of file
part of models;
/// type : 1
/// title : "系统通知"
/// content : "v2.0上线了"
/// status : 0
/// url_id : 0
/// create_time : "2021-09-16 14:01:19"
class MsgModel {
MsgModel({
this.id,
this.type,
this.title,
this.content,
this.status,
this.urlId,
this.createTime,});
MsgModel.fromJson(dynamic json) {
id = json['id'];
type = json['type'];
title = json['title'];
content = json['content'];
status = json['status'];
urlId = json['url_id'];
createTime = json['create_time'];
}
num? id;
num? type;
String? title;
String? content;
num? status;
num? urlId;
String? createTime;
MsgModel copyWith({
num? id,
num? type,
String? title,
String? content,
num? status,
num? urlId,
String? createTime,
}) => MsgModel(
id: id ?? this.id,
type: type ?? this.type,
title: title ?? this.title,
content: content ?? this.content,
status: status ?? this.status,
urlId: urlId ?? this.urlId,
createTime: createTime ?? this.createTime,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['id'] = id;
map['type'] = type;
map['title'] = title;
map['content'] = content;
map['status'] = status;
map['url_id'] = urlId;
map['create_time'] = createTime;
return map;
}
}
\ No newline at end of file
part of models;
class StudyHistoryModel {
StudyHistoryModel({
this.time,
this.courses,
});
StudyHistoryModel.fromJson(dynamic json) {
time = json['time'];
courses = List.generate(json['list'].length, (index) => CourseModel.fromJson(index));
}
String? time;
List<CourseModel>? courses;
}
\ No newline at end of file
part of models;
/// members_id : 1 /// members_id : 1
/// name : "555555" /// name : "555555"
/// password : "637641045c830d80190da7b94f69c2cd" /// password : "637641045c830d80190da7b94f69c2cd"
......
...@@ -3,7 +3,13 @@ part of course; ...@@ -3,7 +3,13 @@ part of course;
class CourseController extends GetxController { class CourseController extends GetxController {
// 课程数组
List<CourseModel> courses = []; List<CourseModel> courses = [];
// 消息数组
List<AdModel> ads = [];
// 消息未读数
int num = 0;
final EasyRefreshController refreshController = EasyRefreshController( final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true, controlFinishLoad: true,
...@@ -14,6 +20,12 @@ class CourseController extends GetxController { ...@@ -14,6 +20,12 @@ class CourseController extends GetxController {
int _page = 1; int _page = 1;
bool _noMore = false; bool _noMore = false;
@override
void onReady() {
_getAds();
getNums();
super.onReady();
}
@override @override
void onClose() { void onClose() {
...@@ -21,14 +33,28 @@ class CourseController extends GetxController { ...@@ -21,14 +33,28 @@ class CourseController extends GetxController {
super.onClose(); super.onClose();
} }
/// 获取广告数据
void _getAds() async {
ads = await CommonAPI.list(type: '2');
update();
}
/// 消息未读数
void getNums() async {
num = await CommonAPI.num();
update();
}
/// 获取课程内图书列表
Future<void> _getCourse([bool isRefresh = false]) async { Future<void> _getCourse([bool isRefresh = false]) async {
if (isRefresh) _page = 1; if (isRefresh) _page = 1;
/// 网路请求 // 网路请求
final result = await CourseAPI.list( final result = await CourseAPI.list(
page: _page, page: _page,
limit: _limit limit: _limit
); );
/// 如果是刷新 清理数据 // 如果是刷新 清理数据
if (isRefresh) courses.clear(); if (isRefresh) courses.clear();
courses.addAll(result); courses.addAll(result);
_page ++; _page ++;
......
...@@ -5,15 +5,14 @@ import 'dart:math'; ...@@ -5,15 +5,14 @@ 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';
import 'package:get/get_state_manager/src/simple/get_controllers.dart'; import 'package:get/get_state_manager/src/simple/get_controllers.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:ionicons/ionicons.dart';
import '../../apis/index.dart'; import '../../apis/index.dart';
import '../../models/index.dart';
import '../../routes/index.dart'; import '../../routes/index.dart';
import '../../store/index.dart'; import '../../store/index.dart';
import '../../utils/index.dart'; import '../../utils/index.dart';
......
...@@ -35,13 +35,17 @@ class _CoursePageState extends State<CoursePage> { ...@@ -35,13 +35,17 @@ class _CoursePageState extends State<CoursePage> {
onPressed: () => context.pushNamed(Routes.studyHistory), onPressed: () => context.pushNamed(Routes.studyHistory),
), ),
GestureDetector( GestureDetector(
onTap: (){ onTap: () async{
context.pushNamed(Routes.msgs); final result = await context.pushNamed(Routes.msgs);
if (result == true) {
controller.getNums();
}
// controller.logout(context); // controller.logout(context);
}, },
child: badges.Badge( child: badges.Badge(
position: badges.BadgePosition.topEnd(top: -5, end: 0), position: badges.BadgePosition.topEnd(top: -5, end: 0),
badgeContent: const Text('10',style: TextStyle(fontSize: 7,color: Colors.white),), showBadge: controller.num == 0?false:true,
badgeContent: Text(controller.num.toString(),style: const TextStyle(fontSize: 7,color: Colors.white),),
badgeStyle: const badges.BadgeStyle( badgeStyle: const badges.BadgeStyle(
badgeColor: AppTheme.primary, badgeColor: AppTheme.primary,
shape: badges.BadgeShape.circle shape: badges.BadgeShape.circle
...@@ -56,23 +60,18 @@ class _CoursePageState extends State<CoursePage> { ...@@ -56,23 +60,18 @@ class _CoursePageState extends State<CoursePage> {
), ),
), ),
) )
// CustomButton.icon(
// padding: EdgeInsets.zero,
// backgroundColor: Colors.transparent,
// icon: const Icon(Ionicons.notifications),
// onPressed: () => context.pushNamed(Routes.msgs),
// ),
], ],
), ),
body:Container( body:Container(
color: const Color(0xFFF9F9F9), color: const Color(0xFFF9F9F9),
child: Column( child: Column(
children: [ children: [
controller.ads.isNotEmpty?
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:controller.ads),
), ):const SizedBox(),
Expanded( Expanded(
child: CustomPullScrollView( child: CustomPullScrollView(
controller: controller.refreshController, controller: controller.refreshController,
......
part of course; part of course;
class BuildBanner extends StatelessWidget { class BuildBanner extends StatelessWidget {
final List items; final List <AdModel>items;
const BuildBanner({ const BuildBanner({
Key? key, Key? key,
this.items = const [], this.items = const [],
...@@ -39,7 +39,7 @@ class BuildBanner extends StatelessWidget { ...@@ -39,7 +39,7 @@ class BuildBanner extends StatelessWidget {
), ),
child: Text('$item'), child: Image.network(item.pic??''),
// child: CustomImage.asset( // child: CustomImage.asset(
// url: 'assets/images/banner.png', // url: 'assets/images/banner.png',
// width: 130.w, // width: 130.w,
......
...@@ -37,7 +37,7 @@ class _LibraryContentPageState extends State<LibraryContentPage> { ...@@ -37,7 +37,7 @@ 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: const BuildBanner(items: ['111','222','333'],),
), ),
]) ])
) )
......
...@@ -14,11 +14,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; ...@@ -14,11 +14,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:get/get_state_manager/src/simple/get_controllers.dart'; import 'package:get/get_state_manager/src/simple/get_controllers.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:ionicons/ionicons.dart';
import '../../models/user_model.dart';
import '../../routes/index.dart'; import '../../routes/index.dart';
import '../../services/index.dart';
import '../../widgets/index.dart'; import '../../widgets/index.dart';
......
library main; library main;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_book/pages/home/index.dart';
import 'package:flutter_book/pages/library/index.dart'; import 'package:flutter_book/pages/library/index.dart';
import 'package:flutter_book/pages/mine/index.dart'; import 'package:flutter_book/pages/mine/index.dart';
import 'package:flutter_book/theme.dart'; import 'package:flutter_book/theme.dart';
import 'package:get/get.dart'; 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 '../../routes/index.dart'; import '../../routes/index.dart';
import '../../store/index.dart'; import '../../store/index.dart';
import '../../widgets/index.dart';
import '../book_shop/index.dart'; import '../book_shop/index.dart';
import '../course/index.dart'; import '../course/index.dart';
import '../record/index.dart';
import '../tts/index.dart';
import '../web/index.dart';
part 'view.dart'; part 'view.dart';
......
...@@ -4,4 +4,30 @@ part of mine; ...@@ -4,4 +4,30 @@ part of mine;
class MineController extends GetxController { class MineController extends GetxController {
List<AdModel> ads = [];
// 消息未读数
int num = 0;
@override
void onReady() {
_getAds();
_getNums();
super.onReady();
}
/// 获取广告数据
void _getAds() async {
ads = await CommonAPI.list(type: '4');
update();
}
/// 消息未读数
void _getNums() async {
num = await CommonAPI.num();
update();
}
} }
\ No newline at end of file
...@@ -9,10 +9,12 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; ...@@ -9,10 +9,12 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:get/get_state_manager/src/simple/get_controllers.dart'; import 'package:get/get_state_manager/src/simple/get_controllers.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:ionicons/ionicons.dart';
import '../../apis/index.dart';
import '../../models/index.dart';
import '../../routes/index.dart'; import '../../routes/index.dart';
import '../course/index.dart'; import '../course/index.dart';
import 'package:badges/badges.dart' as badges;
part 'view.dart'; part 'view.dart';
part 'controller.dart'; part 'controller.dart';
......
...@@ -33,14 +33,29 @@ class _MinePageState extends State<MinePage> { ...@@ -33,14 +33,29 @@ class _MinePageState extends State<MinePage> {
), ),
onPressed: () => context.pushNamed(Routes.msgs), onPressed: () => context.pushNamed(Routes.msgs),
), ),
CustomButton.icon( GestureDetector(
onTap: (){
context.pushNamed(Routes.msgs);
// controller.logout(context);
},
child: badges.Badge(
position: badges.BadgePosition.topEnd(top: -5, end: 0),
showBadge: controller.num == 0?false:true,
badgeContent: Text(controller.num.toString(),style: const TextStyle(fontSize: 7,color: Colors.white),),
badgeStyle: const badges.BadgeStyle(
badgeColor: AppTheme.primary,
shape: badges.BadgeShape.circle
),
child: CustomButton.icon(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
icon: Image.asset( icon: Image.asset(
'assets/images/msg_black.png', 'assets/images/msg_black.png',
), ),
onPressed: () => context.pushNamed(Routes.msgs), // onPressed: () => context.pushNamed(Routes.msgs),
), ),
),
)
], ],
), ),
body: SingleChildScrollView( body: SingleChildScrollView(
...@@ -53,8 +68,13 @@ class _MinePageState extends State<MinePage> { ...@@ -53,8 +68,13 @@ class _MinePageState extends State<MinePage> {
},), },),
Gaps.vGaps10, Gaps.vGaps10,
BuildRead(items: ['1','2','3','4'],), BuildRead(items: ['1','2','3','4'],),
Gaps.vGaps10, controller.ads.isNotEmpty?Gaps.vGaps10:SizedBox(),
BuildBanner(items: ['111','222','333'],), controller.ads.isNotEmpty?
Container(
color: Colors.transparent,
padding: const EdgeInsets.symmetric(horizontal: 10),
child: BuildBanner(items:controller.ads),
):const SizedBox(),
Gaps.vGaps10, Gaps.vGaps10,
BuildAccount(items: ['1','11','紫荆币','1111'],), BuildAccount(items: ['1','11','紫荆币','1111'],),
Gaps.vGaps10, Gaps.vGaps10,
......
part of study_history; part of study_history;
class HistoryController extends GetxController {
final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true,
controlFinishRefresh: true,
);
// 学习历史数组
List<StudyHistoryModel> histories = [];
final int _limit = 10;
int _page = 1;
bool _noMore = false;
@override
void onClose() {
refreshController.dispose();
super.onClose();
}
/// 获取 最近学习数据
Future<void> _getHistory([bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
final result = await CommonAPI.history(
page: _page,
limit: _limit
);
print('11111111111111111111111111$result');
// 如果是刷新 清理数据
if (isRefresh) histories.clear();
histories.addAll(result);
_page ++;
_noMore = result.length < _limit;
update();
}
void onRefresh() async {
try {
await _getHistory(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 _getHistory();
refreshController.finishLoad();
} catch (error) {
refreshController.finishLoad(IndicatorResult.fail);
}
}
}
\ No newline at end of file
...@@ -2,10 +2,15 @@ library study_history; ...@@ -2,10 +2,15 @@ library study_history;
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:get/get.dart';
import '../../models/index.dart';
import '../../theme.dart'; import '../../theme.dart';
import '../../utils/index.dart'; import '../../utils/index.dart';
import '../../widgets/index.dart';
part 'view.dart'; part 'view.dart';
......
...@@ -10,17 +10,25 @@ class StudyHistoryPage extends StatefulWidget { ...@@ -10,17 +10,25 @@ class StudyHistoryPage extends StatefulWidget {
class _StudyHistoryPageState extends State<StudyHistoryPage> { class _StudyHistoryPageState extends State<StudyHistoryPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return GetBuilder<HistoryController>(
init: HistoryController(),
builder:(controller) => Scaffold(
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
title: const Text('最近学习'), title: const Text('最近学习'),
), ),
body: ListView.builder( body: CustomPullScrollView(
controller: controller.refreshController,
onRefresh: controller.onRefresh,
onLoading: controller.onLoading,
child: ListView.builder(
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return BuildDayItem(); return BuildDayItem();
}, },
itemCount: 4, itemCount: 4,
), ),
),
),
); );
} }
} }
...@@ -6,8 +6,7 @@ class BuildDayItem extends StatelessWidget { ...@@ -6,8 +6,7 @@ class BuildDayItem extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
// height: 300, margin: const EdgeInsets.only(left: 10,top: 10,right: 10),
margin: EdgeInsets.only(left: 10,top: 10,right: 10),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
boxShadow: [ boxShadow: [
...@@ -24,8 +23,14 @@ class BuildDayItem extends StatelessWidget { ...@@ -24,8 +23,14 @@ class BuildDayItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( Container(
height: 32, decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(8.0),
topRight: Radius.circular(8.0),
),
color: Colors.cyan, color: Colors.cyan,
),
height: 32,
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text('今天',style: TextStyle(fontSize: 13,height: 1.4,color: Colours.c6),), child: Text('今天',style: TextStyle(fontSize: 13,height: 1.4,color: Colours.c6),),
), ),
...@@ -44,7 +49,7 @@ class BuildDayItem extends StatelessWidget { ...@@ -44,7 +49,7 @@ class BuildDayItem extends StatelessWidget {
Widget _buildItem(){ Widget _buildItem(){
return Container( return Container(
margin: EdgeInsets.only(left: 10,right: 10), margin: const EdgeInsets.only(left: 10,right: 10),
child: Column( child: Column(
children: [ children: [
Container( Container(
...@@ -52,18 +57,33 @@ class BuildDayItem extends StatelessWidget { ...@@ -52,18 +57,33 @@ class BuildDayItem extends StatelessWidget {
height: 2, height: 2,
), ),
Container( Container(
margin: EdgeInsets.only(top: 11.5,bottom: 14.5), margin: const EdgeInsets.only(top: 11.5,bottom: 14.5),
// color: Colors.yellow,
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( Container(
width: 72, width: 72,
height: 87, height: 87,
color: Colors.red, color: Colors.red,
), ),
Expanded(
child: Container(
// color: Colors.green,
padding: const EdgeInsets.only(top: 2.5,left: 13),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text('从现在开始,为精彩活过一百',style: TextStyle(fontSize: 14,height: 1.5,fontWeight: Fonts.medium,color: Colours.c3),maxLines: 1,overflow: TextOverflow.ellipsis,), Text('从现在开始,为精彩活过一百',style: TextStyle(fontSize: 14,height: 1.5,fontWeight: Fonts.medium,color: Colours.c3),maxLines: 1,overflow: TextOverflow.ellipsis,),
Gaps.vGaps5,
Text('李白',style: TextStyle(fontSize: 12,height: 1.4,color: Colours.c6),), Text('李白',style: TextStyle(fontSize: 12,height: 1.4,color: Colours.c6),),
],
),
Gaps.vGaps25,
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
...@@ -72,10 +92,13 @@ class BuildDayItem extends StatelessWidget { ...@@ -72,10 +92,13 @@ class BuildDayItem extends StatelessWidget {
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: const Text('未学习',style: TextStyle(fontSize: 11,height: 1.3,color: Colours.c9),),
), ),
// Spacer(),
const Text('继续学习',style: TextStyle(fontSize: 11,height: 1.3,color: AppTheme.primary),) const Text('继续学习',style: TextStyle(fontSize: 11,height: 1.3,color: AppTheme.primary),)
], ],
) )
], ],
),
),
) )
], ],
), ),
......
part of user_msg;
class MsgController extends GetxController {
List<MsgModel> msgs = [];
final EasyRefreshController refreshController = EasyRefreshController(
controlFinishLoad: true,
controlFinishRefresh: true,
);
final int _limit = 20;
int _page = 1;
bool _noMore = false;
@override
void onClose() {
refreshController.dispose();
super.onClose();
}
/// 消息未读变已读
Future<bool> read(String id) async {
bool result = await CommonAPI.read(id: id);
return result;
}
/// 获取课程内图书列表
Future<void> _getMsgs([bool isRefresh = false]) async {
if (isRefresh) _page = 1;
// 网路请求
final result = await CommonAPI.msgs(
page: _page,
limit: _limit
);
// 如果是刷新 清理数据
if (isRefresh) msgs.clear();
msgs.addAll(result);
_page ++;
_noMore = result.length < _limit;
update();
}
void onRefresh() async {
try {
await _getMsgs(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 _getMsgs();
refreshController.finishLoad();
} catch (error) {
refreshController.finishLoad(IndicatorResult.fail);
}
}
}
\ No newline at end of file
library user_msg; library user_msg;
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/models/index.dart';
import 'package:get/get.dart';
import 'package:go_router/go_router.dart';
import '../../routes/index.dart';
import '../../theme.dart'; import '../../theme.dart';
import '../../utils/index.dart'; import '../../utils/index.dart';
import 'package:badges/badges.dart' as badges; import 'package:badges/badges.dart' as badges;
import '../../widgets/index.dart';
part 'view.dart'; part 'view.dart';
part 'widgets/item.dart'; part 'widgets/item.dart';
part 'controller.dart';
\ No newline at end of file
...@@ -3,20 +3,45 @@ part of user_msg; ...@@ -3,20 +3,45 @@ part of user_msg;
class MsgPage extends StatelessWidget { class MsgPage extends StatelessWidget {
const MsgPage({Key? key}) : super(key: key); const MsgPage({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return WillPopScope(
onWillPop: () async {
context.pop(true);
return false;
},
child: GetBuilder<MsgController>(
init: MsgController(),
builder:(controller) => Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('消息中心'), title: const Text('消息中心'),
centerTitle: true, centerTitle: true,
), ),
body: Container( body: Container(
color: Colours.cF9, color: Colours.cF9,
child: CustomPullScrollView(
controller: controller.refreshController,
onRefresh: controller.onRefresh,
onLoading: controller.onLoading,
child: ListView.builder( child: ListView.builder(
itemBuilder: (BuildContext context, int index){ itemBuilder: (BuildContext context, int index){
return BuildItem(); return GestureDetector(
child: BuildItem(model: controller.msgs[index],),
onTap: () async{
controller.read(controller.msgs[index].id.toString());
final result = await context.pushNamed(Routes.coin);
if (result == true){
controller.onRefresh();
}
}, },
itemCount: 5, );
},
itemCount: controller.msgs.length,
),
),
),
), ),
), ),
); );
......
part of user_msg; part of user_msg;
class BuildItem extends StatelessWidget { class BuildItem extends StatelessWidget {
const BuildItem({Key? key}) : super(key: key); final MsgModel model;
const BuildItem({
Key? key,
required this.model
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
margin: const EdgeInsets.only(left: 10,right: 10,top:10), margin: const EdgeInsets.only(left: 10,right: 10,top:10),
padding: EdgeInsets.symmetric(horizontal: 10,vertical: 10), padding: const EdgeInsets.symmetric(horizontal: 10,vertical: 10),
height: 75, height: 75,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
...@@ -17,6 +21,7 @@ class BuildItem extends StatelessWidget { ...@@ -17,6 +21,7 @@ class BuildItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
badges.Badge( badges.Badge(
showBadge: model.status == 1?false: true,
position: badges.BadgePosition.topEnd(top: 0, end: 0), position: badges.BadgePosition.topEnd(top: 0, end: 0),
badgeStyle: const badges.BadgeStyle( badgeStyle: const badges.BadgeStyle(
badgeColor: AppTheme.primary, badgeColor: AppTheme.primary,
...@@ -36,18 +41,18 @@ class BuildItem extends StatelessWidget { ...@@ -36,18 +41,18 @@ class BuildItem extends StatelessWidget {
), ),
Gaps.hGaps10, Gaps.hGaps10,
Expanded( Expanded(
child: const Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text('积分过期提醒',style: TextStyle(fontSize: 15,height: 1.4,fontWeight: Fonts.medium,color: Colours.c3),), Text(model.title??'',style: const TextStyle(fontSize: 15,height: 1.4,fontWeight: Fonts.medium,color: Colours.c3),),
Text('2023-12-12',style: TextStyle(fontSize:11,height: 1.4,color: Colours.c9)) Text(model.createTime??'',style: const TextStyle(fontSize:11,height: 1.4,color: Colours.c9))
], ],
), ),
Gaps.vGaps5, Gaps.vGaps5,
Text('您有2000积分即将过期。',style: TextStyle(fontSize: 13,height: 1.4,color: Colours.c6),) Text(model.content??'',style: const TextStyle(fontSize: 13,height: 1.4,color: Colours.c6),)
], ],
), ),
) )
......
...@@ -7,7 +7,7 @@ import 'package:flutter_book/services/index.dart'; ...@@ -7,7 +7,7 @@ import 'package:flutter_book/services/index.dart';
import 'package:flutter_book/theme.dart'; import 'package:flutter_book/theme.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../models/user_model.dart'; import '../models/index.dart';
import '../utils/index.dart'; import '../utils/index.dart';
part 'config.dart'; part 'config.dart';
......
...@@ -45,6 +45,7 @@ class Gaps { ...@@ -45,6 +45,7 @@ class Gaps {
static const Widget vGaps10 = SizedBox(height: 10,); static const Widget vGaps10 = SizedBox(height: 10,);
static const Widget vGaps13 = SizedBox(height: 13,); static const Widget vGaps13 = SizedBox(height: 13,);
static const Widget vGaps15 = SizedBox(height: 15,); static const Widget vGaps15 = SizedBox(height: 15,);
static const Widget vGaps25 = SizedBox(height: 25,);
static const Widget vGaps40 = SizedBox(height: 40,); static const Widget vGaps40 = SizedBox(height: 40,);
// static const Widget line = Padding( // static const Widget line = Padding(
// padding: EdgeInsets.symmetric(horizontal: 15.0), // padding: EdgeInsets.symmetric(horizontal: 15.0),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论