mod: 替换无状态组件

This commit is contained in:
guozhigq
2023-05-27 10:54:36 +08:00
parent c2aeb443a0
commit 0d49f9824c
7 changed files with 101 additions and 138 deletions

View File

@ -6,60 +6,58 @@ import 'package:pilipala/common/widgets/overlay_pop.dart';
import 'package:pilipala/common/widgets/video_card_h.dart';
import './controller.dart';
class RelatedVideoPanel extends StatefulWidget {
class RelatedVideoPanel extends GetView<ReleatedController> {
const RelatedVideoPanel({super.key});
@override
State<RelatedVideoPanel> createState() => _RelatedVideoPanelState();
}
class _RelatedVideoPanelState extends State<RelatedVideoPanel> {
final ReleatedController _releatedController =
Get.put(ReleatedController(), tag: Get.arguments['heroTag']);
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _releatedController.queryRelatedVideo(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data!['status']) {
// 请求成功
return SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
if (index == snapshot.data['data'].length) {
return SizedBox(height: MediaQuery.of(context).padding.bottom);
return GetBuilder(
init: ReleatedController(),
id: Get.arguments['heroTag'],
builder: (context) {
return FutureBuilder(
future: ReleatedController().queryRelatedVideo(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data!['status']) {
// 请求成功
return SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
if (index == snapshot.data['data'].length) {
return SizedBox(
height: MediaQuery.of(context).padding.bottom);
} else {
return VideoCardH(
videoItem: snapshot.data['data'][index],
longPress: () {
ReleatedController().popupDialog =
_createPopupDialog(snapshot.data['data'][index]);
Overlay.of(context)
.insert(ReleatedController().popupDialog!);
},
longPressEnd: () {
ReleatedController().popupDialog?.remove();
},
);
}
}, childCount: snapshot.data['data'].length + 1));
} else {
// 请求错误
return const Center(
child: Text('出错了'),
);
}
} else {
return VideoCardH(
videoItem: snapshot.data['data'][index],
longPress: () {
_releatedController.popupDialog =
_createPopupDialog(snapshot.data['data'][index]);
Overlay.of(context)
.insert(_releatedController.popupDialog!);
},
longPressEnd: () {
_releatedController.popupDialog?.remove();
},
// 骨架屏
return SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return const VideoCardHSkeleton();
}, childCount: 5),
);
}
}, childCount: snapshot.data['data'].length + 1));
} else {
// 请求错误
return const Center(
child: Text('出错了'),
);
}
} else {
// 骨架屏
return SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return const VideoCardHSkeleton();
}, childCount: 5),
},
);
}
},
);
});
}
OverlayEntry _createPopupDialog(videoItem) {