opt: trending page

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-18 14:57:44 +08:00
parent 1c4eb0766b
commit 8ca4f7c8d3

View File

@@ -1,3 +1,5 @@
import 'dart:math';
import 'package:PiliPlus/common/widgets/http_error.dart'; import 'package:PiliPlus/common/widgets/http_error.dart';
import 'package:PiliPlus/common/widgets/refresh_indicator.dart'; import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
import 'package:PiliPlus/http/loading_state.dart'; import 'package:PiliPlus/http/loading_state.dart';
@@ -57,89 +59,95 @@ class _SearchTrendingPageState extends State<SearchTrendingPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final removePadding = context.width > 640; return LayoutBuilder(builder: (context, constraints) {
return Scaffold( final width = constraints.maxWidth;
extendBody: true, final maxWidth = constraints.maxWidth > constraints.maxHeight
extendBodyBehindAppBar: true, ? min(640.0, width * 0.6)
appBar: PreferredSize( : width;
preferredSize: Size.fromHeight(56), final removePadding = width > maxWidth;
child: Obx( return Scaffold(
() { extendBody: true,
final half = _scrollRatio.value >= 0.5; extendBodyBehindAppBar: true,
return AppBar( appBar: PreferredSize(
title: Opacity( preferredSize: Size.fromHeight(56),
opacity: _scrollRatio.value, child: Obx(
child: Text( () {
'B站热搜', final half = _scrollRatio.value >= 0.5;
style: TextStyle( return AppBar(
color: half ? null : Colors.white, title: Opacity(
opacity: _scrollRatio.value,
child: Text(
'B站热搜',
style: TextStyle(
color: half ? null : Colors.white,
),
), ),
), ),
), backgroundColor: Theme.of(context)
backgroundColor: Theme.of(context) .colorScheme
.colorScheme .surface
.surface .withOpacity(_scrollRatio.value),
.withOpacity(_scrollRatio.value), foregroundColor: half ? null : Colors.white,
foregroundColor: half ? null : Colors.white, systemOverlayStyle: half
systemOverlayStyle: half ? null
? null : SystemUiOverlayStyle(
: SystemUiOverlayStyle( statusBarBrightness: Brightness.dark,
statusBarBrightness: Brightness.dark, statusBarIconBrightness: Brightness.light,
statusBarIconBrightness: Brightness.light,
),
bottom: _scrollRatio.value == 1
? PreferredSize(
preferredSize: Size.fromHeight(1),
child: Divider(
height: 1,
color: Theme.of(context)
.colorScheme
.outline
.withOpacity(0.1),
), ),
) bottom: _scrollRatio.value == 1
: null, ? PreferredSize(
); preferredSize: Size.fromHeight(1),
}, child: Divider(
height: 1,
color: Theme.of(context)
.colorScheme
.outline
.withOpacity(0.1),
),
)
: null,
);
},
),
), ),
), body: Center(
body: MediaQuery.removePadding(
context: context,
removeLeft: removePadding,
removeRight: removePadding,
child: Center(
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 640), constraints: BoxConstraints(maxWidth: maxWidth),
child: refreshIndicator( child: MediaQuery.removePadding(
onRefresh: () async { context: context,
await _controller.onRefresh(); removeLeft: removePadding,
}, removeRight: removePadding,
child: CustomScrollView( child: refreshIndicator(
controller: _controller.scrollController, onRefresh: () async {
slivers: [ await _controller.onRefresh();
SliverToBoxAdapter( },
child: CachedNetworkImage( child: CustomScrollView(
fit: BoxFit.fitWidth, controller: _controller.scrollController,
fadeInDuration: const Duration(milliseconds: 120), slivers: [
fadeOutDuration: const Duration(milliseconds: 120), SliverToBoxAdapter(
imageUrl: child: CachedNetworkImage(
'https://activity.hdslb.com/blackboard/activity59158/img/hot_banner.fbb081df.png', fit: BoxFit.fitWidth,
placeholder: (context, url) { fadeInDuration: const Duration(milliseconds: 120),
return AspectRatio( fadeOutDuration: const Duration(milliseconds: 120),
aspectRatio: 1125 / 528, imageUrl:
child: Image.asset('assets/images/loading.png'), 'https://activity.hdslb.com/blackboard/activity59158/img/hot_banner.fbb081df.png',
); placeholder: (context, url) {
}, return AspectRatio(
aspectRatio: 1125 / 528,
child: Image.asset('assets/images/loading.png'),
);
},
),
), ),
), Obx(() => _buildBody(_controller.loadingState.value)),
Obx(() => _buildBody(_controller.loadingState.value)), ],
], ),
), ),
), ),
), ),
), ),
), );
); });
} }
Widget _buildBody(LoadingState<List<SearchKeywordList>?> loadingState) { Widget _buildBody(LoadingState<List<SearchKeywordList>?> loadingState) {