Add the possibility to pass a custom Clipper to the slidable

Open
#541 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
dart, flutter
Domain
mobile

Research direction

The relevant code is the private _SlidableClipper class, which the issue's snippet shows with getClip, getApproximateClipRect and shouldReclip, plus the Slidable widget constructor where an optional parameter would go. Start by reading how _SlidableClipper is created and applied, then decide how to expose it, such as an abstract base class with a default implementation. Done means Slidable accepts an optional custom clipper and default behaviour is unchanged. The API shape is not settled in the thread, so confirm it with a maintainer first.

Written by the indexing model from the issue text.

Description

Transform that class in an abstract one and become an optional parameter to the Slidable, i'm struggling to make some custom animations in my code using the package without this customization:

Image
class _SlidableClipper extends CustomClipper<Rect> {
  _SlidableClipper({
    required this.axis,
    required this.controller,
  }) : super(reclip: controller.animation);

  final Axis axis;
  final SlidableController controller;

  @override
  Rect getClip(Size size) {
    switch (axis) {
      case Axis.horizontal:
        final double offset = controller.ratio * size.width;
        if (offset < 0) {
          return Rect.fromLTRB(size.width + offset, 0, size.width, size.height);
        }
        return Rect.fromLTRB(0, 0, offset, size.height);
      case Axis.vertical:
        final double offset = controller.ratio * size.height;
        if (offset < 0) {
          return Rect.fromLTRB(
            0,
            size.height + offset,
            size.width,
            size.height,
          );
        }
        return Rect.fromLTRB(0, 0, size.width, offset);
    }
  }

  @override
  Rect getApproximateClipRect(Size size) => getClip(size);

  @override
  bool shouldReclip(_SlidableClipper oldClipper) {
    return oldClipper.axis != axis;
  }
}
Dominant language
Dart
Stars
2.9k
Forks
646
Avg merge
5m
Merged PRs (30d)
9

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from letsar/flutter_slidable

All issues in letsar/flutter_slidable

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.