mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-22 09:08:45 +00:00
117
lib/pages/member/widget/header_layout_widget.dart
Normal file
117
lib/pages/member/widget/header_layout_widget.dart
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of PiliPlus
|
||||||
|
*
|
||||||
|
* PiliPlus is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* PiliPlus is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with PiliPlus. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import 'dart:math' as math;
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart'
|
||||||
|
show
|
||||||
|
ContainerRenderObjectMixin,
|
||||||
|
MultiChildLayoutParentData,
|
||||||
|
RenderBoxContainerDefaultsMixin,
|
||||||
|
BoxHitTestResult;
|
||||||
|
|
||||||
|
const double kHeaderHeight = 135.0;
|
||||||
|
|
||||||
|
const double kAvatarSize = 80.0;
|
||||||
|
const double _kAvatarLeftPadding = 20.0;
|
||||||
|
const double _kAvatarTopPadding = 110.0;
|
||||||
|
const double _kAvatarEffectiveHeight =
|
||||||
|
kAvatarSize - (kHeaderHeight - _kAvatarTopPadding);
|
||||||
|
|
||||||
|
const double _kActionsTopPadding = 140.0;
|
||||||
|
const double _kActionsLeftPadding = 160.0;
|
||||||
|
const double _kActionsRightPadding = 15.0;
|
||||||
|
|
||||||
|
enum HeaderType { header, avatar, actions }
|
||||||
|
|
||||||
|
class HeaderLayoutWidget extends MultiChildRenderObjectWidget {
|
||||||
|
const HeaderLayoutWidget({
|
||||||
|
super.key,
|
||||||
|
super.children,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
RenderObject createRenderObject(BuildContext context) {
|
||||||
|
return RenderHeaderWidget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RenderHeaderWidget extends RenderBox
|
||||||
|
with
|
||||||
|
ContainerRenderObjectMixin<RenderBox, MultiChildLayoutParentData>,
|
||||||
|
RenderBoxContainerDefaultsMixin<RenderBox, MultiChildLayoutParentData> {
|
||||||
|
@override
|
||||||
|
void setupParentData(RenderBox child) {
|
||||||
|
if (child.parentData is! MultiChildLayoutParentData) {
|
||||||
|
child.parentData = MultiChildLayoutParentData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void performLayout() {
|
||||||
|
double height = kHeaderHeight;
|
||||||
|
RenderBox? child = firstChild;
|
||||||
|
final maxWidth = constraints.maxWidth;
|
||||||
|
while (child != null) {
|
||||||
|
final childParentData = child.parentData! as MultiChildLayoutParentData;
|
||||||
|
|
||||||
|
switch (childParentData.id as HeaderType) {
|
||||||
|
case HeaderType.header:
|
||||||
|
child.layout(constraints);
|
||||||
|
childParentData.offset = .zero;
|
||||||
|
case HeaderType.avatar:
|
||||||
|
child.layout(constraints);
|
||||||
|
childParentData.offset = const Offset(
|
||||||
|
_kAvatarLeftPadding,
|
||||||
|
_kAvatarTopPadding,
|
||||||
|
);
|
||||||
|
case HeaderType.actions:
|
||||||
|
final childSize =
|
||||||
|
(child..layout(
|
||||||
|
BoxConstraints(
|
||||||
|
maxWidth:
|
||||||
|
maxWidth -
|
||||||
|
_kActionsLeftPadding -
|
||||||
|
_kActionsRightPadding,
|
||||||
|
),
|
||||||
|
parentUsesSize: true,
|
||||||
|
))
|
||||||
|
.size;
|
||||||
|
height += (math.max(_kAvatarEffectiveHeight, childSize.height)) + 5.0;
|
||||||
|
childParentData.offset = Offset(
|
||||||
|
maxWidth - childSize.width - _kActionsRightPadding,
|
||||||
|
_kActionsTopPadding,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
child = childParentData.nextSibling;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = constraints.constrainDimensions(maxWidth, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(PaintingContext context, Offset offset) {
|
||||||
|
defaultPaint(context, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) {
|
||||||
|
return defaultHitTestChildren(result, position: position);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import 'package:PiliPlus/models_new/space/space/pr_info.dart';
|
|||||||
import 'package:PiliPlus/pages/fan/view.dart';
|
import 'package:PiliPlus/pages/fan/view.dart';
|
||||||
import 'package:PiliPlus/pages/follow/view.dart';
|
import 'package:PiliPlus/pages/follow/view.dart';
|
||||||
import 'package:PiliPlus/pages/follow_type/followed/view.dart';
|
import 'package:PiliPlus/pages/follow_type/followed/view.dart';
|
||||||
|
import 'package:PiliPlus/pages/member/widget/header_layout_widget.dart';
|
||||||
import 'package:PiliPlus/utils/accounts.dart';
|
import 'package:PiliPlus/utils/accounts.dart';
|
||||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||||
import 'package:PiliPlus/utils/extension/context_ext.dart';
|
import 'package:PiliPlus/utils/extension/context_ext.dart';
|
||||||
@@ -128,7 +129,7 @@ class UserInfoCard extends StatelessWidget {
|
|||||||
tag: imgUrl,
|
tag: imgUrl,
|
||||||
child: CachedNetworkImage(
|
child: CachedNetworkImage(
|
||||||
fit: .cover,
|
fit: .cover,
|
||||||
height: 135,
|
height: kHeaderHeight,
|
||||||
width: width,
|
width: width,
|
||||||
memCacheWidth: width.cacheSize(context),
|
memCacheWidth: width.cacheSize(context),
|
||||||
imageUrl: ImageUtils.thumbnailUrl(imgUrl),
|
imageUrl: ImageUtils.thumbnailUrl(imgUrl),
|
||||||
@@ -457,7 +458,7 @@ class UserInfoCard extends StatelessWidget {
|
|||||||
tag: card.face ?? '',
|
tag: card.face ?? '',
|
||||||
child: PendantAvatar(
|
child: PendantAvatar(
|
||||||
avatar: card.face,
|
avatar: card.face,
|
||||||
size: 80,
|
size: kAvatarSize,
|
||||||
badgeSize: 20,
|
badgeSize: 20,
|
||||||
officialType: card.officialVerify?.type,
|
officialType: card.officialVerify?.type,
|
||||||
isVip: (card.vip?.status ?? -1) > 0,
|
isVip: (card.vip?.status ?? -1) > 0,
|
||||||
@@ -478,29 +479,18 @@ class UserInfoCard extends StatelessWidget {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Stack(
|
HeaderLayoutWidget(
|
||||||
clipBehavior: Clip.none,
|
|
||||||
children: [
|
children: [
|
||||||
Column(
|
LayoutId(
|
||||||
crossAxisAlignment: .stretch,
|
id: HeaderType.header,
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: _buildHeader(context, colorScheme, isLight, width),
|
||||||
children: [
|
|
||||||
_buildHeader(context, colorScheme, isLight, width),
|
|
||||||
SizedBox(
|
|
||||||
height: MediaQuery.textScalerOf(context).scale(30) + 60,
|
|
||||||
),
|
),
|
||||||
],
|
LayoutId(
|
||||||
),
|
id: HeaderType.avatar,
|
||||||
Positioned(
|
|
||||||
top: 110,
|
|
||||||
left: 20,
|
|
||||||
child: _buildAvatar,
|
child: _buildAvatar,
|
||||||
),
|
),
|
||||||
Positioned(
|
LayoutId(
|
||||||
left: 160,
|
id: HeaderType.actions,
|
||||||
top: 140,
|
|
||||||
right: 15,
|
|
||||||
bottom: 0,
|
|
||||||
child: _buildRight(colorScheme),
|
child: _buildRight(colorScheme),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user