Skip to content

Commit e22f5e1

Browse files
committed
Add support for a drawer slide animation
1 parent 8aa024f commit e22f5e1

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

lib/src/widget.dart

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class AdvancedDrawer extends StatefulWidget {
1111
this.backdrop,
1212
this.openRatio = 0.75,
1313
this.openScale = 0.85,
14+
this.drawerSlideRatio = 0,
1415
this.animationDuration = const Duration(milliseconds: 250),
1516
this.animationCurve,
1617
this.childDecoration,
@@ -41,6 +42,11 @@ class AdvancedDrawer extends StatefulWidget {
4142
/// Opening ratio.
4243
final double openScale;
4344

45+
/// How far the drawer segment should slide with the content
46+
/// 0 = no slide distance
47+
/// 1 = slide from completely off screen
48+
final double drawerSlideRatio;
49+
4450
/// Animation duration.
4551
final Duration animationDuration;
4652

@@ -77,6 +83,7 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
7783
late Animation<double> _drawerScaleAnimation;
7884
late Animation<Offset> _childSlideAnimation;
7985
late Animation<double> _childScaleAnimation;
86+
late Animation<Offset> _drawerSlideAnimation;
8087
late Animation<Decoration> _childDecorationAnimation;
8188

8289
late double _offsetValue;
@@ -120,15 +127,18 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
120127
alignment: widget.rtlOpening
121128
? Alignment.centerRight
122129
: Alignment.centerLeft,
123-
child: FractionallySizedBox(
124-
widthFactor: widget.openRatio,
125-
child: ScaleTransition(
126-
scale: _drawerScaleAnimation,
127-
alignment: widget.rtlOpening
128-
? Alignment.centerLeft
129-
: Alignment.centerRight,
130-
child: RepaintBoundary(
131-
child: widget.drawer,
130+
child: SlideTransition(
131+
position: _drawerSlideAnimation,
132+
child: FractionallySizedBox(
133+
widthFactor: widget.openRatio,
134+
child: ScaleTransition(
135+
scale: _drawerScaleAnimation,
136+
alignment: widget.rtlOpening
137+
? Alignment.centerLeft
138+
: Alignment.centerRight,
139+
child: RepaintBoundary(
140+
child: widget.drawer,
141+
),
132142
),
133143
),
134144
),
@@ -232,6 +242,11 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
232242
end: 1.0,
233243
).animate(parentAnimation);
234244

245+
_drawerSlideAnimation = Tween<Offset>(
246+
begin: Offset(-widget.drawerSlideRatio, 0),
247+
end: Offset.zero,
248+
).animate(parentAnimation);
249+
235250
_childSlideAnimation = Tween<Offset>(
236251
begin: Offset.zero,
237252
end: Offset(widget.openRatio, 0),
@@ -252,7 +267,9 @@ class _AdvancedDrawerState extends State<AdvancedDrawer>
252267
// If widget is not mounted do nothing
253268
if (!mounted) return;
254269
// If the value of _controller is visible, forward the animation; otherwise, reverse it
255-
_controller.value.visible ? _animationController.forward() : _animationController.reverse();
270+
_controller.value.visible
271+
? _animationController.forward()
272+
: _animationController.reverse();
256273
}
257274

258275
void _handleDragStart(DragStartDetails details) {

0 commit comments

Comments
 (0)