Skip to content

Commit

Permalink
Merge pull request #13 from letsar/feature/9_enabled
Browse files Browse the repository at this point in the history
Feature/9 enabled
  • Loading branch information
letsar committed Jul 25, 2018
2 parents f64c7be + b6225ed commit e18ba7f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.2
### Added
* The `enabled` argument on `Slidable` constructors to enable or disable the slide effect (enabled by default).

## 0.3.1
### Fixed
* https://github.com/letsar/flutter_slidable/issues/11 (slide action not rebuild after controller dismissed).
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# flutter_slidable

A Flutter implementation of slidable list item with left and right slide actions.
A Flutter implementation of slidable list item with directional slide actions.

[![Pub](https://img.shields.io/pub/v/flutter_slidable.svg)](https://pub.dartlang.org/packages/flutter_slidable)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QTT34M25RDNL6)
Expand All @@ -16,6 +16,7 @@ A Flutter implementation of slidable list item with left and right slide actions
* You can use a builder to create your slide actions if you want special effects during animation.
* Close when a slide action has been tapped (overridable).
* Close when the nearest `Scrollable` starts to scroll (overridable).
* Option to disable the slide effect easily.

## Getting started

Expand All @@ -24,7 +25,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
```yaml
dependencies:
...
flutter_slidable: "^0.3.1"
flutter_slidable: "^0.3.2"
```

In your library add the following import:
Expand Down
22 changes: 17 additions & 5 deletions lib/src/widgets/slidable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class Slidable extends StatefulWidget {
Duration movementDuration = const Duration(milliseconds: 200),
Axis direction = Axis.horizontal,
bool closeOnScroll = true,
bool enabled = true,
}) : this.builder(
key: key,
child: child,
Expand All @@ -425,14 +426,15 @@ class Slidable extends StatefulWidget {
movementDuration: movementDuration,
direction: direction,
closeOnScroll: closeOnScroll,
enabled: enabled,
);

/// Creates a widget that can be slid.
///
/// The [actionDelegate] is a delegate that builds the slide actions that appears when the child has been dragged down or to the right.
/// The [secondaryActionDelegate] is a delegate that builds the slide actions that appears when the child has been dragged up or to the left.
///
/// The [delegate] and [closeOnScroll] arguments must not be null. The [actionExtentRatio]
/// The [delegate], [closeOnScroll] and [enabled] arguments must not be null. The [actionExtentRatio]
/// and [showAllActionsThreshold] arguments must be greater or equal than 0 and less or equal than 1.
Slidable.builder({
Key key,
Expand All @@ -445,6 +447,7 @@ class Slidable extends StatefulWidget {
this.movementDuration = const Duration(milliseconds: 200),
this.direction = Axis.horizontal,
this.closeOnScroll = true,
this.enabled = true,
}) : assert(delegate != null),
assert(direction != null),
assert(
Expand All @@ -458,6 +461,7 @@ class Slidable extends StatefulWidget {
actionExtentRatio <= 1.0,
'actionExtentRatio must be between 0.0 and 1.0'),
assert(closeOnScroll != null),
assert(enabled != null),
super(key: key);

/// The widget below this widget in the tree.
Expand Down Expand Up @@ -495,6 +499,13 @@ class Slidable extends StatefulWidget {
/// Defaults to true.
final bool closeOnScroll;

/// Whether this slidable is interactive.
///
/// If false, the child will not slid to show slide actions.
///
/// Defaults to true.
final bool enabled;

/// The state from the closest instance of this class that encloses the given context.
static SlidableState of(BuildContext context) {
return context.ancestorStateOfType(const TypeMatcher<SlidableState>());
Expand Down Expand Up @@ -640,10 +651,11 @@ class SlidableState extends State<Slidable>
Widget build(BuildContext context) {
super.build(context); // See AutomaticKeepAliveClientMixin.

if ((widget.actionDelegate == null ||
widget.actionDelegate.actionCount == 0) &&
(widget.secondaryActionDelegate == null ||
widget.secondaryActionDelegate.actionCount == 0)) {
if (!widget.enabled ||
((widget.actionDelegate == null ||
widget.actionDelegate.actionCount == 0) &&
(widget.secondaryActionDelegate == null ||
widget.secondaryActionDelegate.actionCount == 0))) {
return widget.child;
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_slidable
description: A Flutter implementation of slidable list item with directional slide actions.
version: 0.3.1
version: 0.3.2
author: Romain Rastel <lets4r@gmail.com>
homepage: https://github.com/letsar/flutter_slidable

Expand Down

0 comments on commit e18ba7f

Please sign in to comment.