├── .github └── workflows │ └── tests.yaml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── example ├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android │ ├── .gitignore │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ ├── debug │ │ │ └── AndroidManifest.xml │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── kotlin │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── example │ │ │ │ │ └── MainActivity.kt │ │ │ └── res │ │ │ │ ├── drawable-v21 │ │ │ │ └── launch_background.xml │ │ │ │ ├── drawable │ │ │ │ └── launch_background.xml │ │ │ │ ├── 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 │ │ │ │ ├── values-night │ │ │ │ └── styles.xml │ │ │ │ └── values │ │ │ │ └── styles.xml │ │ │ └── profile │ │ │ └── AndroidManifest.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ └── settings.gradle ├── assets │ └── shaders │ │ └── shader.frag ├── ios │ ├── .gitignore │ ├── Flutter │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ └── Release.xcconfig │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ ├── 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-83.5x83.5@2x.png │ │ └── LaunchImage.imageset │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.png │ │ │ ├── LaunchImage@2x.png │ │ │ ├── LaunchImage@3x.png │ │ │ └── README.md │ │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── Runner-Bridging-Header.h ├── lib │ ├── examples │ │ ├── adapter_view.dart │ │ ├── everything_view.dart │ │ ├── info_view.dart │ │ ├── playground_view.dart │ │ └── visual_view.dart │ └── main.dart ├── linux │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ │ ├── CMakeLists.txt │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugin_registrant.h │ │ └── generated_plugins.cmake │ ├── main.cc │ ├── my_application.cc │ └── my_application.h ├── macos │ ├── .gitignore │ ├── Flutter │ │ ├── Flutter-Debug.xcconfig │ │ ├── Flutter-Release.xcconfig │ │ └── GeneratedPluginRegistrant.swift │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── app_icon_1024.png │ │ │ ├── app_icon_128.png │ │ │ ├── app_icon_16.png │ │ │ ├── app_icon_256.png │ │ │ ├── app_icon_32.png │ │ │ ├── app_icon_512.png │ │ │ └── app_icon_64.png │ │ ├── Base.lproj │ │ └── MainMenu.xib │ │ ├── Configs │ │ ├── AppInfo.xcconfig │ │ ├── Debug.xcconfig │ │ ├── Release.xcconfig │ │ └── Warnings.xcconfig │ │ ├── DebugProfile.entitlements │ │ ├── Info.plist │ │ ├── MainFlutterWindow.swift │ │ └── Release.entitlements ├── pubspec.lock ├── pubspec.yaml ├── web │ ├── favicon.png │ ├── icons │ │ ├── Icon-192.png │ │ ├── Icon-512.png │ │ ├── Icon-maskable-192.png │ │ └── Icon-maskable-512.png │ ├── index.html │ └── manifest.json └── windows │ ├── .gitignore │ ├── CMakeLists.txt │ ├── flutter │ ├── CMakeLists.txt │ ├── generated_plugin_registrant.cc │ ├── generated_plugin_registrant.h │ └── generated_plugins.cmake │ └── runner │ ├── CMakeLists.txt │ ├── Runner.rc │ ├── flutter_window.cpp │ ├── flutter_window.h │ ├── main.cpp │ ├── resource.h │ ├── resources │ └── app_icon.ico │ ├── runner.exe.manifest │ ├── utils.cpp │ ├── utils.h │ ├── win32_window.cpp │ └── win32_window.h ├── lib ├── flutter_animate.dart └── src │ ├── adapters │ ├── adapter.dart │ ├── adapters.dart │ ├── change_notifier_adapter.dart │ ├── scroll_adapter.dart │ ├── value_adapter.dart │ └── value_notifier_adapter.dart │ ├── animate.dart │ ├── animate_list.dart │ ├── effect_list.dart │ ├── effects │ ├── align_effect.dart │ ├── blur_effect.dart │ ├── box_shadow_effect.dart │ ├── callback_effect.dart │ ├── color_effect.dart │ ├── crossfade_effect.dart │ ├── custom_effect.dart │ ├── effect.dart │ ├── effects.dart │ ├── elevation_effect.dart │ ├── fade_effect.dart │ ├── flip_effect.dart │ ├── follow_path_effect.dart │ ├── listen_effect.dart │ ├── move_effect.dart │ ├── rotate_effect.dart │ ├── saturate_effect.dart │ ├── scale_effect.dart │ ├── shader_effect.dart │ ├── shake_effect.dart │ ├── shimmer_effect.dart │ ├── slide_effect.dart │ ├── swap_effect.dart │ ├── then_effect.dart │ ├── tint_effect.dart │ ├── toggle_effect.dart │ └── visibility_effect.dart │ ├── extensions │ ├── animation_controller_loop_extensions.dart │ ├── extensions.dart │ ├── num_duration_extensions.dart │ └── offset_copy_with_extensions.dart │ ├── flutter_animate.dart │ └── warn.dart ├── pubspec.lock ├── pubspec.yaml └── test ├── animate_list_test.dart ├── core_test.dart ├── effects ├── align_test.dart ├── blur_test.dart ├── box_shadow_test.dart ├── callback_test.dart ├── color_test.dart ├── crossfade_test.dart ├── custom_test.dart ├── effect_test.dart ├── elevation_test.dart ├── fade_test.dart ├── flip_test.dart ├── folow_path_test.dart ├── listen_test.dart ├── move_test.dart ├── rotate_test.dart ├── saturate_test.dart ├── scale_test.dart ├── shake_test.dart ├── shimmer_test.dart ├── slide_test.dart ├── swap_test.dart ├── then_test.dart ├── tint_test.dart ├── toggle_test.dart └── visibility_test.dart ├── extensions_test.dart └── tester_extensions.dart /.github/workflows/tests.yaml: -------------------------------------------------------------------------------- 1 | name: tests 2 | on: [push, workflow_dispatch] 3 | jobs: 4 | drive: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v1 8 | - uses: subosito/flutter-action@v1 9 | - run: flutter test 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | desktop.ini 7 | .DS_Store 8 | .atom/ 9 | .buildlog/ 10 | .history 11 | .svn/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | **/doc/api/ 26 | **/ios/Flutter/.last_build_id 27 | .dart_tool/ 28 | .flutter-plugins 29 | .flutter-plugins-dependencies 30 | .packages 31 | .pub-cache/ 32 | .pub/ 33 | /build/ 34 | 35 | # Web related 36 | lib/generated_plugin_registrant.dart 37 | 38 | # Symbolication related 39 | app.*.symbols 40 | 41 | # Obfuscation related 42 | app.*.map.json 43 | 44 | # Android Studio will place build artifacts here 45 | /android/app/debug 46 | /android/app/profile 47 | /android/app/release 48 | __extras 49 | /coverage 50 | /example/coverage 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2022, Grant Skinner 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | 3 | # Additional information about this file can be found at 4 | # https://dart.dev/guides/language/analysis-options 5 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | migrate_working_dir/ 12 | 13 | # IntelliJ related 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # The .vscode folder contains launch configuration and tasks you configure in 20 | # VS Code which you may wish to be included in version control, so this line 21 | # is commented out by default. 22 | #.vscode/ 23 | 24 | # Flutter/Dart/Pub related 25 | **/doc/api/ 26 | **/ios/Flutter/.last_build_id 27 | .dart_tool/ 28 | .flutter-plugins 29 | .flutter-plugins-dependencies 30 | .packages 31 | .pub-cache/ 32 | .pub/ 33 | /build/ 34 | 35 | # Web related 36 | lib/generated_plugin_registrant.dart 37 | 38 | # Symbolication related 39 | app.*.symbols 40 | 41 | # Obfuscation related 42 | app.*.map.json 43 | 44 | # Android Studio will place build artifacts here 45 | /android/app/debug 46 | /android/app/profile 47 | /android/app/release 48 | -------------------------------------------------------------------------------- /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. 5 | 6 | version: 7 | revision: f92f44110e87bad5ff168335c36da6f6053036e6 8 | channel: stable 9 | 10 | project_type: app 11 | 12 | # Tracks metadata for the flutter migrate command 13 | migration: 14 | platforms: 15 | - platform: root 16 | create_revision: f92f44110e87bad5ff168335c36da6f6053036e6 17 | base_revision: f92f44110e87bad5ff168335c36da6f6053036e6 18 | - platform: web 19 | create_revision: f92f44110e87bad5ff168335c36da6f6053036e6 20 | base_revision: f92f44110e87bad5ff168335c36da6f6053036e6 21 | 22 | # User provided section 23 | 24 | # List of Local paths (relative to this file) that should be 25 | # ignored by the migrate tool. 26 | # 27 | # Files that are not part of the templates will be ignored by default. 28 | unmanaged_files: 29 | - 'lib/main.dart' 30 | - 'ios/Runner.xcodeproj/project.pbxproj' 31 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Flutter Animate Example 2 | A simple example of Flutter Animate in action. -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /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 | **/*.keystore 13 | **/*.jks 14 | -------------------------------------------------------------------------------- /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 flutter.compileSdkVersion 30 | ndkVersion flutter.ndkVersion 31 | 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | 37 | kotlinOptions { 38 | jvmTarget = '1.8' 39 | } 40 | 41 | sourceSets { 42 | main.java.srcDirs += 'src/main/kotlin' 43 | } 44 | 45 | defaultConfig { 46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 47 | applicationId "com.example.example" 48 | // You can update the following values to match your application needs. 49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. 50 | minSdkVersion flutter.minSdkVersion 51 | targetSdkVersion flutter.targetSdkVersion 52 | versionCode flutterVersionCode.toInteger() 53 | versionName flutterVersionName 54 | } 55 | 56 | buildTypes { 57 | release { 58 | // TODO: Add your own signing config for the release build. 59 | // Signing with the debug keys for now, so `flutter run --release` works. 60 | signingConfig signingConfigs.debug 61 | } 62 | } 63 | } 64 | 65 | flutter { 66 | source '../..' 67 | } 68 | 69 | dependencies { 70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 71 | } 72 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 15 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /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/android/app/src/main/res/drawable-v21/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /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/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values-night/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.6.10' 3 | repositories { 4 | google() 5 | mavenCentral() 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:7.1.2' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | google() 17 | mavenCentral() 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/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.useAndroidX=true 3 | android.enableJetifier=true 4 | -------------------------------------------------------------------------------- /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-7.4-all.zip 7 | -------------------------------------------------------------------------------- /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/assets/shaders/shader.frag: -------------------------------------------------------------------------------- 1 | // FRAGMENT SHADER 2 | // This is a simple "dissolve" fragment shader with "standard" uniforms to 3 | // demonstrate ShaderEffect. 4 | 5 | #version 460 core 6 | #include 7 | 8 | precision lowp float; 9 | out vec4 oColor; 10 | 11 | // these are the uniforms set by `ShaderUpdateDetails.updateUniforms` and also 12 | // set by default if you don't specify an `update` handler for `ShaderEffect`: 13 | uniform vec2 size; 14 | uniform float value; 15 | uniform sampler2D image; 16 | 17 | // this is a very basic hash function, to get pseudo-random values: 18 | float rand(vec2 co){ 19 | return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453); 20 | } 21 | 22 | void main() { 23 | vec2 uv = FlutterFragCoord().xy / size; 24 | vec4 px = texture(image, uv); 25 | 26 | float a = rand(uv) * 0.99 + 0.01 > value ? 0 : 1; 27 | 28 | oColor = px * a; 29 | } -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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 | 11.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/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/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /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/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /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/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 | CFBundleDisplayName 8 | Example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | example 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UIViewControllerBasedStatusBarAppearance 45 | 46 | CADisableMinimumFrameDurationOnPhone 47 | 48 | UIApplicationSupportsIndirectInputEvents 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/lib/examples/info_view.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_animate/flutter_animate.dart'; 3 | 4 | import '../main.dart'; 5 | 6 | class InfoView extends StatelessWidget { 7 | const InfoView({Key? key}) : super(key: key); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | Widget title = const Text( 12 | 'Flutter Animate Examples', 13 | style: TextStyle( 14 | fontWeight: FontWeight.w900, 15 | fontSize: 40, 16 | color: Color(0xFF666870), 17 | height: 1, 18 | letterSpacing: -1, 19 | ), 20 | ); 21 | 22 | // here's an interesting little trick, we can nest Animate to have 23 | // effects that repeat and ones that only run once on the same item: 24 | title = title 25 | .animate(onPlay: (controller) => controller.repeat()) 26 | .shimmer(duration: 1200.ms, color: const Color(0xFF80DDFF)) 27 | .animate() // this wraps the previous Animate in another Animate 28 | .fadeIn(duration: 1200.ms, curve: Curves.easeOutQuad) 29 | .slide(); 30 | 31 | List tabInfoItems = [ 32 | for (final tab in FlutterAnimateExample.tabs) 33 | Container( 34 | padding: const EdgeInsets.all(8), 35 | color: Colors.transparent, 36 | child: Row( 37 | crossAxisAlignment: CrossAxisAlignment.start, 38 | children: [ 39 | Icon(tab.icon, color: const Color(0xFF80DDFF)), 40 | const SizedBox(width: 8), 41 | Flexible( 42 | child: Text( 43 | tab.description, 44 | style: const TextStyle(color: Colors.white), 45 | ), 46 | ), 47 | ], 48 | ), 49 | ) 50 | ]; 51 | 52 | // Animate all of the info items in the list: 53 | tabInfoItems = tabInfoItems 54 | .animate(interval: 600.ms) 55 | .fadeIn(duration: 900.ms, delay: 300.ms) 56 | .shimmer(blendMode: BlendMode.srcOver, color: Colors.white12) 57 | .move(begin: const Offset(-16, 0), curve: Curves.easeOutQuad); 58 | 59 | return ListView( 60 | padding: const EdgeInsets.all(24), 61 | children: [ 62 | title, 63 | hr, 64 | const Text(''' 65 | This simple app demonstrates a few features of the flutter_animate library. More examples coming as time permits. 66 | 67 | Switch between examples via the bottom nav bar. Tap again to restart that animation.'''), 68 | hr, 69 | ...tabInfoItems, 70 | hr, 71 | const Text( 72 | 'These examples are over the top for demo purposes. Use restraint. :)'), 73 | ], 74 | ); 75 | } 76 | 77 | Widget get hr => Container( 78 | height: 2, 79 | color: const Color(0x8080DDFF), 80 | margin: const EdgeInsets.symmetric(vertical: 16), 81 | ).animate().scale(duration: 600.ms, alignment: Alignment.centerLeft); 82 | } 83 | -------------------------------------------------------------------------------- /example/lib/examples/playground_view.dart: -------------------------------------------------------------------------------- 1 | // This is a playground view to make it easy to play around with Flutter Animate. 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_animate/flutter_animate.dart'; 5 | 6 | class PlaygroundView extends StatelessWidget { 7 | const PlaygroundView({Key? key}) : super(key: key); 8 | 9 | @override 10 | Widget build(BuildContext context) { 11 | return Center( 12 | child: DefaultTextStyle( 13 | style: const TextStyle(fontSize: 36, fontWeight: FontWeight.bold), 14 | child: const Text("Playground 🛝") 15 | .animate() 16 | .slideY(duration: 900.ms, curve: Curves.easeOutCubic) 17 | .fadeIn(), 18 | ), 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/lib/examples/visual_view.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_animate/flutter_animate.dart'; 3 | 4 | class VisualView extends StatelessWidget { 5 | const VisualView({Key? key}) : super(key: key); 6 | 7 | @override 8 | Widget build(BuildContext context) { 9 | // create our stylish text: 10 | Widget title = const Text( 11 | 'SOME\nVISUAL\nEFFECTS\n\n on\n\nRAINBOW\nTEXT', 12 | style: TextStyle( 13 | fontWeight: FontWeight.w900, 14 | fontSize: 64, 15 | color: Color(0xFF666870), 16 | height: 0.9, 17 | letterSpacing: -5, 18 | ), 19 | ); 20 | 21 | // add a rainbow gradient: 22 | // I'm lazy so I'll just apply a ShimmerEffect, use a ValueAdapter to 23 | // pause it half way, and let it handle the details 24 | title = title.animate(adapter: ValueAdapter(0.5)).shimmer( 25 | colors: [ 26 | const Color(0xFFFFFF00), 27 | const Color(0xFF00FF00), 28 | const Color(0xFF00FFFF), 29 | const Color(0xFF0033FF), 30 | const Color(0xFFFF00FF), 31 | const Color(0xFFFF0000), 32 | const Color(0xFFFFFF00), 33 | ], 34 | ); 35 | 36 | // sequence some visual effects 37 | title = title 38 | .animate(onPlay: (controller) => controller.repeat(reverse: true)) 39 | .saturate(delay: 1.seconds, duration: 2.seconds) 40 | .then() // set baseline time to previous effect's end time 41 | .tint(color: const Color(0xFF80DDFF)) 42 | .then() 43 | .blurXY(end: 24) 44 | .fadeOut(); 45 | 46 | return Padding(padding: const EdgeInsets.all(24), child: title); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'dart:ui'; 2 | 3 | import 'package:example/examples/everything_view.dart'; 4 | import 'package:flutter/material.dart'; 5 | 6 | import 'examples/adapter_view.dart'; 7 | import 'examples/info_view.dart'; 8 | import 'examples/playground_view.dart'; 9 | import 'examples/visual_view.dart'; 10 | 11 | void main() { 12 | runApp(const MyApp()); 13 | _loadShader(); // this is a touch hacky, but works for now. 14 | } 15 | 16 | Future _loadShader() async { 17 | return FragmentProgram.fromAsset('assets/shaders/shader.frag').then( 18 | (FragmentProgram prgm) { 19 | EverythingView.shader = prgm.fragmentShader(); 20 | }, onError: (Object error, StackTrace stackTrace) { 21 | FlutterError.reportError( 22 | FlutterErrorDetails(exception: error, stack: stackTrace)); 23 | }); 24 | } 25 | 26 | class MyApp extends StatelessWidget { 27 | const MyApp({Key? key}) : super(key: key); 28 | 29 | @override 30 | Widget build(BuildContext context) { 31 | return const MaterialApp( 32 | title: 'Flutter Animate Demo', 33 | debugShowCheckedModeBanner: false, 34 | home: FlutterAnimateExample(), 35 | ); 36 | } 37 | } 38 | 39 | // this is a very quick and dirty example. 40 | class FlutterAnimateExample extends StatefulWidget { 41 | const FlutterAnimateExample({Key? key}) : super(key: key); 42 | 43 | static final List tabs = [ 44 | TabInfo(Icons.info_outline, (_) => InfoView(key: UniqueKey()), 'Info', 45 | 'Simple example of Widget & List animations.'), 46 | TabInfo(Icons.palette_outlined, (_) => VisualView(key: UniqueKey()), 47 | 'Visual', 'Visual effects like saturation, tint, & blur.'), 48 | TabInfo(Icons.format_list_bulleted, (_) => const AdapterView(), 'Adapters', 49 | 'Animations driven by scrolling & user input.'), 50 | TabInfo(Icons.grid_on_outlined, (_) => const EverythingView(), 51 | 'Kitchen Sink', 'Grid view of effects with default settings.'), 52 | TabInfo(Icons.science_outlined, (_) => PlaygroundView(key: UniqueKey()), 53 | 'Playground', 'A blank canvas for experimenting.'), 54 | ]; 55 | 56 | @override 57 | State createState() => _FlutterAnimateExampleState(); 58 | } 59 | 60 | class _FlutterAnimateExampleState extends State { 61 | int _viewIndex = 0; 62 | 63 | @override 64 | Widget build(BuildContext context) { 65 | return Scaffold( 66 | backgroundColor: const Color(0xFF404349), 67 | bottomNavigationBar: BottomNavigationBar( 68 | currentIndex: _viewIndex, 69 | selectedFontSize: 12, 70 | unselectedFontSize: 12, 71 | selectedItemColor: const Color(0xFF80DDFF), 72 | unselectedItemColor: const Color(0x998898A0), 73 | showSelectedLabels: false, 74 | showUnselectedLabels: false, 75 | type: BottomNavigationBarType.fixed, 76 | backgroundColor: const Color(0xFF2A2B2F), 77 | elevation: 0, 78 | onTap: (index) => setState(() => _viewIndex = index), 79 | items: [ 80 | for (final tab in FlutterAnimateExample.tabs) 81 | BottomNavigationBarItem( 82 | icon: Icon(tab.icon), 83 | label: tab.label, 84 | ) 85 | ], 86 | ), 87 | body: DefaultTextStyle( 88 | style: const TextStyle( 89 | color: Color(0xFFCCCDCF), 90 | fontSize: 14, 91 | height: 1.5, 92 | ), 93 | child: SafeArea( 94 | bottom: false, 95 | child: FlutterAnimateExample.tabs[_viewIndex].builder(context), 96 | ), 97 | ), 98 | ); 99 | } 100 | } 101 | 102 | class TabInfo { 103 | const TabInfo(this.icon, this.builder, this.label, this.description); 104 | 105 | final IconData icon; 106 | final WidgetBuilder builder; 107 | final String label; 108 | final String description; 109 | } 110 | -------------------------------------------------------------------------------- /example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /example/linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void fl_register_plugins(FlPluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /example/linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "example"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "example"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GObject::dispose. 85 | static void my_application_dispose(GObject* object) { 86 | MyApplication* self = MY_APPLICATION(object); 87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 89 | } 90 | 91 | static void my_application_class_init(MyApplicationClass* klass) { 92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 95 | } 96 | 97 | static void my_application_init(MyApplication* self) {} 98 | 99 | MyApplication* my_application_new() { 100 | return MY_APPLICATION(g_object_new(my_application_get_type(), 101 | "application-id", APPLICATION_ID, 102 | "flags", G_APPLICATION_NON_UNIQUE, 103 | nullptr)); 104 | } 105 | -------------------------------------------------------------------------------- /example/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /example/macos/.gitignore: -------------------------------------------------------------------------------- 1 | # Flutter-related 2 | **/Flutter/ephemeral/ 3 | **/Pods/ 4 | 5 | # Xcode-related 6 | **/dgph 7 | **/xcuserdata/ 8 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/Flutter-Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "ephemeral/Flutter-Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/macos/Flutter/GeneratedPluginRegistrant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | import FlutterMacOS 6 | import Foundation 7 | 8 | 9 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { 10 | } 11 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/macos/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | @main 5 | class AppDelegate: FlutterAppDelegate { 6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 7 | return true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "app_icon_16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "app_icon_32.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "app_icon_32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "app_icon_64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "app_icon_128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "app_icon_256.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "app_icon_256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "app_icon_512.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "app_icon_512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "app_icon_1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png -------------------------------------------------------------------------------- /example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png -------------------------------------------------------------------------------- /example/macos/Runner/Configs/AppInfo.xcconfig: -------------------------------------------------------------------------------- 1 | // Application-level settings for the Runner target. 2 | // 3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the 4 | // future. If not, the values below would default to using the project name when this becomes a 5 | // 'flutter create' template. 6 | 7 | // The application's name. By default this is also the title of the Flutter window. 8 | PRODUCT_NAME = example 9 | 10 | // The application's bundle identifier 11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example 12 | 13 | // The copyright displayed in application information 14 | PRODUCT_COPYRIGHT = Copyright © 2022 com.example. All rights reserved. 15 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Debug.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "../../Flutter/Flutter-Release.xcconfig" 2 | #include "Warnings.xcconfig" 3 | -------------------------------------------------------------------------------- /example/macos/Runner/Configs/Warnings.xcconfig: -------------------------------------------------------------------------------- 1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings 2 | GCC_WARN_UNDECLARED_SELECTOR = YES 3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES 4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE 5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 6 | CLANG_WARN_PRAGMA_PACK = YES 7 | CLANG_WARN_STRICT_PROTOTYPES = YES 8 | CLANG_WARN_COMMA = YES 9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES 10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES 11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES 12 | GCC_WARN_SHADOW = YES 13 | CLANG_WARN_UNREACHABLE_CODE = YES 14 | -------------------------------------------------------------------------------- /example/macos/Runner/DebugProfile.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.cs.allow-jit 8 | 9 | com.apple.security.network.server 10 | 11 | com.apple.security.network.client 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/macos/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | $(PRODUCT_COPYRIGHT) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /example/macos/Runner/MainFlutterWindow.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import FlutterMacOS 3 | 4 | class MainFlutterWindow: NSWindow { 5 | override func awakeFromNib() { 6 | let flutterViewController = FlutterViewController.init() 7 | let windowFrame = self.frame 8 | self.contentViewController = flutterViewController 9 | self.setFrame(windowFrame, display: true) 10 | 11 | RegisterGeneratedPlugins(registry: flutterViewController) 12 | 13 | super.awakeFromNib() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/macos/Runner/Release.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: Flutter Animate example. 3 | 4 | # The following line prevents the package from being accidentally published to 5 | # pub.dev using `flutter 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.19.0 <3.0.0" 22 | 23 | # Dependencies specify other packages that your package needs in order to work. 24 | # To automatically upgrade your package dependencies to the latest versions 25 | # consider running `flutter pub upgrade --major-versions`. Alternatively, 26 | # dependencies can be manually updated by changing the version numbers below to 27 | # the latest version available on pub.dev. To see which dependencies have newer 28 | # versions available, run `flutter pub outdated`. 29 | dependencies: 30 | flutter: 31 | sdk: flutter 32 | flutter_animate: 33 | path: ../ 34 | 35 | 36 | # The following adds the Cupertino Icons font to your application. 37 | # Use with the CupertinoIcons class for iOS style icons. 38 | cupertino_icons: ^1.0.2 39 | 40 | dev_dependencies: 41 | flutter_test: 42 | sdk: flutter 43 | 44 | # The "flutter_lints" package below contains a set of recommended lints to 45 | # encourage good coding practices. The lint set provided by the package is 46 | # activated in the `analysis_options.yaml` file located at the root of your 47 | # package. See that file for information about deactivating specific lint 48 | # rules and activating additional ones. 49 | flutter_lints: ^2.0.0 50 | 51 | # For information on the generic Dart part of this file, see the 52 | # following page: https://dart.dev/tools/pub/pubspec 53 | 54 | # The following section is specific to Flutter packages. 55 | flutter: 56 | 57 | # The following line ensures that the Material Icons font is 58 | # included with your application, so that you can use the icons in 59 | # the material Icons class. 60 | uses-material-design: true 61 | 62 | # To add assets to your application, add an assets section, like this: 63 | # assets: 64 | # - images/a_dot_burr.jpeg 65 | # - images/a_dot_ham.jpeg 66 | shaders: 67 | - assets/shaders/shader.frag 68 | 69 | # An image asset can refer to one or more resolution-specific "variants", see 70 | # https://flutter.dev/assets-and-images/#resolution-aware 71 | 72 | # For details regarding adding assets from package dependencies, see 73 | # https://flutter.dev/assets-and-images/#from-packages 74 | 75 | # To add custom fonts to your application, add a fonts section here, 76 | # in this "flutter" section. Each entry in this list should have a 77 | # "family" key with the font family name, and a "fonts" key with a 78 | # list giving the asset and other descriptors for the font. For 79 | # example: 80 | # fonts: 81 | # - family: Schyler 82 | # fonts: 83 | # - asset: fonts/Schyler-Regular.ttf 84 | # - asset: fonts/Schyler-Italic.ttf 85 | # style: italic 86 | # - family: Trajan Pro 87 | # fonts: 88 | # - asset: fonts/TrajanPro.ttf 89 | # - asset: fonts/TrajanPro_Bold.ttf 90 | # weight: 700 91 | # 92 | # For details regarding fonts from package dependencies, 93 | # see https://flutter.dev/custom-fonts/#from-packages 94 | -------------------------------------------------------------------------------- /example/web/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/web/favicon.png -------------------------------------------------------------------------------- /example/web/icons/Icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/web/icons/Icon-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/web/icons/Icon-512.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/web/icons/Icon-maskable-192.png -------------------------------------------------------------------------------- /example/web/icons/Icon-maskable-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/web/icons/Icon-maskable-512.png -------------------------------------------------------------------------------- /example/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | example 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /example/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "short_name": "example", 4 | "start_url": ".", 5 | "display": "standalone", 6 | "background_color": "#0175C2", 7 | "theme_color": "#0175C2", 8 | "description": "A new Flutter project.", 9 | "orientation": "portrait-primary", 10 | "prefer_related_applications": false, 11 | "icons": [ 12 | { 13 | "src": "icons/Icon-192.png", 14 | "sizes": "192x192", 15 | "type": "image/png" 16 | }, 17 | { 18 | "src": "icons/Icon-512.png", 19 | "sizes": "512x512", 20 | "type": "image/png" 21 | }, 22 | { 23 | "src": "icons/Icon-maskable-192.png", 24 | "sizes": "192x192", 25 | "type": "image/png", 26 | "purpose": "maskable" 27 | }, 28 | { 29 | "src": "icons/Icon-maskable-512.png", 30 | "sizes": "512x512", 31 | "type": "image/png", 32 | "purpose": "maskable" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /example/windows/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.14) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") 12 | 13 | # === Flutter Library === 14 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") 15 | 16 | # Published to parent scope for install step. 17 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 18 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 19 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 20 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) 21 | 22 | list(APPEND FLUTTER_LIBRARY_HEADERS 23 | "flutter_export.h" 24 | "flutter_windows.h" 25 | "flutter_messenger.h" 26 | "flutter_plugin_registrar.h" 27 | "flutter_texture_registrar.h" 28 | ) 29 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") 30 | add_library(flutter INTERFACE) 31 | target_include_directories(flutter INTERFACE 32 | "${EPHEMERAL_DIR}" 33 | ) 34 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") 35 | add_dependencies(flutter flutter_assemble) 36 | 37 | # === Wrapper === 38 | list(APPEND CPP_WRAPPER_SOURCES_CORE 39 | "core_implementations.cc" 40 | "standard_codec.cc" 41 | ) 42 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") 43 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN 44 | "plugin_registrar.cc" 45 | ) 46 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") 47 | list(APPEND CPP_WRAPPER_SOURCES_APP 48 | "flutter_engine.cc" 49 | "flutter_view_controller.cc" 50 | ) 51 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") 52 | 53 | # Wrapper sources needed for a plugin. 54 | add_library(flutter_wrapper_plugin STATIC 55 | ${CPP_WRAPPER_SOURCES_CORE} 56 | ${CPP_WRAPPER_SOURCES_PLUGIN} 57 | ) 58 | apply_standard_settings(flutter_wrapper_plugin) 59 | set_target_properties(flutter_wrapper_plugin PROPERTIES 60 | POSITION_INDEPENDENT_CODE ON) 61 | set_target_properties(flutter_wrapper_plugin PROPERTIES 62 | CXX_VISIBILITY_PRESET hidden) 63 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) 64 | target_include_directories(flutter_wrapper_plugin PUBLIC 65 | "${WRAPPER_ROOT}/include" 66 | ) 67 | add_dependencies(flutter_wrapper_plugin flutter_assemble) 68 | 69 | # Wrapper sources needed for the runner. 70 | add_library(flutter_wrapper_app STATIC 71 | ${CPP_WRAPPER_SOURCES_CORE} 72 | ${CPP_WRAPPER_SOURCES_APP} 73 | ) 74 | apply_standard_settings(flutter_wrapper_app) 75 | target_link_libraries(flutter_wrapper_app PUBLIC flutter) 76 | target_include_directories(flutter_wrapper_app PUBLIC 77 | "${WRAPPER_ROOT}/include" 78 | ) 79 | add_dependencies(flutter_wrapper_app flutter_assemble) 80 | 81 | # === Flutter tool backend === 82 | # _phony_ is a non-existent file to force this command to run every time, 83 | # since currently there's no way to get a full input/output list from the 84 | # flutter tool. 85 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") 86 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) 87 | add_custom_command( 88 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 89 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} 90 | ${CPP_WRAPPER_SOURCES_APP} 91 | ${PHONY_OUTPUT} 92 | COMMAND ${CMAKE_COMMAND} -E env 93 | ${FLUTTER_TOOL_ENVIRONMENT} 94 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" 95 | windows-x64 $ 96 | VERBATIM 97 | ) 98 | add_custom_target(flutter_assemble DEPENDS 99 | "${FLUTTER_LIBRARY}" 100 | ${FLUTTER_LIBRARY_HEADERS} 101 | ${CPP_WRAPPER_SOURCES_CORE} 102 | ${CPP_WRAPPER_SOURCES_PLUGIN} 103 | ${CPP_WRAPPER_SOURCES_APP} 104 | ) 105 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | 10 | void RegisterPlugins(flutter::PluginRegistry* registry) { 11 | } 12 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | ) 7 | 8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 9 | ) 10 | 11 | set(PLUGIN_BUNDLED_LIBRARIES) 12 | 13 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 18 | endforeach(plugin) 19 | 20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin}) 22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 23 | endforeach(ffi_plugin) 24 | -------------------------------------------------------------------------------- /example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | project(runner LANGUAGES CXX) 3 | 4 | # Define the application target. To change its name, change BINARY_NAME in the 5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer 6 | # work. 7 | # 8 | # Any new source files that you add to the application should be added here. 9 | add_executable(${BINARY_NAME} WIN32 10 | "flutter_window.cpp" 11 | "main.cpp" 12 | "utils.cpp" 13 | "win32_window.cpp" 14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 15 | "Runner.rc" 16 | "runner.exe.manifest" 17 | ) 18 | 19 | # Apply the standard set of build settings. This can be removed for applications 20 | # that need different build settings. 21 | apply_standard_settings(${BINARY_NAME}) 22 | 23 | # Disable Windows macros that collide with C++ standard library functions. 24 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 25 | 26 | # Add dependency libraries and include directories. Add any application-specific 27 | # dependencies here. 28 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 29 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 30 | 31 | # Run the Flutter tool portions of the build. This must not be removed. 32 | add_dependencies(${BINARY_NAME} flutter_assemble) 33 | -------------------------------------------------------------------------------- /example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // 60 | // Version 61 | // 62 | 63 | #ifdef FLUTTER_BUILD_NUMBER 64 | #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER 65 | #else 66 | #define VERSION_AS_NUMBER 1,0,0 67 | #endif 68 | 69 | #ifdef FLUTTER_BUILD_NAME 70 | #define VERSION_AS_STRING #FLUTTER_BUILD_NAME 71 | #else 72 | #define VERSION_AS_STRING "1.0.0" 73 | #endif 74 | 75 | VS_VERSION_INFO VERSIONINFO 76 | FILEVERSION VERSION_AS_NUMBER 77 | PRODUCTVERSION VERSION_AS_NUMBER 78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 79 | #ifdef _DEBUG 80 | FILEFLAGS VS_FF_DEBUG 81 | #else 82 | FILEFLAGS 0x0L 83 | #endif 84 | FILEOS VOS__WINDOWS32 85 | FILETYPE VFT_APP 86 | FILESUBTYPE 0x0L 87 | BEGIN 88 | BLOCK "StringFileInfo" 89 | BEGIN 90 | BLOCK "040904e4" 91 | BEGIN 92 | VALUE "CompanyName", "com.example" "\0" 93 | VALUE "FileDescription", "example" "\0" 94 | VALUE "FileVersion", VERSION_AS_STRING "\0" 95 | VALUE "InternalName", "example" "\0" 96 | VALUE "LegalCopyright", "Copyright (C) 2022 com.example. All rights reserved." "\0" 97 | VALUE "OriginalFilename", "example.exe" "\0" 98 | VALUE "ProductName", "example" "\0" 99 | VALUE "ProductVersion", VERSION_AS_STRING "\0" 100 | END 101 | END 102 | BLOCK "VarFileInfo" 103 | BEGIN 104 | VALUE "Translation", 0x409, 1252 105 | END 106 | END 107 | 108 | #endif // English (United States) resources 109 | ///////////////////////////////////////////////////////////////////////////// 110 | 111 | 112 | 113 | #ifndef APSTUDIO_INVOKED 114 | ///////////////////////////////////////////////////////////////////////////// 115 | // 116 | // Generated from the TEXTINCLUDE 3 resource. 117 | // 118 | 119 | 120 | ///////////////////////////////////////////////////////////////////////////// 121 | #endif // not APSTUDIO_INVOKED 122 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project) 8 | : project_(project) {} 9 | 10 | FlutterWindow::~FlutterWindow() {} 11 | 12 | bool FlutterWindow::OnCreate() { 13 | if (!Win32Window::OnCreate()) { 14 | return false; 15 | } 16 | 17 | RECT frame = GetClientArea(); 18 | 19 | // The size here must match the window dimensions to avoid unnecessary surface 20 | // creation / destruction in the startup path. 21 | flutter_controller_ = std::make_unique( 22 | frame.right - frame.left, frame.bottom - frame.top, project_); 23 | // Ensure that basic setup of the controller was successful. 24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 25 | return false; 26 | } 27 | RegisterPlugins(flutter_controller_->engine()); 28 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 29 | return true; 30 | } 31 | 32 | void FlutterWindow::OnDestroy() { 33 | if (flutter_controller_) { 34 | flutter_controller_ = nullptr; 35 | } 36 | 37 | Win32Window::OnDestroy(); 38 | } 39 | 40 | LRESULT 41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 42 | WPARAM const wparam, 43 | LPARAM const lparam) noexcept { 44 | // Give Flutter, including plugins, an opportunity to handle window messages. 45 | if (flutter_controller_) { 46 | std::optional result = 47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 48 | lparam); 49 | if (result) { 50 | return *result; 51 | } 52 | } 53 | 54 | switch (message) { 55 | case WM_FONTCHANGE: 56 | flutter_controller_->engine()->ReloadSystemFonts(); 57 | break; 58 | } 59 | 60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 61 | } 62 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "win32_window.h" 10 | 11 | // A window that does nothing but host a Flutter view. 12 | class FlutterWindow : public Win32Window { 13 | public: 14 | // Creates a new FlutterWindow hosting a Flutter view running |project|. 15 | explicit FlutterWindow(const flutter::DartProject& project); 16 | virtual ~FlutterWindow(); 17 | 18 | protected: 19 | // Win32Window: 20 | bool OnCreate() override; 21 | void OnDestroy() override; 22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 23 | LPARAM const lparam) noexcept override; 24 | 25 | private: 26 | // The project to run. 27 | flutter::DartProject project_; 28 | 29 | // The Flutter instance hosted by this window. 30 | std::unique_ptr flutter_controller_; 31 | }; 32 | 33 | #endif // RUNNER_FLUTTER_WINDOW_H_ 34 | -------------------------------------------------------------------------------- /example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "utils.h" 7 | 8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 9 | _In_ wchar_t *command_line, _In_ int show_command) { 10 | // Attach to console when present (e.g., 'flutter run') or create a 11 | // new console when running with a debugger. 12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 13 | CreateAndAttachConsole(); 14 | } 15 | 16 | // Initialize COM, so that it is available for use in the library and/or 17 | // plugins. 18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 19 | 20 | flutter::DartProject project(L"data"); 21 | 22 | std::vector command_line_arguments = 23 | GetCommandLineArguments(); 24 | 25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); 26 | 27 | FlutterWindow window(project); 28 | Win32Window::Point origin(10, 10); 29 | Win32Window::Size size(1280, 720); 30 | if (!window.CreateAndShow(L"example", origin, size)) { 31 | return EXIT_FAILURE; 32 | } 33 | window.SetQuitOnClose(true); 34 | 35 | ::MSG msg; 36 | while (::GetMessage(&msg, nullptr, 0, 0)) { 37 | ::TranslateMessage(&msg); 38 | ::DispatchMessage(&msg); 39 | } 40 | 41 | ::CoUninitialize(); 42 | return EXIT_SUCCESS; 43 | } 44 | -------------------------------------------------------------------------------- /example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gskinner/flutter_animate/62c12040b1e3f80403b4fbfa48649155df006eb5/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | 24 | std::vector GetCommandLineArguments() { 25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. 26 | int argc; 27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); 28 | if (argv == nullptr) { 29 | return std::vector(); 30 | } 31 | 32 | std::vector command_line_arguments; 33 | 34 | // Skip the first argument as it's the binary name. 35 | for (int i = 1; i < argc; i++) { 36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i])); 37 | } 38 | 39 | ::LocalFree(argv); 40 | 41 | return command_line_arguments; 42 | } 43 | 44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) { 45 | if (utf16_string == nullptr) { 46 | return std::string(); 47 | } 48 | int target_length = ::WideCharToMultiByte( 49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 50 | -1, nullptr, 0, nullptr, nullptr); 51 | std::string utf8_string; 52 | if (target_length == 0 || target_length > utf8_string.max_size()) { 53 | return utf8_string; 54 | } 55 | utf8_string.resize(target_length); 56 | int converted_length = ::WideCharToMultiByte( 57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, 58 | -1, utf8_string.data(), 59 | target_length, nullptr, nullptr); 60 | if (converted_length == 0) { 61 | return std::string(); 62 | } 63 | return utf8_string; 64 | } 65 | -------------------------------------------------------------------------------- /example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | #include 5 | #include 6 | 7 | // Creates a console for the process, and redirects stdout and stderr to 8 | // it for both the runner and the Flutter library. 9 | void CreateAndAttachConsole(); 10 | 11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string 12 | // encoded in UTF-8. Returns an empty std::string on failure. 13 | std::string Utf8FromUtf16(const wchar_t* utf16_string); 14 | 15 | // Gets the command line arguments passed in as a std::vector, 16 | // encoded in UTF-8. Returns an empty std::vector on failure. 17 | std::vector GetCommandLineArguments(); 18 | 19 | #endif // RUNNER_UTILS_H_ 20 | -------------------------------------------------------------------------------- /example/windows/runner/win32_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_WIN32_WINDOW_H_ 2 | #define RUNNER_WIN32_WINDOW_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be 11 | // inherited from by classes that wish to specialize with custom 12 | // rendering and input handling 13 | class Win32Window { 14 | public: 15 | struct Point { 16 | unsigned int x; 17 | unsigned int y; 18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {} 19 | }; 20 | 21 | struct Size { 22 | unsigned int width; 23 | unsigned int height; 24 | Size(unsigned int width, unsigned int height) 25 | : width(width), height(height) {} 26 | }; 27 | 28 | Win32Window(); 29 | virtual ~Win32Window(); 30 | 31 | // Creates and shows a win32 window with |title| and position and size using 32 | // |origin| and |size|. New windows are created on the default monitor. Window 33 | // sizes are specified to the OS in physical pixels, hence to ensure a 34 | // consistent size to will treat the width height passed in to this function 35 | // as logical pixels and scale to appropriate for the default monitor. Returns 36 | // true if the window was created successfully. 37 | bool CreateAndShow(const std::wstring& title, 38 | const Point& origin, 39 | const Size& size); 40 | 41 | // Release OS resources associated with window. 42 | void Destroy(); 43 | 44 | // Inserts |content| into the window tree. 45 | void SetChildContent(HWND content); 46 | 47 | // Returns the backing Window handle to enable clients to set icon and other 48 | // window properties. Returns nullptr if the window has been destroyed. 49 | HWND GetHandle(); 50 | 51 | // If true, closing this window will quit the application. 52 | void SetQuitOnClose(bool quit_on_close); 53 | 54 | // Return a RECT representing the bounds of the current client area. 55 | RECT GetClientArea(); 56 | 57 | protected: 58 | // Processes and route salient window messages for mouse handling, 59 | // size change and DPI. Delegates handling of these to member overloads that 60 | // inheriting classes can handle. 61 | virtual LRESULT MessageHandler(HWND window, 62 | UINT const message, 63 | WPARAM const wparam, 64 | LPARAM const lparam) noexcept; 65 | 66 | // Called when CreateAndShow is called, allowing subclass window-related 67 | // setup. Subclasses should return false if setup fails. 68 | virtual bool OnCreate(); 69 | 70 | // Called when Destroy is called. 71 | virtual void OnDestroy(); 72 | 73 | private: 74 | friend class WindowClassRegistrar; 75 | 76 | // OS callback called by message pump. Handles the WM_NCCREATE message which 77 | // is passed when the non-client area is being created and enables automatic 78 | // non-client DPI scaling so that the non-client area automatically 79 | // responsponds to changes in DPI. All other messages are handled by 80 | // MessageHandler. 81 | static LRESULT CALLBACK WndProc(HWND const window, 82 | UINT const message, 83 | WPARAM const wparam, 84 | LPARAM const lparam) noexcept; 85 | 86 | // Retrieves a class instance pointer for |window| 87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept; 88 | 89 | bool quit_on_close_ = false; 90 | 91 | // window handle for top level window. 92 | HWND window_handle_ = nullptr; 93 | 94 | // window handle for hosted content. 95 | HWND child_content_ = nullptr; 96 | }; 97 | 98 | #endif // RUNNER_WIN32_WINDOW_H_ 99 | -------------------------------------------------------------------------------- /lib/flutter_animate.dart: -------------------------------------------------------------------------------- 1 | export 'src/animate.dart'; 2 | export 'src/animate_list.dart'; 3 | export 'src/effect_list.dart'; 4 | export 'src/flutter_animate.dart'; 5 | export 'src/adapters/adapters.dart'; 6 | export 'src/effects/effects.dart'; 7 | export 'src/extensions/extensions.dart'; 8 | -------------------------------------------------------------------------------- /lib/src/adapters/adapter.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/scheduler.dart'; 4 | import 'package:flutter/widgets.dart'; 5 | 6 | /// Adapters provide a mechanism to drive an animation from an arbitrary source. 7 | /// For example, synchronizing an animation with a scroll, controlling 8 | /// an animation with a slider input, or progressing an animation based on 9 | /// the time of day. 10 | /// 11 | /// [animated] specifies that the adapter should animate to new values. If `false`, it 12 | /// will jump to the new value, if `true` it will animate to the value using a 13 | /// duration calculated from the animation's total duration and the value change. 14 | /// Defaults to `false`. 15 | /// 16 | /// Setting [direction] to [Direction.forward] or [Direction.reverse] will cause 17 | /// the adapter to only update if the new value is greater than or less than the 18 | /// current value respectively. 19 | /// 20 | /// Adapter implementations must expose an [attach] method which accepts the 21 | /// [AnimationController] used by an [Animate] instance, and adds the logic 22 | /// to drive it from an external source by updating its `value` (0-1). See the 23 | /// included adapters for implementation examples. 24 | abstract class Adapter { 25 | Adapter({bool? animated, this.direction}) : animated = animated ?? false; 26 | 27 | final bool animated; 28 | 29 | final Direction? direction; 30 | 31 | AnimationController? _controller; 32 | ChangeNotifier? _notifier; 33 | VoidCallback? _listener; 34 | Ticker? _ticker; 35 | double _value = 0; 36 | int _prevT = 0; 37 | 38 | // this is called by Animate to associate the AnimationController. 39 | // implementers must call config. 40 | void attach(AnimationController controller) => config(controller, 0); 41 | 42 | // disassociates the controller, which also allows the adapter to be re-attached. 43 | @mustCallSuper 44 | void detach() { 45 | _notifier?.removeListener(_listener!); 46 | _notifier = _listener = _controller = null; 47 | _ticker?.stop(); 48 | } 49 | 50 | // called by implementers to attach the controller, and set an initial value. 51 | void config(AnimationController controller, double value, 52 | {ChangeNotifier? notifier, VoidCallback? listener}) { 53 | assert(_controller == null, 'An adapter was assigned twice.'); 54 | assert((notifier == null) == (listener == null)); 55 | _controller = controller; 56 | _controller?.value = _value = value; 57 | _notifier = notifier?..addListener(listener!); 58 | _listener = listener; 59 | _ticker = Ticker(_tick); 60 | } 61 | 62 | // called by implementers to update the value. Manages direction and animated. 63 | void updateValue(double value) { 64 | AnimationController controller = _controller!; 65 | if (_value == value || 66 | (direction == Direction.forward && value < _value) || 67 | (direction == Direction.reverse && value > _value)) { 68 | return; 69 | } 70 | _value = value; 71 | 72 | if (!animated) { 73 | controller.value = value; 74 | } else if (value != controller.value) { 75 | Ticker ticker = _ticker!; 76 | _prevT = DateTime.now().microsecondsSinceEpoch; 77 | if (!ticker.isActive) ticker.start(); 78 | } 79 | } 80 | 81 | // The first tick from a Ticker always has a zero duration, which causes 82 | // animateTo to lock or stutter when changing values repeatedly so this 83 | // uses a custom implementation to animate between values. 84 | void _tick(_) { 85 | AnimationController controller = _controller!; 86 | 87 | int t = DateTime.now().microsecondsSinceEpoch; 88 | double d = (t - _prevT) / controller.duration!.inMicroseconds; 89 | double val = controller.value; 90 | 91 | if (val < _value) { 92 | val = min(_value, val + d); 93 | } else { 94 | val = max(_value, val - d); 95 | } 96 | 97 | _prevT = t; 98 | controller.value = val; 99 | if (val == _value) _ticker!.stop(); 100 | } 101 | } 102 | 103 | enum Direction { forward, reverse } 104 | -------------------------------------------------------------------------------- /lib/src/adapters/adapters.dart: -------------------------------------------------------------------------------- 1 | // collects adapter classes for easy import. 2 | export 'adapter.dart'; 3 | 4 | export 'scroll_adapter.dart'; 5 | export 'value_notifier_adapter.dart'; 6 | export 'change_notifier_adapter.dart'; 7 | export 'value_adapter.dart'; 8 | -------------------------------------------------------------------------------- /lib/src/adapters/change_notifier_adapter.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// Drives an [Animate] animation from a [ChangeNotifier]. The [valueGetter] 6 | /// should provide a value in the range `0-1` when a change occurs. 7 | /// 8 | /// See [Adapter] for information on [direction] and [animated]. 9 | /// 10 | /// This example creates a `ChangeNotifierAdapter` that fades in the `myIcon` 11 | /// widget based on the progress of the `myProgressNotifier` [ChangeNotifier]. 12 | /// The `valueGetter` is called whenever `myProgressNotifier` changes, and 13 | /// returns a position value between `0-1`, calculated from the `loaded` and 14 | /// `total` properties of `myProgressNotifier`. 15 | /// 16 | /// ```dart 17 | /// myIcon.animate( 18 | /// adapter: ChangeNotifierAdapter( 19 | /// myProgressNotifier, 20 | /// () => myProgressNotifier.loaded / myProgressNotifier.total, 21 | /// ) 22 | /// ).fadeIn(); 23 | /// ``` 24 | class ChangeNotifierAdapter extends Adapter { 25 | ChangeNotifierAdapter( 26 | this.notifier, 27 | this.valueGetter, { 28 | bool? animated, 29 | Direction? direction, 30 | }) : super(animated: animated, direction: direction); 31 | 32 | final ChangeNotifier notifier; 33 | final ValueGetter valueGetter; 34 | 35 | @override 36 | void attach(AnimationController controller) { 37 | config( 38 | controller, 39 | valueGetter(), 40 | notifier: notifier, 41 | listener: () => updateValue(valueGetter()), 42 | ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lib/src/adapters/scroll_adapter.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/rendering.dart'; 2 | import 'package:flutter/widgets.dart'; 3 | 4 | import '../../flutter_animate.dart'; 5 | 6 | /// Drives an [Animate] animation from a [ScrollController]. 7 | /// 8 | /// Set [direction] to [ScrollDirection.forward] or [ScrollDirection.reverse] to 9 | /// only trigger updates when the scroll position increases or decreases respectively. 10 | /// 11 | /// [begin] and [end] adjust the pixel range for the scroll to update the animation 12 | /// within. Values `<0` are calculated relative to the end of the scroll. 13 | /// They default to `minScrollExtent` and `maxScrollExtent` respectively. 14 | /// 15 | /// For example, this starts fading/sliding in the text once the list scrolls to 16 | /// 100px, and finishes 200px before the end of the scroll: 17 | /// 18 | /// ``` 19 | /// ListView( 20 | /// controller: scrollController, 21 | /// children: items, 22 | /// ); 23 | /// Text("Hello").animate( 24 | /// adapter: ScrollAdapter( 25 | /// scrollController, 26 | /// begin: 100, // relative to start of scroll 27 | /// end: -200, // relative to end 28 | /// ) 29 | /// ).fadeIn().slide(); 30 | /// ``` 31 | /// 32 | /// See [Adapter] for information on [direction] and [animated]. 33 | class ScrollAdapter extends Adapter { 34 | ScrollAdapter( 35 | this.scrollController, { 36 | this.begin, 37 | this.end, 38 | bool? animated, 39 | Direction? direction, 40 | }) : super(animated: animated, direction: direction); 41 | 42 | final ScrollController scrollController; 43 | final double? begin; 44 | final double? end; 45 | 46 | @override 47 | void attach(AnimationController controller) { 48 | config( 49 | controller, 50 | _getValue() ?? 0, 51 | notifier: scrollController, 52 | listener: () { 53 | double? value = _getValue(); 54 | if (value != null) updateValue(value); 55 | }, 56 | ); 57 | } 58 | 59 | double? _getValue() { 60 | if (!scrollController.hasClients) return null; 61 | ScrollPosition pos = scrollController.position; 62 | if (!pos.hasContentDimensions || !pos.hasPixels) return null; 63 | double min = pos.minScrollExtent, max = pos.maxScrollExtent; 64 | double minPx = _getPx(begin, min, max, min); 65 | double maxPx = _getPx(end, min, max, max); 66 | return (pos.pixels - minPx) / (maxPx - minPx); 67 | } 68 | 69 | double _getPx(double? val, double min, double max, double def) { 70 | if (val == null) return def; 71 | return val + (val <= 0 ? max : min); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /lib/src/adapters/value_adapter.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// Drives an [Animate] animation directly from a value in the range `0-1` 6 | /// 7 | /// For example, this would fade/slide in text based on the value of a `Slider`: 8 | /// 9 | /// ``` 10 | /// // note: Slider range defaults to 0-1 11 | /// Slider( 12 | /// value: _sliderVal 13 | /// onChanged: (val) => setState(() => _sliderVal = val)), 14 | /// ); 15 | /// Text("Hello").animate(adapter: ValueAdapter(_sliderVal)) 16 | /// .fadeIn().slide(); 17 | /// ``` 18 | /// 19 | /// See [Adapter] for information on [direction] and [animated]. 20 | class ValueAdapter extends ValueNotifierAdapter { 21 | ValueAdapter(double value, {bool? animated, Direction? direction}) 22 | : super( 23 | ValueNotifier(value), 24 | animated: animated, 25 | direction: direction, 26 | ); 27 | 28 | set value(double value) => notifier.value = value; 29 | } 30 | -------------------------------------------------------------------------------- /lib/src/adapters/value_notifier_adapter.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// Drives an [Animate] animation from a [ValueNotifier]. The value from the 6 | /// notifier should be in the range `0-1`. 7 | /// 8 | /// See [Adapter] for information on [direction] and [animated]. 9 | class ValueNotifierAdapter extends Adapter { 10 | ValueNotifierAdapter(this.notifier, {bool? animated, Direction? direction}) 11 | : super(animated: animated, direction: direction); 12 | 13 | final ValueNotifier notifier; 14 | 15 | @override 16 | void attach(AnimationController controller) { 17 | config( 18 | controller, 19 | notifier.value, 20 | notifier: notifier, 21 | listener: () => updateValue(notifier.value), 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/effect_list.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | import '../flutter_animate.dart'; 3 | 4 | /// Simple helper class to build a list of effects via the chained api. 5 | /// Example: 6 | /// 7 | /// ``` 8 | /// List myEffects = EffectList().fadeIn().scale(); 9 | /// // ... 10 | /// Animate(effects: myEffects, child: foo); 11 | /// ``` 12 | class EffectList extends ListBase with AnimateManager { 13 | final List _effects = []; 14 | 15 | @override 16 | EffectList addEffect(Effect effect) { 17 | _effects.add(effect); 18 | return this; 19 | } 20 | 21 | // concrete implementations required when extending ListBase: 22 | @override 23 | set length(int length) { 24 | _effects.length = length; 25 | } 26 | 27 | @override 28 | int get length => _effects.length; 29 | 30 | @override 31 | Effect operator [](int index) => _effects[index]; 32 | 33 | @override 34 | void operator []=(int index, Effect value) { 35 | _effects[index] = value; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/src/effects/align_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that animates the target between the specified [begin] and [end] 6 | /// alignments (via [Align]). 7 | /// Defaults to `begin=Align.topCenter, end=Align.center`. 8 | @immutable 9 | class AlignEffect extends Effect { 10 | static const Alignment neutralValue = Alignment.center; 11 | static const Alignment defaultValue = Alignment.topCenter; 12 | 13 | const AlignEffect({ 14 | super.delay, 15 | super.duration, 16 | super.curve, 17 | Alignment? begin, 18 | Alignment? end, 19 | }) : super( 20 | begin: begin ?? (end == null ? defaultValue : neutralValue), 21 | end: end ?? neutralValue, 22 | ); 23 | 24 | @override 25 | Widget build( 26 | BuildContext context, 27 | Widget child, 28 | AnimationController controller, 29 | EffectEntry entry, 30 | ) { 31 | Animation animation = buildAnimation(controller, entry); 32 | return getOptimizedBuilder( 33 | animation: animation, 34 | builder: (_, __) { 35 | return Align( 36 | alignment: animation.value, 37 | child: child, 38 | ); 39 | }, 40 | ); 41 | } 42 | } 43 | 44 | /// Adds [AlignEffect] related extensions to [AnimateManager]. 45 | extension AlignEffectExtensions> on T { 46 | /// Adds an [AlignEffect] that animates the target between the specified 47 | /// [begin] and [end] alignments (via [Align]). 48 | T align({ 49 | Duration? delay, 50 | Duration? duration, 51 | Curve? curve, 52 | Alignment? begin, 53 | Alignment? end, 54 | }) => 55 | addEffect(AlignEffect( 56 | delay: delay, 57 | duration: duration, 58 | curve: curve, 59 | begin: begin, 60 | end: end, 61 | )); 62 | } 63 | -------------------------------------------------------------------------------- /lib/src/effects/box_shadow_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that animates a [BoxShadow] between [begin] and [end] (via [DecoratedBox]). 6 | /// A value of `null` for either will be interpreted as a shadow that matches the other shadow but 7 | /// with a zero offset and blurRadius. 8 | /// You can also specify a [borderRadius] that defines rounded corners for the shadow. 9 | /// Defaults to `begin=null, end=BoxShadow(color: Color(0x80000000), blurRadius: 8.0, offset: Offset(0.0, 4.0))` 10 | /// 11 | /// This can also be used for glow effects (by setting a `0` offset, and a color). 12 | /// 13 | /// See also: [ElevationEffect] for simpler animated shadows based on elevation. 14 | @immutable 15 | class BoxShadowEffect extends Effect { 16 | static const BoxShadow? neutralValue = null; 17 | static const BoxShadow defaultValue = BoxShadow( 18 | color: Color(0x80000000), blurRadius: 8.0, offset: Offset(0.0, 4.0)); 19 | 20 | const BoxShadowEffect({ 21 | super.delay, 22 | super.duration, 23 | super.curve, 24 | BoxShadow? begin, 25 | BoxShadow? end, 26 | this.borderRadius, 27 | }) : super( 28 | begin: begin ?? neutralValue, 29 | end: end ?? (begin == null ? defaultValue : neutralValue), 30 | ); 31 | 32 | final BorderRadius? borderRadius; 33 | 34 | @override 35 | Widget build( 36 | BuildContext context, 37 | Widget child, 38 | AnimationController controller, 39 | EffectEntry entry, 40 | ) { 41 | Animation animation = entry.buildAnimation(controller); 42 | return getOptimizedBuilder( 43 | animation: animation, 44 | builder: (_, __) => DecoratedBox( 45 | decoration: BoxDecoration( 46 | boxShadow: [BoxShadow.lerp(begin, end, animation.value)!], 47 | borderRadius: borderRadius, 48 | ), 49 | child: child, 50 | ), 51 | ); 52 | } 53 | } 54 | 55 | /// Adds [BoxShadowEffect] related extensions to [AnimateManager]. 56 | extension BoxShadowEffectExtensions> on T { 57 | /// Adds a [BoxShadowEffect] which animates a [BoxShadow] between 58 | /// [begin] and [end] (via [DecoratedBox]). 59 | T boxShadow({ 60 | Duration? delay, 61 | Duration? duration, 62 | Curve? curve, 63 | BoxShadow? begin, 64 | BoxShadow? end, 65 | BorderRadius? borderRadius, 66 | }) => 67 | addEffect(BoxShadowEffect( 68 | delay: delay, 69 | duration: duration, 70 | curve: curve, 71 | begin: begin, 72 | end: end, 73 | borderRadius: borderRadius, 74 | )); 75 | } 76 | -------------------------------------------------------------------------------- /lib/src/effects/color_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that animates a [Color] between [begin] and [end], composited with 6 | /// the target using [blendMode] (via [ColorFiltered]). A color value of `null` 7 | /// will be interpreted as a fully transparent version of the other color. 8 | /// Defaults to `begin=null, end=Color(0x800099FF)`. 9 | /// 10 | /// [blendMode] defaults to [BlendMode.color]. 11 | /// Note that most blend modes in Flutter (including `color`) 12 | /// do not preserve the alpha channel correctly. See [BlendMode.srcATop] or 13 | /// [BlendMode.srcIn] for options that do maintain alpha. 14 | /// 15 | /// The following example animates from red to blue with a `multiply` blend: 16 | /// 17 | /// ``` 18 | /// Image.asset('assets/rainbow.jpg').animate() 19 | /// .color(begin: Colors.red, end: Colors.blue, blendMode: BlendMode.multiply) 20 | /// ``` 21 | /// 22 | /// See also: [TintEffect], which provides a simpler interface for single color 23 | /// tints. 24 | @immutable 25 | class ColorEffect extends Effect { 26 | static const Color? neutralValue = null; 27 | static const Color defaultValue = Color(0x800099FF); 28 | static const BlendMode defaultBlendMode = BlendMode.color; 29 | 30 | const ColorEffect({ 31 | super.delay, 32 | super.duration, 33 | super.curve, 34 | Color? begin, 35 | Color? end, 36 | this.blendMode, 37 | }) : super( 38 | begin: begin ?? neutralValue, 39 | end: end ?? (begin == null ? defaultValue : neutralValue), 40 | ); 41 | 42 | final BlendMode? blendMode; 43 | 44 | @override 45 | Widget build( 46 | BuildContext context, 47 | Widget child, 48 | AnimationController controller, 49 | EffectEntry entry, 50 | ) { 51 | Animation animation = entry.buildAnimation(controller); 52 | return getOptimizedBuilder( 53 | animation: animation, 54 | builder: (_, __) { 55 | Color color = ColorTween(begin: begin, end: end).evaluate(animation) ?? 56 | const Color(0x00000000); 57 | return ColorFiltered( 58 | colorFilter: ColorFilter.mode(color, blendMode ?? defaultBlendMode), 59 | child: child, 60 | ); 61 | }, 62 | ); 63 | } 64 | } 65 | 66 | /// Adds [ColorEffect] related extensions to [AnimateManager]. 67 | extension ColorEffectExtension> on T { 68 | /// Adds a [ColorEffect] that animates a [Color] between [begin] and [end], composited with 69 | /// the target using [blendMode] (via [ColorFiltered]). A color value of `null` 70 | /// will be interpreted as a fully transparent version of the other color. 71 | T color({ 72 | Duration? delay, 73 | Duration? duration, 74 | Curve? curve, 75 | Color? begin, 76 | Color? end, 77 | BlendMode? blendMode, 78 | }) => 79 | addEffect(ColorEffect( 80 | delay: delay, 81 | duration: duration, 82 | curve: curve, 83 | begin: begin, 84 | end: end, 85 | blendMode: blendMode, 86 | )); 87 | } 88 | -------------------------------------------------------------------------------- /lib/src/effects/crossfade_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that crossfades the incoming child (including preceeding effects) 6 | /// with a new widget (via [Stack] and [FadeTransition]). It uses a [builder] so 7 | /// that the effect can be reused, but note that the builder is only called once 8 | /// when the effect initially builds. 9 | /// 10 | /// [alignment] adjusts how the widgets are aligned if they are different sizes. 11 | /// Defaults to [Alignment.center]. 12 | @immutable 13 | class CrossfadeEffect extends Effect { 14 | static const Alignment defaultAlignment = Alignment.center; 15 | 16 | const CrossfadeEffect({ 17 | super.delay, 18 | super.duration, 19 | super.curve, 20 | required this.builder, 21 | this.alignment, 22 | }) : super( 23 | begin: 0, 24 | end: 1, 25 | ); 26 | 27 | final WidgetBuilder builder; 28 | final Alignment? alignment; 29 | 30 | @override 31 | Widget build( 32 | BuildContext context, 33 | Widget child, 34 | AnimationController controller, 35 | EffectEntry entry, 36 | ) { 37 | Animation animation = buildAnimation(controller, entry); 38 | return Stack( 39 | alignment: alignment ?? defaultAlignment, 40 | children: [ 41 | FadeTransition(opacity: ReverseAnimation(animation), child: child), 42 | FadeTransition(opacity: animation, child: builder(context)), 43 | ], 44 | ); 45 | } 46 | } 47 | 48 | /// Adds [CrossfadeEffect] related extensions to [AnimateManager]. 49 | extension CrossfadeEffectExtensions> on T { 50 | /// Adds a [CrossfadeEffect] that crossfades the incoming child (including preceeding effects) 51 | /// with a new widget (via [Stack] and [FadeTransition]). 52 | T crossfade({ 53 | Duration? delay, 54 | Duration? duration, 55 | Curve? curve, 56 | required WidgetBuilder builder, 57 | Alignment? alignment, 58 | }) => 59 | addEffect(CrossfadeEffect( 60 | delay: delay, 61 | duration: duration, 62 | curve: curve, 63 | builder: builder, 64 | alignment: alignment, 65 | )); 66 | } 67 | -------------------------------------------------------------------------------- /lib/src/effects/custom_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// Provide an easy way to add custom animated effects via a [builder] method that 6 | /// accepts a [BuildContext], target child, and calculated animation value 7 | /// between [begin] and [end]. 8 | /// 9 | /// For example, this would animate custom padding on the target from `0` to `40`. 10 | /// 11 | /// ``` 12 | /// foo.animate() 13 | /// .custom( 14 | /// duration: 1000.ms, 15 | /// end: 40, 16 | /// builder: (_, value, child) => 17 | /// Padding(padding: EdgeInsets.all(value), child: child) 18 | /// ) 19 | /// ``` 20 | /// 21 | /// Note that the above could also be accomplished in a more reusable way by 22 | /// creating a new [Effect] class. 23 | @immutable 24 | class CustomEffect extends Effect { 25 | const CustomEffect({ 26 | super.delay, 27 | super.duration, 28 | super.curve, 29 | double? begin, 30 | double? end, 31 | required this.builder, 32 | }) : super( 33 | begin: begin ?? 0.0, // Should this use "smart" defaults? 34 | end: end ?? 1.0, 35 | ); 36 | 37 | final CustomEffectBuilder builder; 38 | 39 | @override 40 | Widget build( 41 | BuildContext context, 42 | Widget child, 43 | AnimationController controller, 44 | EffectEntry entry, 45 | ) { 46 | Animation animation = buildAnimation(controller, entry); 47 | return getOptimizedBuilder( 48 | animation: animation, 49 | builder: (ctx, __) => builder(ctx, animation.value, child), 50 | ); 51 | } 52 | } 53 | 54 | /// Adds [CustomEffect] related extensions to [AnimateManager]. 55 | extension CustomEffectExtensions> on T { 56 | /// Adds a [CustomEffect] that animates effects via a [builder] method that 57 | /// accepts a [BuildContext], target child, and calculated animation value 58 | /// between [begin] and [end]. 59 | T custom({ 60 | required CustomEffectBuilder builder, 61 | Duration? delay, 62 | Duration? duration, 63 | Curve? curve, 64 | double? begin, 65 | double? end, 66 | }) => 67 | addEffect(CustomEffect( 68 | builder: builder, 69 | delay: delay, 70 | duration: duration, 71 | curve: curve, 72 | begin: begin, 73 | end: end, 74 | )); 75 | } 76 | 77 | typedef CustomEffectBuilder = Widget Function( 78 | BuildContext context, 79 | double value, 80 | Widget child, 81 | ); 82 | -------------------------------------------------------------------------------- /lib/src/effects/effects.dart: -------------------------------------------------------------------------------- 1 | // collects effect classes for easy import. 2 | export 'effect.dart'; 3 | 4 | export 'align_effect.dart'; 5 | export 'blur_effect.dart'; 6 | export 'box_shadow_effect.dart'; 7 | export 'callback_effect.dart'; 8 | export 'color_effect.dart'; 9 | export 'crossfade_effect.dart'; 10 | export 'custom_effect.dart'; 11 | export 'elevation_effect.dart'; 12 | export 'fade_effect.dart'; 13 | export 'flip_effect.dart'; 14 | export 'follow_path_effect.dart'; 15 | export 'listen_effect.dart'; 16 | export 'move_effect.dart'; 17 | export 'rotate_effect.dart'; 18 | export 'saturate_effect.dart'; 19 | export 'scale_effect.dart'; 20 | export 'shader_effect.dart'; 21 | export 'shake_effect.dart'; 22 | export 'shimmer_effect.dart'; 23 | export 'slide_effect.dart'; 24 | export 'swap_effect.dart'; 25 | export 'then_effect.dart'; 26 | export 'tint_effect.dart'; 27 | export 'toggle_effect.dart'; 28 | export 'visibility_effect.dart'; 29 | -------------------------------------------------------------------------------- /lib/src/effects/elevation_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that animates a Material elevation shadow between [begin] and [end] (via [PhysicalModel]). 6 | /// You can also specify a shadow [color] and [borderRadius] to add rounded corners. 7 | /// It defaults to `begin=0, end=8`. 8 | /// 9 | /// See [PhysicalModel] for more information. 10 | /// 11 | /// See also: [BoxShadowEffect] for more control over animated shadows. 12 | @immutable 13 | class ElevationEffect extends Effect { 14 | static const double neutralValue = 0.0; 15 | static const double defaultValue = 8.0; 16 | 17 | const ElevationEffect({ 18 | super.delay, 19 | super.duration, 20 | super.curve, 21 | double? begin, 22 | double? end, 23 | Color? color, 24 | this.borderRadius, 25 | }) : color = color ?? const Color(0xFF000000), 26 | super( 27 | begin: begin ?? neutralValue, 28 | end: end ?? (begin == null ? defaultValue : neutralValue), 29 | ); 30 | 31 | final Color color; 32 | final BorderRadius? borderRadius; 33 | 34 | @override 35 | Widget build( 36 | BuildContext context, 37 | Widget child, 38 | AnimationController controller, 39 | EffectEntry entry, 40 | ) { 41 | Animation animation = buildAnimation(controller, entry); 42 | return getOptimizedBuilder( 43 | animation: animation, 44 | builder: (_, __) => PhysicalModel( 45 | elevation: animation.value, 46 | shadowColor: color, 47 | color: const Color(0x00000000), 48 | borderRadius: borderRadius, 49 | child: child, 50 | ), 51 | ); 52 | } 53 | } 54 | 55 | /// Adds [ElevationEffect] related extensions to [AnimateManager]. 56 | extension ElevationEffectExtensions> on T { 57 | /// Adds an [ElevationEffect] that animates a Material elevation shadow between [begin] and [end] (via [PhysicalModel]). 58 | /// You can also specify a shadow [color] and [borderRadius] to add rounded corners. 59 | T elevation({ 60 | Duration? delay, 61 | Duration? duration, 62 | Curve? curve, 63 | double? begin, 64 | double? end, 65 | Color? color, 66 | BorderRadius? borderRadius, 67 | }) => 68 | addEffect(ElevationEffect( 69 | delay: delay, 70 | duration: duration, 71 | curve: curve, 72 | begin: begin, 73 | end: end, 74 | color: color, 75 | borderRadius: borderRadius, 76 | )); 77 | } 78 | -------------------------------------------------------------------------------- /lib/src/effects/fade_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// Animates the opacity of the target between the specified 6 | /// [begin] and [end] values (via [FadeTransition]). 7 | /// It defaults to `begin=0, end=1`. 8 | @immutable 9 | class FadeEffect extends Effect { 10 | static const double neutralValue = 1.0; 11 | static const double defaultValue = 0.0; 12 | 13 | const FadeEffect({ 14 | super.delay, 15 | super.duration, 16 | super.curve, 17 | double? begin, 18 | double? end, 19 | }) : super( 20 | begin: begin ?? (end == null ? defaultValue : neutralValue), 21 | end: end ?? neutralValue, 22 | ); 23 | 24 | @override 25 | Widget build( 26 | BuildContext context, 27 | Widget child, 28 | AnimationController controller, 29 | EffectEntry entry, 30 | ) { 31 | return FadeTransition( 32 | opacity: buildAnimation(controller, entry), 33 | child: child, 34 | ); 35 | } 36 | } 37 | 38 | /// Adds [FadeEffect] related extensions to [AnimateManager]. 39 | extension FadeEffectExtensions> on T { 40 | /// Adds a [FadeEffect] that animates the opacity of the target between the 41 | /// specified [begin] and [end] values (via [FadeTransition]). 42 | T fade({ 43 | Duration? delay, 44 | Duration? duration, 45 | Curve? curve, 46 | double? begin, 47 | double? end, 48 | }) => 49 | addEffect(FadeEffect( 50 | delay: delay, 51 | duration: duration, 52 | curve: curve, 53 | begin: begin, 54 | end: end, 55 | )); 56 | 57 | /// Adds a [FadeEffect] that animates the opacity of the target between the 58 | /// specified [begin] value and `1.0` (via [FadeTransition]). 59 | T fadeIn({ 60 | Duration? delay, 61 | Duration? duration, 62 | Curve? curve, 63 | double? begin, 64 | }) => 65 | addEffect(FadeEffect( 66 | delay: delay, 67 | duration: duration, 68 | curve: curve, 69 | begin: begin ?? FadeEffect.defaultValue, 70 | end: 1.0, 71 | )); 72 | 73 | /// Adds a [FadeEffect] that animates the opacity of the target between `0.0` 74 | /// and the specified [end] value (via [FadeTransition]). 75 | T fadeOut({ 76 | Duration? delay, 77 | Duration? duration, 78 | Curve? curve, 79 | double? begin, 80 | }) => 81 | addEffect(FadeEffect( 82 | delay: delay, 83 | duration: duration, 84 | curve: curve, 85 | begin: begin ?? FadeEffect.neutralValue, 86 | end: 0.0, 87 | )); 88 | } 89 | -------------------------------------------------------------------------------- /lib/src/effects/listen_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that calls a [callback] function with its current animation value 6 | /// between [begin] and [end]. 7 | /// 8 | /// By default, the callback will only be called while this effect is "active" 9 | /// (ie. after delay, and before duration) and will return a value between 0-1 10 | /// (unless the curve transforms it beyond this range). If [clamp] is set to `false`, 11 | /// the callback will be called on every tick while the enclosing [Animate] is 12 | /// running, and may return values outside its nominal range (ex. it will return a 13 | /// negative value before delay). 14 | /// 15 | /// This example will print the current animation value (which matches the value 16 | /// of the preceding fade effect's opacity value): 17 | /// 18 | /// ``` 19 | /// Text("Hello").animate().fadeIn(curve: Curves.easeOutExpo) 20 | /// .listen(callback: (value) => print('current opacity: $value')) 21 | /// ``` 22 | /// 23 | /// This can easily be used to drive a [ValueNotifier]: 24 | /// 25 | /// ``` 26 | /// ValueNotifier notifier = ValueNotifier(0); 27 | /// Text("Hello").animate() 28 | /// .fadeIn(delay: 400.ms, duration: 900.ms) 29 | /// .listen(callback: (value) => notifier.value) 30 | /// ``` 31 | /// 32 | /// See also: [CustomEffect] and [CallbackEffect]. 33 | @immutable 34 | class ListenEffect extends Effect { 35 | const ListenEffect({ 36 | super.delay, 37 | super.duration, 38 | super.curve, 39 | double? begin, 40 | double? end, 41 | required this.callback, 42 | this.clamp = true, 43 | }) : super( 44 | begin: begin ?? 0.0, // Should this use "smart" defaults? 45 | end: end ?? 1.0, 46 | ); 47 | 48 | final ValueChanged callback; 49 | final bool clamp; 50 | 51 | @override 52 | Widget build( 53 | BuildContext context, 54 | Widget child, 55 | AnimationController controller, 56 | EffectEntry entry, 57 | ) { 58 | // build an animation without a curve, so we get a linear 0-1 value back so we can determine start / end. 59 | Animation animation = entry.buildAnimation( 60 | controller, 61 | curve: Curves.linear, 62 | ); 63 | double prev = 0.0, begin = this.begin ?? 0.0, end = this.end ?? 1.0; 64 | animation.addListener(() { 65 | double value = animation.value; 66 | if (!clamp || value != prev) { 67 | callback(begin + (end - begin) * entry.curve.transform(value)); 68 | prev = value; 69 | } 70 | }); 71 | return child; 72 | } 73 | } 74 | 75 | /// Adds [ListenEffect] related extensions to [AnimateManager]. 76 | extension ListenEffectExtensions> on T { 77 | /// Adds a [ListenEffect] that calls a [callback] function with its current animation value 78 | /// between [begin] and [end]. 79 | T listen({ 80 | Duration? delay, 81 | Duration? duration, 82 | Curve? curve, 83 | double? begin, 84 | double? end, 85 | required ValueChanged callback, 86 | bool clamp = true, 87 | }) => 88 | addEffect(ListenEffect( 89 | delay: delay, 90 | duration: duration, 91 | curve: curve, 92 | begin: begin, 93 | end: end, 94 | callback: callback, 95 | clamp: clamp, 96 | )); 97 | } 98 | -------------------------------------------------------------------------------- /lib/src/effects/rotate_effect.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math' as math; 2 | 3 | import 'package:flutter/widgets.dart'; 4 | 5 | import '../../flutter_animate.dart'; 6 | 7 | /// Effect that rotates the target between [begin] and [end] (via [RotationTransition]). 8 | /// Values are specified in "turns" (360° or 2𝝅 radians), so a `begin=0.25, end=2.25` would start with the child 9 | /// rotated a quarter turn clockwise (90 degrees), and rotate two full turns (ending at 810 degrees). 10 | /// Defaults to `begin=-1.0, end=0`. 11 | /// 12 | /// [alignment] lets you set the origin of the rotation (the point around which the rotation 13 | /// will occur). For example an alignment of [Alignment.topLeft] would rotate around the top left 14 | /// corner of the child. Defaults to [Alignment.center]. 15 | @immutable 16 | class RotateEffect extends Effect { 17 | static const double neutralValue = 0.0; 18 | static const double defaultValue = -1.0; 19 | static const bool defaultTransformHitTests = true; 20 | 21 | const RotateEffect({ 22 | super.delay, 23 | super.duration, 24 | super.curve, 25 | double? begin, 26 | double? end, 27 | this.alignment, 28 | bool? transformHitTests, 29 | }) : transformHitTests = transformHitTests ?? defaultTransformHitTests, 30 | super( 31 | begin: begin ?? (end == null ? defaultValue : neutralValue), 32 | end: end ?? neutralValue, 33 | ); 34 | 35 | final Alignment? alignment; 36 | final bool transformHitTests; 37 | 38 | @override 39 | Widget build( 40 | BuildContext context, 41 | Widget child, 42 | AnimationController controller, 43 | EffectEntry entry, 44 | ) { 45 | Animation animation = buildAnimation(controller, entry); 46 | return getOptimizedBuilder( 47 | animation: animation, 48 | builder: (_, __) { 49 | return Transform.rotate( 50 | angle: animation.value * 2 * math.pi, 51 | alignment: alignment ?? Alignment.center, 52 | transformHitTests: transformHitTests, 53 | child: child, 54 | ); 55 | }, 56 | ); 57 | } 58 | } 59 | 60 | /// Adds [RotateEffect] related extensions to [AnimateManager]. 61 | extension RotateEffectExtensions> on T { 62 | /// Adds a [RotateEffect] that rotates the target between [begin] and [end] (via [RotationTransition]). 63 | /// Values are specified in "turns" (360° or 2𝝅 radians). 64 | T rotate({ 65 | Duration? delay, 66 | Duration? duration, 67 | Curve? curve, 68 | double? begin, 69 | double? end, 70 | Alignment? alignment, 71 | bool? transformHitTests, 72 | }) => 73 | addEffect(RotateEffect( 74 | delay: delay, 75 | duration: duration, 76 | curve: curve, 77 | begin: begin, 78 | end: end, 79 | alignment: alignment, 80 | transformHitTests: transformHitTests, 81 | )); 82 | } 83 | -------------------------------------------------------------------------------- /lib/src/effects/saturate_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that animates the color saturation of the target. The [begin] and 6 | /// [end] values indicate the saturation level, where `0` is fully desaturated 7 | /// (ie. grayscale) and `1` is normal saturation. Values `>1` will oversaturate. 8 | /// Defaults to `begin=0, end=1`. 9 | /// 10 | /// This example would fade from grayscale to full color: 11 | /// 12 | /// ``` 13 | /// Image.asset('assets/rainbow.jpg').animate() 14 | /// .saturate(duration: 2.seconds) 15 | /// ``` 16 | @immutable 17 | class SaturateEffect extends Effect { 18 | static const double neutralValue = 1.0; 19 | static const double defaultValue = 0.0; 20 | 21 | const SaturateEffect({ 22 | super.delay, 23 | super.duration, 24 | super.curve, 25 | double? begin, 26 | double? end, 27 | }) : super( 28 | begin: begin ?? (end == null ? defaultValue : neutralValue), 29 | end: end ?? neutralValue, 30 | ); 31 | 32 | @override 33 | Widget build( 34 | BuildContext context, 35 | Widget child, 36 | AnimationController controller, 37 | EffectEntry entry, 38 | ) { 39 | Animation animation = buildAnimation(controller, entry); 40 | return getOptimizedBuilder( 41 | animation: animation, 42 | builder: (_, __) => ColorFiltered( 43 | colorFilter: ColorFilter.matrix(getColorMatrix(animation.value)), 44 | child: child, 45 | ), 46 | ); 47 | } 48 | 49 | static List getColorMatrix(double saturation) { 50 | double r0 = 0.33 * (1 - saturation), r1 = saturation + r0; 51 | double g0 = 0.59 * (1 - saturation), g1 = saturation + g0; 52 | double b0 = 0.11 * (1 - saturation), b1 = saturation + b0; 53 | 54 | return [ 55 | r1, g0, b0, 0, 0, // r 56 | r0, g1, b0, 0, 0, // g 57 | r0, g0, b1, 0, 0, // b 58 | 0, 0, 0, 1, 0, // a 59 | ]; 60 | } 61 | } 62 | 63 | /// Adds [SaturateEffect] related extensions to [AnimateManager]. 64 | extension SaturateEffectExtensions> on T { 65 | /// Adds a [SaturateEffect] that animates the color saturation of the target. 66 | /// Defaults to a begin value of `0` (fully desaturated / grayscale) and 67 | /// an end value of `1` (normal saturation). 68 | T saturate({ 69 | Duration? delay, 70 | Duration? duration, 71 | Curve? curve, 72 | double? begin, 73 | double? end, 74 | }) => 75 | addEffect(SaturateEffect( 76 | delay: delay, 77 | duration: duration, 78 | curve: curve, 79 | begin: begin, 80 | end: end, 81 | )); 82 | 83 | /// Adds a [SaturateEffect] that animates the color saturation of the target. 84 | /// Defaults to a begin value of `1` (normal saturation) and 85 | /// an end value of `0` (fully desaturated / grayscale). 86 | T desaturate({ 87 | Duration? delay, 88 | Duration? duration, 89 | Curve? curve, 90 | double? begin, 91 | double? end, 92 | }) => 93 | addEffect(SaturateEffect( 94 | delay: delay, 95 | duration: duration, 96 | curve: curve, 97 | begin: begin ?? SaturateEffect.neutralValue, 98 | end: end ?? SaturateEffect.defaultValue, 99 | )); 100 | } 101 | -------------------------------------------------------------------------------- /lib/src/effects/slide_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that moves the target based on a fraction of its size 6 | /// per the specified [begin] and [end] offsets (via [SlideTransition]). 7 | /// Defaults to `begin=Offset(0, -0.5), end=Offset.zero` 8 | /// (slide down from half its height). 9 | /// 10 | /// See also: [MoveEffect] to use pixel offsets. 11 | @immutable 12 | class SlideEffect extends Effect { 13 | static const Offset neutralValue = Offset(neutralSlide, neutralSlide); 14 | static const Offset defaultValue = Offset(neutralSlide, defaultSlide); 15 | 16 | static const double neutralSlide = 0.0; 17 | static const double defaultSlide = -0.5; 18 | 19 | const SlideEffect({ 20 | super.delay, 21 | super.duration, 22 | super.curve, 23 | Offset? begin, 24 | Offset? end, 25 | }) : super( 26 | begin: begin ?? (end == null ? defaultValue : neutralValue), 27 | end: end ?? neutralValue, 28 | ); 29 | 30 | @override 31 | Widget build( 32 | BuildContext context, 33 | Widget child, 34 | AnimationController controller, 35 | EffectEntry entry, 36 | ) { 37 | return SlideTransition( 38 | position: buildAnimation(controller, entry), 39 | child: child, 40 | ); 41 | } 42 | } 43 | 44 | /// Adds [SlideEffect] related extensions to [AnimateManager]. 45 | extension SlideEffectExtensions> on T { 46 | /// Adds a [SlideEffect] that moves the target based on a fraction of its size 47 | /// per the specified [begin] and [end] offsets (via [SlideTransition]). 48 | T slide({ 49 | Duration? delay, 50 | Duration? duration, 51 | Curve? curve, 52 | Offset? begin, 53 | Offset? end, 54 | }) => 55 | addEffect(SlideEffect( 56 | delay: delay, 57 | duration: duration, 58 | curve: curve, 59 | begin: begin, 60 | end: end, 61 | )); 62 | 63 | /// Adds a [SlideEffect] that moves the target horizontally based on a fraction of its size 64 | /// per the specified [begin] and [end] values (via [SlideTransition]). 65 | T slideX({ 66 | Duration? delay, 67 | Duration? duration, 68 | Curve? curve, 69 | double? begin, 70 | double? end, 71 | }) { 72 | begin ??= end == null ? SlideEffect.defaultSlide : SlideEffect.neutralSlide; 73 | end ??= SlideEffect.neutralSlide; 74 | return addEffect(SlideEffect( 75 | delay: delay, 76 | duration: duration, 77 | curve: curve, 78 | begin: SlideEffect.neutralValue.copyWith(dx: begin), 79 | end: SlideEffect.neutralValue.copyWith(dx: end), 80 | )); 81 | } 82 | 83 | /// Adds a [SlideEffect] that moves the target vertically based on a fraction of its size 84 | /// per the specified [begin] and [end] values (via [SlideTransition]). 85 | T slideY({ 86 | Duration? delay, 87 | Duration? duration, 88 | Curve? curve, 89 | double? begin, 90 | double? end, 91 | }) { 92 | begin ??= end == null ? SlideEffect.defaultSlide : SlideEffect.neutralSlide; 93 | end ??= SlideEffect.neutralSlide; 94 | return addEffect(SlideEffect( 95 | delay: delay, 96 | duration: duration, 97 | curve: curve, 98 | begin: SlideEffect.neutralValue.copyWith(dy: begin), 99 | end: SlideEffect.neutralValue.copyWith(dy: end), 100 | )); 101 | } 102 | 103 | // Note: there is no slideXY because diagonal movement isn't a significant use case. 104 | } 105 | -------------------------------------------------------------------------------- /lib/src/effects/swap_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that swaps out the incoming child for a new child at a particular 6 | /// point in time. This includes all preceding effects. It uses a [builder] so 7 | /// that the effect can be reused, but note that the builder is only called once 8 | /// when the effect initially builds. 9 | /// 10 | /// For example, this would fade out `foo`, swap it for `Bar()` (including 11 | /// discarding the `fadeOut` effect) and apply a fade in effect. 12 | /// 13 | /// ``` 14 | /// foo.animate() 15 | /// .fadeOut(duration: 500.ms) 16 | /// .swap( // inherits duration from fadeOut 17 | /// builder: (_, __) => Bar().animate().fadeIn(), 18 | /// ) 19 | /// ``` 20 | /// 21 | /// It also includes the original child of the animation as a parameter of the 22 | /// builder. For example, normally fading out and then back in will not work 23 | /// as expected because both effects are active (ie. the 0 opacity from 24 | /// fading out is still applied), but you can work around this by beginning a 25 | /// new animation with the original child: 26 | /// 27 | /// ``` 28 | /// foo.animate() 29 | /// .fadeOut(duration: 500.ms) 30 | /// .swap( // inherits duration from fadeOut 31 | /// builder: (_, originalChild) => originalChild.animate().fadeIn(), 32 | /// ) 33 | /// ``` 34 | /// 35 | /// Note that the builder is returning a new [Animate] instance with its own 36 | /// [AnimationController]. So, for example, repeating the first animation (the 37 | /// fade out) via its controller will not affect the second animation (fade in). 38 | @immutable 39 | class SwapEffect extends Effect { 40 | const SwapEffect({ 41 | super.delay, 42 | super.duration, 43 | super.curve, 44 | required this.builder, 45 | }); 46 | 47 | final Widget Function(BuildContext, Widget) builder; 48 | 49 | @override 50 | Widget build( 51 | BuildContext context, 52 | Widget child, 53 | AnimationController controller, 54 | EffectEntry entry, 55 | ) { 56 | // instead of setting up an animation, we can optimize a bit to calculate the callback time once: 57 | double ratio = getEndRatio(controller, entry); 58 | Widget endChild = builder(context, entry.owner.child); 59 | 60 | // this could use toggleBuilder, but everything is pre-built, so this is simpler: 61 | return AnimatedBuilder( 62 | animation: controller, 63 | builder: (_, __) => (controller.value < ratio) ? child : endChild, 64 | ); 65 | } 66 | } 67 | 68 | /// Adds [SwapEffect] related extensions to [AnimateManager]. 69 | extension SwapEffectExtensions> on T { 70 | /// Adds a [SwapEffect] that swaps out the incoming child for a new child at a particular 71 | /// point in time. This includes all preceding effects. 72 | T swap({ 73 | Duration? delay, 74 | Duration? duration, 75 | required TransitionBuilder builder, 76 | }) => 77 | addEffect(SwapEffect( 78 | delay: delay, 79 | duration: duration, 80 | builder: builder, 81 | )); 82 | } 83 | -------------------------------------------------------------------------------- /lib/src/effects/then_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// A special convenience "effect" that makes it easier to sequence effects after 6 | /// one another. It does this by establishing a new baseline time equal to the 7 | /// previous effect's end time and its own optional [delay]. 8 | /// All subsequent effect delays are relative to this new baseline. 9 | /// 10 | /// This example demonstrates [ThenEffect] and how it interacts with [delay]: 11 | /// 12 | /// ``` 13 | /// Text("Hello").animate() 14 | /// .fadeIn(delay: 300.ms, duration: 500.ms) // end @ 800ms 15 | /// .then() // baseline=800ms (prior end) 16 | /// .slide(duration: 400.ms) // start @ 800ms, end @ 1200ms 17 | /// .then(delay: 300.ms) // baseline=1500ms (1200+300) 18 | /// .blur(delay: -150.ms) // start @ 1350ms (1500-150) 19 | /// .tint() // start @ 1350ms (inherited) 20 | /// .shake(delay: 0.ms) // start @ 1500ms (1500+0) 21 | /// ``` 22 | @immutable 23 | class ThenEffect extends Effect { 24 | // NOTE: this is just an empty effect, the logic happens in Animate 25 | // when it recognizes the type. 26 | const ThenEffect({super.delay, super.duration, super.curve}); 27 | } 28 | 29 | /// Adds [ThenEffect] related extensions to [AnimateManager]. 30 | extension ThenEffectExtensions> on T { 31 | /// Adds a [ThenEffect] that makes it easier to sequence effects after 32 | /// one another. It does this by establishing a new baseline time equal to the 33 | /// previous effect's end time and its own optional [delay]. 34 | /// All subsequent effect delays are relative to this new baseline. 35 | T then({Duration? delay, Duration? duration, Curve? curve}) => 36 | addEffect(ThenEffect(delay: delay, duration: duration, curve: curve)); 37 | } 38 | -------------------------------------------------------------------------------- /lib/src/effects/tint_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that applies an animated [color] tint to the target (via [ColorFiltered]). 6 | /// The [begin] and [end] values indicate the strength of the tint (0 - 0% tint, 1 - 100% tint). 7 | /// Defaults to `begin=0, end=1`. 8 | /// 9 | /// The default [color] is opaque black (`Color(0xFF000000)`). 10 | /// The opacity of [color] is multiplied against the strength. 11 | /// For example, `Colors.black54` at strength `0.5` would apply a 27% 12 | /// black tint. 13 | /// 14 | /// This example would animate in a 50% blue tint over 2 seconds: 15 | /// 16 | /// ``` 17 | /// Image.asset('assets/rainbow.jpg').animate() 18 | /// .tint(color: Colors.blue, end: 0.5, duration: 2.seconds) 19 | /// ``` 20 | /// 21 | /// See also: [ColorEffect], which animates between two different colors, and 22 | /// supports blend modes. 23 | @immutable 24 | class TintEffect extends Effect { 25 | static const double neutralValue = 0.0; 26 | static const double defaultValue = 1.0; 27 | 28 | const TintEffect({ 29 | super.delay, 30 | super.duration, 31 | super.curve, 32 | double? begin, 33 | double? end, 34 | Color? color, 35 | }) : color = color ?? const Color(0xFF000000), 36 | super( 37 | begin: begin ?? neutralValue, 38 | end: end ?? (begin == null ? defaultValue : neutralValue), 39 | ); 40 | 41 | final Color color; 42 | 43 | @override 44 | Widget build( 45 | BuildContext context, 46 | Widget child, 47 | AnimationController controller, 48 | EffectEntry entry, 49 | ) { 50 | Animation animation = buildAnimation(controller, entry); 51 | return getOptimizedBuilder( 52 | animation: animation, 53 | builder: (_, __) => ColorFiltered( 54 | colorFilter: ColorFilter.matrix(getTintMatrix(animation.value, color)), 55 | child: child, 56 | ), 57 | ); 58 | } 59 | 60 | static List getTintMatrix(double strength, Color color) { 61 | double v = 1 - strength * color.alpha / 255; 62 | 63 | return [ 64 | v, 0, 0, 0, color.red * (1 - v), // r 65 | 0, v, 0, 0, color.green * (1 - v), // g 66 | 0, 0, v, 0, color.blue * (1 - v), // b 67 | 0, 0, 0, 1, 0, // a 68 | ]; 69 | } 70 | } 71 | 72 | /// Adds [TintEffect] related extensions to [AnimateManager]. 73 | extension TintEffectExtensions> on T { 74 | /// Adds a [TintEffect] that applies an animated [color] tint to the target (via [ColorFiltered]). 75 | /// Defaults to a begin value of `0` (0% tint) and an end value of `1` (100% tint). 76 | T tint({ 77 | Duration? delay, 78 | Duration? duration, 79 | Curve? curve, 80 | double? begin, 81 | double? end, 82 | Color? color, 83 | }) => 84 | addEffect(TintEffect( 85 | delay: delay, 86 | duration: duration, 87 | curve: curve, 88 | begin: begin, 89 | end: end, 90 | color: color, 91 | )); 92 | 93 | /// Adds a [TintEffect] that applies an animated [color] tint to the target (via [ColorFiltered]). 94 | /// Defaults to a begin value of `1` (100% tint) and an end value of `0` (0% tint). 95 | T untint({ 96 | Duration? delay, 97 | Duration? duration, 98 | Curve? curve, 99 | double? begin, 100 | double? end, 101 | Color? color, 102 | }) => 103 | addEffect(TintEffect( 104 | delay: delay, 105 | duration: duration, 106 | curve: curve, 107 | begin: begin ?? 1.0, 108 | end: end ?? TintEffect.neutralValue, 109 | color: color, 110 | )); 111 | } 112 | -------------------------------------------------------------------------------- /lib/src/effects/toggle_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that allows you to toggle the behavior of a [builder] function at a certain 6 | /// point in time. 7 | /// 8 | /// ``` 9 | /// Animate().toggle(duration: 500.ms, builder: (_, value, __) => 10 | /// Text('${value ? "Before Delay" : "After Delay"}')) 11 | /// ``` 12 | /// 13 | /// This is also useful for triggering animation in "Animated" widgets. 14 | /// 15 | /// ``` 16 | /// foo.animate().toggle(duration: 500.ms, builder: (_, value, child) => 17 | /// AnimatedOpacity(opacity: value ? 0 : 1, child: child)) 18 | /// ``` 19 | /// 20 | /// The child of `Animate` is passed through to the builder in the `child` param 21 | /// (possibly already wrapped by prior effects). 22 | @immutable 23 | class ToggleEffect extends Effect { 24 | const ToggleEffect({ 25 | super.delay, 26 | super.duration, 27 | super.curve, 28 | required this.builder, 29 | }); 30 | 31 | final ToggleEffectBuilder builder; 32 | 33 | @override 34 | Widget build( 35 | BuildContext context, 36 | Widget child, 37 | AnimationController controller, 38 | EffectEntry entry, 39 | ) { 40 | double ratio = getEndRatio(controller, entry); 41 | return getToggleBuilder( 42 | animation: controller, 43 | child: child, 44 | toggle: () => controller.value < ratio, 45 | builder: builder, 46 | ); 47 | } 48 | } 49 | 50 | /// Adds [ToggleEffect] related extensions to [AnimateManager]. 51 | extension ToggleEffectExtensions> on T { 52 | /// Adds a [ToggleEffect] that allows you to toggle the behavior of a [builder] function at a certain 53 | /// point in time. 54 | T toggle({ 55 | Duration? delay, 56 | Duration? duration, 57 | required ToggleEffectBuilder builder, 58 | }) => 59 | addEffect(ToggleEffect( 60 | delay: delay, 61 | duration: duration, 62 | builder: builder, 63 | )); 64 | } 65 | 66 | typedef ToggleEffectBuilder = Widget Function( 67 | BuildContext context, 68 | bool value, 69 | Widget child, 70 | ); 71 | -------------------------------------------------------------------------------- /lib/src/effects/visibility_effect.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | import '../../flutter_animate.dart'; 4 | 5 | /// An effect that toggles the visibility of the target (via [Visibility]). 6 | /// Defaults to `end=true`. 7 | /// 8 | /// [maintain] is assigned to the [Visibility] properties `maintainSize`, 9 | /// `maintainAnimation`, `maintainState`, `maintainInteractivity` and `maintainSemantics`. 10 | /// It defaults to `null`. 11 | @immutable 12 | class VisibilityEffect extends Effect { 13 | static const bool neutralValue = true; 14 | 15 | static const bool defaultMaintain = true; 16 | 17 | const VisibilityEffect({ 18 | super.delay, 19 | super.duration, 20 | super.curve, 21 | bool? end, 22 | bool? maintain, 23 | }) : maintain = maintain ?? defaultMaintain, 24 | super( 25 | begin: !(end ?? neutralValue), 26 | end: end ?? neutralValue, 27 | ); 28 | 29 | final bool maintain; 30 | 31 | @override 32 | Widget build(BuildContext context, Widget child, 33 | AnimationController controller, EffectEntry entry) { 34 | double ratio = getEndRatio(controller, entry); 35 | return getToggleBuilder( 36 | animation: controller, 37 | child: child, 38 | toggle: () => begin! == (controller.value < ratio), 39 | builder: (_, b, __) => Visibility( 40 | visible: b, 41 | maintainSize: maintain, 42 | maintainAnimation: maintain, 43 | maintainState: maintain, 44 | maintainSemantics: maintain, 45 | maintainInteractivity: maintain, 46 | child: child, 47 | ), 48 | ); 49 | } 50 | } 51 | 52 | /// Adds [VisibilityEffect] related extensions to [AnimateManager]. 53 | extension VisibilityEffectExtensions> on T { 54 | /// Adds a [VisibilityEffect] that toggles the visibility of the target (via [Visibility]). 55 | T visibility({ 56 | Duration? delay, 57 | Duration? duration, 58 | bool? end, 59 | bool? maintain, 60 | }) => 61 | addEffect(VisibilityEffect( 62 | delay: delay, 63 | duration: duration, 64 | end: end, 65 | maintain: maintain, 66 | )); 67 | 68 | /// Adds a [VisibilityEffect] that toggles the visibility of the target to `true` (via [Visibility]). 69 | T show({ 70 | Duration? delay, 71 | Duration? duration, 72 | bool? maintain, 73 | }) => 74 | addEffect(VisibilityEffect( 75 | delay: delay, 76 | duration: duration, 77 | end: true, 78 | maintain: maintain, 79 | )); 80 | 81 | /// Adds a [VisibilityEffect] that toggles the visibility of the target to `false` (via [Visibility]). 82 | T hide({ 83 | Duration? delay, 84 | Duration? duration, 85 | bool? maintain, 86 | }) => 87 | addEffect(VisibilityEffect( 88 | delay: delay, 89 | duration: duration, 90 | end: false, 91 | maintain: maintain, 92 | )); 93 | } 94 | -------------------------------------------------------------------------------- /lib/src/extensions/animation_controller_loop_extensions.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | /// Adds a [loop] extension on [AnimationController] identical to [repeat] but 4 | /// adding a `count` parameter specifying how many times to repeat before stopping: 5 | /// 6 | /// - `count = null`: the animation loops infinitely 7 | /// - `count = 0`: the animation won't play 8 | /// - `count > 0`: the animation will play `count` times 9 | /// 10 | /// The total time will always be `count * duration` (or `count * period` if specified). 11 | /// Therefore, if `reverse` is true, one "count" is still considered animating in a single direction. 12 | /// 13 | /// For example, the following would play forward (fade in) and back (fade out) once, then stop: 14 | /// 15 | /// ``` 16 | /// Text('Hello World').animate( 17 | /// onPlay: (controller) => controller.loop( 18 | /// reverse: true, 19 | /// count: 2, 20 | /// ), 21 | /// ).fadeIn(); 22 | /// ``` 23 | extension AnimationControllerLoopExtensions on AnimationController { 24 | TickerFuture loop({ 25 | int? count, 26 | bool reverse = false, 27 | double? min, 28 | double? max, 29 | Duration? period, 30 | }) { 31 | assert(count == null || count >= 0); 32 | assert(period != null || duration != null); 33 | 34 | min ??= lowerBound; 35 | max ??= upperBound; 36 | period ??= duration; 37 | 38 | if (count == 0) return animateTo(min, duration: Duration.zero); 39 | 40 | final tickerFuture = repeat( 41 | min: min, 42 | max: max, 43 | reverse: reverse, 44 | period: period, 45 | ); 46 | 47 | if (count != null) { 48 | // timeout ~1 tick before it should complete (@120hz): 49 | int t = period!.inMilliseconds * count - 8; 50 | tickerFuture.timeout(Duration(milliseconds: t), onTimeout: () async { 51 | if (isAnimating) animateTo(reverse && count.isEven ? min! : max!); 52 | }); 53 | } 54 | 55 | return tickerFuture; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /lib/src/extensions/extensions.dart: -------------------------------------------------------------------------------- 1 | // collects extensions for easy import. 2 | export 'animation_controller_loop_extensions.dart'; 3 | export 'num_duration_extensions.dart'; 4 | export 'offset_copy_with_extensions.dart'; 5 | -------------------------------------------------------------------------------- /lib/src/extensions/num_duration_extensions.dart: -------------------------------------------------------------------------------- 1 | /// Adds extensions to num (ie. int & double) to make creating durations simple: 2 | /// 3 | /// ``` 4 | /// 200.ms // equivalent to Duration(milliseconds: 200) 5 | /// 3.seconds // equivalent to Duration(milliseconds: 3000) 6 | /// 1.5.days // equivalent to Duration(hours: 36) 7 | /// ``` 8 | extension NumDurationExtensions on num { 9 | Duration get microseconds => Duration(microseconds: round()); 10 | Duration get ms => (this * 1000).microseconds; 11 | Duration get milliseconds => (this * 1000).microseconds; 12 | Duration get seconds => (this * 1000 * 1000).microseconds; 13 | Duration get minutes => (this * 1000 * 1000 * 60).microseconds; 14 | Duration get hours => (this * 1000 * 1000 * 60 * 60).microseconds; 15 | Duration get days => (this * 1000 * 1000 * 60 * 60 * 24).microseconds; 16 | } 17 | -------------------------------------------------------------------------------- /lib/src/extensions/offset_copy_with_extensions.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | 3 | /// Adds a `copyWith` method to Offset. 4 | extension OffsetCopyWithExtensions on Offset { 5 | Offset copyWith({double? dx, double? dy}) => 6 | Offset(dx ?? this.dx, dy ?? this.dy); 7 | } 8 | -------------------------------------------------------------------------------- /lib/src/flutter_animate.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | import '../flutter_animate.dart'; 3 | 4 | /// Provides a common interface for [Animate] and [AnimateList] to attach [Effect] extensions. 5 | mixin AnimateManager { 6 | T addEffect(Effect effect) => throw (UnimplementedError()); 7 | T addEffects(List effects) { 8 | for (Effect o in effects) { 9 | addEffect(o); 10 | } 11 | return this as T; 12 | } 13 | } 14 | 15 | /// Because [Effect] classes are immutable and may be reused between multiple 16 | /// [Animate] (or [AnimateList]) instances, an [EffectEntry] is created to store 17 | /// values that may be different between instances. For example, due to an 18 | /// `interval` on `AnimateList`, or from inheriting timing parameters. 19 | @immutable 20 | class EffectEntry { 21 | const EffectEntry({ 22 | required this.effect, 23 | required this.delay, 24 | required this.duration, 25 | required this.curve, 26 | required this.owner, 27 | }); 28 | 29 | /// The delay for this entry. 30 | final Duration delay; 31 | 32 | /// The duration for this entry. 33 | final Duration duration; 34 | 35 | /// The curve used by this entry. 36 | final Curve curve; 37 | 38 | /// The effect associated with this entry. 39 | final Effect effect; 40 | 41 | /// The [Animate] instance that created this entry. This can be used by effects 42 | /// to read information about the animation. Effects _should not_ modify 43 | /// the animation (ex. by calling [Animate.addEffect]). 44 | final Animate owner; 45 | 46 | /// The begin time for this entry. 47 | Duration get begin => delay; 48 | 49 | /// The end time for this entry. 50 | Duration get end => delay + duration; 51 | 52 | /// Builds a sub-animation based on the properties of this entry. 53 | Animation buildAnimation( 54 | AnimationController controller, { 55 | Curve? curve, 56 | }) { 57 | int ttlT = controller.duration?.inMicroseconds ?? 0; 58 | int beginT = begin.inMicroseconds, endT = end.inMicroseconds; 59 | return CurvedAnimation( 60 | parent: controller, 61 | curve: Interval(beginT / ttlT, endT / ttlT, curve: curve ?? this.curve), 62 | ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /lib/src/warn.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/foundation.dart'; 2 | 3 | warn(bool condition, String message) { 4 | if (condition) return; 5 | debugPrint('${_bg(229)}${_fg(0)}[flutter_animate] $message$_reset'); 6 | } 7 | 8 | // generate the control codes to set console colors: 9 | String _bg(int color) => '\x1B[48;5;${color}m'; 10 | String _fg(int color) => '\x1B[38;5;${color}m'; 11 | String _reset = '\x1B[0m'; 12 | 13 | /* 14 | printColorTest() { 15 | String str = ''; 16 | for (int i=0; i<256; i++) { 17 | str += '\x1B[48;5;${i}m$i '; 18 | } 19 | debugPrint(str); 20 | } 21 | */ 22 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_animate 2 | description: Add beautiful animated effects & builders in Flutter, via an easy, customizable, unified API. 3 | version: 4.5.2 4 | repository: https://github.com/gskinner/flutter_animate 5 | issue_tracker: https://github.com/gskinner/flutter_animate/issues 6 | topics: 7 | - animation 8 | - ui 9 | - effects 10 | - widgets 11 | - widget 12 | 13 | environment: 14 | sdk: ">=2.17.0 <4.0.0" 15 | flutter: ">=2.0.0" 16 | 17 | dependencies: 18 | flutter: 19 | sdk: flutter 20 | flutter_shaders: ^0.1.2 21 | 22 | dev_dependencies: 23 | flutter_test: 24 | sdk: flutter 25 | flutter_lints: ^2.0.0 26 | 27 | flutter: 28 | -------------------------------------------------------------------------------- /test/animate_list_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import 'tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('AnimateList: core', (tester) async { 9 | var items = const [Spacer(), FlutterLogo(), FlutterLogo()]; 10 | items = items.animate( 11 | effects: [FadeEffect(duration: 1000.ms)], 12 | interval: AnimateList.defaultInterval, 13 | ); 14 | 15 | var widget = Column(children: items); 16 | await tester.pumpAnimation(widget, initialDelay: 500.ms); 17 | 18 | // this should find two Animate instances, because Spacer is in AnimateList.ignoreTypes: 19 | expect( 20 | find.byType(Animate), 21 | findsNWidgets(2), 22 | reason: 'correct item count', 23 | ); 24 | 25 | // verify that the animations are running: 26 | tester.expectWidgetWithDouble( 27 | (o) => o.opacity.value, 0.5, 'opacity'); 28 | 29 | // test list functions: 30 | expect(items[0], isA(), reason: 'get item'); 31 | expect(items.length, 3, reason: 'get length'); 32 | items.length = 2; 33 | expect(items.length, 2, reason: 'set length'); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/core_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_animate/src/warn.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | import 'package:flutter_animate/flutter_animate.dart'; 5 | 6 | import 'tester_extensions.dart'; 7 | 8 | void main() { 9 | // can really only test if warn throws an error: 10 | test('warn', () async { 11 | warn(false, 'testing warn()'); 12 | }); 13 | 14 | testWidgets('curved tween w/ 1000s duration', (tester) async { 15 | const curve = Curves.easeOut; 16 | final animation = const FlutterLogo() 17 | .animate() 18 | .fade(begin: .25, end: .75, duration: 1000.ms, curve: curve); 19 | // wait 500ms and check middle pos 20 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 21 | double expectedValue = .25 + curve.transform(.5) * .5; 22 | tester.expectWidgetWithDouble( 23 | (w) => w.opacity.value, expectedValue, 'opacity'); 24 | // wait another 500ms and check end pos 25 | await tester.pump(500.ms); 26 | expectedValue = .25 + curve.transform(1) * .5; 27 | tester.expectWidgetWithDouble( 28 | (w) => w.opacity.value, expectedValue, 'opacity'); 29 | }); 30 | 31 | testWidgets('linear tween w/ 500ms duration', (tester) async { 32 | final animation = const FlutterLogo() 33 | .animate() 34 | .fade(begin: .25, end: .75, duration: 500.ms); 35 | await tester.pumpAnimation(animation, initialDelay: 250.ms); 36 | // check halfway 37 | tester.expectWidgetWithDouble( 38 | (w) => w.opacity.value, .5, 'opacity'); 39 | // check end 40 | await tester.pump(250.ms); 41 | tester.expectWidgetWithDouble( 42 | (w) => w.opacity.value, .75, 'opacity'); 43 | }); 44 | 45 | testWidgets('delayed tween', (tester) async { 46 | final animation = const FlutterLogo() 47 | .animate() 48 | .fade(delay: 1.seconds, duration: 1.seconds); 49 | 50 | // Wait and expect it hasn't started yet 51 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 52 | tester.expectWidgetWithDouble( 53 | (w) => w.opacity.value, 0, 'opacity'); 54 | 55 | // Wait and expect it is now half-way through 56 | await tester.pump(1000.ms); 57 | tester.expectWidgetWithDouble( 58 | (w) => w.opacity.value, .5, 'opacity'); 59 | }); 60 | 61 | testWidgets('delayed animate', (tester) async { 62 | // use a 1 second delay and 1 second duration 63 | final animation = 64 | const FlutterLogo().animate(delay: 1.seconds).fade(duration: 1.seconds); 65 | 66 | // Wait 500ms expect it hasn't started yet 67 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 68 | tester.expectWidgetWithDouble( 69 | (w) => w.opacity.value, 0, 'opacity'); 70 | 71 | // Wait 1s expect it is now half-way through (two pumps are required to get the delay to fire) 72 | await tester.pump(500.ms); 73 | await tester.pump(500.ms); 74 | tester.expectWidgetWithDouble( 75 | (w) => w.opacity.value, .5, 'opacity'); 76 | }); 77 | } 78 | -------------------------------------------------------------------------------- /test/effects/align_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('AlignEffect: align', (tester) async { 9 | final animation = const FlutterLogo().animate().align( 10 | duration: 1000.ms, 11 | begin: Alignment.topLeft, 12 | end: Alignment.bottomRight, 13 | ); 14 | 15 | // check halfway 16 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 17 | tester.expectWidgetWithDouble( 18 | (o) => (o.alignment as Alignment).x, 0.0, 'x'); 19 | tester.expectWidgetWithDouble( 20 | (o) => (o.alignment as Alignment).y, 0.0, 'y'); 21 | }); 22 | } 23 | 24 | _verifyMove(WidgetTester tester, double x, double y) async { 25 | tester.expectWidgetWithDouble( 26 | (o) => o.transform.getTranslation().x, x, 'x'); 27 | tester.expectWidgetWithDouble( 28 | (o) => o.transform.getTranslation().y, y, 'y'); 29 | } 30 | 31 | const double _moveAmt = 100; 32 | -------------------------------------------------------------------------------- /test/effects/blur_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('BlurEffect: blur', (tester) async { 9 | final animation = const FlutterLogo().animate().blur( 10 | begin: Offset.zero, 11 | end: const Offset(_blurAmt, _blurAmt), 12 | duration: 1000.ms, 13 | ); 14 | 15 | // Check halfway: 16 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 17 | _verifyBlur(tester, _blurAmt / 2, _blurAmt / 2); 18 | }); 19 | 20 | testWidgets('BlurEffect: blurXY', (tester) async { 21 | final animation = const FlutterLogo().animate().blurXY( 22 | end: _blurAmt, 23 | duration: 1000.ms, 24 | ); 25 | 26 | // Check halfway: 27 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 28 | _verifyBlur(tester, _blurAmt / 2, _blurAmt / 2); 29 | }); 30 | 31 | testWidgets('BlurEffect: blurX', (tester) async { 32 | final animation = const FlutterLogo().animate().blurX( 33 | end: _blurAmt, 34 | duration: 1000.ms, 35 | ); 36 | 37 | // Check halfway: 38 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 39 | _verifyBlur(tester, _blurAmt / 2, BlurEffect.minBlur); 40 | }); 41 | 42 | testWidgets('BlurEffect: blurY', (tester) async { 43 | final animation = const FlutterLogo().animate().blurY( 44 | end: _blurAmt, 45 | duration: 1000.ms, 46 | ); 47 | 48 | // Check halfway: 49 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 50 | _verifyBlur(tester, BlurEffect.minBlur, _blurAmt / 2); 51 | }); 52 | } 53 | 54 | _verifyBlur(WidgetTester tester, double x, double y) async { 55 | expect( 56 | tester.widget(find.byType(ImageFiltered).last), 57 | isA() 58 | .having((o) => (o.imageFilter as dynamic).sigmaX, 'sigmaX', x), 59 | ); 60 | expect( 61 | tester.widget(find.byType(ImageFiltered).last), 62 | isA() 63 | .having((o) => (o.imageFilter as dynamic).sigmaY, 'sigmaY', y), 64 | ); 65 | } 66 | 67 | const double _blurAmt = 10; 68 | -------------------------------------------------------------------------------- /test/effects/box_shadow_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('BoxShadowEffect: core', (tester) async { 9 | BoxShadow? begin; 10 | BoxShadow end = const BoxShadow(blurRadius: 32, color: Colors.red); 11 | BorderRadius borderRadius = BorderRadius.circular(8); 12 | 13 | // uses a Placeholder instead of FlutterLogo because the latter apparently has its own DecoratedBox 14 | final animation = const Placeholder().animate().boxShadow( 15 | duration: 1000.ms, 16 | borderRadius: borderRadius, 17 | begin: begin, 18 | end: end, 19 | ); 20 | 21 | // Check middle: 22 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 23 | var expected = BoxShadow.lerp(begin, end, 0.5); 24 | tester.expectWidgetWithBool( 25 | (o) => (o.decoration as BoxDecoration).boxShadow?.first == expected, 26 | true, 27 | 'boxShadow', 28 | ); 29 | tester.expectWidgetWithBool( 30 | (o) => (o.decoration as BoxDecoration).borderRadius == borderRadius, 31 | true, 32 | 'borderRadius', 33 | ); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/effects/callback_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | /// Checks that callbacks do get called, and that they get called at the correct time 9 | testWidgets('CallbackEffect: callback twice while fading', (tester) async { 10 | int callbackCount = 0; 11 | final animation = const FlutterLogo() 12 | .animate() 13 | .effect(duration: 1000.ms) 14 | // Register a callback halfway, 15 | .callback(duration: 500.ms, callback: (_) => callbackCount++) 16 | // Register another callback at the end 17 | .callback(duration: 1000.ms, callback: (_) => callbackCount++); 18 | 19 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 20 | expect(callbackCount, 1); 21 | await tester.pump(500.ms); 22 | expect(callbackCount, 2); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /test/effects/color_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('ColorEffect: core', (tester) async { 9 | BlendMode blend = BlendMode.colorDodge; 10 | Color begin = Colors.blue, end = Colors.red; 11 | 12 | final animation = const FlutterLogo().animate().color( 13 | duration: 1000.ms, 14 | blendMode: blend, 15 | begin: begin, 16 | end: end, 17 | ); 18 | 19 | // Check begin: 20 | await tester.pumpAnimation(animation); 21 | tester.expectWidgetWithBool( 22 | (o) => o.colorFilter == ColorFilter.mode(begin, blend), 23 | true, 24 | 'colorFilter @ 0%', 25 | ); 26 | 27 | // Check end: 28 | await tester.pump(1000.ms); 29 | tester.expectWidgetWithBool( 30 | (o) => o.colorFilter == ColorFilter.mode(end, blend), 31 | true, 32 | 'colorFilter @ 100%', 33 | ); 34 | }); 35 | } 36 | -------------------------------------------------------------------------------- /test/effects/crossfade_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('CrossfadeEffect: core', (tester) async { 9 | Widget beginChild = const FlutterLogo(), endChild = const Placeholder(); 10 | final anim = beginChild.animate().crossfade( 11 | duration: 1000.ms, 12 | delay: 0.ms, 13 | builder: (_) => endChild, 14 | ); 15 | 16 | // At begin, expect beginChild is 100% opaque, endChild is 0% 17 | await tester.pumpAnimation(anim); 18 | tester.expectWidgetWithDouble( 19 | (o) => o.opacity.value, 20 | 1, 21 | 'beginChild opacity @ 0%', 22 | findFirst: true, 23 | ); 24 | tester.expectWidgetWithDouble( 25 | (o) => o.opacity.value, 26 | 0, 27 | 'endChild opacity @ 0%', 28 | findFirst: false, 29 | ); 30 | 31 | // At middle, expect beginChild is 50% opaque, endChild is 50% 32 | await tester.pump(500.ms); 33 | tester.expectWidgetWithDouble( 34 | (o) => o.opacity.value, 35 | 0.5, 36 | 'beginChild opacity @ 50%', 37 | findFirst: true, 38 | ); 39 | tester.expectWidgetWithDouble( 40 | (o) => o.opacity.value, 41 | 0.5, 42 | 'endChild opacity @ 50%', 43 | findFirst: false, 44 | ); 45 | 46 | // At end, expect beginChild is 0% opaque, endChild is 100% 47 | await tester.pump(500.ms); 48 | tester.expectWidgetWithDouble( 49 | (o) => o.opacity.value, 50 | 0, 51 | 'beginChild opacity @ 100%', 52 | findFirst: true, 53 | ); 54 | tester.expectWidgetWithDouble( 55 | (o) => o.opacity.value, 56 | 1, 57 | 'endChild opacity @ 100%', 58 | findFirst: false, 59 | ); 60 | }); 61 | } 62 | -------------------------------------------------------------------------------- /test/effects/custom_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_animate/flutter_animate.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('CustomEffect: core', (tester) async { 9 | final animation = const SizedBox().animate().custom( 10 | duration: 1000.ms, 11 | end: 40, 12 | builder: (_, value, child) => 13 | Padding(padding: EdgeInsets.all(value), child: child), 14 | ); 15 | 16 | // check halfway 17 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 18 | tester.expectWidgetWithDouble( 19 | (o) => (o.padding as EdgeInsets).top, 20, 'padding @ 50%'); 20 | 21 | // check end 22 | await tester.pump(500.ms); 23 | tester.expectWidgetWithDouble( 24 | (o) => (o.padding as EdgeInsets).top, 40, 'padding @ 100%'); 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /test/effects/effect_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('Effect: inherit duration', (tester) async { 9 | final animation = 10 | const FlutterLogo().animate().effect(duration: 1000.ms).moveX(end: 100); 11 | 12 | // check halfway 13 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 14 | tester.expectWidgetWithDouble( 15 | (o) => o.transform.getTranslation().x, 50, 'x @ 50%'); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /test/effects/elevation_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('ElevationEffect: core', (tester) async { 9 | double begin = 4, end = 32; 10 | 11 | final animation = const FlutterLogo().animate().elevation( 12 | duration: 1000.ms, 13 | begin: begin, 14 | end: end, 15 | ); 16 | 17 | // Check begin: 18 | await tester.pumpAnimation(animation); 19 | tester.expectWidgetWithBool( 20 | (o) => o.elevation == begin, true, 'elevation @ 0%'); 21 | 22 | // Check end: 23 | await tester.pump(1000.ms); 24 | tester.expectWidgetWithBool( 25 | (o) => o.elevation == end, true, 'elevation @ 100%'); 26 | }); 27 | } 28 | -------------------------------------------------------------------------------- /test/effects/fade_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('FadeEffect: core', (tester) async { 9 | final animation = const FlutterLogo().animate().fade(duration: 1000.ms); 10 | 11 | // check halfway 12 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 13 | tester.expectWidgetWithDouble( 14 | (o) => o.opacity.value, 0.5, 'opacity'); 15 | }); 16 | } 17 | -------------------------------------------------------------------------------- /test/effects/flip_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('FlipEffect: flip', (tester) async { 9 | Axis direction = Axis.vertical; 10 | final animation = const FlutterLogo().animate().flip( 11 | duration: 1000.ms, 12 | direction: direction, 13 | perspective: _perspective, 14 | begin: 0, 15 | end: 1, 16 | ); 17 | 18 | // Check halfway, 19 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 20 | _verifyPerspective(tester, direction); 21 | }); 22 | 23 | testWidgets('FlipEffect: flipH', (tester) async { 24 | final animation = const FlutterLogo().animate().flipH( 25 | duration: 1000.ms, 26 | perspective: _perspective, 27 | begin: 0, 28 | end: 1, 29 | ); 30 | 31 | // Check halfway, 32 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 33 | _verifyPerspective(tester, Axis.horizontal); 34 | }); 35 | 36 | testWidgets('FlipEffect: flipV', (tester) async { 37 | final animation = const FlutterLogo().animate().flipV( 38 | duration: 1000.ms, 39 | perspective: _perspective, 40 | begin: 0, 41 | end: 1, 42 | ); 43 | 44 | // Check halfway, 45 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 46 | _verifyPerspective(tester, Axis.vertical); 47 | }); 48 | } 49 | 50 | _verifyPerspective(WidgetTester tester, Axis direction) async { 51 | var mtx = FlipEffect.getTransformMatrix(0.5, direction, _perspective); 52 | tester.expectWidgetWithBool( 53 | (o) => o.transform == mtx, true, 'transform'); 54 | } 55 | 56 | const double _perspective = 2; 57 | -------------------------------------------------------------------------------- /test/effects/folow_path_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | import 'package:flutter_animate/flutter_animate.dart'; 6 | 7 | import '../tester_extensions.dart'; 8 | 9 | void main() { 10 | testWidgets('BlurEffect: blur', (tester) async { 11 | final Path path = Path() // 12 | ..lineTo(100, 100); 13 | 14 | final animation = const FlutterLogo() 15 | .animate() 16 | .followPath(path: path, duration: 1000.ms, rotate: true); 17 | 18 | // Check halfway: 19 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 20 | var mtx = FollowPathEffect.getMatrix(50, 50, pi / 4); 21 | tester.expectWidgetWithBool( 22 | (o) => o.transform == mtx, true, 'transform'); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /test/effects/listen_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('ListenEffect: core', (tester) async { 9 | double value = 0; 10 | final animation = const FlutterLogo() 11 | .animate() 12 | .fadeIn(duration: 1000.ms) 13 | .listen(callback: (o) => value = o); 14 | 15 | // Check value halfway 16 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 17 | expect(value, 0.5); 18 | 19 | // Check at the end 20 | await tester.pump(500.ms); 21 | expect(value, 1); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /test/effects/move_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('MoveEffect: move', (tester) async { 9 | final animation = const FlutterLogo().animate().move( 10 | duration: 1000.ms, 11 | end: const Offset(_moveAmt, _moveAmt), 12 | ); 13 | 14 | // check halfway 15 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 16 | _verifyMove(tester, _moveAmt / 2, _moveAmt / 2); 17 | }); 18 | 19 | testWidgets('MoveEffect: moveX', (tester) async { 20 | final animation = const FlutterLogo().animate().moveX( 21 | duration: 1000.ms, 22 | end: _moveAmt, 23 | ); 24 | 25 | // check halfway 26 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 27 | _verifyMove(tester, _moveAmt / 2, 0); 28 | }); 29 | 30 | testWidgets('MoveEffect: moveY', (tester) async { 31 | final animation = const FlutterLogo().animate().moveY( 32 | duration: 1000.ms, 33 | end: _moveAmt, 34 | ); 35 | 36 | // check halfway 37 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 38 | _verifyMove(tester, 0, _moveAmt / 2); 39 | }); 40 | } 41 | 42 | _verifyMove(WidgetTester tester, double x, double y) async { 43 | tester.expectWidgetWithDouble( 44 | (o) => o.transform.getTranslation().x, x, 'x'); 45 | tester.expectWidgetWithDouble( 46 | (o) => o.transform.getTranslation().y, y, 'y'); 47 | } 48 | 49 | const double _moveAmt = 100; 50 | -------------------------------------------------------------------------------- /test/effects/rotate_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | import 'package:flutter_animate/flutter_animate.dart'; 6 | 7 | import '../tester_extensions.dart'; 8 | 9 | void main() { 10 | // TODO: Test alignment 11 | 12 | testWidgets('RotateEffect: core', (tester) async { 13 | final animation = const FlutterLogo().animate().rotate( 14 | duration: 1000.ms, 15 | end: 2, 16 | ); 17 | 18 | // check halfway 19 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 20 | 21 | Matrix4 expectedMatrix = Transform.rotate(angle: (1 * pi * 2)).transform; 22 | tester.expectWidgetWithBool( 23 | (o) => o.transform == expectedMatrix, true, 'rotate'); 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /test/effects/saturate_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('SaturateEffect: saturate', (tester) async { 9 | final animation = const FlutterLogo().animate().saturate(duration: 1000.ms); 10 | 11 | // Check 75% through: 12 | await tester.pumpAnimation(animation, initialDelay: 750.ms); 13 | _verifySaturate(tester, 0.75); 14 | }); 15 | 16 | testWidgets('SaturateEffect: desaturate', (tester) async { 17 | final animation = 18 | const FlutterLogo().animate().desaturate(duration: 1000.ms); 19 | 20 | // Check 75% through: 21 | await tester.pumpAnimation(animation, initialDelay: 750.ms); 22 | _verifySaturate(tester, 0.25); 23 | }); 24 | } 25 | 26 | _verifySaturate(WidgetTester tester, double amt) async { 27 | // Create a colorFilter and compare to the one in the widget tree, they should equal 28 | ColorFilter filter = ColorFilter.matrix(SaturateEffect.getColorMatrix(amt)); 29 | tester.expectWidgetWithBool( 30 | (o) => o.colorFilter == filter, true, 'colorFilter'); 31 | } 32 | -------------------------------------------------------------------------------- /test/effects/scale_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('ScaleEffect: scale', (tester) async { 9 | final animation = const FlutterLogo().animate().scale( 10 | duration: 1000.ms, 11 | end: const Offset(0.5, 2), 12 | ); 13 | 14 | // Check halfway, 15 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 16 | _verifyScale(tester, 0.75, 1.5); 17 | }); 18 | 19 | testWidgets('ScaleEffect: scaleXY', (tester) async { 20 | final animation = 21 | const FlutterLogo().animate().scaleXY(duration: 1000.ms, end: 2); 22 | 23 | // Check halfway, 24 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 25 | _verifyScale(tester, 1.5, 1.5); 26 | }); 27 | 28 | testWidgets('ScaleEffect: scaleX', (tester) async { 29 | final animation = 30 | const FlutterLogo().animate().scaleX(duration: 1000.ms, end: 2); 31 | 32 | // Check halfway, 33 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 34 | _verifyScale(tester, 1.5, 1); 35 | }); 36 | 37 | testWidgets('ScaleEffect: scaleY', (tester) async { 38 | final animation = 39 | const FlutterLogo().animate().scaleY(duration: 1000.ms, end: 2); 40 | 41 | // Check halfway, 42 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 43 | _verifyScale(tester, 1, 1.5); 44 | }); 45 | } 46 | 47 | _verifyScale(WidgetTester tester, double x, double y) async { 48 | Matrix4 expectedMatrix = Transform.scale(scaleX: x, scaleY: y).transform; 49 | tester.expectWidgetWithBool( 50 | (o) => o.transform == expectedMatrix, true, 'scale'); 51 | } 52 | -------------------------------------------------------------------------------- /test/effects/shake_test.dart: -------------------------------------------------------------------------------- 1 | import 'dart:math'; 2 | 3 | import 'package:flutter/material.dart'; 4 | import 'package:flutter_test/flutter_test.dart'; 5 | import 'package:flutter_animate/flutter_animate.dart'; 6 | 7 | import '../tester_extensions.dart'; 8 | 9 | void main() { 10 | testWidgets('ShakeEffect: shake', (tester) async { 11 | final animation = const FlutterLogo().animate().shake( 12 | duration: 1000.ms, 13 | hz: _hz, 14 | rotation: _rotation, 15 | offset: const Offset(_translation, _translation), 16 | ); 17 | 18 | // check 1/4 cycle through: 19 | await tester.pumpAnimation(animation, initialDelay: 250.ms); 20 | _verifyShake(tester, _translation, _translation, _rotation); 21 | }); 22 | 23 | testWidgets('ShakeEffect: shakeX', (tester) async { 24 | final animation = const FlutterLogo().animate().shakeX( 25 | duration: 1000.ms, 26 | hz: _hz, 27 | amount: _translation, 28 | ); 29 | 30 | // check 1/4 cycle through: 31 | await tester.pumpAnimation(animation, initialDelay: 250.ms); 32 | _verifyShake(tester, _translation, 0, 0); 33 | }); 34 | 35 | testWidgets('ShakeEffect: shakeY', (tester) async { 36 | final animation = const FlutterLogo().animate().shakeY( 37 | duration: 1000.ms, 38 | hz: _hz, 39 | amount: _translation, 40 | ); 41 | 42 | // check 1/4 cycle through: 43 | await tester.pumpAnimation(animation, initialDelay: 250.ms); 44 | _verifyShake(tester, 0, _translation, 0); 45 | }); 46 | } 47 | 48 | _verifyShake(WidgetTester tester, double x, double y, double rotation) async { 49 | // check translation 50 | Matrix4 matrix; 51 | if (x != 0 || y != 0) { 52 | matrix = Transform.translate(offset: Offset(x, y)).transform; 53 | tester.expectWidgetWithBool((o) { 54 | return o.transform == matrix; 55 | }, true, 'translation', findFirst: true); 56 | } 57 | 58 | // check rotation 59 | if (rotation != 0) { 60 | matrix = Transform.rotate(angle: rotation).transform; 61 | tester.expectWidgetWithBool( 62 | (o) => o.transform == matrix, true, 'rotation'); 63 | } 64 | } 65 | 66 | const double _hz = 1; 67 | const double _rotation = pi / 36; 68 | const double _translation = 10; 69 | -------------------------------------------------------------------------------- /test/effects/shimmer_test.dart: -------------------------------------------------------------------------------- 1 | void main() { 2 | // TODO: Figure out how to test shimmer 3 | } 4 | -------------------------------------------------------------------------------- /test/effects/slide_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('SlideEffect: slide', (tester) async { 9 | final animation = const FlutterLogo().animate().slide( 10 | duration: 1000.ms, 11 | begin: Offset.zero, 12 | end: const Offset(_slideAmt, _slideAmt), 13 | ); 14 | 15 | // check halfway 16 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 17 | _verifySlide(tester, _slideAmt / 2, _slideAmt / 2); 18 | }); 19 | 20 | testWidgets('SlideEffect: slideX', (tester) async { 21 | final animation = const FlutterLogo().animate().slideX( 22 | duration: 1000.ms, 23 | end: _slideAmt, 24 | ); 25 | 26 | // check halfway 27 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 28 | _verifySlide(tester, _slideAmt / 2, 0); 29 | }); 30 | 31 | testWidgets('SlideEffect: slideY', (tester) async { 32 | final animation = const FlutterLogo().animate().slideY( 33 | duration: 1000.ms, 34 | end: _slideAmt, 35 | ); 36 | 37 | // check halfway 38 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 39 | _verifySlide(tester, 0, _slideAmt / 2); 40 | }); 41 | } 42 | 43 | _verifySlide(WidgetTester tester, double x, double y) async { 44 | tester.expectWidgetWithDouble( 45 | (o) => o.position.value.dx, x, 'dx'); 46 | tester.expectWidgetWithDouble( 47 | (o) => o.position.value.dy, y, 'dy'); 48 | } 49 | 50 | const double _slideAmt = 1; 51 | -------------------------------------------------------------------------------- /test/effects/swap_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('SwapEffect: core', (tester) async { 9 | final anim = const FlutterLogo().animate().fadeOut(duration: 500.ms).swap( 10 | builder: (_, __) => const Placeholder(), 11 | ); 12 | 13 | await tester.pumpAnimation(anim); 14 | // Initially, expect one FlutterLogo, no Placeholder 15 | expect(find.byType(FlutterLogo), findsOneWidget); 16 | expect(find.byType(Placeholder), findsNothing); 17 | 18 | // At the end, expect one Placeholder, no FlutterLogo 19 | await tester.pump(500.ms); 20 | await tester.pump(0.ms); // clear out the callback 21 | expect(find.byType(Placeholder), findsOneWidget); 22 | expect(find.byType(FlutterLogo), findsNothing); 23 | }); 24 | 25 | testWidgets('SwapEffect: fade out/in using swap', (tester) async { 26 | final anim = const FlutterLogo().animate().fadeOut(duration: 500.ms).swap( 27 | builder: (_, originalChild) => 28 | originalChild!.animate().fadeIn(duration: 500.ms), 29 | ); 30 | 31 | await tester.pumpAnimation(anim); 32 | 33 | // Initially, faded in 34 | tester.expectWidgetWithDouble( 35 | (o) => o.opacity.value, 1, 'opacity @ 0%'); 36 | 37 | // halfway, check fadeOut 38 | await tester.pump(500.ms); 39 | await tester.pump(0.ms); 40 | tester.expectWidgetWithDouble( 41 | (o) => o.opacity.value, 0, 'opacity @ 50%'); 42 | 43 | // end, check fadeIn 44 | await tester.pump(500.ms); 45 | await tester.pump(0.ms); 46 | tester.expectWidgetWithDouble( 47 | (o) => o.opacity.value, 1, 'opacity @ 100%'); 48 | }); 49 | } 50 | -------------------------------------------------------------------------------- /test/effects/then_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('ThenEffect: core', (tester) async { 9 | final animation = const FlutterLogo() 10 | .animate() 11 | .fadeIn(duration: 500.ms) 12 | .then() 13 | .scaleXY(begin: 0.50); 14 | 15 | // Wait 500ms, check that opacity has started, but scale has not 16 | await tester.pumpAnimation(animation, initialDelay: 250.ms); 17 | tester.expectWidgetWithDouble( 18 | (o) => o.opacity.value, 0.5, 'opacity @ 25%'); 19 | 20 | Matrix4 expectedMatrix = Transform.scale(scale: 0.5).transform; 21 | tester.expectWidgetWithBool( 22 | (o) => o.transform == expectedMatrix, true, 'scale @ 50%'); 23 | 24 | // Wait another 1s and check that scale is now halfway 25 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 26 | expectedMatrix = Transform.scale(scale: 0.75).transform; 27 | tester.expectWidgetWithBool( 28 | (o) => o.transform == expectedMatrix, true, 'scale @ 75%'); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /test/effects/tint_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('TintEffect: tint', (tester) async { 9 | final animation = const FlutterLogo().animate().tint( 10 | duration: 1000.ms, 11 | color: _color, 12 | ); 13 | 14 | // Check halfway 15 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 16 | _verifyTint(tester, 0.5); 17 | }); 18 | 19 | testWidgets('TintEffect: untint', (tester) async { 20 | final animation = const FlutterLogo().animate().untint( 21 | duration: 1000.ms, 22 | color: _color, 23 | ); 24 | 25 | // Check halfway 26 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 27 | _verifyTint(tester, 0.5); 28 | }); 29 | } 30 | 31 | _verifyTint(WidgetTester tester, double amount) async { 32 | // create a colorFilter to compare to the one in the widget tree 33 | var expectedFilter = 34 | ColorFilter.matrix(TintEffect.getTintMatrix(amount, _color)); 35 | tester.expectWidgetWithBool( 36 | (o) => o.colorFilter == expectedFilter, true, 'colorFilter'); 37 | } 38 | 39 | const Color _color = Colors.blue; 40 | -------------------------------------------------------------------------------- /test/effects/toggle_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_test/flutter_test.dart'; 3 | import 'package:flutter_animate/flutter_animate.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('ToggleEffect: core', (tester) async { 9 | final animation = Animate().toggle( 10 | duration: 1000.ms, 11 | builder: (_, value, __) { 12 | return Opacity(opacity: value ? 0 : 1, child: const FlutterLogo()); 13 | }); 14 | 15 | // Should start with opacity of 0 16 | await tester.pumpWidget(animation); 17 | tester.expectWidgetWithDouble( 18 | (w) => w.opacity, 19 | 0, 20 | 'opacity @ 0%', 21 | ); 22 | 23 | // After 500ms opacity should still be 0 24 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 25 | tester.expectWidgetWithDouble( 26 | (w) => w.opacity, 27 | 0, 28 | 'opacity @ 50%', 29 | ); 30 | 31 | // After another 500ms opacity should be 1 32 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 33 | tester.expectWidgetWithDouble( 34 | (w) => w.opacity, 35 | 1, 36 | 'opacity @ 100%', 37 | ); 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /test/effects/visibility_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/material.dart'; 2 | import 'package:flutter_animate/flutter_animate.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | import '../tester_extensions.dart'; 6 | 7 | void main() { 8 | testWidgets('VisibilityEffect: maintain = true', (tester) async { 9 | final animation = const FlutterLogo() 10 | .animate() 11 | .visibility(duration: 1000.ms, end: true, maintain: true); 12 | 13 | // check halfway 14 | await tester.pumpAnimation(animation, initialDelay: 500.ms); 15 | tester.expectWidgetWithBool( 16 | (o) => o.visible, false, 'visibility @ 50%'); 17 | 18 | // check end 19 | await tester.pump(500.ms); 20 | _verifyVisibility(tester, true, true); 21 | }); 22 | 23 | testWidgets('VisibilityEffect: maintain = false', (tester) async { 24 | final animation = const FlutterLogo() 25 | .animate() 26 | .visibility(duration: 1.seconds, maintain: false); 27 | 28 | await tester.pumpAnimation(animation); 29 | _verifyVisibility(tester, false, false); 30 | }); 31 | 32 | testWidgets('VisibilityEffect: hide', (tester) async { 33 | final animation = const FlutterLogo().animate().hide(duration: 1000.ms); 34 | 35 | // check halfway 36 | await tester.pumpAnimation(animation, initialDelay: 1000.ms); 37 | _verifyVisibility(tester, false); 38 | }); 39 | 40 | testWidgets('VisibilityEffect: show', (tester) async { 41 | final animation = const FlutterLogo().animate().show(duration: 1000.ms); 42 | 43 | // check halfway 44 | await tester.pumpAnimation(animation, initialDelay: 1000.ms); 45 | _verifyVisibility(tester, true); 46 | }); 47 | } 48 | 49 | _verifyVisibility(WidgetTester tester, bool visible, 50 | [bool maintain = VisibilityEffect.defaultMaintain]) async { 51 | tester.expectWidgetWithBool((o) => o.visible, visible, 'visible'); 52 | tester.expectWidgetWithBool( 53 | (o) => o.maintainAnimation, maintain, 'maintainSize'); 54 | tester.expectWidgetWithBool( 55 | (o) => o.maintainInteractivity, maintain, 'maintainInteractivity'); 56 | tester.expectWidgetWithBool( 57 | (o) => o.maintainSemantics, maintain, 'maintainSemantics'); 58 | tester.expectWidgetWithBool( 59 | (o) => o.maintainSize, maintain, 'maintainSize'); 60 | tester.expectWidgetWithBool( 61 | (o) => o.maintainState, maintain, 'maintainState'); 62 | } 63 | -------------------------------------------------------------------------------- /test/extensions_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_test/flutter_test.dart'; 2 | import 'package:flutter_animate/flutter_animate.dart'; 3 | 4 | void main() { 5 | test('NumDurationExtensions', () async { 6 | expect(100.microseconds, const Duration(microseconds: 100)); 7 | expect(100.milliseconds, const Duration(milliseconds: 100)); 8 | expect(100.seconds, const Duration(seconds: 100)); 9 | expect(100.minutes, const Duration(minutes: 100)); 10 | expect(100.hours, const Duration(hours: 100)); 11 | expect(100.days, const Duration(days: 100)); 12 | }); 13 | 14 | test('OffsetCopyWithExtensions', () async { 15 | var offset = const Offset(10, 0); 16 | expect(offset.copyWith(dx: 100, dy: 100), const Offset(100, 100)); 17 | }); 18 | } 19 | -------------------------------------------------------------------------------- /test/tester_extensions.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/widgets.dart'; 2 | import 'package:flutter_animate/flutter_animate.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | extension TesterExtensions on WidgetTester { 6 | /// For some reason, these animations need an extra `pump(0.ms);` to properly start. 7 | /// This eases that boilerplate a bit. Also adds a convenience method for an initial wait time, which is common. 8 | Future pumpAnimation(Widget child, {Duration? initialDelay}) async { 9 | await pumpWidget(child); 10 | await pump(0.ms); 11 | if (initialDelay != null) { 12 | await pump(initialDelay); 13 | } 14 | } 15 | 16 | /// Wraps the built-in `expect(..., ...)` call to make tests more succinct 17 | expectWidgetWithDouble( 18 | double Function(T w) getValue, 19 | double expectedValue, 20 | String debugTitle, { 21 | bool findFirst = false, 22 | }) { 23 | expect( 24 | widget(findFirst ? find.byType(T).first : find.byType(T).last), 25 | isA().having((t) => getValue(t), debugTitle, expectedValue), 26 | ); 27 | } 28 | 29 | /// Wraps the built-in `expect(..., ...)` call to make tests more succinct 30 | expectWidgetWithBool( 31 | bool Function(T w) getValue, 32 | bool expectedValue, 33 | String debugTitle, { 34 | bool findFirst = false, 35 | }) { 36 | expect( 37 | widget(findFirst ? find.byType(T).first : find.byType(T).last), 38 | isA().having((t) => getValue(t), debugTitle, expectedValue), 39 | ); 40 | } 41 | } 42 | --------------------------------------------------------------------------------