├── example ├── ios │ ├── Flutter │ │ ├── Debug.xcconfig │ │ ├── Release.xcconfig │ │ └── AppFrameworkInfo.plist │ ├── Runner │ │ ├── Runner-Bridging-Header.h │ │ ├── Assets.xcassets │ │ │ ├── LaunchImage.imageset │ │ │ │ ├── LaunchImage.png │ │ │ │ ├── LaunchImage@2x.png │ │ │ │ ├── LaunchImage@3x.png │ │ │ │ ├── README.md │ │ │ │ └── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ ├── Icon-App-20x20@1x.png │ │ │ │ ├── Icon-App-20x20@2x.png │ │ │ │ ├── Icon-App-20x20@3x.png │ │ │ │ ├── Icon-App-29x29@1x.png │ │ │ │ ├── Icon-App-29x29@2x.png │ │ │ │ ├── Icon-App-29x29@3x.png │ │ │ │ ├── Icon-App-40x40@1x.png │ │ │ │ ├── Icon-App-40x40@2x.png │ │ │ │ ├── Icon-App-40x40@3x.png │ │ │ │ ├── Icon-App-60x60@2x.png │ │ │ │ ├── Icon-App-60x60@3x.png │ │ │ │ ├── Icon-App-76x76@1x.png │ │ │ │ ├── Icon-App-76x76@2x.png │ │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ │ ├── Icon-App-83.5x83.5@2x.png │ │ │ │ └── Contents.json │ │ ├── AppDelegate.swift │ │ ├── Base.lproj │ │ │ ├── Main.storyboard │ │ │ └── LaunchScreen.storyboard │ │ └── Info.plist │ ├── Runner.xcodeproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── WorkspaceSettings.xcsettings │ │ │ │ └── IDEWorkspaceChecks.plist │ │ ├── xcshareddata │ │ │ └── xcschemes │ │ │ │ └── Runner.xcscheme │ │ └── project.pbxproj │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── WorkspaceSettings.xcsettings │ │ │ └── IDEWorkspaceChecks.plist │ └── .gitignore ├── analysis_options.yaml ├── images │ ├── image_3.jpg │ ├── image_4.jpg │ └── image_5.jpg ├── android │ ├── gradle.properties │ ├── app │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── drawable │ │ │ │ │ │ └── launch_background.xml │ │ │ │ │ ├── drawable-v21 │ │ │ │ │ │ └── launch_background.xml │ │ │ │ │ ├── values │ │ │ │ │ │ └── styles.xml │ │ │ │ │ └── values-night │ │ │ │ │ │ └── styles.xml │ │ │ │ ├── kotlin │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── example │ │ │ │ │ │ └── MainActivity.kt │ │ │ │ └── AndroidManifest.xml │ │ │ ├── debug │ │ │ │ └── AndroidManifest.xml │ │ │ └── profile │ │ │ │ └── AndroidManifest.xml │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ ├── .gitignore │ ├── settings.gradle │ └── build.gradle ├── .metadata ├── test │ └── widget_test.dart ├── README.md ├── .gitignore ├── lib │ ├── theme │ │ └── colors.dart │ ├── widgets │ │ ├── fade_route.dart │ │ ├── card_overlay.dart │ │ ├── general_drawer.dart │ │ ├── card_label.dart │ │ ├── example_card.dart │ │ └── bottom_buttons_row.dart │ ├── examples │ │ ├── basic_example.dart │ │ ├── detectable_directions_example.dart │ │ ├── ignore_vertical_swipe_example.dart │ │ ├── swipe_anchor_example.dart │ │ └── popup_on_swipe_example.dart │ └── main.dart ├── pubspec.yaml └── pubspec.lock ├── analysis_options.yaml ├── lib ├── swipable_stack.dart └── src │ ├── enum │ ├── swipe_anchor.dart │ └── swipe_direction.dart │ ├── callback │ └── callbacks.dart │ ├── animation │ └── animation.dart │ ├── model │ ├── swipe_properties.dart │ ├── swipable_stack_position.dart │ └── swipe_rate_per_threshold.dart │ ├── swipable_stack_controller.dart │ └── swipable_stack.dart ├── .metadata ├── pubspec.yaml ├── LICENSE ├── test └── swipable_stack_test.dart ├── .gitignore ├── CHANGELOG.md ├── README.md └── pubspec.lock /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:pedantic_mono/analysis_options.yaml 2 | 3 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:pedantic_mono/analysis_options.yaml 2 | 3 | -------------------------------------------------------------------------------- /lib/swipable_stack.dart: -------------------------------------------------------------------------------- 1 | library swipable_stack; 2 | 3 | export 'src/swipable_stack.dart'; 4 | -------------------------------------------------------------------------------- /example/images/image_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/images/image_3.jpg -------------------------------------------------------------------------------- /example/images/image_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/images/image_4.jpg -------------------------------------------------------------------------------- /example/images/image_5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/images/image_5.jpg -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /lib/src/enum/swipe_anchor.dart: -------------------------------------------------------------------------------- 1 | part of '../swipable_stack.dart'; 2 | 3 | /// Where to anchor the card during swipe 4 | enum SwipeAnchor { 5 | top, 6 | bottom, 7 | } 8 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/android/app/src/main/kotlin/com/example/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.example 2 | 3 | import io.flutter.embedding.android.FlutterActivity 4 | 5 | class MainActivity: FlutterActivity() { 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeavenOSK/flutter_swipable_stack/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip 7 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 1 | gradle-wrapper.jar 2 | /.gradle 3 | /captures/ 4 | /gradlew 5 | /gradlew.bat 6 | /local.properties 7 | GeneratedPluginRegistrant.java 8 | 9 | # Remember to never publicly share your keystore. 10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app 11 | key.properties 12 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.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: 9b2d32b605630f28625709ebd9d78ab3016b2bf6 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /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: 9b2d32b605630f28625709ebd9d78ab3016b2bf6 8 | channel: stable 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: swipable_stack 2 | description: A widget for stacking cards, which users can swipe horizontally and vertically with beautiful animations like Tinder. 3 | version: 2.0.0 4 | homepage: https://github.com/HeavenOSK/flutter_swipable_stack 5 | environment: 6 | sdk: ">=2.17.0 <3.0.0" 7 | dependencies: 8 | flutter: 9 | sdk: flutter 10 | sprung: ^3.0.0 11 | dev_dependencies: 12 | flutter_test: 13 | sdk: flutter 14 | pedantic_mono: 15 | 16 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | 4 | @UIApplicationMain 5 | @objc class AppDelegate: FlutterAppDelegate { 6 | override func application( 7 | _ application: UIApplication, 8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 9 | ) -> Bool { 10 | GeneratedPluginRegistrant.register(with: self) 11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/enum/swipe_direction.dart: -------------------------------------------------------------------------------- 1 | part of '../swipable_stack.dart'; 2 | 3 | /// The type of Action to use in [SwipableStack]. 4 | enum SwipeDirection { 5 | left(Offset(-1, 0)), 6 | right(Offset(1, 0)), 7 | up(Offset(0, -1)), 8 | down(Offset(0, 1)); 9 | 10 | const SwipeDirection(this.defaultOffset); 11 | final Offset defaultOffset; 12 | } 13 | 14 | extension _SwipeDirectionX on SwipeDirection { 15 | bool get isHorizontal => 16 | this == SwipeDirection.right || this == SwipeDirection.left; 17 | } 18 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties") 4 | def properties = new Properties() 5 | 6 | assert localPropertiesFile.exists() 7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } 8 | 9 | def flutterSdkPath = properties.getProperty("flutter.sdk") 10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties" 11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" 12 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/test/widget_test.dart: -------------------------------------------------------------------------------- 1 | // This is a basic Flutter widget test. 2 | // 3 | // To perform an interaction with a widget in your test, use the WidgetTester 4 | // utility that Flutter provides. For example, you can send tap and scroll 5 | // gestures. You can also use WidgetTester to find child widgets in the widget 6 | // tree, read text, and verify that the values of widget properties are correct. 7 | 8 | import 'package:flutter_test/flutter_test.dart'; 9 | 10 | void main() { 11 | testWidgets('', (WidgetTester tester) async {}); 12 | } 13 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # example 2 | 3 | A new Flutter project. 4 | 5 | ## Getting Started 6 | 7 | This project is a starting point for a Flutter application. 8 | 9 | A few resources to get you started if this is your first Flutter project: 10 | 11 | - [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) 12 | - [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) 13 | 14 | For help getting started with Flutter, view our 15 | [online documentation](https://flutter.dev/docs), which offers tutorials, 16 | samples, guidance on mobile development, and a full API reference. 17 | -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | *.mode1v3 2 | *.mode2v3 3 | *.moved-aside 4 | *.pbxuser 5 | *.perspectivev3 6 | **/*sync/ 7 | .sconsign.dblite 8 | .tags* 9 | **/.vagrant/ 10 | **/DerivedData/ 11 | Icon? 12 | **/Pods/ 13 | **/.symlinks/ 14 | profile 15 | xcuserdata 16 | **/.generated/ 17 | Flutter/App.framework 18 | Flutter/Flutter.framework 19 | Flutter/Flutter.podspec 20 | Flutter/Generated.xcconfig 21 | Flutter/app.flx 22 | Flutter/app.zip 23 | Flutter/flutter_assets/ 24 | Flutter/flutter_export_environment.sh 25 | ServiceDefinitions.json 26 | Runner/GeneratedPluginRegistrant.* 27 | 28 | # Exceptions to above rules. 29 | !default.mode1v3 30 | !default.mode2v3 31 | !default.pbxuser 32 | !default.perspectivev3 33 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.3.50' 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.0' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | jcenter() 18 | } 19 | } 20 | 21 | rootProject.buildDir = '../build' 22 | subprojects { 23 | project.buildDir = "${rootProject.buildDir}/${project.name}" 24 | } 25 | subprojects { 26 | project.evaluationDependsOn(':app') 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | -------------------------------------------------------------------------------- /lib/src/callback/callbacks.dart: -------------------------------------------------------------------------------- 1 | part of '../swipable_stack.dart'; 2 | 3 | /// Callback called when the Swipe is completed. 4 | typedef SwipeCompletionCallback = void Function( 5 | int index, 6 | SwipeDirection direction, 7 | ); 8 | 9 | /// Callback called just before launching the Swipe action. 10 | typedef OnWillMoveNext = bool Function( 11 | int index, 12 | SwipeDirection swipeDirection, 13 | ); 14 | 15 | /// Builder for items to be displayed in [SwipableStack]. 16 | typedef SwipableStackItemBuilder = Widget Function( 17 | BuildContext context, 18 | ItemSwipeProperties swipeProperty, 19 | ); 20 | 21 | /// Builder for displaying an overlay on the most foreground card. 22 | typedef SwipableStackOverlayBuilder = Widget Function( 23 | BuildContext context, 24 | OverlaySwipeProperties swipeProperty, 25 | ); 26 | -------------------------------------------------------------------------------- /example/lib/theme/colors.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:swipable_stack/swipable_stack.dart'; 3 | 4 | class SwipeDirectionColor { 5 | static const right = Color.fromRGBO(70, 195, 120, 1); 6 | static const left = Color.fromRGBO(220, 90, 108, 1); 7 | static const up = Color.fromRGBO(83, 170, 232, 1); 8 | static const down = Color.fromRGBO(154, 85, 215, 1); 9 | } 10 | 11 | extension SwipeDirecionX on SwipeDirection { 12 | Color get color { 13 | switch (this) { 14 | case SwipeDirection.right: 15 | return const Color.fromRGBO(70, 195, 120, 1); 16 | case SwipeDirection.left: 17 | return const Color.fromRGBO(220, 90, 108, 1); 18 | case SwipeDirection.up: 19 | return const Color.fromRGBO(83, 170, 232, 1); 20 | case SwipeDirection.down: 21 | return const Color.fromRGBO(154, 85, 215, 1); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 9.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/lib/widgets/fade_route.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | 3 | class FadeRoute extends PageRoute { 4 | FadeRoute({ 5 | required this.builder, 6 | super.settings, 7 | this.maintainState = true, 8 | super.fullscreenDialog, 9 | }); 10 | 11 | final WidgetBuilder builder; 12 | 13 | @override 14 | Widget buildPage( 15 | BuildContext context, 16 | Animation animation, 17 | Animation secondaryAnimation, 18 | ) => 19 | FadeTransition( 20 | opacity: animation, 21 | child: builder(context), 22 | ); 23 | 24 | @override 25 | final bool maintainState; 26 | 27 | @override 28 | String get debugLabel => '${super.debugLabel}(${settings.name})'; 29 | 30 | @override 31 | Color? get barrierColor => null; 32 | 33 | @override 34 | String? get barrierLabel => null; 35 | 36 | @override 37 | Duration get transitionDuration => const Duration(milliseconds: 300); 38 | } 39 | -------------------------------------------------------------------------------- /lib/src/animation/animation.dart: -------------------------------------------------------------------------------- 1 | part of '../swipable_stack.dart'; 2 | 3 | extension _AnimationControllerX on AnimationController { 4 | bool get animating => 5 | status == AnimationStatus.forward || status == AnimationStatus.reverse; 6 | 7 | Animation tweenCurvedAnimation({ 8 | required Offset startPosition, 9 | required Offset currentPosition, 10 | required Curve curve, 11 | }) { 12 | return Tween( 13 | begin: currentPosition, 14 | end: startPosition, 15 | ).animate( 16 | CurvedAnimation( 17 | parent: this, 18 | curve: curve, 19 | ), 20 | ); 21 | } 22 | 23 | Animation swipeAnimation({ 24 | required Offset startPosition, 25 | required Offset endPosition, 26 | }) { 27 | return Tween( 28 | begin: startPosition, 29 | end: endPosition, 30 | ).animate( 31 | CurvedAnimation( 32 | parent: this, 33 | curve: const Cubic(0.7, 1, 0.73, 1), 34 | ), 35 | ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Ryunosuke Watanabe 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 | -------------------------------------------------------------------------------- /example/lib/widgets/card_overlay.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' as math; 2 | 3 | import 'package:example/widgets/card_label.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:swipable_stack/swipable_stack.dart'; 6 | 7 | class CardOverlay extends StatelessWidget { 8 | const CardOverlay({ 9 | required this.direction, 10 | required this.swipeProgress, 11 | super.key, 12 | }); 13 | final SwipeDirection direction; 14 | final double swipeProgress; 15 | 16 | @override 17 | Widget build(BuildContext context) { 18 | final opacity = math.min(swipeProgress, 1); 19 | 20 | final isRight = direction == SwipeDirection.right; 21 | final isLeft = direction == SwipeDirection.left; 22 | final isUp = direction == SwipeDirection.up; 23 | final isDown = direction == SwipeDirection.down; 24 | return Stack( 25 | children: [ 26 | Opacity( 27 | opacity: isRight ? opacity : 0, 28 | child: CardLabel.right(), 29 | ), 30 | Opacity( 31 | opacity: isLeft ? opacity : 0, 32 | child: CardLabel.left(), 33 | ), 34 | Opacity( 35 | opacity: isUp ? opacity : 0, 36 | child: CardLabel.up(), 37 | ), 38 | Opacity( 39 | opacity: isDown ? opacity : 0, 40 | child: CardLabel.down(), 41 | ), 42 | ], 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/swipable_stack_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:swipable_stack/src/swipable_stack.dart'; 4 | 5 | final _cardColors = [ 6 | ...Colors.primaries, 7 | ...Colors.accents, 8 | ]; 9 | 10 | Widget _buildCard({ 11 | required Color color, 12 | required int index, 13 | }) => 14 | Container( 15 | key: UniqueKey(), 16 | height: double.infinity, 17 | width: double.infinity, 18 | color: color, 19 | alignment: Alignment.center, 20 | child: Text('$index'), 21 | ); 22 | 23 | Widget _buildApp({ 24 | required int cardCount, 25 | }) { 26 | return MaterialApp( 27 | home: Scaffold( 28 | body: SwipableStack( 29 | itemCount: cardCount, 30 | builder: (context, properties) { 31 | final color = _cardColors[properties.index % _cardColors.length]; 32 | return _buildCard( 33 | color: color, 34 | index: properties.index, 35 | ); 36 | }, 37 | ), 38 | ), 39 | ); 40 | } 41 | 42 | void main() { 43 | group( 44 | '[SwipableStack]', 45 | () { 46 | testWidgets( 47 | 'can build when itemCount is 0, 1, 2, 3...10', 48 | (tester) async { 49 | for (var i = 0; i < 10; i++) { 50 | await tester.pumpWidget(_buildApp(cardCount: i)); 51 | } 52 | }, 53 | ); 54 | }, 55 | ); 56 | } 57 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | example 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(FLUTTER_BUILD_NAME) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | .dart_tool/ 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | .packages 29 | .pub-cache/ 30 | .pub/ 31 | build/ 32 | 33 | # Android related 34 | **/android/**/gradle-wrapper.jar 35 | **/android/.gradle 36 | **/android/captures/ 37 | **/android/gradlew 38 | **/android/gradlew.bat 39 | **/android/local.properties 40 | **/android/**/GeneratedPluginRegistrant.java 41 | 42 | # iOS/XCode related 43 | **/ios/**/*.mode1v3 44 | **/ios/**/*.mode2v3 45 | **/ios/**/*.moved-aside 46 | **/ios/**/*.pbxuser 47 | **/ios/**/*.perspectivev3 48 | **/ios/**/*sync/ 49 | **/ios/**/.sconsign.dblite 50 | **/ios/**/.tags* 51 | **/ios/**/.vagrant/ 52 | **/ios/**/DerivedData/ 53 | **/ios/**/Icon? 54 | **/ios/**/Pods/ 55 | **/ios/**/.symlinks/ 56 | **/ios/**/profile 57 | **/ios/**/xcuserdata 58 | **/ios/.generated/ 59 | **/ios/Flutter/App.framework 60 | **/ios/Flutter/Flutter.framework 61 | **/ios/Flutter/Flutter.podspec 62 | **/ios/Flutter/Generated.xcconfig 63 | **/ios/Flutter/app.flx 64 | **/ios/Flutter/app.zip 65 | **/ios/Flutter/flutter_assets/ 66 | **/ios/Flutter/flutter_export_environment.sh 67 | **/ios/ServiceDefinitions.json 68 | **/ios/Runner/GeneratedPluginRegistrant.* 69 | 70 | # Exceptions to above rules. 71 | !**/ios/**/default.mode1v3 72 | !**/ios/**/default.mode2v3 73 | !**/ios/**/default.pbxuser 74 | !**/ios/**/default.perspectivev3 75 | 76 | .vscode 77 | -------------------------------------------------------------------------------- /lib/src/model/swipe_properties.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/rendering.dart'; 2 | import 'package:swipable_stack/src/swipable_stack.dart'; 3 | 4 | abstract class SwipeProperties { 5 | const SwipeProperties({ 6 | required this.index, 7 | required this.constraints, 8 | required this.direction, 9 | required this.swipeProgress, 10 | }); 11 | 12 | ///Index of the current item. 13 | final int index; 14 | 15 | ///[Constraints] of the whole stack. 16 | final BoxConstraints constraints; 17 | 18 | ///Direction of the current swipe action. 19 | final SwipeDirection? direction; 20 | 21 | ///Progress of the current swipe action. 22 | final double swipeProgress; 23 | } 24 | 25 | class OverlaySwipeProperties extends SwipeProperties { 26 | const OverlaySwipeProperties({ 27 | required int index, 28 | required BoxConstraints constraints, 29 | required SwipeDirection direction, 30 | required double swipeProgress, 31 | }) : super( 32 | index: index, 33 | constraints: constraints, 34 | direction: direction, 35 | swipeProgress: swipeProgress, 36 | ); 37 | 38 | ///Direction of the current swipe action. 39 | @override 40 | SwipeDirection get direction => super.direction!; 41 | } 42 | 43 | class ItemSwipeProperties extends SwipeProperties { 44 | const ItemSwipeProperties({ 45 | required int index, 46 | required this.stackIndex, 47 | required BoxConstraints constraints, 48 | required SwipeDirection? direction, 49 | required double swipeProgress, 50 | }) : super( 51 | index: index, 52 | constraints: constraints, 53 | direction: direction, 54 | swipeProgress: swipeProgress, 55 | ); 56 | 57 | ///Index of the current item in the stack. 58 | ///The top item of the stack has index 0 and the rewind item has index -1. 59 | final int stackIndex; 60 | } 61 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply plugin: 'kotlin-android' 26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 27 | 28 | android { 29 | compileSdkVersion 30 30 | 31 | sourceSets { 32 | main.java.srcDirs += 'src/main/kotlin' 33 | } 34 | 35 | defaultConfig { 36 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 37 | applicationId "com.example.example" 38 | minSdkVersion 16 39 | targetSdkVersion 30 40 | versionCode flutterVersionCode.toInteger() 41 | versionName flutterVersionName 42 | } 43 | 44 | buildTypes { 45 | release { 46 | // TODO: Add your own signing config for the release build. 47 | // Signing with the debug keys for now, so `flutter run --release` works. 48 | signingConfig signingConfigs.debug 49 | } 50 | } 51 | } 52 | 53 | flutter { 54 | source '../..' 55 | } 56 | 57 | dependencies { 58 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 59 | } 60 | -------------------------------------------------------------------------------- /example/lib/widgets/general_drawer.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/examples/basic_example.dart'; 2 | import 'package:example/examples/detectable_directions_example.dart'; 3 | import 'package:example/examples/ignore_vertical_swipe_example.dart'; 4 | import 'package:example/examples/popup_on_swipe_example.dart'; 5 | import 'package:example/examples/swipe_anchor_example.dart'; 6 | import 'package:flutter/material.dart'; 7 | 8 | class GeneralDrawer extends StatelessWidget { 9 | const GeneralDrawer({super.key}); 10 | 11 | @override 12 | Widget build(BuildContext context) { 13 | Future navigate(Route route) async { 14 | Navigator.of(context).pop(); 15 | await Future.delayed(const Duration(milliseconds: 150)); 16 | await Navigator.of(context).pushReplacement(route); 17 | } 18 | 19 | return Drawer( 20 | child: ListView( 21 | children: [ 22 | ListTile( 23 | title: const Text('BasicExample'), 24 | onTap: () { 25 | navigate( 26 | BasicExample.route(), 27 | ); 28 | }, 29 | ), 30 | ListTile( 31 | title: const Text('IgnoreVerticalSwipeExample'), 32 | onTap: () { 33 | navigate( 34 | IgnoreVerticalSwipeExample.route(), 35 | ); 36 | }, 37 | ), 38 | ListTile( 39 | title: const Text('PopupOnSwipeExample'), 40 | onTap: () { 41 | navigate( 42 | PopupOnSwipeExample.route(), 43 | ); 44 | }, 45 | ), 46 | ListTile( 47 | title: const Text('SwipeAnchorExample'), 48 | onTap: () { 49 | navigate( 50 | SwipeAnchorExample.route(), 51 | ); 52 | }, 53 | ), 54 | ListTile( 55 | title: const Text('DetectableDirectionsExample'), 56 | onTap: () { 57 | navigate( 58 | DetectableDirectionsExample.route(), 59 | ); 60 | }, 61 | ), 62 | ], 63 | ), 64 | ); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 13 | 17 | 21 | 26 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /example/lib/widgets/card_label.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' as math; 2 | 3 | import 'package:example/theme/colors.dart'; 4 | import 'package:flutter/material.dart'; 5 | 6 | const _labelAngle = math.pi / 2 * 0.2; 7 | 8 | class CardLabel extends StatelessWidget { 9 | const CardLabel._({ 10 | required this.color, 11 | required this.label, 12 | required this.angle, 13 | required this.alignment, 14 | }); 15 | 16 | factory CardLabel.right() { 17 | return const CardLabel._( 18 | color: SwipeDirectionColor.right, 19 | label: 'RIGHT', 20 | angle: -_labelAngle, 21 | alignment: Alignment.topLeft, 22 | ); 23 | } 24 | 25 | factory CardLabel.left() { 26 | return const CardLabel._( 27 | color: SwipeDirectionColor.left, 28 | label: 'LEFT', 29 | angle: _labelAngle, 30 | alignment: Alignment.topRight, 31 | ); 32 | } 33 | 34 | factory CardLabel.up() { 35 | return const CardLabel._( 36 | color: SwipeDirectionColor.up, 37 | label: 'UP', 38 | angle: _labelAngle, 39 | alignment: Alignment(0, 0.5), 40 | ); 41 | } 42 | 43 | factory CardLabel.down() { 44 | return const CardLabel._( 45 | color: SwipeDirectionColor.down, 46 | label: 'DOWN', 47 | angle: -_labelAngle, 48 | alignment: Alignment(0, -0.75), 49 | ); 50 | } 51 | 52 | final Color color; 53 | final String label; 54 | final double angle; 55 | final Alignment alignment; 56 | 57 | @override 58 | Widget build(BuildContext context) { 59 | return Container( 60 | alignment: alignment, 61 | padding: const EdgeInsets.symmetric( 62 | vertical: 36, 63 | horizontal: 36, 64 | ), 65 | child: Transform.rotate( 66 | angle: angle, 67 | child: Container( 68 | decoration: BoxDecoration( 69 | border: Border.all( 70 | color: color, 71 | width: 4, 72 | ), 73 | color: Colors.white, 74 | borderRadius: BorderRadius.circular(4), 75 | ), 76 | padding: const EdgeInsets.all(6), 77 | child: Text( 78 | label, 79 | style: TextStyle( 80 | fontSize: 32, 81 | fontWeight: FontWeight.w600, 82 | letterSpacing: 1.4, 83 | color: color, 84 | height: 1, 85 | ), 86 | ), 87 | ), 88 | ), 89 | ); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/lib/widgets/example_card.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/widgets/bottom_buttons_row.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class ExampleCard extends StatelessWidget { 5 | const ExampleCard({ 6 | required this.name, 7 | required this.assetPath, 8 | super.key, 9 | }); 10 | 11 | final String name; 12 | final String assetPath; 13 | 14 | @override 15 | Widget build(BuildContext context) { 16 | final theme = Theme.of(context); 17 | return ClipRRect( 18 | child: Stack( 19 | children: [ 20 | Positioned.fill( 21 | child: DecoratedBox( 22 | decoration: BoxDecoration( 23 | borderRadius: BorderRadius.circular(14), 24 | image: DecorationImage( 25 | image: AssetImage(assetPath), 26 | fit: BoxFit.cover, 27 | ), 28 | boxShadow: [ 29 | BoxShadow( 30 | offset: const Offset(0, 2), 31 | blurRadius: 26, 32 | color: Colors.black.withOpacity(0.08), 33 | ), 34 | ], 35 | ), 36 | ), 37 | ), 38 | Align( 39 | alignment: Alignment.bottomCenter, 40 | child: Container( 41 | height: 200, 42 | width: double.infinity, 43 | decoration: BoxDecoration( 44 | borderRadius: const BorderRadius.vertical( 45 | bottom: Radius.circular(14), 46 | ), 47 | gradient: LinearGradient( 48 | begin: Alignment.topCenter, 49 | end: Alignment.bottomCenter, 50 | colors: [ 51 | Colors.black12.withOpacity(0), 52 | Colors.black12.withOpacity(.4), 53 | Colors.black12.withOpacity(.82), 54 | ], 55 | ), 56 | ), 57 | ), 58 | ), 59 | Padding( 60 | padding: const EdgeInsets.symmetric(horizontal: 12), 61 | child: Column( 62 | mainAxisAlignment: MainAxisAlignment.end, 63 | crossAxisAlignment: CrossAxisAlignment.start, 64 | children: [ 65 | Text( 66 | name, 67 | style: theme.textTheme.headline6!.copyWith( 68 | color: Colors.white, 69 | ), 70 | ), 71 | const SizedBox(height: BottomButtonsRow.height) 72 | ], 73 | ), 74 | ), 75 | ], 76 | ), 77 | ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: A new Flutter project. 3 | 4 | # The following line prevents the package from being accidentally published to 5 | # pub.dev using `pub publish`. This is preferred for private packages. 6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 7 | 8 | # The following defines the version and build number for your application. 9 | # A version number is three numbers separated by dots, like 1.2.43 10 | # followed by an optional build number separated by a +. 11 | # Both the version and the builder number may be overridden in flutter 12 | # build by specifying --build-name and --build-number, respectively. 13 | # In Android, build-name is used as versionName while build-number used as versionCode. 14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 16 | # Read more about iOS versioning at 17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 18 | version: 1.0.0+1 19 | 20 | environment: 21 | sdk: ">=2.17.0 <3.0.0" 22 | 23 | dependencies: 24 | flutter: 25 | sdk: flutter 26 | 27 | 28 | # The following adds the Cupertino Icons font to your application. 29 | # Use with the CupertinoIcons class for iOS style icons. 30 | swipable_stack: 31 | path: 32 | ../ 33 | 34 | dev_dependencies: 35 | flutter_test: 36 | sdk: flutter 37 | pedantic_mono: 38 | 39 | # For information on the generic Dart part of this file, see the 40 | # following page: https://dart.dev/tools/pub/pubspec 41 | 42 | # The following section is specific to Flutter. 43 | flutter: 44 | 45 | # The following line ensures that the Material Icons font is 46 | # included with your application, so that you can use the icons in 47 | # the material Icons class. 48 | uses-material-design: true 49 | 50 | # To add assets to your application, add an assets section, like this: 51 | assets: 52 | - images/ 53 | 54 | # An image asset can refer to one or more resolution-specific "variants", see 55 | # https://flutter.dev/assets-and-images/#resolution-aware. 56 | 57 | # For details regarding adding assets from package dependencies, see 58 | # https://flutter.dev/assets-and-images/#from-packages 59 | 60 | # To add custom fonts to your application, add a fonts section here, 61 | # in this "flutter" section. Each entry in this list should have a 62 | # "family" key with the font family name, and a "fonts" key with a 63 | # list giving the asset and other descriptors for the font. For 64 | # example: 65 | # fonts: 66 | # - family: Schyler 67 | # fonts: 68 | # - asset: fonts/Schyler-Regular.ttf 69 | # - asset: fonts/Schyler-Italic.ttf 70 | # style: italic 71 | # - family: Trajan Pro 72 | # fonts: 73 | # - asset: fonts/TrajanPro.ttf 74 | # - asset: fonts/TrajanPro_Bold.ttf 75 | # weight: 700 76 | # 77 | # For details regarding fonts from package dependencies, 78 | # see https://flutter.dev/custom-fonts/#from-packages 79 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /lib/src/swipable_stack_controller.dart: -------------------------------------------------------------------------------- 1 | part of 'swipable_stack.dart'; 2 | 3 | /// An object to manipulate the [SwipableStack]. 4 | class SwipableStackController extends ChangeNotifier { 5 | SwipableStackController({ 6 | int initialIndex = 0, 7 | }) : _currentIndex = initialIndex, 8 | assert(initialIndex >= 0); 9 | 10 | /// The key for [SwipableStack] to control. 11 | final _swipableStackStateKey = GlobalKey<_SwipableStackState>(); 12 | 13 | int _currentIndex; 14 | 15 | /// Current index of [SwipableStack]. 16 | int get currentIndex => _currentIndex; 17 | 18 | set currentIndex(int newValue) { 19 | if (_currentIndex == newValue) { 20 | return; 21 | } 22 | _currentIndex = newValue; 23 | notifyListeners(); 24 | } 25 | 26 | _SwipableStackPosition? _currentSessionState; 27 | 28 | /// The current session that user swipes. 29 | /// 30 | /// If you doesn't touch or finished the session, It would be null. 31 | _SwipableStackPosition? get currentSession => _currentSessionState; 32 | 33 | void _updateSwipe(_SwipableStackPosition? session) { 34 | if (_currentSessionState == session) { 35 | return; 36 | } 37 | _currentSessionState = session; 38 | notifyListeners(); 39 | } 40 | 41 | void _initializeSessions() { 42 | _currentSessionState = null; 43 | _previousSession = null; 44 | notifyListeners(); 45 | } 46 | 47 | void _completeAction() { 48 | _previousSession = currentSession?.copyWith(); 49 | _currentIndex += 1; 50 | _currentSessionState = null; 51 | notifyListeners(); 52 | } 53 | 54 | void cancelAction() { 55 | _currentSessionState = null; 56 | notifyListeners(); 57 | } 58 | 59 | void _prepareRewind() { 60 | _currentSessionState = _previousSession?.copyWith(); 61 | _currentIndex -= 1; 62 | notifyListeners(); 63 | } 64 | 65 | _SwipableStackPosition? _previousSession; 66 | 67 | /// Whether to rewind. 68 | bool get canRewind => _previousSession != null && _currentIndex > 0; 69 | 70 | /// Advance to the next card with specified [swipeDirection]. 71 | /// 72 | /// You can reject [SwipableStack.onSwipeCompleted] invocation by 73 | /// setting [shouldCallCompletionCallback] to false. 74 | /// 75 | /// You can ignore checking with [SwipableStack#onWillMoveNext] by 76 | /// setting [ignoreOnWillMoveNext] to true. 77 | /// 78 | /// You can change animation speed by setting [duration]. 79 | void next({ 80 | required SwipeDirection swipeDirection, 81 | bool shouldCallCompletionCallback = true, 82 | bool ignoreOnWillMoveNext = false, 83 | Duration? duration, 84 | }) { 85 | _swipableStackStateKey.currentState?._next( 86 | swipeDirection: swipeDirection, 87 | shouldCallCompletionCallback: shouldCallCompletionCallback, 88 | ignoreOnWillMoveNext: ignoreOnWillMoveNext, 89 | duration: duration, 90 | ); 91 | } 92 | 93 | /// Rewind the most recent action. 94 | /// 95 | /// You can change animation speed by setting [duration]. 96 | void rewind({ 97 | Duration duration = SwipableStack._defaultRewindDuration, 98 | }) { 99 | _swipableStackStateKey.currentState?._rewind( 100 | duration: duration, 101 | ); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /example/lib/widgets/bottom_buttons_row.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/theme/colors.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:swipable_stack/swipable_stack.dart'; 4 | 5 | class BottomButtonsRow extends StatelessWidget { 6 | const BottomButtonsRow({ 7 | required this.onRewindTap, 8 | required this.onSwipe, 9 | required this.canRewind, 10 | super.key, 11 | }); 12 | 13 | final bool canRewind; 14 | final VoidCallback onRewindTap; 15 | final ValueChanged onSwipe; 16 | 17 | static const double height = 100; 18 | 19 | @override 20 | Widget build(BuildContext context) { 21 | return Align( 22 | alignment: Alignment.bottomCenter, 23 | child: Padding( 24 | padding: const EdgeInsets.symmetric(horizontal: 8), 25 | child: SizedBox( 26 | height: height, 27 | child: Row( 28 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, 29 | children: [ 30 | _BottomButton( 31 | color: canRewind ? Colors.amberAccent : Colors.grey, 32 | onPressed: canRewind ? onRewindTap : null, 33 | child: const Icon(Icons.refresh), 34 | ), 35 | _BottomButton( 36 | color: SwipeDirectionColor.left, 37 | child: const Icon(Icons.arrow_back), 38 | onPressed: () { 39 | onSwipe(SwipeDirection.left); 40 | }, 41 | ), 42 | _BottomButton( 43 | color: SwipeDirectionColor.up, 44 | onPressed: () { 45 | onSwipe(SwipeDirection.up); 46 | }, 47 | child: const Icon(Icons.arrow_upward), 48 | ), 49 | _BottomButton( 50 | color: SwipeDirectionColor.right, 51 | onPressed: () { 52 | onSwipe(SwipeDirection.right); 53 | }, 54 | child: const Icon(Icons.arrow_forward), 55 | ), 56 | _BottomButton( 57 | color: SwipeDirectionColor.down, 58 | onPressed: () { 59 | onSwipe(SwipeDirection.down); 60 | }, 61 | child: const Icon(Icons.arrow_downward), 62 | ), 63 | ], 64 | ), 65 | ), 66 | ), 67 | ); 68 | } 69 | } 70 | 71 | class _BottomButton extends StatelessWidget { 72 | const _BottomButton({ 73 | required this.onPressed, 74 | required this.child, 75 | required this.color, 76 | }); 77 | 78 | final VoidCallback? onPressed; 79 | final Icon child; 80 | final Color color; 81 | 82 | @override 83 | Widget build(BuildContext context) { 84 | return SizedBox( 85 | height: 64, 86 | width: 64, 87 | child: ElevatedButton( 88 | style: ButtonStyle( 89 | shape: MaterialStateProperty.resolveWith( 90 | (states) => RoundedRectangleBorder( 91 | borderRadius: BorderRadius.circular(100), 92 | ), 93 | ), 94 | backgroundColor: MaterialStateProperty.resolveWith( 95 | (states) => color, 96 | ), 97 | ), 98 | onPressed: onPressed, 99 | child: child, 100 | ), 101 | ); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /lib/src/model/swipable_stack_position.dart: -------------------------------------------------------------------------------- 1 | part of '../swipable_stack.dart'; 2 | 3 | /// The information to record swiping position for [SwipableStack]. 4 | class _SwipableStackPosition { 5 | const _SwipableStackPosition({ 6 | required this.start, 7 | required this.real, 8 | required this.realLocal, 9 | required this.animationValue, 10 | }); 11 | 12 | factory _SwipableStackPosition.notMoving() { 13 | return const _SwipableStackPosition( 14 | start: Offset.zero, 15 | real: Offset.zero, 16 | realLocal: Offset.zero, 17 | animationValue: 1, 18 | ); 19 | } 20 | 21 | factory _SwipableStackPosition.readyToSwipeAnimation({ 22 | required SwipeDirection direction, 23 | required BoxConstraints areaConstraints, 24 | }) { 25 | Offset localPosition; 26 | switch (direction) { 27 | case SwipeDirection.left: 28 | localPosition = Offset( 29 | areaConstraints.maxWidth * 0.8, 30 | areaConstraints.maxHeight * 0.4, 31 | ); 32 | break; 33 | case SwipeDirection.right: 34 | localPosition = Offset( 35 | areaConstraints.maxWidth * 0.2, 36 | areaConstraints.maxHeight * 0.4, 37 | ); 38 | break; 39 | case SwipeDirection.up: 40 | localPosition = Offset( 41 | areaConstraints.maxWidth / 2, 42 | areaConstraints.maxHeight, 43 | ); 44 | break; 45 | case SwipeDirection.down: 46 | localPosition = Offset( 47 | areaConstraints.maxWidth / 2, 48 | 0, 49 | ); 50 | break; 51 | } 52 | 53 | return _SwipableStackPosition( 54 | start: Offset.zero, 55 | real: Offset.zero, 56 | realLocal: localPosition, 57 | animationValue: 1, 58 | ); 59 | } 60 | 61 | /// The value of _dragStartAnimation. 62 | final double animationValue; 63 | 64 | /// The start point of swipe action. 65 | final Offset start; 66 | 67 | /// The current point of swipe action. 68 | Offset get current => start + (real - start) * animationValue; 69 | 70 | /// The point which user is touching. 71 | final Offset real; 72 | 73 | /// The local point of swipe action. 74 | Offset get local => realLocal * animationValue; 75 | 76 | /// The point which user is touching in the component. 77 | final Offset realLocal; 78 | 79 | @override 80 | bool operator ==(Object other) => 81 | other is _SwipableStackPosition && 82 | start == other.start && 83 | current == other.current && 84 | local == other.local; 85 | 86 | @override 87 | int get hashCode => 88 | runtimeType.hashCode ^ start.hashCode ^ current.hashCode ^ local.hashCode; 89 | 90 | @override 91 | String toString() => '$_SwipableStackPosition(' 92 | 'startPosition:$start,' 93 | 'currentPosition:$current,' 94 | 'realPosition:$real,' 95 | 'localPosition:$local,' 96 | 'realLocalPosition:$realLocal' 97 | ')'; 98 | 99 | _SwipableStackPosition copyWith({ 100 | Offset? startPosition, 101 | Offset? realPosition, 102 | Offset? realLocalPosition, 103 | double? animationValue, 104 | }) => 105 | _SwipableStackPosition( 106 | start: startPosition ?? start, 107 | real: realPosition ?? real, 108 | realLocal: realLocalPosition ?? realLocal, 109 | animationValue: animationValue ?? this.animationValue, 110 | ); 111 | 112 | /// Difference offset from [start] to [current] . 113 | Offset get difference { 114 | return current - start; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [2.0.0] 2 | - Update for Flutter V3 3 | - Improve touch & feelings in Scrollable 4 | - adds `dragStartBehavior` and `hitTestBehavior` 5 | - adds dragstart animation 6 | - Thanks to [MaddinMade](https://github.com/MaddinMade) 7 | - adds readme badges 8 | - Thanks to [MaddinMade](https://github.com/MaddinMade) 9 | 10 | ## [1.3.0] 11 | - Add dragStartBehavior and hitTestBehavior 12 | - Thanks to [MaddinMade](https://github.com/MaddinMade) 13 | 14 | ## [1.2.0] 15 | - Add `detectableSwipeDirections` property. 16 | - The set of `SwipeDirection`s you want to detect as white-list. 17 | ## [1.1.0] 18 | - Improve builder & overlayBuilder 19 | - You can get more information in builder from `SwipeProperties`(e.g. `stackIndex`) 20 | - BREAKING: bundled a lot of parameters of the builder into `SwipeProperties`. 21 | - Thanks to [MaddinMade](https://github.com/MaddinMade) 22 | ## [1.0.0] 23 | - Add examples 24 | - Update README 25 | - Bug fixes 26 | 27 | ## [0.8.1] 28 | - BugFix for [[Invalid value: Not in inclusive range #34 29 | ](https://github.com/HeavenOSK/flutter_swipable_stack/issues/34)] 30 | - Thanks to [@martesabt](https://github.com/martesabt) for the bug report. 31 | 32 | ## [0.8.0] 33 | - Improve cancel & rewind animation 34 | - Added new options `cancelAnimationCurve` & `rewindAnimationCurve` 35 | - Fix detectable area bug. 36 | - Improve example. 37 | ## [0.7.1] 38 | - Add `swipeAnchor` otpion 39 | - An option for setting anchor positon of swipe. 40 | - Thanks [kevsjh](https://github.com/kevsjh) :) 41 | 42 | ## [0.7.0+1] 43 | - Fix typo on CHANGELOG 44 | 45 | ## [0.7.0] 46 | - Add `allowVerticalSwipe` otpion 47 | - An option to controll the interaction for vertical swipe 48 | - Thanks [kevsjh](https://github.com/kevsjh) :) 49 | 50 | 51 | ## [0.6.2] 52 | - Update state when `itemCount` is changed. 53 | 54 | ## [0.6.1] 55 | - Fix [SwipableStackController.currentIndex] update 56 | 57 | ## [0.6.0] 58 | - Add the option `stackClipBehaviour` to SwipableStack 59 | - You can change the `clipBehavior` of Stack. 60 | - Thanks [envomer](https://github.com/envomer) :) 61 | - Optimize the update of SwipableStackController 62 | 63 | 64 | ## [0.5.0] 65 | - Add `SwipableStack#swipeAssistDuration` 66 | - You can change the duration for swipe assist. 67 | - Thanks [rogiervandenberg](https://github.com/rogiervandenberg) :) 68 | 69 | ## [0.4.0] 70 | 71 | - Breaking changes: 72 | - Rename back to `Swipable` from `Swipeable` for consistency with package name. 73 | - Rename from `SwipeableStack` to `SwipableStack`. 74 | - Rename from `SwipeableStackController` to `SwipableStackController`. 75 | - Be able to change duration of swipe & rewind animation. 76 | - Add `ignoreOnWillMoveNext` option for SwipableStackController#next. 77 | - Add `context` & `index` for SwipableStack#overlayBuilder to improve customizability. 78 | 79 | ## [0.3.0] 80 | 81 | - Breaking changes: 82 | - Rename from SwipableStack to SwipeableStack. 83 | - Rename from SwipableStackController to SwipeableStackController. 84 | - Refactor duration initialization for _swipeAssistController. 85 | 86 | ## [0.2.1] Fix typo. 87 | 88 | ## [0.2.0] Remove the suffix `nullsafety`. Fix README. 89 | 90 | ## [0.1.2-nullsafety.2] Add caring about unbound height or width. 91 | 92 | ## [0.1.2] Add caring about unbound height or width. 93 | 94 | ## [0.1.1-nullsafety.0] Migrate 0.1.1 to nullsafety 95 | 96 | ## [0.1.1] Bug fix. 97 | 98 | ## [0.1.0] Migrate to not nullsafety from 0.1.0-nullsafety.1 99 | 100 | ## [0.1.0-nullsafety.1] Refactor. 101 | 102 | ## [0.1.0-nullsafety.0] Migrate to nullsafety. 103 | 104 | ## [0.0.2] Update README.md 105 | 106 | ## [0.0.1] First release. 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /example/lib/examples/basic_example.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/widgets/bottom_buttons_row.dart'; 2 | import 'package:example/widgets/card_overlay.dart'; 3 | import 'package:example/widgets/example_card.dart'; 4 | import 'package:example/widgets/fade_route.dart'; 5 | import 'package:example/widgets/general_drawer.dart'; 6 | import 'package:flutter/foundation.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:swipable_stack/swipable_stack.dart'; 9 | 10 | const _images = [ 11 | 'images/image_5.jpg', 12 | 'images/image_3.jpg', 13 | 'images/image_4.jpg', 14 | ]; 15 | 16 | class BasicExample extends StatefulWidget { 17 | const BasicExample._(); 18 | 19 | static Route route() { 20 | return FadeRoute( 21 | builder: (context) => const BasicExample._(), 22 | ); 23 | } 24 | 25 | @override 26 | _BasicExampleState createState() => _BasicExampleState(); 27 | } 28 | 29 | class _BasicExampleState extends State { 30 | late final SwipableStackController _controller; 31 | 32 | void _listenController() { 33 | setState(() {}); 34 | } 35 | 36 | @override 37 | void initState() { 38 | super.initState(); 39 | _controller = SwipableStackController()..addListener(_listenController); 40 | } 41 | 42 | @override 43 | void dispose() { 44 | super.dispose(); 45 | _controller 46 | ..removeListener(_listenController) 47 | ..dispose(); 48 | } 49 | 50 | @override 51 | Widget build(BuildContext context) { 52 | return Scaffold( 53 | appBar: AppBar( 54 | title: const Text('BasicExample'), 55 | ), 56 | drawer: const GeneralDrawer(), 57 | body: SafeArea( 58 | child: Stack( 59 | children: [ 60 | Positioned.fill( 61 | child: Padding( 62 | padding: const EdgeInsets.all(8), 63 | child: SwipableStack( 64 | detectableSwipeDirections: const { 65 | SwipeDirection.right, 66 | SwipeDirection.left, 67 | }, 68 | controller: _controller, 69 | stackClipBehaviour: Clip.none, 70 | onSwipeCompleted: (index, direction) { 71 | if (kDebugMode) { 72 | print('$index, $direction'); 73 | } 74 | }, 75 | horizontalSwipeThreshold: 0.8, 76 | verticalSwipeThreshold: 0.8, 77 | builder: (context, properties) { 78 | final itemIndex = properties.index % _images.length; 79 | 80 | return Stack( 81 | children: [ 82 | ExampleCard( 83 | name: 'Sample No.${itemIndex + 1}', 84 | assetPath: _images[itemIndex], 85 | ), 86 | // more custom overlay possible than with overlayBuilder 87 | if (properties.stackIndex == 0 && 88 | properties.direction != null) 89 | CardOverlay( 90 | swipeProgress: properties.swipeProgress, 91 | direction: properties.direction!, 92 | ) 93 | ], 94 | ); 95 | }, 96 | ), 97 | ), 98 | ), 99 | BottomButtonsRow( 100 | onSwipe: (direction) { 101 | _controller.next(swipeDirection: direction); 102 | }, 103 | onRewindTap: _controller.rewind, 104 | canRewind: _controller.canRewind, 105 | ), 106 | ], 107 | ), 108 | ), 109 | ); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/widgets/bottom_buttons_row.dart'; 2 | import 'package:example/widgets/card_overlay.dart'; 3 | import 'package:example/widgets/example_card.dart'; 4 | import 'package:example/widgets/general_drawer.dart'; 5 | import 'package:flutter/foundation.dart'; 6 | import 'package:flutter/material.dart'; 7 | import 'package:swipable_stack/swipable_stack.dart'; 8 | 9 | const _images = [ 10 | 'images/image_5.jpg', 11 | 'images/image_3.jpg', 12 | 'images/image_4.jpg', 13 | ]; 14 | 15 | void main() { 16 | WidgetsFlutterBinding.ensureInitialized(); 17 | runApp( 18 | MaterialApp( 19 | title: 'Flutter Demo', 20 | theme: ThemeData( 21 | primarySwatch: Colors.blue, 22 | visualDensity: VisualDensity.adaptivePlatformDensity, 23 | ), 24 | home: const Home(), 25 | ), 26 | ); 27 | } 28 | 29 | class Home extends StatefulWidget { 30 | const Home({super.key}); 31 | 32 | @override 33 | _HomeState createState() => _HomeState(); 34 | } 35 | 36 | class _HomeState extends State { 37 | late final SwipableStackController _controller; 38 | 39 | void _listenController() => setState(() {}); 40 | 41 | @override 42 | void initState() { 43 | super.initState(); 44 | _controller = SwipableStackController()..addListener(_listenController); 45 | } 46 | 47 | @override 48 | void dispose() { 49 | super.dispose(); 50 | _controller 51 | ..removeListener(_listenController) 52 | ..dispose(); 53 | } 54 | 55 | @override 56 | Widget build(BuildContext context) { 57 | return Scaffold( 58 | appBar: AppBar( 59 | title: const Text('BasicExample'), 60 | ), 61 | drawer: const GeneralDrawer(), 62 | body: SafeArea( 63 | top: false, 64 | child: Stack( 65 | children: [ 66 | Positioned.fill( 67 | child: Padding( 68 | padding: const EdgeInsets.all(8), 69 | child: SwipableStack( 70 | detectableSwipeDirections: const { 71 | SwipeDirection.right, 72 | SwipeDirection.left, 73 | }, 74 | controller: _controller, 75 | stackClipBehaviour: Clip.none, 76 | onSwipeCompleted: (index, direction) { 77 | if (kDebugMode) { 78 | print('$index, $direction'); 79 | } 80 | }, 81 | horizontalSwipeThreshold: 0.8, 82 | verticalSwipeThreshold: 0.8, 83 | builder: (context, properties) { 84 | final itemIndex = properties.index % _images.length; 85 | 86 | return Stack( 87 | children: [ 88 | ExampleCard( 89 | name: 'Sample No.${itemIndex + 1}', 90 | assetPath: _images[itemIndex], 91 | ), 92 | // more custom overlay possible than with overlayBuilder 93 | if (properties.stackIndex == 0 && 94 | properties.direction != null) 95 | CardOverlay( 96 | swipeProgress: properties.swipeProgress, 97 | direction: properties.direction!, 98 | ) 99 | ], 100 | ); 101 | }, 102 | ), 103 | ), 104 | ), 105 | BottomButtonsRow( 106 | onSwipe: (direction) { 107 | _controller.next(swipeDirection: direction); 108 | }, 109 | onRewindTap: _controller.rewind, 110 | canRewind: _controller.canRewind, 111 | ), 112 | ], 113 | ), 114 | ), 115 | ); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /lib/src/model/swipe_rate_per_threshold.dart: -------------------------------------------------------------------------------- 1 | part of '../swipable_stack.dart'; 2 | 3 | class _SwipeRatePerThreshold { 4 | _SwipeRatePerThreshold({ 5 | required this.direction, 6 | required this.rate, 7 | }) : assert(rate >= 0); 8 | 9 | final SwipeDirection direction; 10 | final double rate; 11 | } 12 | 13 | extension _DirectionCheck on SwipeDirection { 14 | double clampSwipeRate(double rate) { 15 | switch (this) { 16 | case SwipeDirection.left: 17 | return rate.clamp(double.negativeInfinity, 0); 18 | case SwipeDirection.right: 19 | return rate.clamp(0, double.infinity); 20 | case SwipeDirection.up: 21 | return rate.clamp(double.negativeInfinity, 0); 22 | case SwipeDirection.down: 23 | return rate.clamp(0, double.infinity); 24 | } 25 | } 26 | } 27 | 28 | extension _SwipableStackPositionX on _SwipableStackPosition { 29 | _SwipeRatePerThreshold? swipeDirectionRate({ 30 | required BoxConstraints constraints, 31 | required double horizontalSwipeThreshold, 32 | required double verticalSwipeThreshold, 33 | required Set detectableDirections, 34 | }) { 35 | final horizontalRate = 36 | (difference.dx / constraints.maxWidth) / (horizontalSwipeThreshold / 2); 37 | final verticalRate = 38 | (difference.dy / constraints.maxHeight) / (verticalSwipeThreshold / 2); 39 | 40 | _SwipeRatePerThreshold? horizontalRatePerThreshold() { 41 | final filteredDirs = [SwipeDirection.left, SwipeDirection.right] 42 | .where(detectableDirections.contains); 43 | if (filteredDirs.isEmpty) { 44 | return null; 45 | } 46 | if (filteredDirs.length == 2) { 47 | return _SwipeRatePerThreshold( 48 | direction: 49 | difference.dx >= 0 ? SwipeDirection.right : SwipeDirection.left, 50 | rate: horizontalRate.abs(), 51 | ); 52 | } 53 | final dir = filteredDirs.first; 54 | return _SwipeRatePerThreshold( 55 | direction: dir, 56 | rate: dir.clampSwipeRate(horizontalRate).abs(), 57 | ); 58 | } 59 | 60 | _SwipeRatePerThreshold? verticalRatePerThreshold() { 61 | final filteredDirs = [SwipeDirection.up, SwipeDirection.down] 62 | .where(detectableDirections.contains); 63 | if (filteredDirs.isEmpty) { 64 | return null; 65 | } 66 | if (filteredDirs.length == 2) { 67 | return _SwipeRatePerThreshold( 68 | direction: 69 | difference.dy >= 0 ? SwipeDirection.down : SwipeDirection.up, 70 | rate: verticalRate.abs(), 71 | ); 72 | } 73 | final dir = filteredDirs.first; 74 | return _SwipeRatePerThreshold( 75 | direction: dir, 76 | rate: dir.clampSwipeRate(verticalRate).abs(), 77 | ); 78 | } 79 | 80 | final rateList = [ 81 | verticalRatePerThreshold(), 82 | horizontalRatePerThreshold(), 83 | ].whereType<_SwipeRatePerThreshold>().toList(); 84 | if (rateList.isEmpty) { 85 | return null; 86 | } 87 | return rateList.length == 1 || rateList[0].rate > rateList[1].rate 88 | ? rateList[0] 89 | : rateList[1]; 90 | } 91 | 92 | SwipeDirection? swipeAssistDirection({ 93 | required BoxConstraints constraints, 94 | required double horizontalSwipeThreshold, 95 | required double verticalSwipeThreshold, 96 | required Set detectableDirections, 97 | }) { 98 | final directionRate = swipeDirectionRate( 99 | constraints: constraints, 100 | horizontalSwipeThreshold: horizontalSwipeThreshold, 101 | verticalSwipeThreshold: verticalSwipeThreshold, 102 | detectableDirections: detectableDirections, 103 | ); 104 | if (directionRate == null) { 105 | return null; 106 | } 107 | if (directionRate.rate < 1) { 108 | return null; 109 | } else { 110 | return directionRate.direction; 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /example/lib/examples/detectable_directions_example.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/widgets/bottom_buttons_row.dart'; 2 | import 'package:example/widgets/card_overlay.dart'; 3 | import 'package:example/widgets/example_card.dart'; 4 | import 'package:example/widgets/fade_route.dart'; 5 | import 'package:example/widgets/general_drawer.dart'; 6 | import 'package:flutter/foundation.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:swipable_stack/swipable_stack.dart'; 9 | 10 | const _images = [ 11 | 'images/image_5.jpg', 12 | 'images/image_3.jpg', 13 | 'images/image_4.jpg', 14 | ]; 15 | 16 | class DetectableDirectionsExample extends StatefulWidget { 17 | const DetectableDirectionsExample._(); 18 | 19 | static Route route() { 20 | return FadeRoute( 21 | builder: (context) => const DetectableDirectionsExample._(), 22 | ); 23 | } 24 | 25 | @override 26 | _DetectableDirectionsExampleState createState() => 27 | _DetectableDirectionsExampleState(); 28 | } 29 | 30 | class _DetectableDirectionsExampleState 31 | extends State { 32 | late final SwipableStackController _controller; 33 | 34 | void _listenController() { 35 | setState(() {}); 36 | } 37 | 38 | @override 39 | void initState() { 40 | super.initState(); 41 | _controller = SwipableStackController()..addListener(_listenController); 42 | } 43 | 44 | @override 45 | void dispose() { 46 | super.dispose(); 47 | _controller 48 | ..removeListener(_listenController) 49 | ..dispose(); 50 | } 51 | 52 | @override 53 | Widget build(BuildContext context) { 54 | return Scaffold( 55 | appBar: AppBar( 56 | title: const Text('DetectableDirectionsExample'), 57 | ), 58 | drawer: const GeneralDrawer(), 59 | body: SafeArea( 60 | child: Stack( 61 | children: [ 62 | Positioned.fill( 63 | child: Padding( 64 | padding: const EdgeInsets.all(8), 65 | child: SwipableStack( 66 | detectableSwipeDirections: const { 67 | SwipeDirection.right, 68 | SwipeDirection.left, 69 | }, 70 | controller: _controller, 71 | stackClipBehaviour: Clip.none, 72 | onSwipeCompleted: (index, direction) { 73 | if (kDebugMode) { 74 | print('$index, $direction'); 75 | } 76 | }, 77 | horizontalSwipeThreshold: 0.8, 78 | verticalSwipeThreshold: 0.8, 79 | builder: (context, properties) { 80 | final itemIndex = properties.index % _images.length; 81 | 82 | return Stack( 83 | children: [ 84 | ExampleCard( 85 | name: 'Sample No.${itemIndex + 1}', 86 | assetPath: _images[itemIndex], 87 | ), 88 | // more custom overlay possible than with overlayBuilder 89 | if (properties.stackIndex == 0 && 90 | properties.direction != null) 91 | CardOverlay( 92 | swipeProgress: properties.swipeProgress, 93 | direction: properties.direction!, 94 | ) 95 | ], 96 | ); 97 | }, 98 | ), 99 | ), 100 | ), 101 | BottomButtonsRow( 102 | onSwipe: (direction) { 103 | _controller.next(swipeDirection: direction); 104 | }, 105 | onRewindTap: _controller.rewind, 106 | canRewind: _controller.canRewind, 107 | ), 108 | ], 109 | ), 110 | ), 111 | ); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /example/lib/examples/ignore_vertical_swipe_example.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/widgets/bottom_buttons_row.dart'; 2 | import 'package:example/widgets/card_overlay.dart'; 3 | import 'package:example/widgets/example_card.dart'; 4 | import 'package:example/widgets/fade_route.dart'; 5 | import 'package:example/widgets/general_drawer.dart'; 6 | import 'package:flutter/foundation.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:swipable_stack/swipable_stack.dart'; 9 | 10 | const _images = [ 11 | 'images/image_5.jpg', 12 | 'images/image_3.jpg', 13 | 'images/image_4.jpg', 14 | ]; 15 | 16 | class IgnoreVerticalSwipeExample extends StatefulWidget { 17 | const IgnoreVerticalSwipeExample._(); 18 | 19 | static Route route() { 20 | return FadeRoute( 21 | builder: (context) => const IgnoreVerticalSwipeExample._(), 22 | ); 23 | } 24 | 25 | @override 26 | _IgnoreVerticalSwipeExampleState createState() => 27 | _IgnoreVerticalSwipeExampleState(); 28 | } 29 | 30 | class _IgnoreVerticalSwipeExampleState 31 | extends State { 32 | late final SwipableStackController _controller; 33 | 34 | void _listenController() { 35 | setState(() {}); 36 | } 37 | 38 | @override 39 | void initState() { 40 | super.initState(); 41 | _controller = SwipableStackController()..addListener(_listenController); 42 | } 43 | 44 | @override 45 | void dispose() { 46 | super.dispose(); 47 | _controller 48 | ..removeListener(_listenController) 49 | ..dispose(); 50 | } 51 | 52 | @override 53 | Widget build(BuildContext context) { 54 | return Scaffold( 55 | appBar: AppBar( 56 | title: const Text('IgnoreVerticalSwipeExample'), 57 | ), 58 | drawer: const GeneralDrawer(), 59 | body: SafeArea( 60 | child: Stack( 61 | children: [ 62 | Positioned.fill( 63 | child: Padding( 64 | padding: const EdgeInsets.all(8), 65 | child: SwipableStack( 66 | controller: _controller, 67 | stackClipBehaviour: Clip.none, 68 | allowVerticalSwipe: false, 69 | onWillMoveNext: (index, swipeDirection) { 70 | // Return true for the desired swipe direction. 71 | switch (swipeDirection) { 72 | case SwipeDirection.left: 73 | case SwipeDirection.right: 74 | return true; 75 | case SwipeDirection.up: 76 | case SwipeDirection.down: 77 | return false; 78 | } 79 | }, 80 | onSwipeCompleted: (index, direction) { 81 | if (kDebugMode) { 82 | print('$index, $direction'); 83 | } 84 | }, 85 | horizontalSwipeThreshold: 0.8, 86 | // Set max value to ignore vertical threshold. 87 | verticalSwipeThreshold: 1, 88 | overlayBuilder: ( 89 | context, 90 | properties, 91 | ) => 92 | CardOverlay( 93 | swipeProgress: properties.swipeProgress, 94 | direction: properties.direction, 95 | ), 96 | builder: (context, properties) { 97 | final itemIndex = properties.index % _images.length; 98 | return ExampleCard( 99 | name: 'Sample No.${itemIndex + 1}', 100 | assetPath: _images[itemIndex], 101 | ); 102 | }, 103 | ), 104 | ), 105 | ), 106 | BottomButtonsRow( 107 | onSwipe: (direction) { 108 | _controller.next(swipeDirection: direction); 109 | }, 110 | onRewindTap: _controller.rewind, 111 | canRewind: _controller.canRewind, 112 | ), 113 | ], 114 | ), 115 | ), 116 | ); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /example/lib/examples/swipe_anchor_example.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/widgets/bottom_buttons_row.dart'; 2 | import 'package:example/widgets/card_overlay.dart'; 3 | import 'package:example/widgets/example_card.dart'; 4 | import 'package:example/widgets/fade_route.dart'; 5 | import 'package:example/widgets/general_drawer.dart'; 6 | import 'package:flutter/foundation.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:swipable_stack/swipable_stack.dart'; 9 | 10 | const _images = [ 11 | 'images/image_5.jpg', 12 | 'images/image_3.jpg', 13 | 'images/image_4.jpg', 14 | ]; 15 | 16 | class SwipeAnchorExample extends StatefulWidget { 17 | const SwipeAnchorExample._(); 18 | 19 | static Route route() { 20 | return FadeRoute( 21 | builder: (context) => const SwipeAnchorExample._(), 22 | ); 23 | } 24 | 25 | @override 26 | _SwipeAnchorExampleState createState() => _SwipeAnchorExampleState(); 27 | } 28 | 29 | class _SwipeAnchorExampleState extends State { 30 | late final SwipableStackController _controller; 31 | 32 | void _listenController() { 33 | setState(() {}); 34 | } 35 | 36 | @override 37 | void initState() { 38 | super.initState(); 39 | _controller = SwipableStackController()..addListener(_listenController); 40 | } 41 | 42 | @override 43 | void dispose() { 44 | super.dispose(); 45 | _controller 46 | ..removeListener(_listenController) 47 | ..dispose(); 48 | } 49 | 50 | @override 51 | Widget build(BuildContext context) { 52 | return Scaffold( 53 | appBar: AppBar( 54 | title: const Text('SwipeAnchorExample'), 55 | ), 56 | drawer: const GeneralDrawer(), 57 | body: SafeArea( 58 | child: Stack( 59 | children: [ 60 | Positioned.fill( 61 | child: Padding( 62 | padding: const EdgeInsets.all(8), 63 | child: SwipableStack( 64 | controller: _controller, 65 | stackClipBehaviour: Clip.none, 66 | // If you want to change the position of anchor for cards, 67 | // set [swipeAnchor]. 68 | swipeAnchor: SwipeAnchor.bottom, 69 | onWillMoveNext: (index, swipeDirection) { 70 | // Return true for the desired swipe direction. 71 | switch (swipeDirection) { 72 | case SwipeDirection.left: 73 | case SwipeDirection.right: 74 | return true; 75 | case SwipeDirection.up: 76 | case SwipeDirection.down: 77 | return false; 78 | } 79 | }, 80 | onSwipeCompleted: (index, direction) { 81 | if (kDebugMode) { 82 | print('$index, $direction'); 83 | } 84 | }, 85 | horizontalSwipeThreshold: 0.8, 86 | // Set max value to ignore vertical threshold. 87 | verticalSwipeThreshold: 1, 88 | overlayBuilder: ( 89 | context, 90 | properties, 91 | ) => 92 | CardOverlay( 93 | swipeProgress: properties.swipeProgress, 94 | direction: properties.direction, 95 | ), 96 | builder: (context, properties) { 97 | final itemIndex = properties.index % _images.length; 98 | return ExampleCard( 99 | name: 'Sample No.${itemIndex + 1}', 100 | assetPath: _images[itemIndex], 101 | ); 102 | }, 103 | ), 104 | ), 105 | ), 106 | BottomButtonsRow( 107 | onSwipe: (direction) { 108 | _controller.next(swipeDirection: direction); 109 | }, 110 | onRewindTap: _controller.rewind, 111 | canRewind: _controller.canRewind, 112 | ), 113 | ], 114 | ), 115 | ), 116 | ); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # swipable_stack 2 | pub.dev 3 | github 4 | [![likes](https://badges.bar/swipable_stack/likes)](https://pub.dev/packages/swipable_stack/score) 5 | [![popularity](https://badges.bar/swipable_stack/popularity)](https://pub.dev/packages/swipable_stack/score) 6 | [![pub points](https://badges.bar/swipable_stack/pub%20points)](https://pub.dev/packages/swipable_stack/score) 7 | license 8 | 9 | A widget for stacking cards, which users can swipe horizontally and vertically with beautiful animations like Tinder UI. 10 | 11 | ![demo](https://github.com/HeavenOSK/gif_repository/blob/main/swipable_stack/demo.gif?raw=true) 12 | 13 | (Sorry, the package name `swipable_stack` is typo of swipeable stack) 14 | 15 | # Usage 16 | ## `builder` 17 | A `SwipableStack` uses a builder to display widgets. 18 | ```dart 19 | SwipableStack( 20 | builder: (context, properties) { 21 | return Image.asset(imagePath); 22 | }, 23 | ), 24 | ``` 25 | ## `onSwipeCompleted` 26 | You can get completion event with `onSwipeCompleted`. 27 | ```dart 28 | SwipableStack( 29 | onSwipeCompleted: (index, direction) { 30 | print('$index, $direction'); 31 | }, 32 | ) 33 | ``` 34 | 35 | ## `overlayBuilder` 36 | You can show overlay on the front card with `overlayBuilder`. 37 | ```dart 38 | SwipableStack( 39 | overlayBuilder: (context, properties) { 40 | final opacity = min(properties.swipeProgress, 1.0); 41 | final isRight = properties.direction == SwipeDirection.right; 42 | return Opacity( 43 | opacity: isRight ? opacity : 0, 44 | child: CardLabel.right(), 45 | ); 46 | }, 47 | ) 48 | ``` 49 | 50 | ## `controller` 51 | `SwipableStackController` allows you to control swipe action & also rewind recent action. 52 | 53 | ```dart 54 | final controller = SwipableStackController(); 55 | 56 | SwipableStack( 57 | controller:controller, 58 | builder: (context, properties) { 59 | return Image.asset(imagePath); 60 | }, 61 | ); 62 | controller.next( 63 | swipeDirection: SwipeDirection.right, 64 | ); 65 | controller.rewind(); 66 | ``` 67 | 68 | `SwipableStackController` provides to access `currentIndex` of `SwipableStack`. 69 | ```dart 70 | final controller = SwipableStackController(); 71 | controller.addListener(() { 72 | print('${_controller.currentIndex}'); 73 | }); 74 | ``` 75 | 76 | ## `onWillMoveNext` 77 | You can also restrict user actions according to index or action with `onWillMoveNext`. 78 | ```dart 79 | SwipableStack( 80 | onWillMoveNext: (index, direction) { 81 | final allowedActions = [ 82 | SwipeDirection.right, 83 | SwipeDirection.left, 84 | ]; 85 | return allowedActions.contains(direction); 86 | }, 87 | ); 88 | ``` 89 | 90 | ## `swipeAssistDuration` 91 | 92 | You can set the speed the user is able to swipe through Widgets with the `swipeAssistDuration`. 93 | 94 | ```dart 95 | SwipableStack( 96 | swipeAssistDuration: Duration(milliseconds: 100), 97 | ) 98 | ``` 99 | 100 | The default is 650ms. 101 | 102 | ## `stackClipBehaviour` 103 | 104 | You can set the clipBehaviour of the stack with the `stackClipBehaviour`. 105 | Change it to `Clip.none` to exceed the boundaries of parent widget size. 106 | 107 | ```dart 108 | SwipableStack( 109 | stackClipBehaviour: Clip.none, 110 | ) 111 | ``` 112 | 113 | The default is Clip.hardEdge. 114 | 115 | 116 | ## `allowVerticalSwipe` 117 | 118 | Disable vertical swipe with `allowVerticalSwipe`. 119 | Changing to `false` disable vertical swipe capabilities 120 | 121 | ```dart 122 | SwipableStack( 123 | allowVerticalSwipe: false, 124 | ) 125 | ``` 126 | 127 | The default is true. 128 | 129 | ## `swipeTopAnchor` 130 | 131 | Set the swipe anchor with `swipeAnchor` with the following enum 132 | SwipeAnchor.top : card rotation on bottom and anchored on top 133 | SwipeAnchor.bottom : card rotation on top and anchored on bottom 134 | 135 | ```dart 136 | SwipableStack( 137 | swipeAnchor: SwipeAnchor.top, 138 | ) 139 | ``` 140 | 141 | The default is SwipeAnchor.top. 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "2.8.2" 11 | boolean_selector: 12 | dependency: transitive 13 | description: 14 | name: boolean_selector 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "2.1.0" 18 | characters: 19 | dependency: transitive 20 | description: 21 | name: characters 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "1.2.0" 25 | charcode: 26 | dependency: transitive 27 | description: 28 | name: charcode 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "1.3.1" 32 | clock: 33 | dependency: transitive 34 | description: 35 | name: clock 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "1.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.16.0" 46 | fake_async: 47 | dependency: transitive 48 | description: 49 | name: fake_async 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "1.3.0" 53 | flutter: 54 | dependency: "direct main" 55 | description: flutter 56 | source: sdk 57 | version: "0.0.0" 58 | flutter_lints: 59 | dependency: transitive 60 | description: 61 | name: flutter_lints 62 | url: "https://pub.dartlang.org" 63 | source: hosted 64 | version: "1.0.4" 65 | flutter_test: 66 | dependency: "direct dev" 67 | description: flutter 68 | source: sdk 69 | version: "0.0.0" 70 | lints: 71 | dependency: transitive 72 | description: 73 | name: lints 74 | url: "https://pub.dartlang.org" 75 | source: hosted 76 | version: "1.0.1" 77 | matcher: 78 | dependency: transitive 79 | description: 80 | name: matcher 81 | url: "https://pub.dartlang.org" 82 | source: hosted 83 | version: "0.12.11" 84 | material_color_utilities: 85 | dependency: transitive 86 | description: 87 | name: material_color_utilities 88 | url: "https://pub.dartlang.org" 89 | source: hosted 90 | version: "0.1.4" 91 | meta: 92 | dependency: transitive 93 | description: 94 | name: meta 95 | url: "https://pub.dartlang.org" 96 | source: hosted 97 | version: "1.7.0" 98 | path: 99 | dependency: transitive 100 | description: 101 | name: path 102 | url: "https://pub.dartlang.org" 103 | source: hosted 104 | version: "1.8.1" 105 | pedantic_mono: 106 | dependency: "direct dev" 107 | description: 108 | name: pedantic_mono 109 | url: "https://pub.dartlang.org" 110 | source: hosted 111 | version: "1.15.0" 112 | sky_engine: 113 | dependency: transitive 114 | description: flutter 115 | source: sdk 116 | version: "0.0.99" 117 | source_span: 118 | dependency: transitive 119 | description: 120 | name: source_span 121 | url: "https://pub.dartlang.org" 122 | source: hosted 123 | version: "1.8.2" 124 | sprung: 125 | dependency: "direct main" 126 | description: 127 | name: sprung 128 | url: "https://pub.dartlang.org" 129 | source: hosted 130 | version: "3.0.0" 131 | stack_trace: 132 | dependency: transitive 133 | description: 134 | name: stack_trace 135 | url: "https://pub.dartlang.org" 136 | source: hosted 137 | version: "1.10.0" 138 | stream_channel: 139 | dependency: transitive 140 | description: 141 | name: stream_channel 142 | url: "https://pub.dartlang.org" 143 | source: hosted 144 | version: "2.1.0" 145 | string_scanner: 146 | dependency: transitive 147 | description: 148 | name: string_scanner 149 | url: "https://pub.dartlang.org" 150 | source: hosted 151 | version: "1.1.0" 152 | term_glyph: 153 | dependency: transitive 154 | description: 155 | name: term_glyph 156 | url: "https://pub.dartlang.org" 157 | source: hosted 158 | version: "1.2.0" 159 | test_api: 160 | dependency: transitive 161 | description: 162 | name: test_api 163 | url: "https://pub.dartlang.org" 164 | source: hosted 165 | version: "0.4.9" 166 | vector_math: 167 | dependency: transitive 168 | description: 169 | name: vector_math 170 | url: "https://pub.dartlang.org" 171 | source: hosted 172 | version: "2.1.2" 173 | sdks: 174 | dart: ">=2.17.0 <3.0.0" 175 | -------------------------------------------------------------------------------- /example/lib/examples/popup_on_swipe_example.dart: -------------------------------------------------------------------------------- 1 | import 'package:example/widgets/bottom_buttons_row.dart'; 2 | import 'package:example/widgets/card_overlay.dart'; 3 | import 'package:example/widgets/example_card.dart'; 4 | import 'package:example/widgets/fade_route.dart'; 5 | import 'package:example/widgets/general_drawer.dart'; 6 | import 'package:flutter/foundation.dart'; 7 | import 'package:flutter/material.dart'; 8 | import 'package:swipable_stack/swipable_stack.dart'; 9 | 10 | const _images = [ 11 | 'images/image_5.jpg', 12 | 'images/image_3.jpg', 13 | 'images/image_4.jpg', 14 | ]; 15 | 16 | class PopupOnSwipeExample extends StatefulWidget { 17 | const PopupOnSwipeExample._(); 18 | 19 | static Route route() { 20 | return FadeRoute( 21 | builder: (context) => const PopupOnSwipeExample._(), 22 | ); 23 | } 24 | 25 | @override 26 | _PopupOnSwipeExampleState createState() => _PopupOnSwipeExampleState(); 27 | } 28 | 29 | class _PopupOnSwipeExampleState extends State { 30 | late final SwipableStackController _controller; 31 | 32 | void _listenController() { 33 | setState(() {}); 34 | } 35 | 36 | @override 37 | void initState() { 38 | super.initState(); 39 | _controller = SwipableStackController()..addListener(_listenController); 40 | } 41 | 42 | @override 43 | void dispose() { 44 | super.dispose(); 45 | _controller 46 | ..removeListener(_listenController) 47 | ..dispose(); 48 | } 49 | 50 | @override 51 | Widget build(BuildContext context) { 52 | const pointCount = 0; 53 | return Scaffold( 54 | appBar: AppBar( 55 | title: const Text('PopupOnSwipeExample'), 56 | ), 57 | drawer: const GeneralDrawer(), 58 | body: SafeArea( 59 | child: Stack( 60 | children: [ 61 | Positioned.fill( 62 | child: Padding( 63 | padding: const EdgeInsets.all(8), 64 | child: SwipableStack( 65 | controller: _controller, 66 | stackClipBehaviour: Clip.none, 67 | onWillMoveNext: (index, direction) { 68 | // You can reject user swipe actions and also 69 | // show popup as following. 70 | if (pointCount <= 0) { 71 | Future(() async { 72 | await _PopUp.show(context: context); 73 | }); 74 | return false; 75 | } 76 | return true; 77 | }, 78 | onSwipeCompleted: (index, direction) { 79 | if (kDebugMode) { 80 | print('$index, $direction'); 81 | } 82 | }, 83 | horizontalSwipeThreshold: 0.8, 84 | verticalSwipeThreshold: 0.8, 85 | overlayBuilder: ( 86 | context, 87 | properties, 88 | ) => 89 | CardOverlay( 90 | swipeProgress: properties.swipeProgress, 91 | direction: properties.direction, 92 | ), 93 | builder: (context, properties) { 94 | final itemIndex = properties.index % _images.length; 95 | return ExampleCard( 96 | name: 'Sample No.${itemIndex + 1}', 97 | assetPath: _images[itemIndex], 98 | ); 99 | }, 100 | ), 101 | ), 102 | ), 103 | BottomButtonsRow( 104 | onSwipe: (direction) async { 105 | _controller.next(swipeDirection: direction); 106 | }, 107 | onRewindTap: _controller.rewind, 108 | canRewind: _controller.canRewind, 109 | ), 110 | ], 111 | ), 112 | ), 113 | ); 114 | } 115 | } 116 | 117 | class _PopUp { 118 | const _PopUp._(); 119 | 120 | static Future show({ 121 | required BuildContext context, 122 | }) async { 123 | await showDialog( 124 | context: context, 125 | builder: (context) => AlertDialog( 126 | title: const Text('Example Popup'), 127 | content: const Text( 128 | 'Example message\n' 129 | '- You need more points. \n' 130 | '- Your account is not available\n', 131 | ), 132 | actions: [ 133 | ElevatedButton( 134 | onPressed: () { 135 | Navigator.of(context).pop(); 136 | }, 137 | child: const Text('CLOSE'), 138 | ), 139 | ], 140 | ), 141 | ); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /example/pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | async: 5 | dependency: transitive 6 | description: 7 | name: async 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "2.8.2" 11 | boolean_selector: 12 | dependency: transitive 13 | description: 14 | name: boolean_selector 15 | url: "https://pub.dartlang.org" 16 | source: hosted 17 | version: "2.1.0" 18 | characters: 19 | dependency: transitive 20 | description: 21 | name: characters 22 | url: "https://pub.dartlang.org" 23 | source: hosted 24 | version: "1.2.0" 25 | charcode: 26 | dependency: transitive 27 | description: 28 | name: charcode 29 | url: "https://pub.dartlang.org" 30 | source: hosted 31 | version: "1.3.1" 32 | clock: 33 | dependency: transitive 34 | description: 35 | name: clock 36 | url: "https://pub.dartlang.org" 37 | source: hosted 38 | version: "1.1.0" 39 | collection: 40 | dependency: transitive 41 | description: 42 | name: collection 43 | url: "https://pub.dartlang.org" 44 | source: hosted 45 | version: "1.16.0" 46 | fake_async: 47 | dependency: transitive 48 | description: 49 | name: fake_async 50 | url: "https://pub.dartlang.org" 51 | source: hosted 52 | version: "1.3.0" 53 | flutter: 54 | dependency: "direct main" 55 | description: flutter 56 | source: sdk 57 | version: "0.0.0" 58 | flutter_lints: 59 | dependency: transitive 60 | description: 61 | name: flutter_lints 62 | url: "https://pub.dartlang.org" 63 | source: hosted 64 | version: "1.0.4" 65 | flutter_test: 66 | dependency: "direct dev" 67 | description: flutter 68 | source: sdk 69 | version: "0.0.0" 70 | lints: 71 | dependency: transitive 72 | description: 73 | name: lints 74 | url: "https://pub.dartlang.org" 75 | source: hosted 76 | version: "1.0.1" 77 | matcher: 78 | dependency: transitive 79 | description: 80 | name: matcher 81 | url: "https://pub.dartlang.org" 82 | source: hosted 83 | version: "0.12.11" 84 | material_color_utilities: 85 | dependency: transitive 86 | description: 87 | name: material_color_utilities 88 | url: "https://pub.dartlang.org" 89 | source: hosted 90 | version: "0.1.4" 91 | meta: 92 | dependency: transitive 93 | description: 94 | name: meta 95 | url: "https://pub.dartlang.org" 96 | source: hosted 97 | version: "1.7.0" 98 | path: 99 | dependency: transitive 100 | description: 101 | name: path 102 | url: "https://pub.dartlang.org" 103 | source: hosted 104 | version: "1.8.1" 105 | pedantic_mono: 106 | dependency: "direct dev" 107 | description: 108 | name: pedantic_mono 109 | url: "https://pub.dartlang.org" 110 | source: hosted 111 | version: "1.19.0+1" 112 | sky_engine: 113 | dependency: transitive 114 | description: flutter 115 | source: sdk 116 | version: "0.0.99" 117 | source_span: 118 | dependency: transitive 119 | description: 120 | name: source_span 121 | url: "https://pub.dartlang.org" 122 | source: hosted 123 | version: "1.8.2" 124 | sprung: 125 | dependency: transitive 126 | description: 127 | name: sprung 128 | url: "https://pub.dartlang.org" 129 | source: hosted 130 | version: "3.0.0" 131 | stack_trace: 132 | dependency: transitive 133 | description: 134 | name: stack_trace 135 | url: "https://pub.dartlang.org" 136 | source: hosted 137 | version: "1.10.0" 138 | stream_channel: 139 | dependency: transitive 140 | description: 141 | name: stream_channel 142 | url: "https://pub.dartlang.org" 143 | source: hosted 144 | version: "2.1.0" 145 | string_scanner: 146 | dependency: transitive 147 | description: 148 | name: string_scanner 149 | url: "https://pub.dartlang.org" 150 | source: hosted 151 | version: "1.1.0" 152 | swipable_stack: 153 | dependency: "direct main" 154 | description: 155 | path: ".." 156 | relative: true 157 | source: path 158 | version: "2.0.0" 159 | term_glyph: 160 | dependency: transitive 161 | description: 162 | name: term_glyph 163 | url: "https://pub.dartlang.org" 164 | source: hosted 165 | version: "1.2.0" 166 | test_api: 167 | dependency: transitive 168 | description: 169 | name: test_api 170 | url: "https://pub.dartlang.org" 171 | source: hosted 172 | version: "0.4.9" 173 | vector_math: 174 | dependency: transitive 175 | description: 176 | name: vector_math 177 | url: "https://pub.dartlang.org" 178 | source: hosted 179 | version: "2.1.2" 180 | sdks: 181 | dart: ">=2.17.0 <3.0.0" 182 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 11 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 12 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 13 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 14 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 15 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXCopyFilesBuildPhase section */ 19 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = { 20 | isa = PBXCopyFilesBuildPhase; 21 | buildActionMask = 2147483647; 22 | dstPath = ""; 23 | dstSubfolderSpec = 10; 24 | files = ( 25 | ); 26 | name = "Embed Frameworks"; 27 | runOnlyForDeploymentPostprocessing = 0; 28 | }; 29 | /* End PBXCopyFilesBuildPhase section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 33 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 34 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 35 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 36 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 37 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 38 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 39 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 40 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 42 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 43 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 44 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | ); 53 | runOnlyForDeploymentPostprocessing = 0; 54 | }; 55 | /* End PBXFrameworksBuildPhase section */ 56 | 57 | /* Begin PBXGroup section */ 58 | 9740EEB11CF90186004384FC /* Flutter */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 62 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 63 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 64 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 65 | ); 66 | name = Flutter; 67 | sourceTree = ""; 68 | }; 69 | 97C146E51CF9000F007C117D = { 70 | isa = PBXGroup; 71 | children = ( 72 | 9740EEB11CF90186004384FC /* Flutter */, 73 | 97C146F01CF9000F007C117D /* Runner */, 74 | 97C146EF1CF9000F007C117D /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | 97C146EF1CF9000F007C117D /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 97C146EE1CF9000F007C117D /* Runner.app */, 82 | ); 83 | name = Products; 84 | sourceTree = ""; 85 | }; 86 | 97C146F01CF9000F007C117D /* Runner */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 90 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 91 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 92 | 97C147021CF9000F007C117D /* Info.plist */, 93 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 94 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 95 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, 96 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, 97 | ); 98 | path = Runner; 99 | sourceTree = ""; 100 | }; 101 | /* End PBXGroup section */ 102 | 103 | /* Begin PBXNativeTarget section */ 104 | 97C146ED1CF9000F007C117D /* Runner */ = { 105 | isa = PBXNativeTarget; 106 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 107 | buildPhases = ( 108 | 9740EEB61CF901F6004384FC /* Run Script */, 109 | 97C146EA1CF9000F007C117D /* Sources */, 110 | 97C146EB1CF9000F007C117D /* Frameworks */, 111 | 97C146EC1CF9000F007C117D /* Resources */, 112 | 9705A1C41CF9048500538489 /* Embed Frameworks */, 113 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 114 | ); 115 | buildRules = ( 116 | ); 117 | dependencies = ( 118 | ); 119 | name = Runner; 120 | productName = Runner; 121 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 122 | productType = "com.apple.product-type.application"; 123 | }; 124 | /* End PBXNativeTarget section */ 125 | 126 | /* Begin PBXProject section */ 127 | 97C146E61CF9000F007C117D /* Project object */ = { 128 | isa = PBXProject; 129 | attributes = { 130 | LastUpgradeCheck = 1300; 131 | ORGANIZATIONNAME = ""; 132 | TargetAttributes = { 133 | 97C146ED1CF9000F007C117D = { 134 | CreatedOnToolsVersion = 7.3.1; 135 | LastSwiftMigration = 1100; 136 | }; 137 | }; 138 | }; 139 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 140 | compatibilityVersion = "Xcode 9.3"; 141 | developmentRegion = en; 142 | hasScannedForEncodings = 0; 143 | knownRegions = ( 144 | en, 145 | Base, 146 | ); 147 | mainGroup = 97C146E51CF9000F007C117D; 148 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 149 | projectDirPath = ""; 150 | projectRoot = ""; 151 | targets = ( 152 | 97C146ED1CF9000F007C117D /* Runner */, 153 | ); 154 | }; 155 | /* End PBXProject section */ 156 | 157 | /* Begin PBXResourcesBuildPhase section */ 158 | 97C146EC1CF9000F007C117D /* Resources */ = { 159 | isa = PBXResourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 163 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 164 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 165 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 166 | ); 167 | runOnlyForDeploymentPostprocessing = 0; 168 | }; 169 | /* End PBXResourcesBuildPhase section */ 170 | 171 | /* Begin PBXShellScriptBuildPhase section */ 172 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 173 | isa = PBXShellScriptBuildPhase; 174 | buildActionMask = 2147483647; 175 | files = ( 176 | ); 177 | inputPaths = ( 178 | ); 179 | name = "Thin Binary"; 180 | outputPaths = ( 181 | ); 182 | runOnlyForDeploymentPostprocessing = 0; 183 | shellPath = /bin/sh; 184 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; 185 | }; 186 | 9740EEB61CF901F6004384FC /* Run Script */ = { 187 | isa = PBXShellScriptBuildPhase; 188 | buildActionMask = 2147483647; 189 | files = ( 190 | ); 191 | inputPaths = ( 192 | ); 193 | name = "Run Script"; 194 | outputPaths = ( 195 | ); 196 | runOnlyForDeploymentPostprocessing = 0; 197 | shellPath = /bin/sh; 198 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 199 | }; 200 | /* End PBXShellScriptBuildPhase section */ 201 | 202 | /* Begin PBXSourcesBuildPhase section */ 203 | 97C146EA1CF9000F007C117D /* Sources */ = { 204 | isa = PBXSourcesBuildPhase; 205 | buildActionMask = 2147483647; 206 | files = ( 207 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, 208 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 209 | ); 210 | runOnlyForDeploymentPostprocessing = 0; 211 | }; 212 | /* End PBXSourcesBuildPhase section */ 213 | 214 | /* Begin PBXVariantGroup section */ 215 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 216 | isa = PBXVariantGroup; 217 | children = ( 218 | 97C146FB1CF9000F007C117D /* Base */, 219 | ); 220 | name = Main.storyboard; 221 | sourceTree = ""; 222 | }; 223 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 224 | isa = PBXVariantGroup; 225 | children = ( 226 | 97C147001CF9000F007C117D /* Base */, 227 | ); 228 | name = LaunchScreen.storyboard; 229 | sourceTree = ""; 230 | }; 231 | /* End PBXVariantGroup section */ 232 | 233 | /* Begin XCBuildConfiguration section */ 234 | 249021D3217E4FDB00AE95B9 /* Profile */ = { 235 | isa = XCBuildConfiguration; 236 | buildSettings = { 237 | ALWAYS_SEARCH_USER_PATHS = NO; 238 | CLANG_ANALYZER_NONNULL = YES; 239 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 240 | CLANG_CXX_LIBRARY = "libc++"; 241 | CLANG_ENABLE_MODULES = YES; 242 | CLANG_ENABLE_OBJC_ARC = YES; 243 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 244 | CLANG_WARN_BOOL_CONVERSION = YES; 245 | CLANG_WARN_COMMA = YES; 246 | CLANG_WARN_CONSTANT_CONVERSION = YES; 247 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 248 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 249 | CLANG_WARN_EMPTY_BODY = YES; 250 | CLANG_WARN_ENUM_CONVERSION = YES; 251 | CLANG_WARN_INFINITE_RECURSION = YES; 252 | CLANG_WARN_INT_CONVERSION = YES; 253 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 254 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 255 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 256 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 257 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 258 | CLANG_WARN_STRICT_PROTOTYPES = YES; 259 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 260 | CLANG_WARN_UNREACHABLE_CODE = YES; 261 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 262 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 263 | COPY_PHASE_STRIP = NO; 264 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 265 | ENABLE_NS_ASSERTIONS = NO; 266 | ENABLE_STRICT_OBJC_MSGSEND = YES; 267 | GCC_C_LANGUAGE_STANDARD = gnu99; 268 | GCC_NO_COMMON_BLOCKS = YES; 269 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 270 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 271 | GCC_WARN_UNDECLARED_SELECTOR = YES; 272 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 273 | GCC_WARN_UNUSED_FUNCTION = YES; 274 | GCC_WARN_UNUSED_VARIABLE = YES; 275 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 276 | MTL_ENABLE_DEBUG_INFO = NO; 277 | SDKROOT = iphoneos; 278 | SUPPORTED_PLATFORMS = iphoneos; 279 | TARGETED_DEVICE_FAMILY = "1,2"; 280 | VALIDATE_PRODUCT = YES; 281 | }; 282 | name = Profile; 283 | }; 284 | 249021D4217E4FDB00AE95B9 /* Profile */ = { 285 | isa = XCBuildConfiguration; 286 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 287 | buildSettings = { 288 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 289 | CLANG_ENABLE_MODULES = YES; 290 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 291 | ENABLE_BITCODE = NO; 292 | FRAMEWORK_SEARCH_PATHS = ( 293 | "$(inherited)", 294 | "$(PROJECT_DIR)/Flutter", 295 | ); 296 | INFOPLIST_FILE = Runner/Info.plist; 297 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 298 | LIBRARY_SEARCH_PATHS = ( 299 | "$(inherited)", 300 | "$(PROJECT_DIR)/Flutter", 301 | ); 302 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example; 303 | PRODUCT_NAME = "$(TARGET_NAME)"; 304 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 305 | SWIFT_VERSION = 5.0; 306 | VERSIONING_SYSTEM = "apple-generic"; 307 | }; 308 | name = Profile; 309 | }; 310 | 97C147031CF9000F007C117D /* Debug */ = { 311 | isa = XCBuildConfiguration; 312 | buildSettings = { 313 | ALWAYS_SEARCH_USER_PATHS = NO; 314 | CLANG_ANALYZER_NONNULL = YES; 315 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 316 | CLANG_CXX_LIBRARY = "libc++"; 317 | CLANG_ENABLE_MODULES = YES; 318 | CLANG_ENABLE_OBJC_ARC = YES; 319 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 320 | CLANG_WARN_BOOL_CONVERSION = YES; 321 | CLANG_WARN_COMMA = YES; 322 | CLANG_WARN_CONSTANT_CONVERSION = YES; 323 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 324 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 325 | CLANG_WARN_EMPTY_BODY = YES; 326 | CLANG_WARN_ENUM_CONVERSION = YES; 327 | CLANG_WARN_INFINITE_RECURSION = YES; 328 | CLANG_WARN_INT_CONVERSION = YES; 329 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 330 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 331 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 332 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 333 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 334 | CLANG_WARN_STRICT_PROTOTYPES = YES; 335 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 336 | CLANG_WARN_UNREACHABLE_CODE = YES; 337 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 338 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 339 | COPY_PHASE_STRIP = NO; 340 | DEBUG_INFORMATION_FORMAT = dwarf; 341 | ENABLE_STRICT_OBJC_MSGSEND = YES; 342 | ENABLE_TESTABILITY = YES; 343 | GCC_C_LANGUAGE_STANDARD = gnu99; 344 | GCC_DYNAMIC_NO_PIC = NO; 345 | GCC_NO_COMMON_BLOCKS = YES; 346 | GCC_OPTIMIZATION_LEVEL = 0; 347 | GCC_PREPROCESSOR_DEFINITIONS = ( 348 | "DEBUG=1", 349 | "$(inherited)", 350 | ); 351 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 352 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 353 | GCC_WARN_UNDECLARED_SELECTOR = YES; 354 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 355 | GCC_WARN_UNUSED_FUNCTION = YES; 356 | GCC_WARN_UNUSED_VARIABLE = YES; 357 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 358 | MTL_ENABLE_DEBUG_INFO = YES; 359 | ONLY_ACTIVE_ARCH = YES; 360 | SDKROOT = iphoneos; 361 | TARGETED_DEVICE_FAMILY = "1,2"; 362 | }; 363 | name = Debug; 364 | }; 365 | 97C147041CF9000F007C117D /* Release */ = { 366 | isa = XCBuildConfiguration; 367 | buildSettings = { 368 | ALWAYS_SEARCH_USER_PATHS = NO; 369 | CLANG_ANALYZER_NONNULL = YES; 370 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 371 | CLANG_CXX_LIBRARY = "libc++"; 372 | CLANG_ENABLE_MODULES = YES; 373 | CLANG_ENABLE_OBJC_ARC = YES; 374 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 375 | CLANG_WARN_BOOL_CONVERSION = YES; 376 | CLANG_WARN_COMMA = YES; 377 | CLANG_WARN_CONSTANT_CONVERSION = YES; 378 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 379 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 380 | CLANG_WARN_EMPTY_BODY = YES; 381 | CLANG_WARN_ENUM_CONVERSION = YES; 382 | CLANG_WARN_INFINITE_RECURSION = YES; 383 | CLANG_WARN_INT_CONVERSION = YES; 384 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 385 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 386 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 387 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 388 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 389 | CLANG_WARN_STRICT_PROTOTYPES = YES; 390 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 391 | CLANG_WARN_UNREACHABLE_CODE = YES; 392 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 393 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 394 | COPY_PHASE_STRIP = NO; 395 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 396 | ENABLE_NS_ASSERTIONS = NO; 397 | ENABLE_STRICT_OBJC_MSGSEND = YES; 398 | GCC_C_LANGUAGE_STANDARD = gnu99; 399 | GCC_NO_COMMON_BLOCKS = YES; 400 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 401 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 402 | GCC_WARN_UNDECLARED_SELECTOR = YES; 403 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 404 | GCC_WARN_UNUSED_FUNCTION = YES; 405 | GCC_WARN_UNUSED_VARIABLE = YES; 406 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 407 | MTL_ENABLE_DEBUG_INFO = NO; 408 | SDKROOT = iphoneos; 409 | SUPPORTED_PLATFORMS = iphoneos; 410 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 411 | TARGETED_DEVICE_FAMILY = "1,2"; 412 | VALIDATE_PRODUCT = YES; 413 | }; 414 | name = Release; 415 | }; 416 | 97C147061CF9000F007C117D /* Debug */ = { 417 | isa = XCBuildConfiguration; 418 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 419 | buildSettings = { 420 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 421 | CLANG_ENABLE_MODULES = YES; 422 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 423 | ENABLE_BITCODE = NO; 424 | FRAMEWORK_SEARCH_PATHS = ( 425 | "$(inherited)", 426 | "$(PROJECT_DIR)/Flutter", 427 | ); 428 | INFOPLIST_FILE = Runner/Info.plist; 429 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 430 | LIBRARY_SEARCH_PATHS = ( 431 | "$(inherited)", 432 | "$(PROJECT_DIR)/Flutter", 433 | ); 434 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example; 435 | PRODUCT_NAME = "$(TARGET_NAME)"; 436 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 437 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 438 | SWIFT_VERSION = 5.0; 439 | VERSIONING_SYSTEM = "apple-generic"; 440 | }; 441 | name = Debug; 442 | }; 443 | 97C147071CF9000F007C117D /* Release */ = { 444 | isa = XCBuildConfiguration; 445 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 446 | buildSettings = { 447 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 448 | CLANG_ENABLE_MODULES = YES; 449 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 450 | ENABLE_BITCODE = NO; 451 | FRAMEWORK_SEARCH_PATHS = ( 452 | "$(inherited)", 453 | "$(PROJECT_DIR)/Flutter", 454 | ); 455 | INFOPLIST_FILE = Runner/Info.plist; 456 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 457 | LIBRARY_SEARCH_PATHS = ( 458 | "$(inherited)", 459 | "$(PROJECT_DIR)/Flutter", 460 | ); 461 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example; 462 | PRODUCT_NAME = "$(TARGET_NAME)"; 463 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; 464 | SWIFT_VERSION = 5.0; 465 | VERSIONING_SYSTEM = "apple-generic"; 466 | }; 467 | name = Release; 468 | }; 469 | /* End XCBuildConfiguration section */ 470 | 471 | /* Begin XCConfigurationList section */ 472 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 473 | isa = XCConfigurationList; 474 | buildConfigurations = ( 475 | 97C147031CF9000F007C117D /* Debug */, 476 | 97C147041CF9000F007C117D /* Release */, 477 | 249021D3217E4FDB00AE95B9 /* Profile */, 478 | ); 479 | defaultConfigurationIsVisible = 0; 480 | defaultConfigurationName = Release; 481 | }; 482 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 483 | isa = XCConfigurationList; 484 | buildConfigurations = ( 485 | 97C147061CF9000F007C117D /* Debug */, 486 | 97C147071CF9000F007C117D /* Release */, 487 | 249021D4217E4FDB00AE95B9 /* Profile */, 488 | ); 489 | defaultConfigurationIsVisible = 0; 490 | defaultConfigurationName = Release; 491 | }; 492 | /* End XCConfigurationList section */ 493 | }; 494 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 495 | } 496 | -------------------------------------------------------------------------------- /lib/src/swipable_stack.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' as math; 2 | 3 | import 'package:flutter/gestures.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'package:sprung/sprung.dart'; 6 | import 'package:swipable_stack/src/model/swipe_properties.dart'; 7 | 8 | part 'animation/animation.dart'; 9 | part 'callback/callbacks.dart'; 10 | part 'enum/swipe_anchor.dart'; 11 | part 'enum/swipe_direction.dart'; 12 | part 'model/swipable_stack_position.dart'; 13 | part 'model/swipe_rate_per_threshold.dart'; 14 | part 'swipable_stack_controller.dart'; 15 | 16 | const _kStackMaxCount = 3; 17 | 18 | /// A widget for stacking cards, which users can swipe horizontally and 19 | /// vertically with beautiful animations. 20 | class SwipableStack extends StatefulWidget { 21 | SwipableStack({ 22 | required this.builder, 23 | SwipableStackController? controller, 24 | this.onSwipeCompleted, 25 | this.onWillMoveNext, 26 | this.overlayBuilder, 27 | this.horizontalSwipeThreshold = _defaultHorizontalSwipeThreshold, 28 | this.verticalSwipeThreshold = _defaultVerticalSwipeThreshold, 29 | this.itemCount, 30 | this.viewFraction = _defaultViewFraction, 31 | this.swipeAssistDuration = _defaultSwipeAssistDuration, 32 | this.stackClipBehaviour = _defaultStackClipBehaviour, 33 | this.detectableSwipeDirections = _defaultDetectableSwipeDirections, 34 | this.allowVerticalSwipe = true, 35 | Curve? cancelAnimationCurve, 36 | Curve? rewindAnimationCurve, 37 | this.swipeAnchor, 38 | this.dragStartBehavior = DragStartBehavior.start, 39 | this.hitTestBehavior = HitTestBehavior.deferToChild, 40 | this.dragStartDuration = const Duration(milliseconds: 150), 41 | this.dragStartCurve = Curves.easeOut, 42 | }) : controller = controller ?? SwipableStackController(), 43 | cancelAnimationCurve = 44 | cancelAnimationCurve ?? _defaultCancelAnimationCurve, 45 | rewindAnimationCurve = 46 | rewindAnimationCurve ?? _defaultRewindAnimationCurve, 47 | assert(0 <= viewFraction && viewFraction <= 1), 48 | assert(0 <= horizontalSwipeThreshold && horizontalSwipeThreshold <= 1), 49 | assert(0 <= verticalSwipeThreshold && verticalSwipeThreshold <= 1), 50 | assert(itemCount == null || itemCount >= 0), 51 | super(key: controller?._swipableStackStateKey); 52 | 53 | /// Builder for items to be displayed in [SwipableStack]. 54 | final SwipableStackItemBuilder builder; 55 | 56 | /// An object to manipulate the [SwipableStack]. 57 | final SwipableStackController controller; 58 | 59 | /// Callback called when the Swipe is completed. 60 | final SwipeCompletionCallback? onSwipeCompleted; 61 | 62 | /// Callback called just before launching the Swipe action. 63 | /// 64 | /// If this Callback returns false, the action will be canceled. 65 | final OnWillMoveNext? onWillMoveNext; 66 | 67 | /// Builder for displaying an overlay on the most foreground card. 68 | final SwipableStackOverlayBuilder? overlayBuilder; 69 | 70 | /// The count of items to display. 71 | final int? itemCount; 72 | 73 | /// The second child size rate. 74 | final double viewFraction; 75 | 76 | /// The threshold for horizontal swipes. 77 | final double horizontalSwipeThreshold; 78 | 79 | /// The threshold for vertical swipes. 80 | final double verticalSwipeThreshold; 81 | 82 | /// The set of [SwipeDirection]s you want to detect. 83 | final Set detectableSwipeDirections; 84 | 85 | static const _defaultDetectableSwipeDirections = { 86 | SwipeDirection.right, 87 | SwipeDirection.left, 88 | SwipeDirection.up, 89 | SwipeDirection.down, 90 | }; 91 | 92 | /// How fast should the widget be swiped out of the screen when letting go? 93 | /// The faster you set this, the faster you're able to swipe another Widget 94 | /// of your stack. 95 | final Duration swipeAssistDuration; 96 | 97 | final Clip stackClipBehaviour; 98 | 99 | /// Allow vertical swipe 100 | final bool allowVerticalSwipe; 101 | 102 | /// Where should the card be anchored on during swipe rotation 103 | final SwipeAnchor? swipeAnchor; 104 | 105 | /// A curve to animate the card when canceling the swipe. 106 | final Curve cancelAnimationCurve; 107 | 108 | /// A curve to animate the card when rewinding the swipe. 109 | final Curve rewindAnimationCurve; 110 | 111 | /// The [DragStartBehavior] of the swipes. 112 | final DragStartBehavior dragStartBehavior; 113 | 114 | /// The [HitTestBehavior] of the underlying [GestureDetector]. 115 | final HitTestBehavior hitTestBehavior; 116 | 117 | /// The [Duration] of the dragStartAnimation. 118 | /// 119 | /// Only relevant if [dragStartBehavior] is [DragStartBehavior.down]. 120 | final Duration dragStartDuration; 121 | 122 | /// The [Curve] of the dragStartAnimation. 123 | /// 124 | /// Only relevant if [dragStartBehavior] is [DragStartBehavior.down]. 125 | final Curve dragStartCurve; 126 | 127 | static const double _defaultHorizontalSwipeThreshold = 0.44; 128 | static const double _defaultVerticalSwipeThreshold = 0.32; 129 | static const double _defaultViewFraction = 0.94; 130 | 131 | static const _defaultRewindDuration = Duration(milliseconds: 650); 132 | 133 | static const _defaultSwipeAssistDuration = Duration(milliseconds: 650); 134 | 135 | static const _defaultStackClipBehaviour = Clip.hardEdge; 136 | 137 | static final _defaultCancelAnimationCurve = Sprung.custom( 138 | damping: 17, 139 | mass: 0.5, 140 | ); 141 | static const _defaultRewindAnimationCurve = ElasticOutCurve(0.95); 142 | 143 | @override 144 | _SwipableStackState createState() => _SwipableStackState(); 145 | } 146 | 147 | class _SwipableStackState extends State 148 | with TickerProviderStateMixin { 149 | late final AnimationController _swipeCancelAnimationController = 150 | AnimationController( 151 | vsync: this, 152 | duration: const Duration(milliseconds: 500), 153 | ); 154 | 155 | late final AnimationController _rewindAnimationController = 156 | AnimationController( 157 | vsync: this, 158 | duration: const Duration(milliseconds: 800), 159 | ); 160 | 161 | late final AnimationController _swipeAnimationController = 162 | AnimationController( 163 | vsync: this, 164 | ); 165 | 166 | late final AnimationController _swipeAssistController = AnimationController( 167 | vsync: this, 168 | ); 169 | 170 | late final AnimationController _dragStartController; 171 | 172 | late final CurvedAnimation _dragStartAnimation; 173 | 174 | double _distanceToAssist({ 175 | required BuildContext context, 176 | required Offset difference, 177 | required SwipeDirection swipeDirection, 178 | }) { 179 | final deviceSize = MediaQuery.of(context).size; 180 | if (swipeDirection.isHorizontal) { 181 | double _backMoveDistance({ 182 | required double moveDistance, 183 | required double maxWidth, 184 | required double maxHeight, 185 | }) { 186 | final cardAngle = _SwipablePositioned.calculateAngle( 187 | moveDistance, 188 | maxWidth, 189 | ).abs(); 190 | return math.cos(math.pi / 2 - cardAngle) * maxHeight; 191 | } 192 | 193 | double _remainingDistance({ 194 | required double moveDistance, 195 | required double maxWidth, 196 | required double maxHeight, 197 | }) { 198 | final backMoveDistance = _backMoveDistance( 199 | moveDistance: moveDistance, 200 | maxHeight: maxHeight, 201 | maxWidth: maxWidth, 202 | ); 203 | final diff = maxWidth - (moveDistance - backMoveDistance); 204 | return diff < 1 205 | ? moveDistance 206 | : _remainingDistance( 207 | moveDistance: moveDistance + diff, 208 | maxWidth: maxWidth, 209 | maxHeight: maxHeight, 210 | ); 211 | } 212 | 213 | final maxWidth = _areConstraints?.maxWidth ?? deviceSize.width; 214 | final maxHeight = _areConstraints?.maxHeight ?? deviceSize.height; 215 | final maxDistance = _remainingDistance( 216 | moveDistance: maxWidth, 217 | maxWidth: maxWidth, 218 | maxHeight: maxHeight, 219 | ); 220 | return maxDistance - difference.dx.abs(); 221 | } else { 222 | return deviceSize.height - difference.dy.abs(); 223 | } 224 | } 225 | 226 | Offset _offsetToAssist({ 227 | required Offset difference, 228 | required BuildContext context, 229 | required SwipeDirection swipeDirection, 230 | required double distToAssist, 231 | }) { 232 | final isHorizontal = swipeDirection.isHorizontal; 233 | if (isHorizontal) { 234 | final adjustedHorizontally = Offset(difference.dx * 2, difference.dy); 235 | final absX = adjustedHorizontally.dx.abs(); 236 | final rate = distToAssist / absX; 237 | return adjustedHorizontally * rate; 238 | } else { 239 | final adjustedVertically = Offset(difference.dx, difference.dy * 2); 240 | final absY = adjustedVertically.dy.abs(); 241 | final rate = distToAssist / absY; 242 | return adjustedVertically * rate; 243 | } 244 | } 245 | 246 | Duration _getSwipeAssistDuration({ 247 | required SwipeDirection swipeDirection, 248 | required Offset difference, 249 | required double distToAssist, 250 | }) { 251 | final pixelPerMilliseconds = swipeDirection.isHorizontal ? 1.5 : 2; 252 | 253 | return Duration( 254 | milliseconds: math.min( 255 | distToAssist ~/ pixelPerMilliseconds, 256 | widget.swipeAssistDuration.inMilliseconds, 257 | ), 258 | ); 259 | } 260 | 261 | Duration _getSwipeAnimationDuration({ 262 | required SwipeDirection swipeDirection, 263 | required Offset difference, 264 | required double distToAssist, 265 | }) { 266 | final rate = swipeDirection.isHorizontal ? 0.85 : 0.7; 267 | 268 | return Duration( 269 | milliseconds: (450 * rate).toInt(), 270 | ); 271 | } 272 | 273 | /// The index of the item which displays front. 274 | int get _currentIndex => widget.controller.currentIndex; 275 | 276 | bool get canSwipe => 277 | !_swipeAssistController.animating && 278 | !_swipeAnimationController.animating && 279 | !_rewindAnimationController.animating; 280 | 281 | bool get canAnimationStart => 282 | !_swipeAssistController.animating && 283 | !_swipeAnimationController.animating && 284 | !_swipeCancelAnimationController.animating && 285 | !_rewindAnimationController.animating; 286 | 287 | bool get _rewinding => _rewindAnimationController.animating; 288 | 289 | /// The current session of swipe action. 290 | _SwipableStackPosition? get _currentSession => 291 | widget.controller.currentSession; 292 | 293 | BoxConstraints? _areConstraints; 294 | 295 | void _listenController() { 296 | setState(() {}); 297 | } 298 | 299 | @override 300 | void initState() { 301 | super.initState(); 302 | widget.controller.addListener(_listenController); 303 | _dragStartController = AnimationController( 304 | vsync: this, 305 | duration: widget.dragStartBehavior == DragStartBehavior.down 306 | ? widget.dragStartDuration 307 | : Duration.zero, 308 | ); 309 | _dragStartAnimation = CurvedAnimation( 310 | curve: widget.dragStartCurve, 311 | parent: _dragStartController, 312 | )..addListener(() { 313 | widget.controller._updateSwipe(widget.controller._currentSessionState 314 | ?.copyWith(animationValue: _dragStartAnimation.value)); 315 | }); 316 | } 317 | 318 | @override 319 | void didUpdateWidget(covariant SwipableStack oldWidget) { 320 | super.didUpdateWidget(oldWidget); 321 | if (oldWidget.itemCount != widget.itemCount) { 322 | WidgetsBinding.instance.addPostFrameCallback((_) { 323 | setState(() {}); 324 | }); 325 | } 326 | 327 | if (widget.dragStartBehavior == DragStartBehavior.down) { 328 | _dragStartAnimation.curve = widget.dragStartCurve; 329 | _dragStartController.duration = widget.dragStartDuration; 330 | } else { 331 | // The animation is deactivated by setting its duration to zero 332 | // This way the listeners of the _dragStartAnimation are called 333 | // in contrast to the approach of just not calling the controller. 334 | _dragStartController.duration = Duration.zero; 335 | } 336 | } 337 | 338 | @override 339 | void dispose() { 340 | _swipeCancelAnimationController.dispose(); 341 | _swipeAnimationController.dispose(); 342 | _swipeAssistController.dispose(); 343 | _rewindAnimationController.dispose(); 344 | widget.controller.removeListener(_listenController); 345 | super.dispose(); 346 | } 347 | 348 | @override 349 | Widget build(BuildContext context) { 350 | return LayoutBuilder( 351 | builder: (context, constraints) { 352 | _assertLayout(constraints); 353 | _areConstraints = constraints; 354 | return GestureDetector( 355 | behavior: widget.hitTestBehavior, 356 | dragStartBehavior: widget.dragStartBehavior, 357 | onPanStart: (d) { 358 | if (!canSwipe) { 359 | return; 360 | } 361 | 362 | if (_swipeCancelAnimationController.animating) { 363 | _swipeCancelAnimationController 364 | ..stop() 365 | ..reset(); 366 | } 367 | widget.controller._updateSwipe( 368 | _SwipableStackPosition( 369 | realLocal: d.localPosition, 370 | start: d.globalPosition, 371 | real: d.globalPosition, 372 | animationValue: 0, 373 | ), 374 | ); 375 | 376 | // This line must be executed in any case, so that the listeners of 377 | // the animation are called. Even if the duration of the animation 378 | // is zero. 379 | _dragStartController.forward(from: 0); 380 | }, 381 | onPanUpdate: (d) { 382 | if (!canSwipe) { 383 | return; 384 | } 385 | if (_swipeCancelAnimationController.animating) { 386 | _swipeCancelAnimationController 387 | ..stop() 388 | ..reset(); 389 | } 390 | //do not update dy if vertical swipe is not allowed 391 | final updated = _currentSession?.copyWith( 392 | realPosition: widget.allowVerticalSwipe 393 | ? d.globalPosition 394 | : Offset(d.globalPosition.dx, _currentSession!.current.dy), 395 | ); 396 | widget.controller._updateSwipe( 397 | updated ?? 398 | _SwipableStackPosition( 399 | realLocal: d.localPosition, 400 | start: d.globalPosition, 401 | real: d.globalPosition, 402 | animationValue: 1, 403 | ), 404 | ); 405 | }, 406 | onPanEnd: (d) { 407 | if (!canSwipe) { 408 | return; 409 | } 410 | final swipeAssistDirection = _currentSession?.swipeAssistDirection( 411 | constraints: constraints, 412 | horizontalSwipeThreshold: widget.horizontalSwipeThreshold, 413 | verticalSwipeThreshold: widget.verticalSwipeThreshold, 414 | detectableDirections: widget.detectableSwipeDirections, 415 | ); 416 | 417 | if (swipeAssistDirection == null) { 418 | _cancelSwipe(); 419 | return; 420 | } 421 | final allowMoveNext = widget.onWillMoveNext?.call( 422 | _currentIndex, 423 | swipeAssistDirection, 424 | ) ?? 425 | true; 426 | if (!allowMoveNext) { 427 | _cancelSwipe(); 428 | return; 429 | } 430 | _swipeNext(swipeAssistDirection); 431 | }, 432 | child: Stack( 433 | clipBehavior: widget.stackClipBehaviour, 434 | children: _buildCards( 435 | context, 436 | constraints, 437 | ), 438 | ), 439 | ); 440 | }, 441 | ); 442 | } 443 | 444 | void _assertLayout(BoxConstraints constraints) { 445 | assert(() { 446 | if (!constraints.hasBoundedHeight) { 447 | throw FlutterError('SwipableStack was given unbounded height.'); 448 | } 449 | if (!constraints.hasBoundedWidth) { 450 | throw FlutterError('SwipableStack was given unbounded width.'); 451 | } 452 | return true; 453 | }()); 454 | } 455 | 456 | List _buildCards(BuildContext context, BoxConstraints constraints) { 457 | final stackCount = () { 458 | final itemCount = widget.itemCount; 459 | if (itemCount == null) { 460 | return _kStackMaxCount; 461 | } 462 | final remainingCount = itemCount - _currentIndex; 463 | return math.min(remainingCount, _kStackMaxCount); 464 | }(); 465 | if (stackCount <= 0) { 466 | return []; 467 | } 468 | 469 | final swipeDirectionRate = _currentSession?.swipeDirectionRate( 470 | constraints: constraints, 471 | horizontalSwipeThreshold: widget.horizontalSwipeThreshold, 472 | verticalSwipeThreshold: widget.verticalSwipeThreshold, 473 | detectableDirections: widget.detectableSwipeDirections, 474 | ); 475 | 476 | final session = _currentSession ?? _SwipableStackPosition.notMoving(); 477 | final cards = List.generate( 478 | stackCount, 479 | (index) { 480 | final itemIndex = _currentIndex + index; 481 | final child = widget.builder( 482 | context, 483 | ItemSwipeProperties( 484 | index: itemIndex, 485 | stackIndex: index, 486 | constraints: constraints, 487 | direction: swipeDirectionRate?.direction, 488 | swipeProgress: swipeDirectionRate?.rate ?? 0.0, 489 | ), 490 | ); 491 | return _SwipablePositioned( 492 | key: child.key ?? ValueKey(_currentIndex + index), 493 | session: session, 494 | index: index, 495 | viewFraction: widget.viewFraction, 496 | swipeAnchor: widget.swipeAnchor, 497 | areaConstraints: constraints, 498 | child: child, 499 | ); 500 | }, 501 | ).reversed.toList(); 502 | // preparing rewind 503 | if (widget.controller.canRewind) { 504 | final rewindTargetIndex = _currentIndex - 1; 505 | final child = widget.builder( 506 | context, 507 | ItemSwipeProperties( 508 | index: rewindTargetIndex, 509 | stackIndex: -1, 510 | constraints: constraints, 511 | direction: swipeDirectionRate?.direction, 512 | swipeProgress: swipeDirectionRate?.rate ?? 0.0, 513 | ), 514 | ); 515 | final previousSession = widget.controller._previousSession; 516 | if (previousSession != null) { 517 | cards.add( 518 | _SwipablePositioned( 519 | key: child.key ?? ValueKey(rewindTargetIndex), 520 | session: previousSession, 521 | index: -1, 522 | viewFraction: widget.viewFraction, 523 | swipeAnchor: widget.swipeAnchor, 524 | areaConstraints: constraints, 525 | child: child, 526 | ), 527 | ); 528 | } 529 | } 530 | 531 | if (cards.isEmpty) { 532 | return []; 533 | } 534 | final overlay = _buildOverlay( 535 | constraints: constraints, 536 | swipeDirectionRate: swipeDirectionRate, 537 | ); 538 | if (overlay != null) { 539 | cards.add(overlay); 540 | } 541 | return cards; 542 | } 543 | 544 | Widget? _buildOverlay({ 545 | required BoxConstraints constraints, 546 | required _SwipeRatePerThreshold? swipeDirectionRate, 547 | }) { 548 | if (_rewinding) { 549 | return null; 550 | } 551 | if (swipeDirectionRate == null) { 552 | return null; 553 | } 554 | final overlay = widget.overlayBuilder?.call( 555 | context, 556 | OverlaySwipeProperties( 557 | index: _currentIndex, 558 | constraints: constraints, 559 | direction: swipeDirectionRate.direction, 560 | swipeProgress: swipeDirectionRate.rate, 561 | ), 562 | ); 563 | if (overlay == null) { 564 | return null; 565 | } 566 | final session = _currentSession ?? _SwipableStackPosition.notMoving(); 567 | return _SwipablePositioned.overlay( 568 | viewFraction: widget.viewFraction, 569 | session: session, 570 | areaConstraints: constraints, 571 | swipeAnchor: widget.swipeAnchor, 572 | child: overlay, 573 | ); 574 | } 575 | 576 | void _animatePosition(Animation positionAnimation) { 577 | widget.controller._updateSwipe( 578 | widget.controller.currentSession?.copyWith( 579 | realPosition: positionAnimation.value, 580 | ), 581 | ); 582 | } 583 | 584 | void _rewind({ 585 | required Duration duration, 586 | }) { 587 | if (!canAnimationStart) { 588 | return; 589 | } 590 | final previousSession = widget.controller._previousSession; 591 | if (previousSession == null) { 592 | return; 593 | } 594 | widget.controller._prepareRewind(); 595 | _rewindAnimationController.duration = duration; 596 | final rewindAnimation = _rewindAnimationController.tweenCurvedAnimation( 597 | startPosition: previousSession.start, 598 | currentPosition: previousSession.current, 599 | curve: widget.rewindAnimationCurve, 600 | ); 601 | void _animate() { 602 | _animatePosition(rewindAnimation); 603 | } 604 | 605 | rewindAnimation.addListener(_animate); 606 | _rewindAnimationController.forward(from: 0).then( 607 | (_) { 608 | rewindAnimation.removeListener(_animate); 609 | widget.controller._initializeSessions(); 610 | }, 611 | ).catchError((dynamic c) { 612 | rewindAnimation.removeListener(_animate); 613 | widget.controller._initializeSessions(); 614 | }); 615 | } 616 | 617 | void _cancelSwipe() { 618 | final currentSession = widget.controller.currentSession; 619 | if (currentSession == null) { 620 | return; 621 | } 622 | final cancelAnimation = 623 | _swipeCancelAnimationController.tweenCurvedAnimation( 624 | startPosition: currentSession.start, 625 | currentPosition: currentSession.current, 626 | curve: widget.cancelAnimationCurve, 627 | ); 628 | void _animate() { 629 | _animatePosition(cancelAnimation); 630 | } 631 | 632 | cancelAnimation.addListener(_animate); 633 | _swipeCancelAnimationController.forward(from: 0).then( 634 | (_) { 635 | cancelAnimation.removeListener(_animate); 636 | widget.controller.cancelAction(); 637 | }, 638 | ).catchError((dynamic c) { 639 | cancelAnimation.removeListener(_animate); 640 | widget.controller.cancelAction(); 641 | }); 642 | } 643 | 644 | void _swipeNext(SwipeDirection swipeDirection) { 645 | if (!canSwipe) { 646 | return; 647 | } 648 | final currentSession = widget.controller.currentSession; 649 | if (currentSession == null) { 650 | return; 651 | } 652 | final distToAssist = _distanceToAssist( 653 | swipeDirection: swipeDirection, 654 | context: context, 655 | difference: currentSession.difference, 656 | ); 657 | _swipeAssistController.duration = _getSwipeAssistDuration( 658 | distToAssist: distToAssist, 659 | swipeDirection: swipeDirection, 660 | difference: currentSession.difference, 661 | ); 662 | 663 | final animation = _swipeAssistController.swipeAnimation( 664 | startPosition: currentSession.current, 665 | endPosition: currentSession.current + 666 | _offsetToAssist( 667 | distToAssist: distToAssist, 668 | difference: currentSession.difference, 669 | context: context, 670 | swipeDirection: swipeDirection, 671 | ), 672 | ); 673 | 674 | void animate() { 675 | _animatePosition(animation); 676 | } 677 | 678 | animation.addListener(animate); 679 | _swipeAssistController.forward(from: 0).then( 680 | (_) { 681 | animation.removeListener(animate); 682 | widget.onSwipeCompleted?.call( 683 | _currentIndex, 684 | swipeDirection, 685 | ); 686 | widget.controller._completeAction(); 687 | }, 688 | ).catchError((dynamic c) { 689 | animation.removeListener(animate); 690 | widget.controller.cancelAction(); 691 | }); 692 | } 693 | 694 | void _next({ 695 | required SwipeDirection swipeDirection, 696 | required bool shouldCallCompletionCallback, 697 | required bool ignoreOnWillMoveNext, 698 | Duration? duration, 699 | }) { 700 | if (!canAnimationStart) { 701 | return; 702 | } 703 | 704 | if (!ignoreOnWillMoveNext) { 705 | final allowMoveNext = widget.onWillMoveNext?.call( 706 | _currentIndex, 707 | swipeDirection, 708 | ) ?? 709 | true; 710 | if (!allowMoveNext) { 711 | return; 712 | } 713 | } 714 | final startPosition = _SwipableStackPosition.readyToSwipeAnimation( 715 | direction: swipeDirection, 716 | areaConstraints: _areConstraints!, 717 | ); 718 | widget.controller._updateSwipe(startPosition); 719 | final distToAssist = _distanceToAssist( 720 | swipeDirection: swipeDirection, 721 | context: context, 722 | difference: startPosition.difference, 723 | ); 724 | _swipeAnimationController.duration = duration ?? 725 | _getSwipeAnimationDuration( 726 | distToAssist: distToAssist, 727 | swipeDirection: swipeDirection, 728 | difference: startPosition.difference, 729 | ); 730 | 731 | final animation = _swipeAnimationController.swipeAnimation( 732 | startPosition: startPosition.current, 733 | endPosition: _offsetToAssist( 734 | distToAssist: distToAssist, 735 | difference: swipeDirection.defaultOffset, 736 | context: context, 737 | swipeDirection: swipeDirection, 738 | ), 739 | ); 740 | 741 | void animate() { 742 | _animatePosition(animation); 743 | } 744 | 745 | animation.addListener(animate); 746 | _swipeAnimationController.forward(from: 0).then( 747 | (_) { 748 | if (shouldCallCompletionCallback) { 749 | widget.onSwipeCompleted?.call( 750 | _currentIndex, 751 | swipeDirection, 752 | ); 753 | } 754 | animation.removeListener(animate); 755 | widget.controller._completeAction(); 756 | }, 757 | ).catchError((dynamic c) { 758 | animation.removeListener(animate); 759 | widget.controller.cancelAction(); 760 | }); 761 | } 762 | } 763 | 764 | class _SwipablePositioned extends StatelessWidget { 765 | const _SwipablePositioned({ 766 | required this.index, 767 | required this.session, 768 | required this.areaConstraints, 769 | required this.child, 770 | required this.viewFraction, 771 | required this.swipeAnchor, 772 | Key? key, 773 | }) : assert(0 <= viewFraction && viewFraction <= 1), 774 | super(key: key); 775 | 776 | static Widget overlay({ 777 | required _SwipableStackPosition session, 778 | required BoxConstraints areaConstraints, 779 | required Widget child, 780 | required double viewFraction, 781 | required SwipeAnchor? swipeAnchor, 782 | }) { 783 | return _SwipablePositioned( 784 | key: const ValueKey('overlay'), 785 | session: session, 786 | index: 0, 787 | viewFraction: viewFraction, 788 | areaConstraints: areaConstraints, 789 | swipeAnchor: swipeAnchor, 790 | child: IgnorePointer( 791 | child: child, 792 | ), 793 | ); 794 | } 795 | 796 | final int index; 797 | final _SwipableStackPosition session; 798 | final Widget child; 799 | final BoxConstraints areaConstraints; 800 | final double viewFraction; 801 | final SwipeAnchor? swipeAnchor; 802 | 803 | Offset get _currentPositionDiff => session.difference; 804 | 805 | bool get _isRewindTarget => index < 0; 806 | 807 | bool get _isFirst => index == 0; 808 | 809 | bool get _isSecond => index == 1; 810 | 811 | bool get _swipingTop => session.start.dy < areaConstraints.maxHeight / 2; 812 | 813 | double get _rotationAngle { 814 | if (!_isFirst) { 815 | return 0; 816 | } 817 | final angle = calculateAngle( 818 | _currentPositionDiff.dx, 819 | areaConstraints.maxWidth, 820 | ); 821 | switch (swipeAnchor) { 822 | case SwipeAnchor.top: 823 | return angle; 824 | case SwipeAnchor.bottom: 825 | return -angle; 826 | case null: 827 | return _swipingTop ? -angle : angle; 828 | } 829 | } 830 | 831 | static double calculateAngle(double differenceX, double areaWidth) { 832 | return -differenceX / areaWidth * math.pi / 180 * 15; 833 | } 834 | 835 | Offset get _rotationOrigin => _isFirst ? session.local : Offset.zero; 836 | 837 | double get _animationRate => 1 - viewFraction; 838 | 839 | double _animationProgress() { 840 | final offset = Offset( 841 | areaConstraints.maxWidth / 2, 842 | 0, 843 | ); 844 | final rate = _currentPositionDiff.distanceSquared / offset.distanceSquared; 845 | return Curves.easeOutCubic.transform( 846 | math.min(rate, 1), 847 | ); 848 | } 849 | 850 | BoxConstraints _constraints(BuildContext context) { 851 | if (_isFirst) { 852 | return areaConstraints; 853 | } else if (_isSecond) { 854 | return areaConstraints * 855 | (1 - _animationRate + _animationRate * _animationProgress()); 856 | } else { 857 | return areaConstraints * (1 - _animationRate); 858 | } 859 | } 860 | 861 | Offset _preferredPosition(BuildContext context) { 862 | if (_isFirst) { 863 | return _currentPositionDiff; 864 | } else if (_isSecond) { 865 | final constraintsDiff = 866 | areaConstraints * (1 - _animationProgress()) * _animationRate / 2; 867 | return Offset( 868 | constraintsDiff.maxWidth, 869 | constraintsDiff.maxHeight, 870 | ); 871 | } else { 872 | final maxDiff = areaConstraints * _animationRate / 2; 873 | return Offset( 874 | maxDiff.maxWidth, 875 | maxDiff.maxHeight, 876 | ); 877 | } 878 | } 879 | 880 | @override 881 | Widget build(BuildContext context) { 882 | final position = _preferredPosition(context); 883 | return Positioned( 884 | top: position.dy, 885 | left: position.dx, 886 | child: Transform.rotate( 887 | angle: _rotationAngle, 888 | alignment: Alignment.topLeft, 889 | origin: _rotationOrigin, 890 | child: ConstrainedBox( 891 | constraints: _constraints(context), 892 | child: Opacity( 893 | opacity: _isRewindTarget ? 0 : 1, 894 | child: IgnorePointer( 895 | ignoring: !_isFirst, 896 | child: child, 897 | ), 898 | ), 899 | ), 900 | ), 901 | ); 902 | } 903 | } 904 | --------------------------------------------------------------------------------