Skip to content

Commit a563a88

Browse files
committed
Add documentation and some features
1 parent ca0376c commit a563a88

9 files changed

+116
-74
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.5.4
2+
### Added
3+
* Ripple effect when tapping on the IconSlideAction (https://github.com/letsar/flutter_slidable/pull/89)
4+
* Option to make the widget non-dismissible by dragging (https://github.com/letsar/flutter_slidable/pull/101)
5+
16
## 0.5.3
27
### Fixed
38
* Fix SlidableDrawerActionPane when different than 2 actions (https://github.com/letsar/flutter_slidable/pull/74).

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
2727
```yaml
2828
dependencies:
2929
...
30-
flutter_slidable: "^0.5.3"
30+
flutter_slidable: "^0.5.4"
3131
```
3232
3333
In your library add the following import:

example/lib/main.dart

+10-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class _MyHomePageState extends State<MyHomePage> {
3131
final List<_HomeItem> items = List.generate(
3232
20,
3333
(i) => _HomeItem(
34-
i,
35-
'Tile n°$i',
36-
_getSubtitle(i),
37-
_getAvatarColor(i),
38-
),
34+
i,
35+
'Tile n°$i',
36+
_getSubtitle(i),
37+
_getAvatarColor(i),
38+
),
3939
);
4040

4141
@protected
@@ -148,6 +148,11 @@ class _MyHomePageState extends State<MyHomePage> {
148148
),
149149
],
150150
secondaryActions: <Widget>[
151+
Container(
152+
height: 800,
153+
color: Colors.green,
154+
child: Text('a'),
155+
),
151156
IconSlideAction(
152157
caption: 'More',
153158
color: Colors.grey.shade200,

lib/src/widgets/fractionnally_aligned_sized_box.dart

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import 'package:flutter/widgets.dart';
22

3+
/// A widget that positions its child to a fraction of the total available space.
34
class FractionallyAlignedSizedBox extends StatelessWidget {
5+
/// Creates a widget that positions its child to a fraction of the total available space.
6+
///
7+
/// Only two out of the three horizontal values ([leftFactor], [rightFactor],
8+
/// [widthFactor]), and only two out of the three vertical values ([topFactor],
9+
/// [bottomFactor], [heightFactor]), can be set. In each case, at least one of
10+
/// the three must be null.
11+
///
12+
/// If non-null, the [widthFactor] and [heightFactor] arguments must be
13+
/// non-negative.
414
FractionallyAlignedSizedBox({
515
Key key,
616
@required this.child,
@@ -18,12 +28,25 @@ class FractionallyAlignedSizedBox extends StatelessWidget {
1828
assert(heightFactor == null || heightFactor >= 0.0),
1929
super(key: key);
2030

31+
/// The relative distance that the child's left edge is inset from the left of the parent.
2132
final double leftFactor;
33+
34+
/// The relative distance that the child's top edge is inset from the top of the parent.
2235
final double topFactor;
36+
37+
/// The relative distance that the child's right edge is inset from the right of the parent.
2338
final double rightFactor;
39+
40+
/// The relative distance that the child's bottom edge is inset from the bottom of the parent.
2441
final double bottomFactor;
42+
43+
/// The child's width relative to its parent's width.
2544
final double widthFactor;
45+
46+
/// The child's height relative to its parent's height.
2647
final double heightFactor;
48+
49+
/// The widget below this widget in the tree.
2750
final Widget child;
2851

2952
@override

lib/src/widgets/slidable.dart

+61-9
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class SlideActionListDelegate extends SlideActionDelegate {
134134
/// The slide actions.
135135
final List<Widget> actions;
136136

137+
/// The number of actions.
137138
@override
138139
int get actionCount => actions?.length ?? 0;
139140

@@ -156,6 +157,7 @@ class _SlidableScope extends InheritedWidget {
156157
bool updateShouldNotify(_SlidableScope oldWidget) => oldWidget.state != state;
157158
}
158159

160+
/// The data used by a [Slidable].
159161
class SlidableData extends InheritedWidget {
160162
SlidableData({
161163
Key key,
@@ -174,17 +176,35 @@ class SlidableData extends InheritedWidget {
174176
@required Widget child,
175177
}) : super(key: key, child: child);
176178

179+
/// The type of slide action that is currently been showed by the [Slidable].
177180
final SlideActionType actionType;
181+
182+
/// The rendering mode in which the [Slidable] is.
178183
final SlidableRenderingMode renderingMode;
184+
185+
/// The total extent of all the actions
179186
final double totalActionsExtent;
187+
188+
/// The offset threshold the item has to be dragged in order to be considered
189+
/// dismissed.
180190
final double dismissThreshold;
191+
192+
/// Indicates whether the [Slidable] can be dismissed.
181193
final bool dismissible;
182194

183195
/// The current actions that have to be shown.
184196
final SlideActionDelegate actionDelegate;
197+
198+
/// Animation for the whole movement.
185199
final Animation<double> overallMoveAnimation;
200+
201+
/// Animation for the actions.
186202
final Animation<double> actionsMoveAnimation;
203+
204+
/// Dismiss animation.
187205
final Animation<double> dismissAnimation;
206+
207+
/// The slidable.
188208
final Slidable slidable;
189209

190210
/// Relative ratio between one slide action and the extent of the child.
@@ -193,16 +213,31 @@ class SlidableData extends InheritedWidget {
193213
/// The direction in which this widget can be slid.
194214
final Axis direction;
195215

216+
/// Indicates whether the primary actions are currently shown.
196217
bool get showActions => actionType == SlideActionType.primary;
218+
219+
/// The number of actions.
197220
int get actionCount => actionDelegate?.actionCount ?? 0;
221+
222+
/// If the [actionType] is [SlideActionType.primary] returns 1, -1 otherwise.
198223
double get actionSign => actionType == SlideActionType.primary ? 1.0 : -1.0;
224+
225+
/// Indicates wheter the direction is horizontal.
199226
bool get directionIsXAxis => direction == Axis.horizontal;
227+
228+
/// The alignment of the actions.
200229
Alignment get alignment => Alignment(
201230
directionIsXAxis ? -actionSign : 0.0,
202231
directionIsXAxis ? 0.0 : -actionSign,
203232
);
233+
234+
/// If the [direction] is horizontal, returns the [totalActionsExtent]
235+
/// otherwise null.
204236
double get actionPaneWidthFactor =>
205237
directionIsXAxis ? totalActionsExtent : null;
238+
239+
/// If the [direction] is vertical, returns the [totalActionsExtent]
240+
/// otherwise null.
206241
double get actionPaneHeightFactor =>
207242
directionIsXAxis ? null : totalActionsExtent;
208243

@@ -238,6 +273,7 @@ class SlidableData extends InheritedWidget {
238273
);
239274
}
240275

276+
/// Creates a [FractionallyAlignedSizedBox] related to the current direction and showed actions.
241277
FractionallyAlignedSizedBox createFractionallyAlignedSizedBox({
242278
Widget child,
243279
double extentFactor,
@@ -262,14 +298,16 @@ class SlidableData extends InheritedWidget {
262298
return List.generate(
263299
actionCount,
264300
(int index) => actionDelegate.build(
265-
context,
266-
index,
267-
actionsMoveAnimation,
268-
SlidableRenderingMode.slide,
269-
),
301+
context,
302+
index,
303+
actionsMoveAnimation,
304+
SlidableRenderingMode.slide,
305+
),
270306
);
271307
}
272308

309+
/// Whether the framework should notify widgets that inherit from this widget.
310+
@override
273311
bool updateShouldNotify(SlidableData oldWidget) =>
274312
(oldWidget.actionType != actionType) ||
275313
(oldWidget.renderingMode != renderingMode) ||
@@ -288,19 +326,29 @@ class SlidableData extends InheritedWidget {
288326
/// A controller that keep tracks of the active [SlidableState] and close
289327
/// the previous one.
290328
class SlidableController {
329+
/// Creates a controller that keep tracks of the active [SlidableState] and close
330+
/// the previous one.
291331
SlidableController({
292332
this.onSlideAnimationChanged,
293333
this.onSlideIsOpenChanged,
294334
});
295335

336+
/// Function called when the animation changed.
296337
final ValueChanged<Animation<double>> onSlideAnimationChanged;
338+
339+
/// Function called when the [Slidable] open status changed.
297340
final ValueChanged<bool> onSlideIsOpenChanged;
341+
298342
bool _isSlideOpen;
299343

300344
Animation<double> _slideAnimation;
301345

302346
SlidableState _activeState;
347+
348+
/// The state of the active [Slidable].
303349
SlidableState get activeState => _activeState;
350+
351+
/// Changes the state of the active [Slidable].
304352
set activeState(SlidableState value) {
305353
_activeState?._flingAnimationController();
306354

@@ -559,8 +607,11 @@ class SlidableState extends State<Slidable>
559607
double get _totalActionsExtent => widget.actionExtentRatio * (_actionCount);
560608

561609
double get _dismissThreshold {
562-
if (widget.dismissal == null) return _kDismissThreshold;
563-
else return widget.dismissal.dismissThresholds[actionType] ?? _kDismissThreshold;
610+
if (widget.dismissal == null)
611+
return _kDismissThreshold;
612+
else
613+
return widget.dismissal.dismissThresholds[actionType] ??
614+
_kDismissThreshold;
564615
}
565616

566617
bool get _dismissible => widget.dismissal != null && _dismissThreshold < 1.0;
@@ -716,8 +767,9 @@ class SlidableState extends State<Slidable>
716767
if (_dismissible && !widget.dismissal.dragDismissible) {
717768
// If the widget is not dismissible by dragging, clamp drag result
718769
// so the widget doesn't slide past [_totalActionsExtent].
719-
_overallMoveController.value = (_dragExtent.abs() / _overallDragAxisExtent)
720-
.clamp(0.0, _totalActionsExtent);
770+
_overallMoveController.value =
771+
(_dragExtent.abs() / _overallDragAxisExtent)
772+
.clamp(0.0, _totalActionsExtent);
721773
} else {
722774
_overallMoveController.value =
723775
_dragExtent.abs() / _overallDragAxisExtent;

lib/src/widgets/slidable_action_pane.dart

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class SlidableBehindActionPane extends StatelessWidget {
102102

103103
/// An action pane that creates actions which follow the item while it's sliding.
104104
class SlidableScrollActionPane extends StatelessWidget {
105+
/// Creates an action pane that creates actions which follow the item while it's sliding.
105106
const SlidableScrollActionPane({Key key}) : super(key: key);
106107

107108
@override
@@ -139,6 +140,7 @@ class SlidableScrollActionPane extends StatelessWidget {
139140

140141
/// An action pane that creates actions which animate like drawers while the item is sliding.
141142
class SlidableDrawerActionPane extends StatelessWidget {
143+
/// Creates an action pane that creates actions which animate like drawers while the item is sliding.
142144
const SlidableDrawerActionPane({Key key}) : super(key: key);
143145

144146
@override

lib/src/widgets/slidable_dismissal.dart

+6-56
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import 'package:flutter/widgets.dart';
2-
import 'package:flutter_slidable/src/widgets/fractionnally_aligned_sized_box.dart';
32
import 'package:flutter_slidable/src/widgets/slidable.dart';
43

54
const Duration _kResizeDuration = const Duration(milliseconds: 300);
65

7-
/// A wiget that controls how the [Slidable] is dismissed.
6+
/// A widget that controls how the [Slidable] is dismissed.
87
///
98
/// The [Slidable] widget calls the [onDismissed] callback either after its size has
109
/// collapsed to zero (if [resizeDuration] is non-null) or immediately after
@@ -17,6 +16,7 @@ const Duration _kResizeDuration = const Duration(milliseconds: 300);
1716
/// * [SlidableDrawerDismissal], which creates slide actions that are displayed like drawers
1817
/// while the item is dismissing.
1918
class SlidableDismissal extends StatelessWidget {
19+
/// Creates a widget that controls how the [Slidable] is dismissed.
2020
const SlidableDismissal({
2121
@required this.child,
2222
this.dismissThresholds = const <SlideActionType, double>{},
@@ -84,6 +84,7 @@ class SlidableDismissal extends StatelessWidget {
8484
/// The widget to show when the [Slidable] enters dismiss mode.
8585
final Widget child;
8686

87+
@override
8788
Widget build(BuildContext context) {
8889
final SlidableData data = SlidableData.of(context);
8990

@@ -105,8 +106,11 @@ class SlidableDismissal extends StatelessWidget {
105106
/// while the item is dismissing.
106107
/// The further slide action will grow faster than the other ones.
107108
class SlidableDrawerDismissal extends StatelessWidget {
109+
/// Creates a specific dismissal that creates slide actions that are displayed like drawers
110+
/// while the item is dismissing.
108111
const SlidableDrawerDismissal({Key key}) : super(key: key);
109112

113+
@override
110114
Widget build(BuildContext context) {
111115
final SlidableData data = SlidableData.of(context);
112116

@@ -151,61 +155,7 @@ class SlidableDrawerDismissal extends StatelessWidget {
151155
}),
152156
),
153157
);
154-
// return Stack(
155-
// children: List.generate(data.actionCount, (index) {
156-
// // For the main actions we have to reverse the order if we want the last item at the bottom of the stack.
157-
// int displayIndex =
158-
// data.showActions ? data.actionCount - index - 1 : index;
159-
160-
// return data.createFractionallyAlignedSizedBox(
161-
// positionFactor:
162-
// data.actionExtentRatio * (data.actionCount - index - 1),
163-
// extentFactor: extentAnimations[index].value,
164-
// child: data.actionDelegate.build(context, displayIndex,
165-
// data.actionsMoveAnimation, data.renderingMode),
166-
// );
167-
// }),
168-
// );
169158
}),
170-
// Positioned.fill(
171-
// child: LayoutBuilder(builder: (context, constraints) {
172-
// final count = data.actionCount;
173-
// final double totalExtent = data.getMaxExtent(constraints);
174-
// final double actionExtent = totalExtent * data.actionExtentRatio;
175-
176-
// final extentAnimations = Iterable.generate(count).map((index) {
177-
// return Tween<double>(
178-
// begin: actionExtent,
179-
// end: totalExtent -
180-
// (actionExtent * (data.actionCount - index - 1)),
181-
// ).animate(
182-
// CurvedAnimation(
183-
// parent: data.overallMoveAnimation,
184-
// curve: Interval(data.totalActionsExtent, 1.0),
185-
// ),
186-
// );
187-
// }).toList();
188-
189-
// return AnimatedBuilder(
190-
// animation: data.overallMoveAnimation,
191-
// builder: (context, child) {
192-
// return Stack(
193-
// children: List.generate(data.actionCount, (index) {
194-
// // For the main actions we have to reverse the order if we want the last item at the bottom of the stack.
195-
// int displayIndex = data.showActions
196-
// ? data.actionCount - index - 1
197-
// : index;
198-
// return data.createPositioned(
199-
// position: actionExtent * (data.actionCount - index - 1),
200-
// extent: extentAnimations[index].value,
201-
// child: data.actionDelegate.build(context, displayIndex,
202-
// data.actionsMoveAnimation, data.renderingMode),
203-
// );
204-
// }),
205-
// );
206-
// });
207-
// }),
208-
// ),
209159
SlideTransition(
210160
position: animation,
211161
child: data.slidable.child,

0 commit comments

Comments
 (0)