mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-08-03 17:20:16 +08:00
@@ -6,8 +6,102 @@ import 'package:flutter/rendering.dart'
|
||||
typedef Heights = ({double from, double to});
|
||||
|
||||
/// ref [AnimatedSize]
|
||||
class AnimatedHeight extends StatefulWidget {
|
||||
const AnimatedHeight({
|
||||
|
||||
class AnimatedHeightWidgetExt extends AnimatedHeightWidget {
|
||||
const AnimatedHeightWidgetExt({
|
||||
super.key,
|
||||
required super.child,
|
||||
super.curve,
|
||||
required super.duration,
|
||||
super.reverseDuration,
|
||||
super.clipBehavior,
|
||||
required super.expand,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AnimatedHeightWidget> createState() => _AnimatedHeightWidgetExtState();
|
||||
}
|
||||
|
||||
class _AnimatedHeightWidgetExtState extends _AnimatedHeightWidgetState {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedHeightExt(
|
||||
curve: widget.curve,
|
||||
duration: widget.duration,
|
||||
reverseDuration: widget.reverseDuration,
|
||||
vsync: this,
|
||||
clipBehavior: widget.clipBehavior,
|
||||
expand: widget.expand,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AnimatedHeightExt extends AnimatedHeight {
|
||||
const AnimatedHeightExt({
|
||||
super.key,
|
||||
required super.child,
|
||||
super.curve,
|
||||
required super.duration,
|
||||
super.reverseDuration,
|
||||
required super.vsync,
|
||||
super.clipBehavior,
|
||||
required super.expand,
|
||||
});
|
||||
|
||||
@override
|
||||
RenderAnimatedHeight createRenderObject(BuildContext context) {
|
||||
return RenderAnimatedHeightExt(
|
||||
duration: duration,
|
||||
reverseDuration: reverseDuration,
|
||||
curve: curve,
|
||||
vsync: vsync,
|
||||
clipBehavior: clipBehavior,
|
||||
expand: expand,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RenderAnimatedHeightExt extends RenderAnimatedHeight {
|
||||
RenderAnimatedHeightExt({
|
||||
required super.vsync,
|
||||
required super.duration,
|
||||
super.reverseDuration,
|
||||
super.curve,
|
||||
super.clipBehavior,
|
||||
required super.expand,
|
||||
});
|
||||
|
||||
bool get _isInvisible => !isAnimating && !expand;
|
||||
|
||||
@override
|
||||
double animTo(Size childSize) => expand ? childSize.height : 0.0;
|
||||
|
||||
@override
|
||||
void performLayout() {
|
||||
if (_isInvisible) {
|
||||
_heights = const (from: 0, to: 0);
|
||||
child!.layout(constraints);
|
||||
size = constraints.constrain(.zero);
|
||||
return;
|
||||
}
|
||||
|
||||
super.performLayout();
|
||||
}
|
||||
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
if (_isInvisible) {
|
||||
_clipRectLayer.layer = null;
|
||||
return;
|
||||
}
|
||||
|
||||
super.paint(context, offset);
|
||||
}
|
||||
}
|
||||
|
||||
class AnimatedHeightWidget extends StatefulWidget {
|
||||
const AnimatedHeightWidget({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.curve = Curves.linear,
|
||||
@@ -25,14 +119,14 @@ class AnimatedHeight extends StatefulWidget {
|
||||
final bool expand;
|
||||
|
||||
@override
|
||||
State<AnimatedHeight> createState() => _AnimatedHeightState();
|
||||
State<AnimatedHeightWidget> createState() => _AnimatedHeightWidgetState();
|
||||
}
|
||||
|
||||
class _AnimatedHeightState extends State<AnimatedHeight>
|
||||
class _AnimatedHeightWidgetState extends State<AnimatedHeightWidget>
|
||||
with SingleTickerProviderStateMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _AnimatedHeight(
|
||||
return AnimatedHeight(
|
||||
curve: widget.curve,
|
||||
duration: widget.duration,
|
||||
reverseDuration: widget.reverseDuration,
|
||||
@@ -44,8 +138,9 @@ class _AnimatedHeightState extends State<AnimatedHeight>
|
||||
}
|
||||
}
|
||||
|
||||
class _AnimatedHeight extends SingleChildRenderObjectWidget {
|
||||
const _AnimatedHeight({
|
||||
class AnimatedHeight extends SingleChildRenderObjectWidget {
|
||||
const AnimatedHeight({
|
||||
super.key,
|
||||
required Widget super.child,
|
||||
this.curve = Curves.linear,
|
||||
required this.duration,
|
||||
@@ -123,7 +218,6 @@ class RenderAnimatedHeight extends RenderProxyBox {
|
||||
|
||||
late final AnimationController _controller;
|
||||
bool get isAnimating => _controller.isAnimating;
|
||||
bool get _isInvisible => !isAnimating && !expand;
|
||||
|
||||
double? _lastValue;
|
||||
Heights? _heights;
|
||||
@@ -178,17 +272,12 @@ class RenderAnimatedHeight extends RenderProxyBox {
|
||||
super.detach();
|
||||
}
|
||||
|
||||
double animTo(Size childSize) => childSize.height;
|
||||
|
||||
@override
|
||||
void performLayout() {
|
||||
final BoxConstraints constraints = this.constraints;
|
||||
|
||||
if (_isInvisible) {
|
||||
_heights = const (from: 0, to: 0);
|
||||
child!.layout(constraints);
|
||||
size = constraints.constrain(.zero);
|
||||
return;
|
||||
}
|
||||
|
||||
_lastValue = _controller.value;
|
||||
|
||||
final childSize = (child!..layout(constraints, parentUsesSize: true)).size;
|
||||
@@ -196,7 +285,7 @@ class RenderAnimatedHeight extends RenderProxyBox {
|
||||
final Size animatedSize;
|
||||
|
||||
if (isAnimating && _heights != null) {
|
||||
final to = expand ? childSize.height : 0.0;
|
||||
final to = animTo(childSize);
|
||||
if (_heights!.to != to) {
|
||||
_heights = (from: size.height, to: to);
|
||||
}
|
||||
@@ -214,11 +303,6 @@ class RenderAnimatedHeight extends RenderProxyBox {
|
||||
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
if (_isInvisible) {
|
||||
_clipRectLayer.layer = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAnimating && clipBehavior != .none) {
|
||||
final Rect rect = Offset.zero & size;
|
||||
_clipRectLayer.layer = context.pushClipRect(
|
||||
|
||||
@@ -33,10 +33,8 @@ class _MiniBottomSheetState extends BottomSheetState {
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
if (widget.enableDrag) {
|
||||
_verticalDragGestureRecognizer?.dispose();
|
||||
_verticalDragGestureRecognizer = null;
|
||||
}
|
||||
_verticalDragGestureRecognizer?.dispose();
|
||||
_verticalDragGestureRecognizer = null;
|
||||
}
|
||||
|
||||
void _onPointerDown(PointerDownEvent event) {
|
||||
|
||||
Reference in New Issue
Block a user