Add drawer

master
落雨楓 2 years ago
parent d9c92541d1
commit 1faaf0e222

@ -1,5 +1,6 @@
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter_slider_drawer/flutter_slider_drawer.dart';
class Utils {
@ -8,16 +9,23 @@ class Utils {
///
Utils._();
static Offset getOffsetValues(SlideDirection direction, double value) {
static Offset getOffsetValues(SlideDirection direction, double value,
double sliderCloseSize, double sliderOpenSize) {
final sliderAnimateSize = sliderOpenSize - sliderCloseSize;
final sliderCurrentSize = clampDouble(
sliderAnimateSize * value + sliderCloseSize,
sliderCloseSize,
sliderOpenSize);
switch (direction) {
case SlideDirection.LEFT_TO_RIGHT:
return Offset(value, 0);
return Offset(sliderCurrentSize, 0);
case SlideDirection.RIGHT_TO_LEFT:
return Offset(-value, 0);
return Offset(-sliderCurrentSize, 0);
case SlideDirection.TOP_TO_BOTTOM:
return Offset(0, value);
return Offset(0, sliderCurrentSize);
default:
return Offset(value, 0);
return Offset(sliderCurrentSize, 0);
}
}

@ -60,6 +60,12 @@ class SliderDrawer extends StatefulWidget {
///
final bool isDraggable;
///[bool] whether show cover on child when slider is opened
final bool showCover;
///[Color] whether show cover on child when slider is opened
final Color coverColor;
///[appBar] if you set [null] then it will not display app bar
///
final Widget? appBar;
@ -104,7 +110,9 @@ class SliderDrawer extends StatefulWidget {
this.slideDirection = SlideDirection.LEFT_TO_RIGHT,
this.sliderBoxShadow,
this.appBar = const SliderAppBar(),
this.isCupertino = false})
this.isCupertino = false,
this.showCover = false,
this.coverColor = const Color.fromRGBO(0, 0, 0, 0.3)})
: super(key: key);
@override
@ -119,7 +127,7 @@ class SliderDrawerState extends State<SliderDrawer>
double _percent = 0.0;
late AnimationController _animationDrawerController;
late Animation _animation;
late Animation<double> _animation;
bool _isDragging = false;
@ -149,9 +157,7 @@ class SliderDrawerState extends State<SliderDrawer>
vsync: this,
duration: Duration(milliseconds: widget.animationDuration));
_animation =
Tween<double>(begin: widget.sliderCloseSize, end: widget.sliderOpenSize)
.animate(CurvedAnimation(
_animation = Tween<double>(begin: 0, end: 1).animate(CurvedAnimation(
parent: _animationDrawerController,
curve: Curves.decelerate,
reverseCurve: Curves.decelerate));
@ -163,6 +169,9 @@ class SliderDrawerState extends State<SliderDrawer>
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constrain) {
void onHorizontalDragUpdate(DragUpdateDetails detail) =>
_onHorizontalDragUpdate(detail, constrain);
return SizedBox(
child: Stack(children: [
///Menu
@ -189,15 +198,31 @@ class SliderDrawerState extends State<SliderDrawer>
builder: (_, child) {
return Transform.translate(
offset: Utils.getOffsetValues(
widget.slideDirection, _animation.value),
child: child,
);
widget.slideDirection,
_animation.value,
widget.sliderCloseSize,
widget.sliderOpenSize),
child: Stack(children: [
child ?? const SizedBox(),
!widget.showCover || _animation.isDismissed
? const SizedBox()
: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: _onCoverTap,
onHorizontalDragStart: _onHorizontalDragStart,
onHorizontalDragEnd: _onHorizontalDragEnd,
onHorizontalDragUpdate: onHorizontalDragUpdate,
child: Container(
color: widget.coverColor.withAlpha(
(_animation.value * widget.coverColor.alpha)
.round())),
),
]));
},
child: GestureDetector(
onHorizontalDragStart: _onHorizontalDragStart,
onHorizontalDragEnd: _onHorizontalDragEnd,
onHorizontalDragUpdate: (detail) =>
_onHorizontalDragUpdate(detail, constrain),
onHorizontalDragUpdate: onHorizontalDragUpdate,
child: Container(
width: double.infinity,
height: double.infinity,
@ -303,6 +328,12 @@ class SliderDrawerState extends State<SliderDrawer>
}
}
void _onCoverTap() {
if (_animation.isCompleted) {
closeSlider();
}
}
move(double percent) {
_percent = percent;
_animationDrawerController.value = percent;

Loading…
Cancel
Save