mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 03:06:59 +08:00
94
lib/common/widgets/extra_hittest_stack.dart
Normal file
94
lib/common/widgets/extra_hittest_stack.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart'
|
||||
show RenderStack, BoxHitTestResult, BoxHitTestEntry;
|
||||
|
||||
class ExtraHitTestStack extends Stack {
|
||||
const ExtraHitTestStack({
|
||||
super.key,
|
||||
super.alignment,
|
||||
super.textDirection,
|
||||
super.fit,
|
||||
super.clipBehavior,
|
||||
super.children,
|
||||
});
|
||||
|
||||
@override
|
||||
RenderExtraHitTestStack createRenderObject(BuildContext context) {
|
||||
return RenderExtraHitTestStack(
|
||||
alignment: alignment,
|
||||
textDirection: textDirection ?? Directionality.maybeOf(context),
|
||||
fit: fit,
|
||||
clipBehavior: clipBehavior,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void updateRenderObject(
|
||||
BuildContext context,
|
||||
RenderExtraHitTestStack renderObject,
|
||||
) {
|
||||
renderObject
|
||||
..alignment = alignment
|
||||
..textDirection = textDirection ?? Directionality.maybeOf(context)
|
||||
..fit = fit
|
||||
..clipBehavior = clipBehavior;
|
||||
}
|
||||
}
|
||||
|
||||
class RenderExtraHitTestStack extends RenderStack {
|
||||
RenderExtraHitTestStack({
|
||||
super.children,
|
||||
super.alignment,
|
||||
super.textDirection,
|
||||
super.fit,
|
||||
super.clipBehavior,
|
||||
});
|
||||
|
||||
@override
|
||||
bool hitTest(BoxHitTestResult result, {required Offset position}) {
|
||||
assert(() {
|
||||
if (!hasSize) {
|
||||
if (debugNeedsLayout) {
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary(
|
||||
'Cannot hit test a render box that has never been laid out.',
|
||||
),
|
||||
describeForError(
|
||||
'The hitTest() method was called on this RenderBox',
|
||||
),
|
||||
ErrorDescription(
|
||||
"Unfortunately, this object's geometry is not known at this time, "
|
||||
'probably because it has never been laid out. '
|
||||
'This means it cannot be accurately hit-tested.',
|
||||
),
|
||||
ErrorHint(
|
||||
'If you are trying '
|
||||
'to perform a hit test during the layout phase itself, make sure '
|
||||
"you only hit test nodes that have completed layout (e.g. the node's "
|
||||
'children, after their layout() method has been called).',
|
||||
),
|
||||
]);
|
||||
}
|
||||
throw FlutterError.fromParts(<DiagnosticsNode>[
|
||||
ErrorSummary('Cannot hit test a render box with no size.'),
|
||||
describeForError('The hitTest() method was called on this RenderBox'),
|
||||
ErrorDescription(
|
||||
'Although this node is not marked as needing layout, '
|
||||
'its size is not set.',
|
||||
),
|
||||
ErrorHint(
|
||||
'A RenderBox object must have an '
|
||||
'explicit size before it can be hit-tested. Make sure '
|
||||
'that the RenderBox in question sets its size during layout.',
|
||||
),
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
}());
|
||||
if (hitTestChildren(result, position: position) || hitTestSelf(position)) {
|
||||
result.add(BoxHitTestEntry(this, position));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/common/assets.dart';
|
||||
import 'package:PiliPlus/common/style.dart';
|
||||
import 'package:PiliPlus/common/widgets/extra_hittest_stack.dart';
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/models/common/avatar_badge_type.dart';
|
||||
import 'package:PiliPlus/models/common/image_type.dart';
|
||||
@@ -82,7 +83,7 @@ class PendantAvatar extends StatelessWidget {
|
||||
child: avatar,
|
||||
);
|
||||
}
|
||||
Widget child = Stack(
|
||||
Widget child = ExtraHitTestStack(
|
||||
clipBehavior: .none,
|
||||
alignment: .center,
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user