diff --git a/lib/pages/dynamics/controller.dart b/lib/pages/dynamics/controller.dart index 0fb9460c..27ad2b89 100644 --- a/lib/pages/dynamics/controller.dart +++ b/lib/pages/dynamics/controller.dart @@ -17,7 +17,8 @@ class DynamicsController extends GetxController { final ScrollController scrollController = ScrollController(); Rx upData = FollowUpModel().obs; // 默认获取全部动态 - int mid = -1; + RxInt mid = (-1).obs; + Rx 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(); } diff --git a/lib/pages/dynamics/view.dart b/lib/pages/dynamics/view.dart index 73fdf28a..59abafc7 100644 --- a/lib/pages/dynamics/view.dart +++ b/lib/pages/dynamics/view.dart @@ -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 Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Obx( - () => SegmentedButton( - 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 animation) { + return ScaleTransition( + scale: animation, child: child); + }, + child: Text( + '${_dynamicsController.upInfo.value.uname!}的动态', + key: ValueKey( + _dynamicsController.upInfo.value.uname!), + style: TextStyle( + fontSize: Theme.of(context) + .textTheme + .labelLarge! + .fontSize, + )), ), - ), - segments: >[ - for (var i in _dynamicsController.filterTypeList) ...[ - ButtonSegment( - 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( + 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: { - _dynamicsController.dynamicsType.value - }, - onSelectionChanged: (Set 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 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 List 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( diff --git a/lib/pages/dynamics/widgets/up_panel.dart b/lib/pages/dynamics/widgets/up_panel.dart index 0f499694..60317fd0 100644 --- a/lib/pages/dynamics/widgets/up_panel.dart +++ b/lib/pages/dynamics/widgets/up_panel.dart @@ -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 { 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 { onTap: () { if (data.type == 'up') { currentMid = data.mid; - Get.find().mid = data.mid; + Get.find().mid.value = data.mid; + Get.find().upInfo.value = data; Get.find().onSelectUp(data.mid); int liveLen = liveList.length; int upLen = upList.length; diff --git a/pubspec.lock b/pubspec.lock index 7e5d3983..a2e405ef 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index 4eea40fc..c96b86f3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -84,7 +84,8 @@ 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: sdk: flutter