opt: member page

This commit is contained in:
bggRGjQaUbCoE
2024-10-18 11:25:35 +08:00
parent 122328c18e
commit b57d1a0a62
6 changed files with 100 additions and 59 deletions

View File

@@ -16,7 +16,7 @@ Tab _$TabFromJson(Map<String, dynamic> json) => Tab(
coin: json['coin'] as bool?, coin: json['coin'] as bool?,
like: json['like'] as bool?, like: json['like'] as bool?,
community: json['community'] as bool?, community: json['community'] as bool?,
dyn: json['dynamic'] as bool?, dyn: false, //json['dynamic'] as bool?,
audios: json['audios'] as bool?, audios: json['audios'] as bool?,
shop: json['shop'] as bool?, shop: json['shop'] as bool?,
mall: json['mall'] as bool?, mall: json['mall'] as bool?,

View File

@@ -53,7 +53,7 @@ class _MemberVideoState extends State<MemberVideo>
} }
_buildBody(LoadingState loadingState) { _buildBody(LoadingState loadingState) {
return loadingState is Success return loadingState is Success && loadingState.response is List
? RefreshIndicator( ? RefreshIndicator(
onRefresh: () async { onRefresh: () async {
await _controller.onRefresh(); await _controller.onRefresh();
@@ -137,20 +137,22 @@ class _MemberVideoState extends State<MemberVideo>
], ],
), ),
) )
: loadingState is Error : loadingState is Loading
? Center( ? Center(
child: CircularProgressIndicator(),
)
: Center(
child: CustomScrollView( child: CustomScrollView(
shrinkWrap: true, shrinkWrap: true,
slivers: [ slivers: [
HttpError( HttpError(
errMsg: loadingState.errMsg, errMsg: loadingState is Error
? (loadingState as Error?)?.errMsg
: 'EMPTY',
fn: _controller.onReload, fn: _controller.onReload,
), ),
], ],
), ),
)
: Center(
child: CircularProgressIndicator(),
); );
} }
} }

View File

@@ -10,6 +10,7 @@ import 'package:PiliPalaX/pages/member/new/content/member_contribute/member_cont
import 'package:PiliPalaX/pages/member/new/controller.dart'; import 'package:PiliPalaX/pages/member/new/controller.dart';
import 'package:PiliPalaX/utils/grid.dart'; import 'package:PiliPalaX/utils/grid.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
class MemberHome extends StatefulWidget { class MemberHome extends StatefulWidget {
@@ -70,6 +71,33 @@ class _MemberHomeState extends State<MemberHome>
), ),
), ),
], ],
if (loadingState.response?.favourite2?.item?.isNotEmpty ==
true) ...[
_videoHeader(
title: '收藏',
param: 'favorite',
count: loadingState.response.favourite2.count,
),
// TODO
],
if (loadingState.response?.coinArchive?.item?.isNotEmpty ==
true) ...[
_videoHeader(
title: '最近投币的视频',
param: 'coinArchive',
count: loadingState.response.coinArchive.count,
),
// TODO
],
if (loadingState.response?.likeArchive?.item?.isNotEmpty ==
true) ...[
_videoHeader(
title: '最近点赞的视频',
param: 'coinArchive',
count: loadingState.response.likeArchive.count,
),
// TODO
],
if (loadingState.response?.article?.item?.isNotEmpty == true) ...[ if (loadingState.response?.article?.item?.isNotEmpty == true) ...[
_videoHeader( _videoHeader(
title: '专栏', title: '专栏',
@@ -159,6 +187,7 @@ class _MemberHomeState extends State<MemberHome>
onTap: () { onTap: () {
int index = int index =
_ctr.tab2!.indexWhere((item) => item.param == param); _ctr.tab2!.indexWhere((item) => item.param == param);
if (index != -1) {
if (['video', 'article', 'audio'].contains(param1)) { if (['video', 'article', 'audio'].contains(param1)) {
List<Item> items = _ctr.tab2! List<Item> items = _ctr.tab2!
.firstWhere((item) => item.param == param) .firstWhere((item) => item.param == param)
@@ -178,8 +207,10 @@ class _MemberHomeState extends State<MemberHome>
print('not initialized'); print('not initialized');
} }
} }
if (index != -1) {
_ctr.tabController.animateTo(index); _ctr.tabController.animateTo(index);
} else {
// TODO
SmartDialog.showToast('view $param');
} }
}, },
child: Text.rich( child: Text.rich(

View File

@@ -39,27 +39,26 @@ class MemberControllerNew extends CommonController
relation.value = response.response?.relation ?? 1; relation.value = response.response?.relation ?? 1;
tab2 = response.response.tab2; tab2 = response.response.tab2;
if (tab2 != null && tab2!.isNotEmpty) { if (tab2 != null && tab2!.isNotEmpty) {
int initialIndex = tab2! if (!response.response.tab.toJson().values.contains(true) &&
.indexWhere((item) => item.param == response.response.defaultTab); tab2!.first.param == 'home') {
if (initialIndex == 0 && // remove empty home tab
!response.response.tab.toJson().values.contains('true')) { tab2!.removeAt(0);
if (tab2!.length > 1) {
initialIndex = 1;
} }
// TODO if (tab2!.isNotEmpty) {
// tab2!.removeAt(0); if (response.response.defaultTab == 'video') {
response.response.defaultTab = 'dynamic';
} }
int initialIndex = tab2!.indexWhere((item) {
return item.param == response.response.defaultTab;
});
tabs = tab2!.map((item) => Tab(text: item.title ?? '')).toList(); tabs = tab2!.map((item) => Tab(text: item.title ?? '')).toList();
tabController = TabController( tabController = TabController(
vsync: this, vsync: this,
length: response.response.tab2.length, length: response.response.tab2.length,
initialIndex: initialIndex == -1 initialIndex: initialIndex == -1 ? 0 : initialIndex,
? tab2!.length > 1
? 1
: 0
: initialIndex,
); );
} }
}
loadingState.value = response; loadingState.value = response;
return true; return true;
} }

View File

@@ -67,8 +67,7 @@ class _MemberPageNewState extends State<MemberPageNew>
), ),
]; ];
}, },
body: _userController.tab2 != null && body: _userController.tab2?.isNotEmpty == true
_userController.tab2!.isNotEmpty
? LayoutBuilder( ? LayoutBuilder(
builder: (context, _) { builder: (context, _) {
return Padding( return Padding(
@@ -103,8 +102,16 @@ class _MemberPageNewState extends State<MemberPageNew>
child: Column( child: Column(
children: [ children: [
SizedBox(height: _userController.top), SizedBox(height: _userController.top),
if ((_userController.tab2?.length ?? -1) > 1)
_buildTab, _buildTab,
Expanded(child: _buildBody), Expanded(
child:
_userController.tab2?.isNotEmpty == true
? _buildBody
: Center(
child: const Text('EMPTY'),
),
),
], ],
), ),
), ),
@@ -172,9 +179,7 @@ class _MemberPageNewState extends State<MemberPageNew>
pinned: true, pinned: true,
scrolledUnderElevation: 0, scrolledUnderElevation: 0,
flexibleSpace: _buildUserInfo(_userController.loadingState.value), flexibleSpace: _buildUserInfo(_userController.loadingState.value),
bottom: needTab && bottom: needTab && (_userController.tab2?.length ?? -1) > 1
_userController.tab2 != null &&
_userController.tab2!.isNotEmpty
? PreferredSize( ? PreferredSize(
preferredSize: Size.fromHeight(48), preferredSize: Size.fromHeight(48),
child: Material( child: Material(
@@ -293,13 +298,17 @@ class _MemberPageNewState extends State<MemberPageNew>
return _errorWidget(userState.errMsg); return _errorWidget(userState.errMsg);
case Success(): case Success():
return Obx( return Obx(
() => UserInfoCard( () => Padding(
padding: EdgeInsets.only(
bottom: (_userController.tab2?.length ?? 0) > 1 ? 48 : 0),
child: UserInfoCard(
relation: _userController.relation.value, relation: _userController.relation.value,
isFollow: _userController.isFollow.value, isFollow: _userController.isFollow.value,
card: userState.response.card, card: userState.response.card,
images: userState.response.images, images: userState.response.images,
onFollow: () => _userController.onFollow(context), onFollow: () => _userController.onFollow(context),
), ),
),
); );
} }
return const CircularProgressIndicator(); return const CircularProgressIndicator();

View File

@@ -416,7 +416,7 @@ class UserInfoCard extends StatelessWidget {
// .toList(), // .toList(),
// ), // ),
// ), // ),
const SizedBox(height: 50), const SizedBox(height: 5),
], ],
); );
} }