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

feature/custom_slidable #314

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 27 additions & 5 deletions lib/src/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import 'slidable.dart';
/// Signature for [CustomSlidableAction.onPressed].
typedef SlidableActionCallback = void Function(BuildContext context);

const int _kFlex = 1;
const Color _kBackgroundColor = Colors.white;
const bool _kAutoClose = true;
const _kFlex = 1;
const _kBackgroundColor = Colors.white;
const _kAutoClose = true;
const _kborderSide = BorderSide.none;
const _kshape = RoundedRectangleBorder();

/// Represents an action of an [ActionPane].
class CustomSlidableAction extends StatelessWidget {
Expand All @@ -23,6 +25,8 @@ class CustomSlidableAction extends StatelessWidget {
this.backgroundColor = _kBackgroundColor,
this.foregroundColor,
this.autoClose = _kAutoClose,
this.side,
this.shape,
required this.onPressed,
required this.child,
}) : assert(flex > 0),
Expand Down Expand Up @@ -69,6 +73,14 @@ class CustomSlidableAction extends StatelessWidget {
/// Typically the action's icon or label.
final Widget child;

/// Defaults to [BorderSide.none].
/// {@endtemplate}
final BorderSide? side;

/// Defaults to [RoundedRectangleBorder].
/// {@endtemplate}
final OutlinedBorder? shape;

@override
Widget build(BuildContext context) {
final effectiveForegroundColor = foregroundColor ??
Expand All @@ -86,8 +98,8 @@ class CustomSlidableAction extends StatelessWidget {
backgroundColor: backgroundColor,
primary: effectiveForegroundColor,
onSurface: effectiveForegroundColor,
shape: const RoundedRectangleBorder(),
side: BorderSide.none,
shape: shape,
side: side,
),
child: child,
),
Expand Down Expand Up @@ -123,6 +135,8 @@ class SlidableAction extends StatelessWidget {
this.icon,
this.spacing = 4,
this.label,
this.side = _kborderSide,
this.shape = _kshape,
}) : assert(flex > 0),
assert(icon != null || label != null),
super(key: key);
Expand All @@ -133,6 +147,12 @@ class SlidableAction extends StatelessWidget {
/// {@macro slidable.actions.backgroundColor}
final Color backgroundColor;

/// {@macro slidable.actions.side}
final BorderSide side;

/// {@macro slidable.actions.shape}
final OutlinedBorder shape;

/// {@macro slidable.actions.foregroundColor}
final Color? foregroundColor;

Expand Down Expand Up @@ -197,6 +217,8 @@ class SlidableAction extends StatelessWidget {
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
flex: flex,
side: side,
shape: shape,
child: child,
);
}
Expand Down
47 changes: 31 additions & 16 deletions lib/src/slidable.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_slidable/src/auto_close_behavior.dart';
import 'package:flutter_slidable/src/notifications_old.dart';

import 'action_pane_configuration.dart';
import 'controller.dart';
Expand All @@ -28,6 +27,8 @@ class Slidable extends StatefulWidget {
this.dragStartBehavior = DragStartBehavior.down,
this.useTextDirection = true,
required this.child,
this.backgroundColor,
this.borderRadius,
}) : super(key: key);

/// Whether this slidable is interactive.
Expand All @@ -37,6 +38,14 @@ class Slidable extends StatefulWidget {
/// Defaults to true.
final bool enabled;

/// Defaults to [Colors.Transparent].
/// {@endtemplate}
final Color? backgroundColor;

/// Defaults to [BorderRadius.zero].
/// {@endtemplate}
final BorderRadius? borderRadius;

/// Specifies to close this [Slidable] after the closest [Scrollable]'s
/// position changed.
///
Expand Down Expand Up @@ -237,30 +246,36 @@ class _SlidableState extends State<Slidable>
),
);

content = Stack(
children: <Widget>[
if (actionPane != null)
Positioned.fill(
child: ClipRect(
clipper: _SlidableClipper(
axis: widget.direction,
controller: controller,
content = ClipRRect(
borderRadius: widget.borderRadius ?? BorderRadius.zero,
child: Container(
color: widget.backgroundColor,
child: Stack(
children: <Widget>[
if (actionPane != null)
Positioned.fill(
child: ClipRect(
clipper: _SlidableClipper(
axis: widget.direction,
controller: controller,
),
child: actionPane,
),
),
child: actionPane,
),
),
content,
],
content,
],
),
),
);

return SlidableGestureDetector(
enabled: widget.enabled,
controller: controller,
direction: widget.direction,
dragStartBehavior: widget.dragStartBehavior,
child: SlidableNotificationSender(
tag: widget.groupTag,
child: SlidableAutoCloseNotificationSender(
controller: controller,
groupTag: widget.groupTag,
child: SlidableScrollingBehavior(
controller: controller,
closeOnScroll: widget.closeOnScroll,
Expand Down