child: Stack(
children: <Widget>[
Container(
color: widget?.backgroundColor,
child: buildContent(),
),
buildTop(),
buildRight(),
],),複製代碼
onVerticalDragUpdate: _inContent
? (details) {
calculateOffsetY(
details,
((widget?.topPopConfig?.topMaxHeight ?? 0) <= 0
? _height
: (widget?.topPopConfig?.topMaxHeight ?? 0)) -
(widget?.topPopConfig?.topMinHeight ?? 0));
}
: null,
複製代碼
class TopPop extends StatelessWidget {
final double offsetY;
final double height;
final double minHeight;
final double parentHeight;
final Widget child;
final Color backgroupColor;
final bool needDarker;
final GestureTapCallback onDarkerTap;
TopPop(
{Key key,
this.offsetY = 0.0,
this.height = 0.0,
this.minHeight = 0.0,
this.parentHeight = 0.0,
this.child,
this.backgroupColor,
this.needDarker = false,
this.onDarkerTap})
: super(key: key);
@override
Widget build(BuildContext context) {
double tempOffsetY = 0.0;
if (offsetY >= 0.0) {
tempOffsetY = max(0.0, (parentHeight - minHeight));
} else {
tempOffsetY = offsetY + max(0.0, (parentHeight - minHeight));
}
double opacity = offsetY.abs() / height;
debugPrint(
'++++++++offsetY = ${offsetY.toString()}+++++++++opacity = ${opacity.toString()}+++++parentHeight= ${parentHeight.toString()}++ height=${height.toString()}++++++++++minHeight=${minHeight.toString()}+++++++++++++++++++');
return Stack(
children: <Widget>[
needDarker && opacity > 0
? GestureDetector(
onTap: onDarkerTap,
child: Opacity(
opacity: opacity,
child: Container(
width: MediaQuery.of(context).size.width,
height: parentHeight,
color: Color(0x4C000000),
),
),
)
: Container(),
Transform.translate(
offset: Offset(0, tempOffsetY),
child: Container(
color: backgroupColor ?? Color(0x00000000),
width: MediaQuery.of(context).size.width,
height: height,
child: child,
))
],
);
}
}
複製代碼
onVerticalDragEnd: (_) {
if (_offsetY.abs() >
(widget?.topPopConfig?.topAutoAnimDistance ?? 20) &&
topDirection == AxisDirection.up) {
animateToTop();
} else {
animateToBottom();
}
},
複製代碼
onVerticalDragStart: (_) {
_animationControllerX?.stop();
_animationControllerY?.stop();
},
複製代碼
代碼地址:
github.com/sail-coder/…
git