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

feat: shape and side for SlidableAction and CustomSlidableAction #255

Open
wants to merge 5 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions example/lib/main_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,36 @@ class _MyHomePageState extends State<MyHomePage> {
),
child: const Tile(color: Colors.grey, text: 'hello'),
),
Slidable(
direction: direction,
startActionPane: ActionPane(
motion: const BehindMotion(),
children: [
SlideAction(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(19),
),
color: Colors.green.withOpacity(0.8),
icon: Icons.share,
),
SlideAction(
color: Colors.amber.withOpacity(0.8),
icon: Icons.delete,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(19),
),
),
],
),
endActionPane: const ActionPane(
motion: BehindMotion(),
children: [
SlideAction(color: Colors.red, icon: Icons.delete_forever),
SlideAction(color: Colors.blue, icon: Icons.alarm, flex: 2),
],
),
child: const Tile(color: Colors.red, text: 'hello'),
),
],
),
),
Expand All @@ -250,20 +280,23 @@ class _MyHomePageState extends State<MyHomePage> {

class SlideAction extends StatelessWidget {
const SlideAction({
Key? key,
required this.color,
required this.icon,
Key? key,
this.flex = 1,
}) : super(key: key);

final Color color;
final IconData icon;
final int flex;

final OutlinedBorder shape;
final BorderSide side;
@override
Widget build(BuildContext context) {
return SlidableAction(
flex: flex,
shape: shape,
side: side,
backgroundColor: color,
foregroundColor: Colors.white,
onPressed: (_) {
Expand Down Expand Up @@ -291,7 +324,7 @@ class Tile extends StatelessWidget {
return ActionTypeListener(
child: GestureDetector(
onTap: () {
print('$text');
print(text);
},
onLongPress: () => Slidable.of(context)!.openEndActionPane(),
child: Container(
Expand Down
28 changes: 25 additions & 3 deletions lib/src/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class CustomSlidableAction extends StatelessWidget {
this.backgroundColor = _kBackgroundColor,
this.foregroundColor,
this.autoClose = _kAutoClose,
this.shape,
this.side,
required this.onPressed,
required this.child,
}) : assert(flex > 0),
Expand Down Expand Up @@ -69,14 +71,24 @@ class CustomSlidableAction extends StatelessWidget {
/// Typically the action's icon or label.
final Widget child;

/// {@template slidable.actions.shape}
/// [OutlinedBorder] of action, if is null, then [RoundedRectangleBorder]
/// used by default
/// {@endtemplate}
final OutlinedBorder? shape;

/// {@template slidable.actions.side}
/// [BorderSide] of action, if is null, then [BorderSide.none] used by default
/// {@endtemplate}
final BorderSide? side;

@override
Widget build(BuildContext context) {
final effectiveForegroundColor = foregroundColor ??
(ThemeData.estimateBrightnessForColor(backgroundColor) ==
Brightness.light
? Colors.black
: Colors.white);

return Expanded(
flex: flex,
child: SizedBox.expand(
Expand All @@ -86,8 +98,8 @@ class CustomSlidableAction extends StatelessWidget {
backgroundColor: backgroundColor,
primary: effectiveForegroundColor,
onSurface: effectiveForegroundColor,
shape: const RoundedRectangleBorder(),
side: BorderSide.none,
shape: shape ?? const RoundedRectangleBorder(),
side: side ?? BorderSide.none,
),
child: child,
),
Expand Down Expand Up @@ -123,6 +135,8 @@ class SlidableAction extends StatelessWidget {
this.icon,
this.spacing = 4,
this.label,
this.shape,
this.side,
}) : assert(flex > 0),
assert(icon != null || label != null),
super(key: key);
Expand Down Expand Up @@ -153,6 +167,12 @@ class SlidableAction extends StatelessWidget {
/// A label to display below the [icon].
final String? label;

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

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

@override
Widget build(BuildContext context) {
final children = <Widget>[];
Expand Down Expand Up @@ -197,6 +217,8 @@ class SlidableAction extends StatelessWidget {
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
flex: flex,
shape: shape,
side: side,
child: child,
);
}
Expand Down