Skip to content

Commit

Permalink
indicate color
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed Sep 8, 2024
1 parent 6bb5a4f commit 2d024de
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 88 deletions.
117 changes: 57 additions & 60 deletions lib/component/painer_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -50,73 +52,68 @@ 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)],
),
),
),
);
}

_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) {
Expand Down Expand Up @@ -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)),
),
],
),
Expand Down
5 changes: 4 additions & 1 deletion lib/component/pixez_default_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 30 additions & 8 deletions lib/page/hello/recom/recom_user_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

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;
Expand Down Expand Up @@ -65,16 +68,35 @@ class _RecomUserPageState extends State<RecomUserPage> {
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,
);
},
);
}
}
39 changes: 20 additions & 19 deletions lib/page/painter/painter_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,31 +79,31 @@ class _PainterListState extends State<PainterList> {
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),
);
}
}

0 comments on commit 2d024de

Please sign in to comment.