Making.School.Asignment.app/lib/page/home_page/home_view.dart

464 lines
19 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:functional_widget_annotation/functional_widget_annotation.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:school_asignment_app/common/job/work_student.dart';
import 'package:school_asignment_app/common/store/app_storage_key.dart';
import 'package:school_asignment_app/common/utils/storage.dart';
import 'package:school_asignment_app/common/utils/utils.dart';
import 'package:school_asignment_app/page/global_widget/MyEmptyWidget.dart';
import 'package:school_asignment_app/page/global_widget/global_scaffold.dart';
import 'package:school_asignment_app/page/global_widget/my_text.dart';
import 'package:school_asignment_app/page/home_page/widget/task_list_item.dart';
import 'package:school_asignment_app/page/home_page/widget/top_user_info.dart';
import 'package:school_asignment_app/routes/app_pages.dart';
import 'home_logic.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final logic = Get.find<HomeLogic>();
final state = Get
.find<HomeLogic>()
.state;
@override
Widget build(BuildContext context) {
return GlobalScaffold(
active: state.active,
body: AnnotatedRegion(
value: const SystemUiOverlayStyle(
systemNavigationBarColor: Color(0xFF000000),
systemNavigationBarDividerColor: null,
statusBarColor: Colors.white,
systemNavigationBarIconBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.light,
),
child: Scaffold(
backgroundColor: const Color.fromRGBO(244, 244, 244, 1),
body: OrientationBuilder(
builder: (BuildContext context, Orientation orientation) {
return Column(
children: <Widget>[
Container(
color: Colors.white,
margin: EdgeInsets.only(top: MediaQuery
.of(context)
.padding
.top),
padding: EdgeInsets.only(bottom: 9.h, top: 4.h),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Expanded(flex: 1, child: SizedBox()),
Expanded(
flex: 4,
child: Container(
padding: EdgeInsets.symmetric(vertical: 2.h),
alignment: Alignment.center,
decoration: BoxDecoration(
color: const Color.fromRGBO(243, 243, 243, 1),
borderRadius: BorderRadius.circular(8.r),
),
child: TabBar(
padding: EdgeInsets.zero,
indicatorPadding: EdgeInsets.zero,
indicatorWeight: 0,
labelPadding: EdgeInsets.symmetric(
horizontal: 2.w),
controller: logic.tabController,
unselectedLabelStyle: TextStyle(
fontSize: 14.sp,
color: const Color.fromRGBO(69, 83, 100, 1),
),
labelStyle: TextStyle(
fontSize: 14.sp,
color: const Color.fromRGBO(104, 136, 253, 1),
),
// labelColor: const Color.fromRGBO(45, 56, 76, 1),
indicator: const BoxDecoration(),
onTap: (index) {
state.tabIndex.value = index;
if (index == 1 && state.completedToRefresh) {
// 已阅卷
// _refreshController2.callRefresh();
state.completedToRefresh = false;
}
logic.getList();
},
tabs: <Widget>[
Tab(
iconMargin: EdgeInsets.zero,
height: 34.h,
child: Obx(() {
return Container(
width: 140.w,
alignment: Alignment.center,
decoration: BoxDecoration(
color: state.tabIndex.value == 0
? const Color.fromRGBO(
255, 255, 255, 1)
: null,
borderRadius: BorderRadius.all(
Radius.circular(8.r)),
),
child: quickText(
'待批阅',
size: 14.sp,
color: state.tabIndex.value == 0
? Theme
.of(context)
.primaryColor
: const Color.fromRGBO(
80, 94, 110, 1),
fontWeight: state.tabIndex.value == 0
? FontWeight.bold
: null,
),
);
}),
),
Tab(
iconMargin: EdgeInsets.zero,
height: 34.h,
child: Obx(() {
return Container(
width: 140.w,
alignment: Alignment.center,
decoration: BoxDecoration(
color: state.tabIndex.value == 1
? const Color.fromRGBO(
255, 255, 255, 1)
: null,
borderRadius: BorderRadius.all(
Radius.circular(8.r)),
),
child: quickText(
'已批阅',
size: 14.sp,
color: state.tabIndex.value == 1
? Theme
.of(context)
.primaryColor
: const Color.fromRGBO(
80, 94, 110, 1),
fontWeight: state.tabIndex.value == 1
? FontWeight
.bold
: null,
),
);
}),
),
],
),
),
),
Expanded(
flex: 1,
child: InkWell(
onTap: () {
/* RouterManager.router
.navigateTo(
context, RouterManager.jobStudentGroupPath,
transition: getTransition());*/
},
child: Icon(
const IconData(
0xe63e, fontFamily: "AlibabaIcon"),
color: const Color.fromRGBO(44, 48, 63, 1),
size: 24.sp),
),
),
],
),
),
/* if (state.tabIndex.value == 1)
$CompletedJobConditionFilter(
controller: _tabController2,
jobType: params2.markingType ?? 1,
customTime: _tabController2.index != 3 ||
(params2.startTime == null && params2.endTime == null)
? null
: PickerDateRange(
params2.startTime == null ? null : DateTime.parse(
params2.startTime!),
params2.endTime == null ? null : DateTime.parse(params2
.endTime!),
),
onJobTypeTap: (int jobTypeVal) {
params2.markingType = jobTypeVal;
_refreshController2.callRefresh();
},
onTimeFilter: (String? startTime, String? endTime) {
if (startTime == null && endTime == null &&
_tabController2.index == 3) {
_tabController2.animateTo(0);
}
params2.endTime = endTime;
params2.startTime = startTime;
_refreshController2.callRefresh();
},
),*/
Expanded(
child: IndexedStack(
index: state.tabIndex.value,
children: <Widget>[
$easyRefresh(
controller: logic.refreshController1,
tab: 1,
type: state.active,
data: state.workList,
onLoad: logic.onMyLoad,
onRefresh: logic.onMyRefresh,
logic: logic
),
$easyRefresh(
controller: logic.refreshController2,
tab: 2,
type: state.active,
data: state.workList,
onLoad: logic.onMyLoad,
onRefresh: logic.onMyRefresh,
logic: logic
),
],
)
),
],
);
},
),
),
),
);
}
@override
void dispose() {
Get.delete<HomeLogic>();
super.dispose();
}
}
/// 已阅卷
/// OnRefreshCallback? onRefresh
///
@swidget
Widget $easyRefresh({
required EasyRefreshController controller,
required Future<
void> Function(EasyRefreshController controller, int tab) onRefresh,
required Future<
void> Function(EasyRefreshController controller, int tab) onLoad,
required List<Items> data,
required int tab,
required int type,
required HomeLogic logic,
}) {
bool completed = tab == 2; // 是否是待批阅
bool isPadFlag = Utils.isPad();
return Obx(() {
return EasyRefresh(
firstRefresh: false,
taskIndependence: true,
/*enableControlFinishLoad: true,
enableControlFinishRefresh: true,*/
emptyWidget: data.isEmpty ? const MyEmptyWidget() : null,
controller: controller,
header: MaterialHeader(),
footer: TaurusFooter(),
child: completed && isPadFlag
? GridView(
padding: EdgeInsets.only(
top: 11.h, bottom: 10.h, left: 12.w, right: 12.w),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, //横轴三个子widget
mainAxisSpacing: 10.h,
crossAxisSpacing: 6.w,
childAspectRatio: 1.81 //宽高比为1时子widget
),
children: List.generate(data.length, (index) {
Items item = data[index];
String subjectName = logic.formatSubject(item.subject);
return $reviewedItem(jobTaskItem: item,type: type,subjectName:subjectName);
}),
)
: ListView.builder(
padding: EdgeInsets.only(top: 11.h, bottom: 10.h, left: 12.w, right: 12.w),
itemBuilder: (context, index) {
Items item = data[index];
return TaskListItem(completed:completed,jobTaskItem:item,type:type,logic: logic,);
/*HomeworkTasksViewItem(
completed: completed,
jobTaskItem: data[index],
call: () => controller.callRefresh(),
);*/
},
itemCount: data.length,
),
onRefresh: () => onRefresh(controller, tab),
onLoad: () => onLoad(controller, tab),
);
});
}
@swidget
Widget $reviewedItem({ required Items jobTaskItem, required int type,required String subjectName}) {
EdgeInsets padEdg = EdgeInsets.symmetric(horizontal: 10.w);
return InkWell(
onTap: () {
/* String url =
'${RouterManager.jobListParticipateInClassPath}?&jobId=${jobTaskItem.id}&genderName=${Uri.encodeComponent(jobTaskItem.genderName)}&jobName=${Uri.encodeComponent(jobTaskItem.title)}&completed=${true}';
RouterManager.router.navigateTo(context, url, transition: getTransition());*/
},
child: Container(
padding: EdgeInsets.only(top: 10.h),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6.r),
color: Colors.white,
boxShadow: const [
BoxShadow(
color: Color.fromRGBO(210, 216, 241, 1),
offset: Offset.zero, //阴影y轴偏移量
blurRadius: 5.8, //阴影模糊程度
spreadRadius: 0, //阴影扩散程度
)
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// 顶部任务名称
Padding(
padding: padEdg,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 32.w,
height: 18.h,
alignment: Alignment.center,
padding: EdgeInsets.only(left: 2.w),
decoration: BoxDecoration(
color: type == 1
? const Color.fromRGBO(104, 136, 253, 1)
: const Color.fromRGBO(255, 175, 56, 1),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(14.r),
topRight: Radius.circular(3.r),
bottomLeft: Radius.circular(4.r),
bottomRight: Radius.circular(4.r),
),
),
margin: EdgeInsets.only(right: 4.w),
child: quickText(type == 1 ? '作业' : '考试', color: Colors.white,
size: 10.sp),
),
Expanded(
child: quickText(jobTaskItem.name, size: 14.sp,
color: const Color.fromRGBO(70, 70, 70, 1),
maxLines: 2),
)
],
),
),
Padding(
padding: padEdg,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
quickText(
jobTaskItem.publishTime.substring(0, 10),
color: const Color.fromRGBO(97, 97, 97, 1),
size: 10.sp,
fontWeight: FontWeight.w500,
),
quickText(' / ', color: const Color.fromRGBO(76, 199, 147, 1),
size: 10.sp,
fontWeight: FontWeight.w500),
quickText(
'参与班级:',
color: const Color.fromRGBO(76, 199, 147, 1),
size: 9.sp,
),
quickText(
'${jobTaskItem.classCount}',
color: const Color.fromRGBO(76, 199, 147, 1),
size: 10.sp,
),
quickText(' / ', color: const Color.fromRGBO(116, 145, 253, 1),
size: 10.sp,
fontWeight: FontWeight.w500),
quickText(
'科目:$subjectName',
color: const Color.fromRGBO(116, 145, 253, 1),
size: 9.sp,
),
],
),
),
/*Padding(
padding: EdgeInsets.symmetric(horizontal: 10.w),
child: FavoriteButton(
jobTaskItem.id,
jobTaskItem.title,
margin: EdgeInsets.only(top: 4.h, bottom: 6.h),
),
),*/
GestureDetector(
onTap: () {
/* RouterManager.router.navigateTo(
context,
RouterManager.jobReportPagePath +
'?title=${Uri.encodeComponent(jobTaskItem.title)}&id=${jobTaskItem.id}',
transition: getTransition(),
);*/
},
child: Container(
padding: EdgeInsets.symmetric(vertical: 6.h),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(6.r),
bottomRight: Radius.circular(6.r)),
color: Colors.white,
boxShadow: const [
BoxShadow(
color: Color.fromRGBO(0, 0, 0, 0.15),
offset: Offset(0, -0.0001), //阴影y轴偏移量
blurRadius: 4, //阴影模糊程度
spreadRadius: 0, //阴影扩散程度
)
],
),
child: Row(children: [
Expanded(
child: Container(
alignment: Alignment.center,
child: quickText(
'查看报告', color: const Color.fromRGBO(118, 118, 118, 1),
size: 11.sp),
),
),
]),
),
),
],
),
),
);
}