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 1 commit
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
37 changes: 36 additions & 1 deletion example/lib/main_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,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 @@ -246,17 +276,22 @@ class SlideAction extends StatelessWidget {
Key key,
@required this.color,
@required this.icon,
this.shape = const RoundedRectangleBorder(),
this.side = BorderSide.none,
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
10 changes: 5 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -87,7 +87,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand All @@ -106,7 +106,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -141,7 +141,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.4.2"
typed_data:
dependency: transitive
description:
Expand Down
30 changes: 26 additions & 4 deletions lib/src/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ class CustomSlidableAction extends StatelessWidget {
this.backgroundColor = _kBackgroundColor,
this.foregroundColor,
this.autoClose = _kAutoClose,
this.shape = const RoundedRectangleBorder(),
this.side = BorderSide.none,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if we let them null by default so that we can easily extend this class and keep the default values without redefining them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, fixed

required this.onPressed,
required this.child,
}) : assert(flex > 0),
}) : assert(flex > 0),
super(key: key);

/// {@template slidable.actions.flex}
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make OutlinedBorder nullable then.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make BorderSide nullable too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


@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,
side: side,
),
child: child,
),
Expand Down Expand Up @@ -123,6 +135,8 @@ class SlidableAction extends StatelessWidget {
this.icon,
this.spacing = 4,
this.label,
this.shape = const RoundedRectangleBorder(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By following the previous comment, we dont' need to redefine them here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

this.side = BorderSide.none,
}) : 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
23 changes: 15 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -49,7 +49,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
cli_util:
dependency: transitive
description:
Expand Down Expand Up @@ -116,6 +116,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
frontend_server_client:
dependency: transitive
description:
name: frontend_server_client
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
glob:
dependency: transitive
description:
Expand Down Expand Up @@ -171,7 +178,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
mime:
dependency: transitive
description:
Expand All @@ -192,7 +199,7 @@ packages:
name: node_preamble
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.13"
version: "2.0.1"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -281,7 +288,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -316,21 +323,21 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.5"
version: "1.17.10"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.4.2"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.15"
version: "0.4.0"
typed_data:
dependency: transitive
description:
Expand Down