An extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.

Related tags

Widgets flutter-snap
Overview

snap

Cosmos Software Awesome Flutter

Pub License

An extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.

Inspired by WhatsApp's in-app Youtube player.

It is highly recommended to read the documentation and run the example project on a real device to fully understand and inspect the full range of capabilities.

Media | Description | How-to-Use

Notice

  • flick works as intended on actual devices even if it might appear to fail rarely on simulators. Don't be discouraged!

Recent

  • flick is now added. It is amazing! See Media for examples.

Media

Watch on Youtube:

v1.0.0 with Flick

v0.1.0



Description

This is an extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.

Just wrap your snapper widget with the SnapController widget, fill the parameters, define your snappable widget and this package will take care of everything else.

How-to-Use

"The view is what is being moved. It is the widget that snaps to the bound. The bound is what the view is being snapped to."

First, define two GlobalKeys- one for your view and one for your bound:

GlobalKey bound = GlobalKey();
GlobalKey view = GlobalKey();

Then, create a SnapController such as:

SnapController(
  uiChild(),                //uiChild
  false,                    //useCache
  view,                     //viewKey
  bound,                    //boundKey
  Offset.zero,              //constraintsMin
  const Offset(1.0, 1.0),   //constraintsMax
  const Offset(0.75, 0.75), //flexibilityMin
  const Offset(0.75, 0.75), //flexibilityMax
 {Key key,
  customBoundWidth  : 0,
  customBoundHeight : 0,
  snapTargets       : [
    const SnapTarget(Pivot.topLeft, Pivot.topLeft),
    const SnapTarget(Pivot.topRight, Pivot.topRight),
    const SnapTarget(Pivot.bottomLeft, Pivot.bottomLeft),
    const SnapTarget(Pivot.bottomRight, Pivot.bottomRight),
    const SnapTarget(Pivot.center, Pivot.center)
  ],
  animateSnap       : true,
  useFlick          : true,
  flickSensitivity  : 0.075,
  onMove            : _onMove,
  onDragStart       : _onDragStart,
  onDragUpdate      : _onDragUpdate,
  onDragEnd         : _onDragEnd,
  onSnap            : _onSnap})

Widget uiChild() {
  return Container(
    key: view,
    ...
  ); 
}

void _onMove(Offset offset);

void _onDragStart(dynamic dragDetails);
void _onDragUpdate(dynamic dragDetails);
void _onDragEnd(dynamic dragDetails);

void _onSnap(Offset offset);

Further Explanations:

For a complete set of descriptions for all parameters and methods, see the documentation.

  • Set [useCache] to true if your [uiChild] doesn't change during the Peek & Pop process.
  • Consider the following example:
Column(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: [
    Expanded(
      child: Align(
        key: bound,
        alignment: const Alignment(-1.0, -1.0),
        child: SnapController(
          uiChild(),
          true,
          view,
          bound,
          Offset.zero,
          const Offset(1.0, 1.0),
          const Offset(0.75, 0.75),
          const Offset(0.75, 0.75),
          snapTargets: [
            const SnapTarget(Pivot.topLeft, Pivot.topLeft),
            const SnapTarget(Pivot.topRight, Pivot.topRight),
            const SnapTarget(Pivot.bottomLeft, Pivot.bottomLeft),
            const SnapTarget(Pivot.bottomRight, Pivot.bottomRight),
            const SnapTarget(Pivot.center, Pivot.center)
          ]
        )
      )
    )
  ]
)

In this excerpt, the bound is an Align widget which expands through a Column widget.

The SnapController is confined between Offset.zero and Offset(1.0, 1.0). This means the view will not exceed the limits of the bound.

The flexibility is confined between Offset(0.75, 0.75) and Offset(0.75, 0.75). This means that the view can be moved beyond the horizontal/vertical min/max constraints with a flexibility of 0.75 before it snaps.

The snapTargets determine from where and to where the view should snap once the movement is over. In this example:

  1. The top left corner of the view can snap to the top left corner of the bound.
  2. The top right corner of the view can snap to the top right corner of the bound.
  3. The bottom left corner of the view can snap to the bottom left corner of the bound.
  4. The bottom right corner of the view can snap to the bottom right corner of the bound.
  5. The center of the view can snap to the center of the bound.

Keep in mind that these constant values are provided only for the ease of use. snapTargets can consist of any values you wish.

  • Use [SnapControllerState]'s [bool isMoved(double treshold)] method to determine if the view is moved or not where [treshold] is the distance at which the view should be considered to be moved.

Notes

I started using and learning Flutter only some weeks ago so this package might have some parts that don't make sense, that should be completely different, that could be much better, etc. Please let me know! Nicely!

Any help, suggestion or criticism is appreciated!

Cheers.





Comments
  • Null-Safety Support

    Null-Safety Support

    Hi, i really love your plugins, and its working like what i expected,

    Btw, Do you have any chances to make it support for latest flutter sdk with Nullsafety? it must be amazing :)

    opened by nizwar 3
  • Snap only when close to center

    Snap only when close to center

    Hello! THIS IS AN AMAZING LIBRARY, THANK YOU SO MUCH! I want something like this:

    1. Snap to the sides when close to them.
    2. Snap to the center when close to it.
    3. If both are far, DON'T SNAP. I can do the former two things. But how do I accomplish the third thing? Thanks!
    opened by night-wielder 3
  • Problem when using Hero

    Problem when using Hero

    When I try to use the with a Hero widget I get following error:

    'package:flutter/src/rendering/object.dart': Failed assertion: line 2293 pos 14: 'renderer != null': is not true. I suspect it has something to do with the Global Keys.

    Do you know how to handle this issue?

    opened by DennisKragekjaer 2
  • Calendar use case

    Calendar use case

    This is a cool library. Congrats.

    I immediately thought of making a calendar widget where you can drag the calendar events to different times. Same as how Google calendar works basically.

    Do you think this is appropriate ?

    opened by joeblew99 2
  • Widget not snapping after changing its dimensions.

    Widget not snapping after changing its dimensions.

    Here is the code using which I have implemented.

    SnapController(
                    AnimatedContainer(
                      height: !isInPipMode?MediaQuery.of(context).size.height: 100,
                      ...
    

    Now when the video is switched into the pip mode, the height of the widget changes but it does not scroll or snap. Basically, the SnapController is maybe taking the dimensions initially and not reading to any new changes probably. Please help me out in fixing this issue

    opened by Maadhav 0
  • Handling dynamic size widget

    Handling dynamic size widget

    Hi Ali :) Thanks for this awesome package. I am using Snap with an expanding widget. (it has a shrink and an expanded state. Basically it does this with an AnimatedContainer and setting width/height according to the isExpanded:true. Nothing special. When the widget is in the shrink state, I can snap this widget to all 4 corners no problem. There are no clippings happening.

    If I expand the widget and try snapping, most of the widget stays behind the frame. Is there somehow a way to keep both states of the widget inside the bound and snapping?

    Btw when I try to get the snap Offset, I see wrong numbers. Is onSnap not supposed to give us the last Offset the view snapped to? Like 4 corners of the screen? It always gives different numbers.

    Lastly, in order to snap to only sides or the corners without getting stuck in somewhere in the mid areas, I need to set the minSnapDistance to a very high value. Is this how it should be used as?

    Take care.

    opened by aytunch 1
Owner
AliYigitBireroglu
"It's true that we love one another, I love programming like a little brother."
AliYigitBireroglu
React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.

English | Português Flutter Hooks A Flutter implementation of React hooks: https://medium.com/@dan_abramov/making-sense-of-react-hooks-fdbde8803889 Ho

Remi Rousselet 2.6k Dec 29, 2022
📸 Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget.

?? Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget. Photo View is largely used to show interacive images and other stuff such as SVG.

Blue Fire 1.7k Jan 7, 2023
Responsive Widgets Prefix allows you to add the "Responsive" prefix to any widget that needs scaling or font size increases

Responsive Widgets Prefix allows you to add the Responsive prefix to any widget that needs scaling or font size increases (for varying device screen sizes).

The Mobile Applications Community 2 Apr 18, 2022
GetX demo Counter with full understanding of State Management, Route Management and SnackBar

GetX demo Counter with full understanding of State Management, Route Management and SnackBar

TAD 1 Apr 4, 2022
Custom widgets and utils using Flutter framework widgets and Dart language

reuse_widgets_and_utils The custom widgets and utils using Flutter framework widgets and Dart programming language. Getting Started This project is a

null 1 Oct 29, 2021
The SpannableGrid is a Flutter widget that allows its cells to span columns and rows and supports moving cells inside the grid.

Spannable Grid The SpannableGrid is a Flutter widget that allows its cells to span columns and rows and supports moving cells inside the grid. Feature

Evgeny Cherkasov 17 Nov 7, 2022
Flutter package: Assorted layout widgets that boldly go where no native Flutter widgets have gone before.

assorted_layout_widgets I will slowly but surely add interesting widgets, classes and methods to this package. Despite the package name, they are not

Marcelo Glasberg 122 Dec 22, 2022
Flutter-useful-widgets - Flutter Useful Widgets

useful_widgets This package makes it easy to build apps by providing a list of simple and useful widgets. import 'package:useful_widgets/useful_widget

Ricardo Crescenti 6 Jun 20, 2022
Widgets beginner - Widgets beginner with flutter

Widgets beginner - Widgets beginner with flutter

Tukhtamurodov Sardorbek 2 Feb 6, 2022
An alternative to Overlay which allows you to easily render and hit test a widget outside its parent bounds

An alternative to Overlay which allows you to easily render and hit test a widget outside its parent bounds. Based on the original idea by @shrouxm he

gskinner team 26 Dec 31, 2022
The flutter_otp_text_field package for flutter is a TextField widget that allows you to display different style pin.

flutter_otp_text_field flutter_otp_text_field The flutter_otp_text_field package for flutter is a TextField widget that allows you to display differen

David-Legend 30 Nov 8, 2022
SmartSelect allows you to easily convert your usual form select or dropdown into dynamic page

SmartSelect allows you to easily convert your usual form select or dropdown into dynamic page, popup dialog, or sliding bottom sheet with various choices input such as radio, checkbox, switch, chips, or even custom input. Supports single and multiple choice.

Irfan Vigma Taufik 332 Dec 20, 2022
A flutter widget for comparing two stacked widgets by dragging a slider thumb to reveal either sides of the slider horizontally or vertically.

Juxtapose A flutter widget for comparing two stacked widgets by dragging a slider thumb to reveal either sides of the slider horizontally or verticall

Leslie Arkorful 74 Nov 24, 2022
Flutter ScrollView Observer - a library of widget that can be used to listen for child widgets those are being displayed in the scroll view

Flutter ScrollView Observer - a library of widget that can be used to listen for child widgets those are being displayed in the scroll view

林洵锋 67 Jan 6, 2023
Code generation for Flutter Padding widgets based on your constants

Code generation for Flutter Padding widgets based on your constants

Emanuele 14 Oct 20, 2022
A collection of widgets for making amazing onboarding experience in your flutter applications

Pal widgets A flutter package for better onboarding. A set of amazing onboarding widgets for your flutter applications. Install package add in your pu

Apparence.io 25 Oct 7, 2022
Dialog-manager - A Flutter package that allows for neater declaration, abstraction and use of customisable dialogs

flutter_dialog_manager A Flutter package that allows for neater declaration, abs

Lucky Ebere 2 Dec 28, 2022
A flutter carousel widget, support infinite scroll, and custom child widget.

carousel_slider A carousel slider widget. Features Infinite scroll Custom child widgets Auto play Supported platforms Flutter Android Flutter iOS Flut

Bart T 1 Nov 25, 2021
Progress Dialog widget for flutter projects with ability to customize loading widget, background color and background blur.

DISCONTINUED Checkout ArsDialog ars_progress_dialog Customizable progress dialog for Flutter applications with smooth animation for background dim col

Arsam 8 Apr 15, 2022