Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SNAPPED PanelState #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions lib/src/panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum SlideDirection {
DOWN,
}

enum PanelState { OPEN, CLOSED }
enum PanelState { OPEN, CLOSED, SNAPPED }

class SlidingUpPanel extends StatefulWidget {
/// The Widget that slides into view. When the
Expand Down Expand Up @@ -153,10 +153,11 @@ class SlidingUpPanel extends StatefulWidget {
/// down on the panel.
final SlideDirection slideDirection;

/// The default state of the panel; either PanelState.OPEN or PanelState.CLOSED.
/// The default state of the panel; PanelState.OPEN, PanelState.CLOSED or PanelState.SNAPPED.
/// This value defaults to PanelState.CLOSED which indicates that the panel is
/// in the closed position and must be opened. PanelState.OPEN indicates that
/// by default the Panel is open and must be swiped closed by the user.
/// PanelState.SNAPPED indicates that by default the Pnale is opened only to the [snapPoint] position.
final PanelState defaultPanelState;

SlidingUpPanel(
Expand Down Expand Up @@ -220,13 +221,10 @@ class _SlidingUpPanelState extends State<SlidingUpPanel>
super.initState();

_ac = new AnimationController(
vsync: this,
duration: const Duration(milliseconds: 300),
value: widget.defaultPanelState == PanelState.CLOSED
? 0.0
: 1.0 //set the default panel state (i.e. set initial value of _ac)
)
..addListener(() {
vsync: this,
duration: const Duration(milliseconds: 300),
value: _getDefaultAnimationValue(),
)..addListener(() {
if (widget.onPanelSlide != null) widget.onPanelSlide!(_ac.value);

if (widget.onPanelOpened != null && _ac.value == 1.0)
Expand Down Expand Up @@ -435,6 +433,20 @@ class _SlidingUpPanelState extends State<SlidingUpPanel>
widget.parallaxOffset;
}

// set default panel state (i.e set initial value of AnimationController)
double _getDefaultAnimationValue() {
switch (widget.defaultPanelState) {
case PanelState.OPEN:
return 1.0;
case PanelState.SNAPPED:
assert(widget.snapPoint != null,
"SlidingUpPanel snapPoint property must not be null");
return widget.snapPoint!;
default:
return 0.0;
}
}

// returns a gesture detector if panel is used
// and a listener if panelBuilder is used.
// this is because the listener is designed only for use with linking the scrolling of
Expand Down