From 2d024dee14daef8b19a17d1b0f69e3069af517f6 Mon Sep 17 00:00:00 2001 From: perol Date: Sun, 8 Sep 2024 14:00:18 +0800 Subject: [PATCH] indicate color --- lib/component/painer_card.dart | 117 +++++++++++----------- lib/component/pixez_default_header.dart | 5 +- lib/page/hello/recom/recom_user_page.dart | 38 +++++-- lib/page/painter/painter_list.dart | 39 ++++---- 4 files changed, 111 insertions(+), 88 deletions(-) diff --git a/lib/component/painer_card.dart b/lib/component/painer_card.dart index fe94ce595..cd3c2dbf3 100644 --- a/lib/component/painer_card.dart +++ b/lib/component/painer_card.dart @@ -14,6 +14,8 @@ * */ +import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:pixez/component/painter_avatar.dart'; import 'package:pixez/component/pixiv_image.dart'; @@ -50,13 +52,8 @@ class PainterCard extends StatelessWidget { child: Card( clipBehavior: Clip.antiAlias, child: Container( - height: (MediaQuery.of(context).size.width - 4) / 3 + 80, - child: CustomScrollView( - physics: NeverScrollableScrollPhysics(), - slivers: [ - _buildPreviewSlivers(context), - SliverToBoxAdapter(child: buildPadding(context)) - ], + child: Column( + children: [_buildPreviewSlivers(context), buildPadding(context)], ), ), ), @@ -64,59 +61,59 @@ class PainterCard extends StatelessWidget { } _buildPreviewSlivers(BuildContext context) { - final needBlankSliver = - (isNovel && user.novels.isEmpty) || (!isNovel && user.illusts.isEmpty); - if (needBlankSliver) - return SliverToBoxAdapter( - child: Container( - height: (MediaQuery.of(context).size.width) / 3, - ), - ); return (isNovel) - ? SliverGrid( - gridDelegate: - SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), - delegate: SliverChildBuilderDelegate((context, index) { - if (index >= user.novels.length) return Container(); - final novel = user.novels[index]; - return Stack( - children: [ - PixivImage( - novel.imageUrls.squareMedium, - fit: BoxFit.cover, - ), - Align( - alignment: Alignment.topCenter, - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Text( - novel.title, - style: Theme.of(context).textTheme.titleSmall, - maxLines: 3, - overflow: TextOverflow.ellipsis, - ), - ), - ) - ], - ); - }, childCount: user.illusts.length)) - : SliverGrid( - gridDelegate: - SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), - delegate: SliverChildBuilderDelegate((context, index) { - if (index >= user.illusts.length) return Container(); - var currentIllust = user.illusts[index]; - if (currentIllust.hIsNotAllow()) { - return Container( - color: Colors.white, - child: Image.asset('assets/images/h.jpg'), - ); - } - return PixivImage( - currentIllust.imageUrls.squareMedium, - fit: BoxFit.cover, - ); - }, childCount: user.illusts.length)); + ? Row( + children: [ + for (var i = 0; i < 3; i++) + Expanded( + child: i < user.novels.length + ? AspectRatio( + aspectRatio: 1.0, + child: Stack( + children: [ + AspectRatio( + aspectRatio: 1.0, + child: PixivImage( + user.novels[i].imageUrls.squareMedium, + fit: BoxFit.cover, + ), + ), + Align( + alignment: Alignment.bottomCenter, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text( + user.novels[i].title, + style: + Theme.of(context).textTheme.titleSmall, + maxLines: 3, + overflow: TextOverflow.ellipsis, + ), + ), + ) + ], + ), + ) + : Container(), + ) + ], + ) + : Row( + children: [ + for (var i = 0; i < 3; i++) + Expanded( + child: i < user.illusts.length + ? AspectRatio( + aspectRatio: 1.0, + child: PixivImage( + user.illusts[i].imageUrls.squareMedium, + fit: BoxFit.cover, + ), + ) + : Container(), + ) + ], + ); } Widget buildPadding(BuildContext context) { @@ -150,7 +147,7 @@ class PainterCard extends StatelessWidget { ), Padding( padding: const EdgeInsets.all(16.0), - child: Text(user.user.name), + child: Center(child: Text(user.user.name)), ), ], ), diff --git a/lib/component/pixez_default_header.dart b/lib/component/pixez_default_header.dart index 066fe62dd..b0d81ef20 100644 --- a/lib/component/pixez_default_header.dart +++ b/lib/component/pixez_default_header.dart @@ -6,7 +6,10 @@ class PixezDefault { static Header header(BuildContext context, {IndicatorPosition position = IndicatorPosition.above, bool safeArea = true}) { - return MaterialHeader(position: position, safeArea: safeArea); + return MaterialHeader( + position: position, + safeArea: safeArea, + backgroundColor: Theme.of(context).scaffoldBackgroundColor); } static Footer footer(BuildContext context, diff --git a/lib/page/hello/recom/recom_user_page.dart b/lib/page/hello/recom/recom_user_page.dart index 9d09775f2..611641ba8 100644 --- a/lib/page/hello/recom/recom_user_page.dart +++ b/lib/page/hello/recom/recom_user_page.dart @@ -13,13 +13,16 @@ * this program. If not, see . */ +import 'dart:math'; import 'package:easy_refresh/easy_refresh.dart'; import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:pixez/component/painer_card.dart'; import 'package:pixez/i18n.dart'; +import 'package:pixez/main.dart'; import 'package:pixez/page/hello/recom/recom_user_store.dart'; +import 'package:waterfall_flow/waterfall_flow.dart'; class RecomUserPage extends StatefulWidget { final RecomUserStore? recomUserStore; @@ -65,16 +68,35 @@ class _RecomUserPageState extends State { onRefresh: () => _recomUserStore.fetch(), onLoad: () => _recomUserStore.next(), refreshOnStart: widget.recomUserStore == null, - child: ListView.builder( - itemCount: _recomUserStore.users.length, - itemBuilder: (context, index) { - final data = _recomUserStore.users[index]; - return PainterCard( - user: data, - ); - }), + child: _buildList(), ), ); }); } + + int _buildSliderValue(BuildContext context, Orientation orientation) { + final currentValue = (orientation == Orientation.portrait + ? userSetting.crossAdapterWidth + : userSetting.hCrossAdapterWidth) + .toDouble(); + var nowAdaptWidth = max(currentValue, 50.0); + nowAdaptWidth = min(nowAdaptWidth, 2160); + return max((MediaQuery.of(context).size.width / nowAdaptWidth), 1.0) + .toInt(); + } + + Widget _buildList() { + return WaterfallFlow.builder( + gridDelegate: SliverWaterfallFlowDelegateWithMaxCrossAxisExtent( + maxCrossAxisExtent: 600, + ), + itemCount: _recomUserStore.users.length, + itemBuilder: (context, index) { + final data = _recomUserStore.users[index]; + return PainterCard( + user: data, + ); + }, + ); + } } diff --git a/lib/page/painter/painter_list.dart b/lib/page/painter/painter_list.dart index 6acfe6641..81e6e28f9 100644 --- a/lib/page/painter/painter_list.dart +++ b/lib/page/painter/painter_list.dart @@ -21,6 +21,7 @@ import 'package:pixez/component/painer_card.dart'; import 'package:pixez/component/pixez_default_header.dart'; import 'package:pixez/lighting/lighting_store.dart'; import 'package:pixez/page/painter/painter_list_store.dart'; +import 'package:waterfall_flow/waterfall_flow.dart'; class PainterList extends StatefulWidget { final FutureGet futureGet; @@ -78,31 +79,31 @@ class _PainterListState extends State { onLoad: () => _painterListStore.next(), onRefresh: () => _painterListStore.fetch(), child: _painterListStore.users.isNotEmpty - ? ListView.builder( - controller: _scrollController, - padding: EdgeInsets.all(0), - itemBuilder: (context, index) { - if (index == 0 && widget.header != null) { - return widget.header!; - } - - if (widget.header != null) return _itemBuilder(index - 1); - return _itemBuilder(index); - }, - itemCount: widget.header == null - ? _painterListStore.users.length - : _painterListStore.users.length + 1, + ? CustomScrollView( + slivers: [ + if (widget.header != null) + SliverToBoxAdapter( + child: widget.header!, + ), + _buildList(), + ], ) : Container(), ); }); } - Widget _itemBuilder(int index) { - final user = _painterListStore.users[index]; - return PainterCard( - user: user, - isNovel: widget.isNovel, + Widget _buildList() { + return SliverWaterfallFlow( + delegate: SliverChildBuilderDelegate((context, index) { + final data = _painterListStore.users[index]; + return PainterCard( + user: data, + isNovel: widget.isNovel, + ); + }, childCount: _painterListStore.users.length), + gridDelegate: SliverWaterfallFlowDelegateWithMaxCrossAxisExtent( + maxCrossAxisExtent: 600), ); } }