初始化
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import 'package:hgdj/tools_base/base_list_controller.dart';
|
||||
|
||||
import '../../../hj_model/home/module_detail_model.dart';
|
||||
import '../../../hj_utils/api_service/vid_service.dart';
|
||||
|
||||
class SectionAllLogic extends ListBaseLogic<AllSection> {
|
||||
final String id;
|
||||
|
||||
SectionAllLogic(this.id);
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
loadData();
|
||||
}
|
||||
|
||||
//isRefresh 下拉刷新/加载更多;showLoading 重试时先清空显示 loading
|
||||
void loadData({bool isRefresh = true, bool showLoading = false}) {
|
||||
if (showLoading) {
|
||||
dataList = null;
|
||||
update();
|
||||
}
|
||||
fetchData(isRefresh: isRefresh, fetch: _fetch);
|
||||
}
|
||||
|
||||
Future<(List<AllSection>?, bool)> _fetch(int page) async {
|
||||
final resp =
|
||||
await VidService.fetchSectionAll(id, pageNumber: page, pageSize: 20);
|
||||
//hasNext 为 null 时按"有更多"处理(保持原 == false 判断语义)
|
||||
return (resp?.list, resp?.hasNext != false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hgdj/hj_utils/screen.dart';
|
||||
import 'package:hgdj/tools_base/loading/loading_center_widget.dart';
|
||||
import 'package:hgdj/tools_base/refresh/pull_refresh.dart';
|
||||
import 'package:hgdj/tools_base/widget/net_image_widget.dart';
|
||||
|
||||
import '../../../hj_model/home/module_detail_model.dart';
|
||||
import '../special_topic_detail/special_topics_detail_page.dart';
|
||||
import 'section_all_logic.dart';
|
||||
|
||||
class SectionAllPage extends StatelessWidget {
|
||||
final String id;
|
||||
|
||||
const SectionAllPage(this.id, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<SectionAllLogic>(
|
||||
init: SectionAllLogic(id),
|
||||
builder: (logic) => Scaffold(
|
||||
appBar: AppBar(title: Text("原创达人")),
|
||||
body: pullYsRefresh(
|
||||
onInit: (ctr) => logic.refreshCtr = ctr,
|
||||
onRefresh: (ctr) => logic.loadData(),
|
||||
onLoading: (ctr) => logic.loadData(isRefresh: false),
|
||||
child: () {
|
||||
if (logic.isLoading) {
|
||||
return LoadingCenterWidget();
|
||||
} else if (logic.isEmptyData) {
|
||||
return CErrorWidget(
|
||||
retryOnTap: () => logic.loadData(showLoading: true),
|
||||
);
|
||||
} else {
|
||||
final list = logic.dataList!;
|
||||
return ListView.builder(
|
||||
padding: EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
itemExtent: 62, //item 固定高 50 + 底部 margin 12,跳过逐项测量
|
||||
itemCount: list.length,
|
||||
itemBuilder: (context, index) {
|
||||
AllSection model = list[index];
|
||||
return InkWell(
|
||||
enableFeedback: false,
|
||||
onTap: () {
|
||||
Get.to(SpecialTopicsDetailPage(model),
|
||||
preventDuplicates: false);
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(bottom: 12),
|
||||
height: 50,
|
||||
child: Row(
|
||||
children: [
|
||||
NetworkImageLoader(
|
||||
imageUrl: model.sectionCover,
|
||||
width: 50,
|
||||
height: 50,
|
||||
borderRadius: 50,
|
||||
),
|
||||
12.sizeBoxW,
|
||||
Expanded(
|
||||
child: Text(
|
||||
model.sectionName ?? "",
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Color(0xffFFFFFF),
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
12.sizeBoxW,
|
||||
Icon(Icons.keyboard_arrow_right,
|
||||
color: Colors.white, size: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user