mod: 动态页面

This commit is contained in:
guozhigq
2023-07-10 21:14:11 +08:00
parent b1cd8bbed3
commit bc3ac3c9f6
5 changed files with 124 additions and 47 deletions

View File

@ -17,7 +17,8 @@ class DynamicsController extends GetxController {
final ScrollController scrollController = ScrollController();
Rx<FollowUpModel> upData = FollowUpModel().obs;
// 默认获取全部动态
int mid = -1;
RxInt mid = (-1).obs;
Rx<UpItem> upInfo = UpItem().obs;
List filterTypeList = [
{
'label': DynamicsType.all.labels,
@ -41,6 +42,7 @@ class DynamicsController extends GetxController {
},
];
bool flag = false;
RxInt initialValue = 1.obs;
Future queryFollowDynamic({type = 'init'}) async {
// if (type == 'init') {
@ -50,7 +52,7 @@ class DynamicsController extends GetxController {
page: type == 'init' ? 1 : page,
type: dynamicsType.value.values,
offset: offset,
mid: mid,
mid: mid.value,
);
if (res['status']) {
if (type == 'init') {
@ -65,7 +67,10 @@ class DynamicsController extends GetxController {
}
onSelectType(value) async {
dynamicsType.value = value;
dynamicsType.value = filterTypeList[value - 1]['value'];
dynamicsList!.value = [DynamicItemModel()];
page = 1;
initialValue.value = value;
await queryFollowDynamic();
scrollController.jumpTo(0);
}
@ -127,7 +132,8 @@ class DynamicsController extends GetxController {
onSelectUp(mid) async {
dynamicsType.value = DynamicsType.values[0];
dynamicsList!.value = [DynamicItemModel()];
page = 1;
queryFollowDynamic();
}

View File

@ -1,3 +1,5 @@
import 'package:custom_sliding_segmented_control/custom_sliding_segmented_control.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
@ -59,40 +61,94 @@ class _DynamicsPageState extends State<DynamicsPage>
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Obx(
() => SegmentedButton<DynamicsType>(
showSelectedIcon: false,
style: ButtonStyle(
padding: MaterialStateProperty.all(
const EdgeInsets.symmetric(
vertical: 0, horizontal: 10)),
side: MaterialStateProperty.all(
BorderSide(
color: Theme.of(context).hintColor, width: 0.5),
Obx(() {
if (_dynamicsController.mid.value != -1 &&
_dynamicsController.upInfo.value.uname != null) {
return SizedBox(
height: 36,
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
transitionBuilder:
(Widget child, Animation<double> animation) {
return ScaleTransition(
scale: animation, child: child);
},
child: Text(
'${_dynamicsController.upInfo.value.uname!}的动态',
key: ValueKey<String>(
_dynamicsController.upInfo.value.uname!),
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelLarge!
.fontSize,
)),
),
),
segments: <ButtonSegment<DynamicsType>>[
for (var i in _dynamicsController.filterTypeList) ...[
ButtonSegment<DynamicsType>(
value: i['value'],
label: Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Text(i['label']),
);
} else {
return const SizedBox();
}
}),
Obx(() => Visibility(
visible: _dynamicsController.mid.value == -1,
child: CustomSlidingSegmentedControl<int>(
initialValue: _dynamicsController.initialValue.value,
children: {
1: Text(
'全部',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelMedium!
.fontSize),
),
enabled: i['enabled'],
2: Text('投稿',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelMedium!
.fontSize)),
3: Text('番剧',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelMedium!
.fontSize)),
// 4: Text(
// '专栏',
// style: TextStyle(
// fontSize: Theme.of(context)
// .textTheme
// .labelMedium!
// .fontSize),
// ),
},
padding: 16.0,
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.surfaceVariant
.withOpacity(0.7),
borderRadius: BorderRadius.circular(20),
),
]
],
selected: <DynamicsType>{
_dynamicsController.dynamicsType.value
},
onSelectionChanged: (Set<DynamicsType> newSelection) {
_dynamicsController.dynamicsType.value =
newSelection.first;
_dynamicsController.onSelectType(newSelection.first);
},
),
),
thumbDecoration: BoxDecoration(
color: Theme.of(context).colorScheme.background,
borderRadius: BorderRadius.circular(20),
border: Border.all(
width: 1.2,
color: Theme.of(context)
.colorScheme
.surfaceVariant
.withOpacity(0.7),
),
),
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
onValueChanged: (v) {
_dynamicsController.onSelectType(v);
},
),
))
],
),
Positioned(
@ -102,7 +158,7 @@ class _DynamicsPageState extends State<DynamicsPage>
child: IconButton(
padding: EdgeInsets.zero,
onPressed: () {
_dynamicsController.mid = -1;
_dynamicsController.mid.value = -1;
_dynamicsController.dynamicsType.value =
DynamicsType.values[0];
SmartDialog.showToast('还原默认加载',
@ -150,11 +206,14 @@ class _DynamicsPageState extends State<DynamicsPage>
List<DynamicItemModel> list =
_dynamicsController.dynamicsList!;
return Obx(
() => SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return DynamicPanel(item: list[index]);
}, childCount: list.length),
),
() => list.length == 1
? skeleton()
: SliverList(
delegate:
SliverChildBuilderDelegate((context, index) {
return DynamicPanel(item: list[index]);
}, childCount: list.length),
),
);
} else {
return HttpError(

View File

@ -1,10 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_meedu_media_kit/meedu_player.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pilipala/common/widgets/badge.dart';
import 'package:pilipala/common/widgets/network_img_layer.dart';
import 'package:pilipala/models/common/dynamics_type.dart';
import 'package:pilipala/models/dynamics/up.dart';
import 'package:pilipala/pages/dynamics/controller.dart';
@ -29,7 +26,12 @@ class _UpPanelState extends State<UpPanel> {
super.initState();
upList = widget.upData!.upList!;
liveList = widget.upData!.liveUsers!.items!;
upList.insert(0, UpItem(face: '', uname: '全部动态', mid: -1));
upList.insert(
0,
UpItem(
face: 'https://files.catbox.moe/8uc48f.png',
uname: '全部动态',
mid: -1));
}
@override
@ -103,7 +105,8 @@ class _UpPanelState extends State<UpPanel> {
onTap: () {
if (data.type == 'up') {
currentMid = data.mid;
Get.find<DynamicsController>().mid = data.mid;
Get.find<DynamicsController>().mid.value = data.mid;
Get.find<DynamicsController>().upInfo.value = data;
Get.find<DynamicsController>().onSelectUp(data.mid);
int liveLen = liveList.length;
int upLen = upList.length;

View File

@ -225,6 +225,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.5"
custom_sliding_segmented_control:
dependency: "direct main"
description:
name: custom_sliding_segmented_control
sha256: a12d1908bb3fe06aabd4becd7def608cdd77b01b7a9f79e37d9414b478523a34
url: "https://pub.dev"
source: hosted
version: "1.7.5"
dart_style:
dependency: transitive
description:

View File

@ -84,6 +84,7 @@ dependencies:
url: https://github.com/guozhigq/flutter_meedu_media_kit.git
ref: feature-custom
path: package
custom_sliding_segmented_control: ^1.7.5
dev_dependencies:
flutter_test: