├── .gitignore
├── LICENSE
├── README.md
└── snap
├── .gitignore
├── .metadata
├── CHANGELOG.md
├── LICENSE
├── README.md
├── example
├── .gitignore
├── .metadata
├── CHANGELOG.md
├── LICENSE
├── README.md
├── lib
│ └── main.dart
├── pubspec.lock
├── pubspec.yaml
├── test
│ └── example_test.dart
└── web
│ ├── favicon.png
│ ├── icons
│ ├── Icon-192.png
│ └── Icon-512.png
│ ├── index.html
│ └── manifest.json
├── lib
├── Export.dart
├── misc.dart
├── snap.dart
└── snap_controller.dart
├── pubspec.lock
├── pubspec.yaml
└── test
└── snap_test.dart
/.gitignore:
--------------------------------------------------------------------------------
1 | /gitignore
2 | /android
3 | /build
4 | /ios
5 | .notes.md
6 | .notes.txt
7 |
8 | # Miscellaneous
9 | *.class
10 | *.log
11 | *.pyc
12 | *.swp
13 | .DS_Store
14 | .atom/
15 | .buildlog/
16 | .history
17 | .svn/
18 |
19 | # IntelliJ related
20 | *.iml
21 | *.ipr
22 | *.iws
23 | .idea/
24 |
25 | # The .vscode folder contains launch configuration and tasks you configure in
26 | # VS Code which you may wish to be included in version control, so this line
27 | # is commented out by default.
28 | #.vscode/
29 |
30 | # Flutter/Dart/Pub related
31 | **/doc/api/
32 | .dart_tool/
33 | .flutter-plugins
34 | .packages
35 | .pub-cache/
36 | .pub/
37 | build/
38 |
39 | # Android related
40 | **/android/**/gradle-wrapper.jar
41 | **/android/.gradle
42 | **/android/captures/
43 | **/android/gradlew
44 | **/android/gradlew.bat
45 | **/android/local.properties
46 | **/android/**/GeneratedPluginRegistrant.java
47 |
48 | # iOS/XCode related
49 | **/ios/**/*.mode1v3
50 | **/ios/**/*.mode2v3
51 | **/ios/**/*.moved-aside
52 | **/ios/**/*.pbxuser
53 | **/ios/**/*.perspectivev3
54 | **/ios/**/*sync/
55 | **/ios/**/.sconsign.dblite
56 | **/ios/**/.tags*
57 | **/ios/**/.vagrant/
58 | **/ios/**/DerivedData/
59 | **/ios/**/Icon?
60 | **/ios/**/Pods/
61 | **/ios/**/.symlinks/
62 | **/ios/**/profile
63 | **/ios/**/xcuserdata
64 | **/ios/.generated/
65 | **/ios/Flutter/App.framework
66 | **/ios/Flutter/Flutter.framework
67 | **/ios/Flutter/Generated.xcconfig
68 | **/ios/Flutter/app.flx
69 | **/ios/Flutter/app.zip
70 | **/ios/Flutter/flutter_assets/
71 | **/ios/ServiceDefinitions.json
72 | **/ios/Runner/GeneratedPluginRegistrant.*
73 |
74 | # Exceptions to above rules.
75 | !**/ios/**/default.mode1v3
76 | !**/ios/**/default.mode2v3
77 | !**/ios/**/default.pbxuser
78 | !**/ios/**/default.perspectivev3
79 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
80 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Ali Yigit Bireroglu
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # snap
2 |
3 | [comment]: <> (Badges)
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | [](https://pub.dev/packages/snap)
12 | [](https://github.com/aliyigitbireroglu/flutter-snap/blob/master/LICENSE)
13 |
14 | [comment]: <> (Introduction)
15 | An extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.
16 |
17 | Inspired by WhatsApp's in-app Youtube player.
18 |
19 | **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
20 | of capabilities.**
21 |
22 | [comment]: <> (ToC)
23 | [Media](#media) | [Description](#description) | [How-to-Use](#howtouse)
24 |
25 | [comment]: <> (Notice)
26 | ## Notice
27 | * **[flick](https://pub.dev/packages/flick) works as intended on actual devices even if it might appear to fail rarely on simulators. Don't be
28 | discouraged!**
29 | * * *
30 | [comment]: <> (Recent)
31 | ## Recent
32 | * **[flick](https://pub.dev/packages/flick) is now added. It is amazing! See [Media](#media) for examples.**
33 | * * *
34 |
35 |
36 | [comment]: <> (Media)
37 |
38 | ## Media
39 |
40 | Watch on **Youtube**:
41 |
42 | [v1.0.0 with Flick](https://youtu.be/vNTBsMg1NXg)
43 |
44 | [v0.1.0](https://youtu.be/anHHG3JJPrI)
45 |
46 |
47 |
48 |
49 |
50 | [comment]: <> (Description)
51 |
52 | ## Description
53 | This is an extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.
54 |
55 | Just wrap your *snapper* widget with the SnapController widget, fill the parameters, define your *snappable* widget and this package will take care
56 | of everything else.
57 |
58 |
59 | [comment]: <> (How-to-Use)
60 |
61 | ## How-to-Use
62 | *"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."*
63 |
64 | First, define two GlobalKeys- one for your view and one for your bound:
65 |
66 | ```
67 | GlobalKey bound = GlobalKey();
68 | GlobalKey view = GlobalKey();
69 | ```
70 |
71 | Then, create a SnapController such as:
72 |
73 | ```
74 | SnapController(
75 | uiChild(), //uiChild
76 | false, //useCache
77 | view, //viewKey
78 | bound, //boundKey
79 | Offset.zero, //constraintsMin
80 | const Offset(1.0, 1.0), //constraintsMax
81 | const Offset(0.75, 0.75), //flexibilityMin
82 | const Offset(0.75, 0.75), //flexibilityMax
83 | {Key key,
84 | customBoundWidth : 0,
85 | customBoundHeight : 0,
86 | snapTargets : [
87 | const SnapTarget(Pivot.topLeft, Pivot.topLeft),
88 | const SnapTarget(Pivot.topRight, Pivot.topRight),
89 | const SnapTarget(Pivot.bottomLeft, Pivot.bottomLeft),
90 | const SnapTarget(Pivot.bottomRight, Pivot.bottomRight),
91 | const SnapTarget(Pivot.center, Pivot.center)
92 | ],
93 | animateSnap : true,
94 | useFlick : true,
95 | flickSensitivity : 0.075,
96 | onMove : _onMove,
97 | onDragStart : _onDragStart,
98 | onDragUpdate : _onDragUpdate,
99 | onDragEnd : _onDragEnd,
100 | onSnap : _onSnap})
101 |
102 | Widget uiChild() {
103 | return Container(
104 | key: view,
105 | ...
106 | );
107 | }
108 |
109 | void _onMove(Offset offset);
110 |
111 | void _onDragStart(dynamic dragDetails);
112 | void _onDragUpdate(dynamic dragDetails);
113 | void _onDragEnd(dynamic dragDetails);
114 |
115 | void _onSnap(Offset offset);
116 | ```
117 |
118 | **Further Explanations:**
119 |
120 | *For a complete set of descriptions for all parameters and methods, see the [documentation](https://pub.dev/documentation/snap/latest/).*
121 |
122 | * Set [useCache] to true if your [uiChild] doesn't change during the Peek & Pop process.
123 | * Consider the following example:
124 |
125 | ```
126 | Column(
127 | crossAxisAlignment: CrossAxisAlignment.start,
128 | children: [
129 | Expanded(
130 | child: Align(
131 | key: bound,
132 | alignment: const Alignment(-1.0, -1.0),
133 | child: SnapController(
134 | uiChild(),
135 | true,
136 | view,
137 | bound,
138 | Offset.zero,
139 | const Offset(1.0, 1.0),
140 | const Offset(0.75, 0.75),
141 | const Offset(0.75, 0.75),
142 | snapTargets: [
143 | const SnapTarget(Pivot.topLeft, Pivot.topLeft),
144 | const SnapTarget(Pivot.topRight, Pivot.topRight),
145 | const SnapTarget(Pivot.bottomLeft, Pivot.bottomLeft),
146 | const SnapTarget(Pivot.bottomRight, Pivot.bottomRight),
147 | const SnapTarget(Pivot.center, Pivot.center)
148 | ]
149 | )
150 | )
151 | )
152 | ]
153 | )
154 | ```
155 |
156 | In this excerpt, the bound is an Align widget which expands through a Column widget.
157 |
158 | 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.
159 |
160 | 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
161 | min/max constraints with a flexibility of 0.75 before it snaps.
162 |
163 | The snapTargets determine from where and to where the view should snap once the movement is over. In this example:
164 |
165 | 1. The top left corner of the view can snap to the top left corner of the bound.
166 | 2. The top right corner of the view can snap to the top right corner of the bound.
167 | 3. The bottom left corner of the view can snap to the bottom left corner of the bound.
168 | 4. The bottom right corner of the view can snap to the bottom right corner of the bound.
169 | 5. The center of the view can snap to the center of the bound.
170 |
171 | Keep in mind that these constant values are provided only for the ease of use. snapTargets can consist of any values you wish.
172 |
173 | * Use [SnapControllerState]'s [bool isMoved(double treshold)] method to determine if the view is moved or not where [treshold] is the distance at
174 | which the view should be considered to be moved.
175 |
176 |
177 | [comment]: <> (Notes)
178 | ## Notes
179 | 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
180 | different, that could be much better, etc. Please let me know! Nicely!
181 |
182 | Any help, suggestion or criticism is appreciated!
183 |
184 | Cheers.
185 |
186 | [comment]: <> (CosmosSoftware)
187 |
188 |
189 |
--------------------------------------------------------------------------------
/snap/.gitignore:
--------------------------------------------------------------------------------
1 | /gitignore
2 | /android
3 | /build
4 | /ios
5 | .notes.md
6 | .notes.txt
7 |
8 | # Miscellaneous
9 | *.class
10 | *.log
11 | *.pyc
12 | *.swp
13 | .DS_Store
14 | .atom/
15 | .buildlog/
16 | .history
17 | .svn/
18 |
19 | # IntelliJ related
20 | *.iml
21 | *.ipr
22 | *.iws
23 | .idea/
24 |
25 | # The .vscode folder contains launch configuration and tasks you configure in
26 | # VS Code which you may wish to be included in version control, so this line
27 | # is commented out by default.
28 | #.vscode/
29 |
30 | # Flutter/Dart/Pub related
31 | **/doc/api/
32 | .dart_tool/
33 | .flutter-plugins
34 | .packages
35 | .pub-cache/
36 | .pub/
37 | build/
38 |
39 | # Android related
40 | **/android/**/gradle-wrapper.jar
41 | **/android/.gradle
42 | **/android/captures/
43 | **/android/gradlew
44 | **/android/gradlew.bat
45 | **/android/local.properties
46 | **/android/**/GeneratedPluginRegistrant.java
47 |
48 | # iOS/XCode related
49 | **/ios/**/*.mode1v3
50 | **/ios/**/*.mode2v3
51 | **/ios/**/*.moved-aside
52 | **/ios/**/*.pbxuser
53 | **/ios/**/*.perspectivev3
54 | **/ios/**/*sync/
55 | **/ios/**/.sconsign.dblite
56 | **/ios/**/.tags*
57 | **/ios/**/.vagrant/
58 | **/ios/**/DerivedData/
59 | **/ios/**/Icon?
60 | **/ios/**/Pods/
61 | **/ios/**/.symlinks/
62 | **/ios/**/profile
63 | **/ios/**/xcuserdata
64 | **/ios/.generated/
65 | **/ios/Flutter/App.framework
66 | **/ios/Flutter/Flutter.framework
67 | **/ios/Flutter/Generated.xcconfig
68 | **/ios/Flutter/app.flx
69 | **/ios/Flutter/app.zip
70 | **/ios/Flutter/flutter_assets/
71 | **/ios/ServiceDefinitions.json
72 | **/ios/Runner/GeneratedPluginRegistrant.*
73 |
74 | # Exceptions to above rules.
75 | !**/ios/**/default.mode1v3
76 | !**/ios/**/default.mode2v3
77 | !**/ios/**/default.pbxuser
78 | !**/ios/**/default.perspectivev3
79 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
80 |
--------------------------------------------------------------------------------
/snap/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 20e59316b8b8474554b38493b8ca888794b0234a
8 | channel: stable
9 |
10 | project_type: package
11 |
--------------------------------------------------------------------------------
/snap/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [2.0.0] - 04.05.2021
2 |
3 | * Migrated to Null Safety.
4 |
5 | ## [1.0.6] - 11.10.2020
6 |
7 | * Regular maintenance.
8 |
9 | ## [1.0.5] - 21.11.2019
10 |
11 | * [minSnapDistance] is added. If set, the snapping will not occur when no [SnapTarget] is found that is closer to the [uiChild] than this value.
12 |
13 | * Updated README.
14 |
15 | ## [1.0.4] - 07.09.2019
16 |
17 | * Minor changes.
18 |
19 | ## [1.0.3] - 30.08.2019
20 |
21 | * Minor changes.
22 |
23 | * Improved code style.
24 |
25 | * [1.0.3+1] Updated README.
26 |
27 | * [1.0.3+2] Updated README.
28 |
29 | ## [1.0.2] - 23.08.2019
30 |
31 | * Minor changes.
32 |
33 | * Improved code style with trailing commas.
34 |
35 | * [1.0.2+1] Minor changes.
36 |
37 | ## [1.0.1] - 20.08.2019
38 |
39 | * Improved code style.
40 |
41 | * Code excerpt added to the README.
42 |
43 | * [1.0.1+1] Updated README.
44 |
45 | ## [1.0.0] - 18.08.2019
46 |
47 | * [flick](https://pub.dev/packages/flick) is now implemented directly to the package.
48 |
49 | * Fine tuning.
50 |
51 | * [1.0.0+1] Updated README.
52 |
53 | ## [0.1.3] - 08.08.2019
54 |
55 | * Improved code style.
56 |
57 | ## [0.1.2] - 08.08.2019
58 |
59 | * Minor changes.
60 |
61 | ## [0.1.1] - 08.08.2019
62 |
63 | * Minor changes.
64 |
65 | * Documentation added.
66 |
67 | ## [0.1.0] - 07.08.2019
68 |
69 | * Initial release. Documentation pending.
70 |
--------------------------------------------------------------------------------
/snap/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Ali Yigit Bireroglu
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/snap/README.md:
--------------------------------------------------------------------------------
1 | # snap
2 |
3 | [comment]: <> (Badges)
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | [](https://pub.dev/packages/snap)
12 | [](https://github.com/aliyigitbireroglu/flutter-snap/blob/master/LICENSE)
13 |
14 | [comment]: <> (Introduction)
15 | An extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.
16 |
17 | Inspired by WhatsApp's in-app Youtube player.
18 |
19 | **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
20 | of capabilities.**
21 |
22 | [comment]: <> (ToC)
23 | [Media](#media) | [Description](#description) | [How-to-Use](#howtouse)
24 |
25 | [comment]: <> (Notice)
26 | ## Notice
27 | * **[flick](https://pub.dev/packages/flick) works as intended on actual devices even if it might appear to fail rarely on simulators. Don't be
28 | discouraged!**
29 | * * *
30 | [comment]: <> (Recent)
31 | ## Recent
32 | * **[flick](https://pub.dev/packages/flick) is now added. It is amazing! See [Media](#media) for examples.**
33 | * * *
34 |
35 |
36 | [comment]: <> (Media)
37 |
38 | ## Media
39 |
40 | Watch on **Youtube**:
41 |
42 | [v1.0.0 with Flick](https://youtu.be/vNTBsMg1NXg)
43 |
44 | [v0.1.0](https://youtu.be/anHHG3JJPrI)
45 |
46 |
47 |
48 |
49 |
50 | [comment]: <> (Description)
51 |
52 | ## Description
53 | This is an extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.
54 |
55 | Just wrap your *snapper* widget with the SnapController widget, fill the parameters, define your *snappable* widget and this package will take care
56 | of everything else.
57 |
58 |
59 | [comment]: <> (How-to-Use)
60 |
61 | ## How-to-Use
62 | *"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."*
63 |
64 | First, define two GlobalKeys- one for your view and one for your bound:
65 |
66 | ```
67 | GlobalKey bound = GlobalKey();
68 | GlobalKey view = GlobalKey();
69 | ```
70 |
71 | Then, create a SnapController such as:
72 |
73 | ```
74 | SnapController(
75 | uiChild(), //uiChild
76 | false, //useCache
77 | view, //viewKey
78 | bound, //boundKey
79 | Offset.zero, //constraintsMin
80 | const Offset(1.0, 1.0), //constraintsMax
81 | const Offset(0.75, 0.75), //flexibilityMin
82 | const Offset(0.75, 0.75), //flexibilityMax
83 | {Key key,
84 | customBoundWidth : 0,
85 | customBoundHeight : 0,
86 | snapTargets : [
87 | const SnapTarget(Pivot.topLeft, Pivot.topLeft),
88 | const SnapTarget(Pivot.topRight, Pivot.topRight),
89 | const SnapTarget(Pivot.bottomLeft, Pivot.bottomLeft),
90 | const SnapTarget(Pivot.bottomRight, Pivot.bottomRight),
91 | const SnapTarget(Pivot.center, Pivot.center)
92 | ],
93 | minSnapDistance : 100.0,
94 | animateSnap : true,
95 | useFlick : true,
96 | flickSensitivity : 0.075,
97 | onMove : _onMove,
98 | onDragStart : _onDragStart,
99 | onDragUpdate : _onDragUpdate,
100 | onDragEnd : _onDragEnd,
101 | onSnap : _onSnap})
102 |
103 | Widget uiChild() {
104 | return Container(
105 | key: view,
106 | ...
107 | );
108 | }
109 |
110 | void _onMove(Offset offset);
111 |
112 | void _onDragStart(dynamic dragDetails);
113 | void _onDragUpdate(dynamic dragDetails);
114 | void _onDragEnd(dynamic dragDetails);
115 |
116 | void _onSnap(Offset offset);
117 | ```
118 |
119 | **Further Explanations:**
120 |
121 | *For a complete set of descriptions for all parameters and methods, see the [documentation](https://pub.dev/documentation/snap/latest/).*
122 |
123 | * Set [useCache] to true if your [uiChild] doesn't change at runtime.
124 | * Consider the following example:
125 |
126 | ```
127 | Column(
128 | crossAxisAlignment: CrossAxisAlignment.start,
129 | children: [
130 | Expanded(
131 | child: Align(
132 | key: bound,
133 | alignment: const Alignment(-1.0, -1.0),
134 | child: SnapController(
135 | uiChild(),
136 | true,
137 | view,
138 | bound,
139 | Offset.zero,
140 | const Offset(1.0, 1.0),
141 | const Offset(0.75, 0.75),
142 | const Offset(0.75, 0.75),
143 | snapTargets: [
144 | const SnapTarget(Pivot.topLeft, Pivot.topLeft),
145 | const SnapTarget(Pivot.topRight, Pivot.topRight),
146 | const SnapTarget(Pivot.bottomLeft, Pivot.bottomLeft),
147 | const SnapTarget(Pivot.bottomRight, Pivot.bottomRight),
148 | const SnapTarget(Pivot.center, Pivot.center)
149 | ]
150 | )
151 | )
152 | )
153 | ]
154 | )
155 | ```
156 |
157 | In this excerpt, the bound is an Align widget which expands through a Column widget.
158 |
159 | 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.
160 |
161 | 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
162 | min/max constraints with a flexibility of 0.75 before it snaps.
163 |
164 | The snapTargets determine from where and to where the view should snap once the movement is over. In this example:
165 |
166 | 1. The top left corner of the view can snap to the top left corner of the bound.
167 | 2. The top right corner of the view can snap to the top right corner of the bound.
168 | 3. The bottom left corner of the view can snap to the bottom left corner of the bound.
169 | 4. The bottom right corner of the view can snap to the bottom right corner of the bound.
170 | 5. The center of the view can snap to the center of the bound.
171 |
172 | Keep in mind that these constant values are provided only for the ease of use. snapTargets can consist of any values you wish.
173 |
174 | * Use [SnapControllerState]'s [bool isMoved(double treshold)] method to determine if the view is moved or not where [treshold] is the distance at
175 | which the view should be considered to be moved.
176 |
177 |
178 | [comment]: <> (Notes)
179 | ## Notes
180 | 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
181 | different, that could be much better, etc. Please let me know! Nicely!
182 |
183 | Any help, suggestion or criticism is appreciated!
184 |
185 | Cheers.
186 |
187 | [comment]: <> (CosmosSoftware)
188 |
189 |
190 |
191 |
--------------------------------------------------------------------------------
/snap/example/.gitignore:
--------------------------------------------------------------------------------
1 | /gitignore
2 | /android
3 | /build
4 | /ios
5 | .notes.md
6 | .notes.txt
7 |
8 | # Miscellaneous
9 | *.class
10 | *.log
11 | *.pyc
12 | *.swp
13 | .DS_Store
14 | .atom/
15 | .buildlog/
16 | .history
17 | .svn/
18 |
19 | # IntelliJ related
20 | *.iml
21 | *.ipr
22 | *.iws
23 | .idea/
24 |
25 | # The .vscode folder contains launch configuration and tasks you configure in
26 | # VS Code which you may wish to be included in version control, so this line
27 | # is commented out by default.
28 | #.vscode/
29 |
30 | # Flutter/Dart/Pub related
31 | **/doc/api/
32 | .dart_tool/
33 | .flutter-plugins
34 | .packages
35 | .pub-cache/
36 | .pub/
37 | build/
38 |
39 | # Android related
40 | **/android/**/gradle-wrapper.jar
41 | **/android/.gradle
42 | **/android/captures/
43 | **/android/gradlew
44 | **/android/gradlew.bat
45 | **/android/local.properties
46 | **/android/**/GeneratedPluginRegistrant.java
47 |
48 | # iOS/XCode related
49 | **/ios/**/*.mode1v3
50 | **/ios/**/*.mode2v3
51 | **/ios/**/*.moved-aside
52 | **/ios/**/*.pbxuser
53 | **/ios/**/*.perspectivev3
54 | **/ios/**/*sync/
55 | **/ios/**/.sconsign.dblite
56 | **/ios/**/.tags*
57 | **/ios/**/.vagrant/
58 | **/ios/**/DerivedData/
59 | **/ios/**/Icon?
60 | **/ios/**/Pods/
61 | **/ios/**/.symlinks/
62 | **/ios/**/profile
63 | **/ios/**/xcuserdata
64 | **/ios/.generated/
65 | **/ios/Flutter/App.framework
66 | **/ios/Flutter/Flutter.framework
67 | **/ios/Flutter/Generated.xcconfig
68 | **/ios/Flutter/app.flx
69 | **/ios/Flutter/app.zip
70 | **/ios/Flutter/flutter_assets/
71 | **/ios/ServiceDefinitions.json
72 | **/ios/Runner/GeneratedPluginRegistrant.*
73 |
74 | # Exceptions to above rules.
75 | !**/ios/**/default.mode1v3
76 | !**/ios/**/default.mode2v3
77 | !**/ios/**/default.pbxuser
78 | !**/ios/**/default.perspectivev3
79 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
80 |
--------------------------------------------------------------------------------
/snap/example/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: 20e59316b8b8474554b38493b8ca888794b0234a
8 | channel: stable
9 |
10 | project_type: app
11 |
--------------------------------------------------------------------------------
/snap/example/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [2.0.0] - 04.05.2021
2 |
3 | * Migrated to Null Safety.
4 |
5 | ## [1.0.6] - 11.10.2020
6 |
7 | * Regular maintenance.
8 |
9 | ## [1.0.5] - 21.11.2019
10 |
11 | * [minSnapDistance] is added. If set, the snapping will not occur when no [SnapTarget] is found that is closer to the [uiChild] than this value.
12 |
13 | * Updated README.
14 |
15 | ## [1.0.4] - 07.09.2019
16 |
17 | * Minor changes.
18 |
19 | ## [1.0.3] - 30.08.2019
20 |
21 | * Minor changes.
22 |
23 | * Improved code style.
24 |
25 | * [1.0.3+1] Updated README.
26 |
27 | * [1.0.3+2] Updated README.
28 |
29 | ## [1.0.2] - 23.08.2019
30 |
31 | * Minor changes.
32 |
33 | * Improved code style with trailing commas.
34 |
35 | * [1.0.2+1] Minor changes.
36 |
37 | ## [1.0.1] - 20.08.2019
38 |
39 | * Improved code style.
40 |
41 | * Code excerpt added to the README.
42 |
43 | * [1.0.1+1] Updated README.
44 |
45 | ## [1.0.0] - 18.08.2019
46 |
47 | * [flick](https://pub.dev/packages/flick) is now implemented directly to the package.
48 |
49 | * Fine tuning.
50 |
51 | * [1.0.0+1] Updated README.
52 |
53 | ## [0.1.3] - 08.08.2019
54 |
55 | * Improved code style.
56 |
57 | ## [0.1.2] - 08.08.2019
58 |
59 | * Minor changes.
60 |
61 | ## [0.1.1] - 08.08.2019
62 |
63 | * Minor changes.
64 |
65 | * Documentation added.
66 |
67 | ## [0.1.0] - 07.08.2019
68 |
69 | * Initial release. Documentation pending.
70 |
--------------------------------------------------------------------------------
/snap/example/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Ali Yigit Bireroglu
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/snap/example/README.md:
--------------------------------------------------------------------------------
1 | # example
2 |
3 | Example Project for snap.
4 |
5 |
6 | # snap
7 |
8 | [comment]: <> (Badges)
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | [](https://pub.dev/packages/snap)
17 | [](https://github.com/aliyigitbireroglu/flutter-snap/blob/master/LICENSE)
18 |
19 | [comment]: <> (Introduction)
20 | An extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.
21 |
22 | Inspired by WhatsApp's in-app Youtube player.
23 |
24 | **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
25 | of capabilities.**
26 |
27 | [comment]: <> (ToC)
28 | [Media](#media) | [Description](#description) | [How-to-Use](#howtouse)
29 |
30 | [comment]: <> (Notice)
31 | ## Notice
32 | * **[flick](https://pub.dev/packages/flick) works as intended on actual devices even if it might appear to fail rarely on simulators. Don't be
33 | discouraged!**
34 | * * *
35 | [comment]: <> (Recent)
36 | ## Recent
37 | * **[flick](https://pub.dev/packages/flick) is now added. It is amazing! See [Media](#media) for examples.**
38 | * * *
39 |
40 |
41 | [comment]: <> (Media)
42 |
43 | ## Media
44 |
45 | Watch on **Youtube**:
46 |
47 | [v1.0.0 with Flick](https://youtu.be/vNTBsMg1NXg)
48 |
49 | [v0.1.0](https://youtu.be/anHHG3JJPrI)
50 |
51 |
52 |
53 |
54 |
55 | [comment]: <> (Description)
56 |
57 | ## Description
58 | This is an extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.
59 |
60 | Just wrap your *snapper* widget with the SnapController widget, fill the parameters, define your *snappable* widget and this package will take care
61 | of everything else.
62 |
63 |
64 | [comment]: <> (How-to-Use)
65 |
66 | ## How-to-Use
67 | *"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."*
68 |
69 | First, define two GlobalKeys- one for your view and one for your bound:
70 |
71 | ```
72 | GlobalKey bound = GlobalKey();
73 | GlobalKey view = GlobalKey();
74 | ```
75 |
76 | Then, create a SnapController such as:
77 |
78 | ```
79 | SnapController(
80 | uiChild(), //uiChild
81 | false, //useCache
82 | view, //viewKey
83 | bound, //boundKey
84 | Offset.zero, //constraintsMin
85 | const Offset(1.0, 1.0), //constraintsMax
86 | const Offset(0.75, 0.75), //flexibilityMin
87 | const Offset(0.75, 0.75), //flexibilityMax
88 | {Key key,
89 | customBoundWidth : 0,
90 | customBoundHeight : 0,
91 | snapTargets : [
92 | const SnapTarget(Pivot.topLeft, Pivot.topLeft),
93 | const SnapTarget(Pivot.topRight, Pivot.topRight),
94 | const SnapTarget(Pivot.bottomLeft, Pivot.bottomLeft),
95 | const SnapTarget(Pivot.bottomRight, Pivot.bottomRight),
96 | const SnapTarget(Pivot.center, Pivot.center)
97 | ],
98 | minSnapDistance : 100.0,
99 | animateSnap : true,
100 | useFlick : true,
101 | flickSensitivity : 0.075,
102 | onMove : _onMove,
103 | onDragStart : _onDragStart,
104 | onDragUpdate : _onDragUpdate,
105 | onDragEnd : _onDragEnd,
106 | onSnap : _onSnap})
107 |
108 | Widget uiChild() {
109 | return Container(
110 | key: view,
111 | ...
112 | );
113 | }
114 |
115 | void _onMove(Offset offset);
116 |
117 | void _onDragStart(dynamic dragDetails);
118 | void _onDragUpdate(dynamic dragDetails);
119 | void _onDragEnd(dynamic dragDetails);
120 |
121 | void _onSnap(Offset offset);
122 | ```
123 |
124 | **Further Explanations:**
125 |
126 | *For a complete set of descriptions for all parameters and methods, see the [documentation](https://pub.dev/documentation/snap/latest/).*
127 |
128 | * Set [useCache] to true if your [uiChild] doesn't change at runtime.
129 | * Consider the following example:
130 |
131 | ```
132 | Column(
133 | crossAxisAlignment: CrossAxisAlignment.start,
134 | children: [
135 | Expanded(
136 | child: Align(
137 | key: bound,
138 | alignment: const Alignment(-1.0, -1.0),
139 | child: SnapController(
140 | uiChild(),
141 | true,
142 | view,
143 | bound,
144 | Offset.zero,
145 | const Offset(1.0, 1.0),
146 | const Offset(0.75, 0.75),
147 | const Offset(0.75, 0.75),
148 | snapTargets: [
149 | const SnapTarget(Pivot.topLeft, Pivot.topLeft),
150 | const SnapTarget(Pivot.topRight, Pivot.topRight),
151 | const SnapTarget(Pivot.bottomLeft, Pivot.bottomLeft),
152 | const SnapTarget(Pivot.bottomRight, Pivot.bottomRight),
153 | const SnapTarget(Pivot.center, Pivot.center)
154 | ]
155 | )
156 | )
157 | )
158 | ]
159 | )
160 | ```
161 |
162 | In this excerpt, the bound is an Align widget which expands through a Column widget.
163 |
164 | 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.
165 |
166 | 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
167 | min/max constraints with a flexibility of 0.75 before it snaps.
168 |
169 | The snapTargets determine from where and to where the view should snap once the movement is over. In this example:
170 |
171 | 1. The top left corner of the view can snap to the top left corner of the bound.
172 | 2. The top right corner of the view can snap to the top right corner of the bound.
173 | 3. The bottom left corner of the view can snap to the bottom left corner of the bound.
174 | 4. The bottom right corner of the view can snap to the bottom right corner of the bound.
175 | 5. The center of the view can snap to the center of the bound.
176 |
177 | Keep in mind that these constant values are provided only for the ease of use. snapTargets can consist of any values you wish.
178 |
179 | * Use [SnapControllerState]'s [bool isMoved(double treshold)] method to determine if the view is moved or not where [treshold] is the distance at
180 | which the view should be considered to be moved.
181 |
182 |
183 | [comment]: <> (Notes)
184 | ## Notes
185 | 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
186 | different, that could be much better, etc. Please let me know! Nicely!
187 |
188 | Any help, suggestion or criticism is appreciated!
189 |
190 | Cheers.
191 |
192 | [comment]: <> (CosmosSoftware)
193 |