|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
import 'package:huixiang/data/banner.dart';
|
|
|
|
import 'package:huixiang/data/base_data.dart';
|
|
|
|
import 'package:huixiang/data/base_list_data.dart';
|
|
|
|
import 'package:huixiang/data/brand.dart';
|
|
|
|
import 'package:huixiang/data/category_select.dart';
|
|
|
|
import 'package:huixiang/data/collect_class.dart';
|
|
|
|
import 'package:huixiang/data/course.dart';
|
|
|
|
import 'package:huixiang/data/page.dart';
|
|
|
|
import 'package:huixiang/main.dart';
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:huixiang/utils/event_type.dart';
|
|
|
|
import 'package:huixiang/utils/shared_preference.dart';
|
|
|
|
import 'package:huixiang/view_widget/classic_header.dart';
|
|
|
|
import 'package:huixiang/view_widget/my_footer.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
import 'community_view/class_list_view.dart';
|
|
|
|
import 'community_view/class_title_tab.dart';
|
|
|
|
import 'community_view/course_banner.dart';
|
|
|
|
import 'community_view/home_class.dart';
|
|
|
|
|
|
|
|
class CommunityCourse extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _CommunityCourse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CommunityCourse extends State<CommunityCourse>
|
|
|
|
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
|
|
|
final ScrollController scrollController = ScrollController();
|
|
|
|
final RefreshController refreshController = RefreshController();
|
|
|
|
|
|
|
|
ApiService? apiService;
|
|
|
|
List<GlobalKey> globaKeys = [];
|
|
|
|
List<Brand> brands = [];
|
|
|
|
List<BannerData> bannerData = [];
|
|
|
|
List<CategorySelect> classSelectList = [];
|
|
|
|
List<Course> classList = [];
|
|
|
|
List<Course> classTabList = [];
|
|
|
|
List<CollectClass> collectList = [];
|
|
|
|
int checkIndex = 0;
|
|
|
|
Map<String, List<Course>> collectMap = new Map();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
eventBus.on<EventType>().listen((event) {
|
|
|
|
print("object: CommunityCourse");
|
|
|
|
if (event.type < 3) {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
apiService ??= ApiService(
|
|
|
|
Dio(),
|
|
|
|
context: context,
|
|
|
|
token: SharedInstance.instance.token,
|
|
|
|
);
|
|
|
|
_onRefresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
///banner
|
|
|
|
queryCourseBanner() async {
|
|
|
|
apiService ??= ApiService(
|
|
|
|
Dio(),
|
|
|
|
context: context,
|
|
|
|
token: SharedInstance.instance.token,
|
|
|
|
);
|
|
|
|
BaseData<PageInfo<BannerData>>? baseData = await apiService?.queryBanner({
|
|
|
|
"model": {"type": "COURSE_BANNER"},
|
|
|
|
}).catchError((onError) {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
return BaseData<PageInfo<BannerData>>()..isSuccess = false;
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
bannerData.clear();
|
|
|
|
bannerData.addAll(baseData?.data?.records ?? []);
|
|
|
|
refreshController.refreshCompleted();
|
|
|
|
} else {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
// SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///课程分类列表
|
|
|
|
classListAsync() async {
|
|
|
|
BaseListData<CategorySelect>? baseData = await apiService?.categoryList().catchError((onError) {
|
|
|
|
return BaseListData<CategorySelect>()..isSuccess = false;
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
setState(() {
|
|
|
|
classSelectList = baseData!.data ?? [];
|
|
|
|
});
|
|
|
|
queryClassList("");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///课程列表
|
|
|
|
queryClassList(categoryId) async {
|
|
|
|
BaseData<PageInfo<Course>>? baseData = await apiService?.courseList({
|
|
|
|
"categoryId": categoryId,
|
|
|
|
"pageNum": 1,
|
|
|
|
"pageSize": 10,
|
|
|
|
"searchKey": "",
|
|
|
|
"state": 0
|
|
|
|
}).catchError((error) {
|
|
|
|
if (categoryId == "") {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
refreshController.loadFailed();
|
|
|
|
}
|
|
|
|
return BaseData<PageInfo<Course>>()..isSuccess = false;
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
if (categoryId == "") {
|
|
|
|
refreshController.refreshCompleted();
|
|
|
|
refreshController.loadComplete();
|
|
|
|
setState(() {
|
|
|
|
classList.clear();
|
|
|
|
classList.addAll(baseData?.data?.list ?? []);
|
|
|
|
});
|
|
|
|
if (classSelectList.length > 0)
|
|
|
|
queryClassList(classSelectList[checkIndex].id);
|
|
|
|
} else {
|
|
|
|
setState(() {
|
|
|
|
classTabList.clear();
|
|
|
|
classTabList.addAll(baseData?.data?.list ?? []);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///课程的合集列表
|
|
|
|
collectionList() async {
|
|
|
|
BaseListData<CollectClass>? baseData = await apiService?.collectList()
|
|
|
|
.catchError((onError) {
|
|
|
|
return BaseListData<CollectClass>()..isSuccess = false;
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
setState(() {
|
|
|
|
collectList.clear();
|
|
|
|
collectList.addAll(baseData!.data ?? []);
|
|
|
|
collectList.forEach((element) {
|
|
|
|
collectCourse(element.id);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///合集包含的课程列表
|
|
|
|
collectCourse(collectId) async {
|
|
|
|
BaseListData<Course>? baseData = await apiService?.collect(collectId).catchError((error) {
|
|
|
|
return BaseListData<Course>()..isSuccess = false;
|
|
|
|
});
|
|
|
|
if (baseData?.isSuccess ?? false) {
|
|
|
|
setState(() {
|
|
|
|
if (!collectMap.containsKey(collectId)) {
|
|
|
|
collectMap[collectId] = [];
|
|
|
|
}
|
|
|
|
collectMap[collectId]?.clear();
|
|
|
|
collectMap[collectId]?.addAll(baseData!.data ?? []);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_onRefresh() {
|
|
|
|
queryCourseBanner();
|
|
|
|
classListAsync();
|
|
|
|
collectionList();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
super.build(context);
|
|
|
|
return SmartRefresher(
|
|
|
|
controller: refreshController,
|
|
|
|
enablePullDown: true,
|
|
|
|
enablePullUp: false,
|
|
|
|
header: MyHeader(),
|
|
|
|
footer: CustomFooter(
|
|
|
|
builder: (context, mode) {
|
|
|
|
return MyFooter(mode);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
onRefresh: () {
|
|
|
|
setState(() {
|
|
|
|
_onRefresh();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
physics: BouncingScrollPhysics(),
|
|
|
|
scrollController: scrollController,
|
|
|
|
child: Container(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
physics: NeverScrollableScrollPhysics(),
|
|
|
|
child: Container(
|
|
|
|
color: Color(0xFFF7F7F7),
|
|
|
|
margin: EdgeInsets.only(top: 16.h),
|
|
|
|
child: Column(
|
|
|
|
children: classChildItem(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Widget> classChildItem() {
|
|
|
|
var widgets = <Widget>[
|
|
|
|
///课程banner
|
|
|
|
CourseBanner(
|
|
|
|
bannerData,
|
|
|
|
),
|
|
|
|
|
|
|
|
SizedBox(height: 18.h),
|
|
|
|
|
|
|
|
///合集列表
|
|
|
|
HomeClass(
|
|
|
|
collectMap,
|
|
|
|
collectList,
|
|
|
|
),
|
|
|
|
|
|
|
|
///课程导航栏
|
|
|
|
ClassTitleTab(classSelectList, (index) {
|
|
|
|
checkIndex = index;
|
|
|
|
queryClassList(classSelectList[index].id);
|
|
|
|
}),
|
|
|
|
|
|
|
|
///课程列表
|
|
|
|
ClassListView(classTabList),
|
|
|
|
];
|
|
|
|
|
|
|
|
return widgets;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool get wantKeepAlive => true;
|
|
|
|
}
|