diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c0a824..1a1379f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,37 @@ +## [1.4.0] 2026-02-07 +* BREAKING: Flutter 3.38 updates +* BREAKING: Bump minimum supported Flutter version to 3.35 +* Upgrade example app to Gradle 8.14 and Gradle Plugin DSL +* Upgrade example sourceCompatibility JavaVersion.VERSION_17, targetCompatibility JavaVersion.VERSION_17 +* Upgrade example Kotlin to 2.2.21 + +## [1.3.2] 2025-08-03 +* Flutter 3.32 updates +## [1.3.1] 2024-10-08 +* Example app: Upgrade kotlin plugin from 1.7.20 to 1.8.22 and Gradle from 8.2 to 8.3, to sync it with Flutter 3.24 +## [1.3.0] 2024-09-20 +* BREAKING: Update minimum supported Flutter to 3.22, Dart to 3.3 +## [1.2.2] 2024-08-31 +* Upgrade example app dependencies cupertino_icons +## [1.2.1] 2023-12-21 +* Flutter 3.16 updates +## [1.2.0] 2023-10-27 +* Update sdk constraints to >=3.0.0 <4.0.0 +* Upgrade example app dependencies cupertino_icons +## [1.1.0] 2023-06-11 +* Flutter 3.10 updates +## [1.0.1] - 20230317 +* Flutter 3.7 updates +* Fix lint issues +## [1.0.0] - 20221016 +* Flutter 3.3 fixes +* Upgrade dependencies cupertino_icons +* Bump sdk from >=2.12.0 to >=2.17.0 +* Bump flutter from >1.21.0 to flutter: >=3.0.0 +## [0.1.1] - 20220516 +* Flutter 3 fixes +## [0.1.0] - 20220206 +* Null safety version ## [0.0.6] - 20200918 * Update to Flutter breaking change, VelocityTracker now takes an argument. * Removed unused import. diff --git a/README.md b/README.md index 3b72e21..f31c1d1 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,11 @@ An optimized class on flutter GestureDetector. Flutter's GestureDetector has its **1.add dependencies** ``` dependencies: - optimized_gesture_detector: ^0.0.6 + optimized_gesture_detector: ^0.1.1 ``` ## Notes * Version 0.0.5 is for use with Flutter versions prior to 1.22.0 * Version 0.0.6 is for use with Flutter version 1.22.0 and newer. +* Version 0.1.0 Null safety version. +* Version 0.1.1 Flutter 3 fixes. \ No newline at end of file diff --git a/example/.gitignore b/example/.gitignore index ac4a906..a5b6046 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -70,3 +70,5 @@ !**/ios/**/default.pbxuser !**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages + +**/ios/Flutter/flutter_export_environment.sh diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 4089a56..51dc684 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' @@ -21,12 +22,21 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { - compileSdkVersion 28 + compileSdkVersion flutter.compileSdkVersion + ndkVersion flutter.ndkVersion + + compileOptions { + // Flag to enable support for the new language APIs + coreLibraryDesugaringEnabled true + // Sets Java compatibility + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_17.toString() + } sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -39,8 +49,8 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.lqy.example" - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -60,7 +70,6 @@ flutter { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' diff --git a/example/android/build.gradle b/example/android/build.gradle index b7faad8..bc157bd 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,20 +1,7 @@ -buildscript { - ext.kotlin_version = '1.2.71' - repositories { - google() - jcenter() - } - - dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() - jcenter() + mavenCentral() } } @@ -26,6 +13,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 2bd6f4f..8bf2b5f 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,2 +1,2 @@ -org.gradle.jvmargs=-Xmx1536M +org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 2819f02..60f07d9 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip \ No newline at end of file diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 5a2f14f..0008767 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,15 +1,26 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + } + settings.ext.flutterSdkPath = flutterSdkPath() -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() + includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle") -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } } -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":$name" - project(":$name").projectDir = pluginDirectory +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version '8.13.2' apply false + id "org.jetbrains.kotlin.android" version "2.2.21" apply false } + +include ":app" diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 9367d48..8d4492f 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 9.0 diff --git a/example/ios/Flutter/ephemeral/flutter_lldb_helper.py b/example/ios/Flutter/ephemeral/flutter_lldb_helper.py new file mode 100644 index 0000000..a88caf9 --- /dev/null +++ b/example/ios/Flutter/ephemeral/flutter_lldb_helper.py @@ -0,0 +1,32 @@ +# +# Generated file, do not edit. +# + +import lldb + +def handle_new_rx_page(frame: lldb.SBFrame, bp_loc, extra_args, intern_dict): + """Intercept NOTIFY_DEBUGGER_ABOUT_RX_PAGES and touch the pages.""" + base = frame.register["x0"].GetValueAsAddress() + page_len = frame.register["x1"].GetValueAsUnsigned() + + # Note: NOTIFY_DEBUGGER_ABOUT_RX_PAGES will check contents of the + # first page to see if handled it correctly. This makes diagnosing + # misconfiguration (e.g. missing breakpoint) easier. + data = bytearray(page_len) + data[0:8] = b'IHELPED!' + + error = lldb.SBError() + frame.GetThread().GetProcess().WriteMemory(base, data, error) + if not error.Success(): + print(f'Failed to write into {base}[+{page_len}]', error) + return + +def __lldb_init_module(debugger: lldb.SBDebugger, _): + target = debugger.GetDummyTarget() + # Caveat: must use BreakpointCreateByRegEx here and not + # BreakpointCreateByName. For some reasons callback function does not + # get carried over from dummy target for the later. + bp = target.BreakpointCreateByRegex("^NOTIFY_DEBUGGER_ABOUT_RX_PAGES$") + bp.SetScriptCallbackFunction('{}.handle_new_rx_page'.format(__name__)) + bp.SetAutoContinue(True) + print("-- LLDB integration loaded --") diff --git a/example/ios/Flutter/ephemeral/flutter_lldbinit b/example/ios/Flutter/ephemeral/flutter_lldbinit new file mode 100644 index 0000000..e3ba6fb --- /dev/null +++ b/example/ios/Flutter/ephemeral/flutter_lldbinit @@ -0,0 +1,5 @@ +# +# Generated file, do not edit. +# + +command script import --relative-to-command-file flutter_lldb_helper.py diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 72648f3..34ef170 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -9,11 +9,7 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; @@ -27,8 +23,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -39,13 +33,11 @@ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; - 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -58,8 +50,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -69,9 +59,7 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, - 9740EEBA1CF902C7004384FC /* Flutter.framework */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 9740EEB31CF90195004384FC /* Generated.xcconfig */, @@ -203,7 +191,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; @@ -255,7 +243,6 @@ /* Begin XCBuildConfiguration section */ 249021D3217E4FDB00AE95B9 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -293,7 +280,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -329,7 +316,6 @@ }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -373,7 +359,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -383,7 +369,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -421,7 +406,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a1..919434a 100644 --- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/example/pubspec.lock b/example/pubspec.lock index b1801b2..9c3b3c7 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,58 +5,58 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + url: "https://pub.dev" source: hosted - version: "2.5.0-nullsafety" + version: "2.13.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" + url: "https://pub.dev" source: hosted - version: "2.1.0-nullsafety" + version: "2.1.2" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 + url: "https://pub.dev" source: hosted - version: "1.1.0-nullsafety.2" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety" + version: "1.4.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" source: hosted - version: "1.1.0-nullsafety" + version: "1.1.2" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" source: hosted - version: "1.15.0-nullsafety.2" + version: "1.19.1" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 + url: "https://pub.dev" source: hosted - version: "0.1.3" + version: "1.0.8" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" + url: "https://pub.dev" source: hosted - version: "1.1.0-nullsafety" + version: "1.3.3" flutter: dependency: "direct main" description: flutter @@ -67,95 +67,138 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" + url: "https://pub.dev" + source: hosted + version: "11.0.2" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" + url: "https://pub.dev" + source: hosted + version: "3.0.10" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" + url: "https://pub.dev" + source: hosted + version: "3.0.2" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 + url: "https://pub.dev" + source: hosted + version: "0.12.17" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + url: "https://pub.dev" source: hosted - version: "0.12.10-nullsafety" + version: "0.11.1" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" source: hosted - version: "1.3.0-nullsafety.2" + version: "1.17.0" optimized_gesture_detector: dependency: "direct main" description: path: ".." relative: true source: path - version: "0.0.6" + version: "1.4.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" source: hosted - version: "1.8.0-nullsafety" + version: "1.9.1" sky_engine: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_span: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "56a02f1f4cd1a2d96303c0144c93bd6d909eea6bee6bf5a0e0b685edbd4c47ab" + url: "https://pub.dev" source: hosted - version: "1.8.0-nullsafety" + version: "1.10.2" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" + url: "https://pub.dev" source: hosted - version: "1.10.0-nullsafety" + version: "1.12.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" source: hosted - version: "2.1.0-nullsafety" + version: "2.1.4" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" source: hosted - version: "1.1.0-nullsafety" + version: "1.4.1" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" source: hosted - version: "1.2.0-nullsafety" + version: "1.2.2" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55 + url: "https://pub.dev" source: hosted - version: "0.2.19-nullsafety" - typed_data: + version: "0.7.7" + vector_math: dependency: transitive description: - name: typed_data - url: "https://pub.dartlang.org" + name: vector_math + sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b + url: "https://pub.dev" source: hosted - version: "1.3.0-nullsafety.2" - vector_math: + version: "2.2.0" + vm_service: dependency: transitive description: - name: vector_math - url: "https://pub.dartlang.org" + name: vm_service + sha256: "45caa6c5917fa127b5dbcfbd1fa60b14e583afdc08bfc96dda38886ca252eb60" + url: "https://pub.dev" source: hosted - version: "2.1.0-nullsafety.2" + version: "15.0.2" sdks: - dart: ">=2.10.0-0.0.dev <2.10.0" - flutter: ">1.21.0" + dart: ">=3.10.8 <4.0.0" + flutter: ">=3.35.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 072a683..97a93bd 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -11,10 +11,10 @@ description: A new Flutter application. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+1 +version: 1.3.0 environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=3.10.8 <4.0.0' dependencies: flutter: @@ -24,7 +24,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 + cupertino_icons: ^1.0.8 dev_dependencies: flutter_test: @@ -41,34 +41,3 @@ flutter: # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: true - - # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware. - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/assets-and-images/#from-packages - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages diff --git a/lib/details.dart b/lib/details.dart index 1df0987..ec3c299 100644 --- a/lib/details.dart +++ b/lib/details.dart @@ -2,7 +2,7 @@ import 'package:flutter/gestures.dart'; import 'package:optimized_gesture_detector/direction.dart'; class OpsMoveStartDetails { - OpsMoveStartDetails({this.globalPoint = Offset.zero, Offset localPoint}) + OpsMoveStartDetails({this.globalPoint = Offset.zero, Offset? localPoint}) : localPoint = localPoint ?? globalPoint; final Offset localPoint; @@ -10,7 +10,7 @@ class OpsMoveStartDetails { } class OpsMoveUpdateDetails { - OpsMoveUpdateDetails({this.globalPoint = Offset.zero, Offset localPoint}) + OpsMoveUpdateDetails({this.globalPoint = Offset.zero, Offset? localPoint}) : localPoint = localPoint ?? globalPoint; final Offset localPoint; @@ -21,7 +21,7 @@ class OpsMoveEndDetails { OpsMoveEndDetails( {this.velocity = Velocity.zero, this.globalPoint = Offset.zero, - Offset localPoint}) + Offset? localPoint}) : localPoint = localPoint ?? globalPoint; final Velocity velocity; @@ -30,7 +30,7 @@ class OpsMoveEndDetails { } class OpsScaleStartDetails { - OpsScaleStartDetails({this.globalPoint = Offset.zero, Offset localPoint}) + OpsScaleStartDetails({this.globalPoint = Offset.zero, Offset? localPoint}) : localPoint = localPoint ?? globalPoint; final Offset localPoint; @@ -40,8 +40,8 @@ class OpsScaleStartDetails { class OpsScaleUpdateDetails { OpsScaleUpdateDetails( {this.globalFocalPoint = Offset.zero, - Offset localFocalPoint, - Direction mainDirection, + Offset? localFocalPoint, + Direction? mainDirection, this.scale = 1.0, this.horizontalScale = 1.0, this.verticalScale = 1.0, @@ -62,7 +62,7 @@ class OpsScaleEndDetails { OpsScaleEndDetails( {this.velocity = Velocity.zero, this.globalPoint = Offset.zero, - Offset localPoint}) + Offset? localPoint}) : localPoint = localPoint ?? globalPoint; final Velocity velocity; diff --git a/lib/gesture_dectetor.dart b/lib/gesture_dectetor.dart index 1eabd44..433843b 100644 --- a/lib/gesture_dectetor.dart +++ b/lib/gesture_dectetor.dart @@ -5,7 +5,7 @@ import 'package:optimized_gesture_detector/scale.dart' as scale; class CoreGestureDetector extends StatelessWidget { CoreGestureDetector( - {Key key, + {Key? key, this.child, this.onTapDown, this.onTapUp, @@ -21,26 +21,24 @@ class CoreGestureDetector extends StatelessWidget { this.dragStartBehavior = DragStartBehavior.start, this.canHDragDown, this.canVDragDown}) - : assert(excludeFromSemantics != null), - assert(dragStartBehavior != null), - super(key: key); + : super(key: key); /// The widget below this widget in the tree. /// /// {@macro flutter.widgets.child} - final Widget child; + final Widget? child; - final GestureTapDownCallback onTapDown; - final GestureTapUpCallback onTapUp; - final GestureTapCancelCallback onTapCancel; + final GestureTapDownCallback? onTapDown; + final GestureTapUpCallback? onTapUp; + final GestureTapCancelCallback? onTapCancel; - final GestureLongPressStartCallback onLongPressStart; - final GestureLongPressMoveUpdateCallback onLongPressMoveUpdate; - final GestureLongPressEndCallback onLongPressEnd; + final GestureLongPressStartCallback? onLongPressStart; + final GestureLongPressMoveUpdateCallback? onLongPressMoveUpdate; + final GestureLongPressEndCallback? onLongPressEnd; - final scale.GestureScaleStartCallback onScaleStart; - final scale.GestureScaleUpdateCallback onScaleUpdate; - final scale.GestureScaleEndCallback onScaleEnd; + final scale.GestureScaleStartCallback? onScaleStart; + final scale.GestureScaleUpdateCallback? onScaleUpdate; + final scale.GestureScaleEndCallback? onScaleEnd; // /// The pointer is in contact with the screen and has pressed with sufficient // /// force to initiate a force press. The amount of force is at least @@ -77,7 +75,7 @@ class CoreGestureDetector extends StatelessWidget { /// /// This defaults to [HitTestBehavior.deferToChild] if [child] is not null and /// [HitTestBehavior.translucent] if child is null. - final HitTestBehavior behavior; + final HitTestBehavior? behavior; /// Whether to exclude these gestures from the semantics tree. For /// example, the long-press gesture for showing a tooltip is @@ -109,8 +107,8 @@ class CoreGestureDetector extends StatelessWidget { final GestureArenaTeam _team = GestureArenaTeam(); - final CanDragDownFunction canHDragDown; - final CanDragDownFunction canVDragDown; + final CanDragDownFunction? canHDragDown; + final CanDragDownFunction? canVDragDown; @override Widget build(BuildContext context) { @@ -202,16 +200,16 @@ class CoreGestureDetector extends StatelessWidget { ); } - GestureDragDownCallback _gestureVDragDownCallback() { + GestureDragDownCallback? _gestureVDragDownCallback() { if (canVDragDown == null) return null; - return canVDragDown() ? (e) {} : null; + return canVDragDown!() ? (e) {} : null; } - GestureDragDownCallback _gestureHDragDownCallback() { + GestureDragDownCallback? _gestureHDragDownCallback() { if (canHDragDown == null) return null; - return canHDragDown() ? (e) {} : null; + return canHDragDown!() ? (e) {} : null; } @override diff --git a/lib/optimized_gesture_detector.dart b/lib/optimized_gesture_detector.dart index 04cec6c..11e558a 100644 --- a/lib/optimized_gesture_detector.dart +++ b/lib/optimized_gesture_detector.dart @@ -19,68 +19,69 @@ class OptimizedGestureDetector extends StatelessWidget { static const Offset ZERO = Offset(0, 0); - final OpsTapDownCallback _tapDownCallback; - final OpsSingleTapUpCallback _singleTapCallback; - final OpsDoubleTapUpCallback _doubleTapCallback; - final OpsDragStartCallback _dragStartCallback; - final OpsDragUpdateCallback _dragUpdateCallback; - final OpsDragEndCallback _dragEndCallback; - final OpsMoveStartCallback _moveStartCallback; - final OpsMoveUpdateCallback _moveUpdateCallback; - final OpsMoveEndCallback _moveEndCallback; - final OpsScaleStartCallback _scaleStartCallback; - final OpsScaleUpdateCallback _scaleUpdateCallback; - final OpsScaleEndCallback _scaleEndCallback; - - final OpsTapCancelCallback _tapCancelCallback; - final OpsMoveCancelCallback _moveCancelCallback; - final OpsScaleCancelCallback _scaleCancelCallback; + final OpsTapDownCallback? _tapDownCallback; + final OpsSingleTapUpCallback? _singleTapCallback; + final OpsDoubleTapUpCallback? _doubleTapCallback; + final OpsDragStartCallback? _dragStartCallback; + final OpsDragUpdateCallback? _dragUpdateCallback; + final OpsDragEndCallback? _dragEndCallback; + final OpsMoveStartCallback? _moveStartCallback; + final OpsMoveUpdateCallback? _moveUpdateCallback; + final OpsMoveEndCallback? _moveEndCallback; + final OpsScaleStartCallback? _scaleStartCallback; + final OpsScaleUpdateCallback? _scaleUpdateCallback; + final OpsScaleEndCallback? _scaleEndCallback; + + final OpsTapCancelCallback? _tapCancelCallback; + final OpsMoveCancelCallback? _moveCancelCallback; + final OpsScaleCancelCallback? _scaleCancelCallback; int _tapDownTime = INITIAL_INT_VALUE; bool _isSingleTap = false; bool _isDoubleTap = false; - bool _isRealScale; + bool? _isRealScale; bool _isMoveCancel = false; bool _isScaleCancel = false; - Timer _singleTapTimer; + Timer? _singleTapTimer; - Direction _scaleMainDirection; + Direction? _scaleMainDirection; - Offset _lastMoveUpdateGolbalPos; - Offset _lastMoveUpdateLocalPos; + Offset? _lastMoveUpdateGolbalPos; + Offset? _lastMoveUpdateLocalPos; - Offset _lastScaleUpdateGolbalPos; - Offset _lastScaleUpdateLocalPos; + Offset? _lastScaleUpdateGolbalPos; + Offset? _lastScaleUpdateLocalPos; - List _scaleTwoKeys = List(); + // ignore: deprecated_member_use + List _scaleTwoKeys = []; - final Widget child; + final Widget? child; - final gd.CanDragDownFunction _canHDragDown; - final gd.CanDragDownFunction _canVDragDown; + final gd.CanDragDownFunction? _canHDragDown; + final gd.CanDragDownFunction? _canVDragDown; OptimizedGestureDetector( - {Key key, - OpsTapDownCallback tapDown, - OpsSingleTapUpCallback singleTapUp, - OpsTapCancelCallback tapCancel, - OpsDoubleTapUpCallback doubleTapUp, - OpsDragStartCallback dragStart, - OpsDragUpdateCallback dragUpdate, - OpsDragEndCallback dragEnd, - OpsMoveStartCallback moveStart, - OpsMoveCancelCallback moveCancel, - OpsMoveUpdateCallback moveUpdate, - OpsMoveEndCallback moveEnd, - OpsScaleStartCallback scaleStart, - OpsScaleCancelCallback scaleCancel, - OpsScaleUpdateCallback scaleUpdate, - OpsScaleEndCallback scaleEnd, - gd.CanDragDownFunction needHorizontalConflictFunc, - gd.CanDragDownFunction needVerticalConflictFunc, + {Key? key, + OpsTapDownCallback? tapDown, + OpsSingleTapUpCallback? singleTapUp, + OpsTapCancelCallback? tapCancel, + OpsDoubleTapUpCallback? doubleTapUp, + OpsDragStartCallback? dragStart, + OpsDragUpdateCallback? dragUpdate, + OpsDragEndCallback? dragEnd, + OpsMoveStartCallback? moveStart, + OpsMoveCancelCallback? moveCancel, + OpsMoveUpdateCallback? moveUpdate, + OpsMoveEndCallback? moveEnd, + OpsScaleStartCallback? scaleStart, + OpsScaleCancelCallback? scaleCancel, + OpsScaleUpdateCallback? scaleUpdate, + OpsScaleEndCallback? scaleEnd, + gd.CanDragDownFunction? needHorizontalConflictFunc, + gd.CanDragDownFunction? needVerticalConflictFunc, this.child}) : _tapDownCallback = tapDown, _tapCancelCallback = tapCancel, @@ -125,9 +126,7 @@ class OptimizedGestureDetector extends StatelessWidget { } } - if (_tapDownCallback != null) { - _tapDownCallback(details); - } + _tapDownCallback?.call(details); }, onTapUp: (details) { Util.L1("onTapUp", details); @@ -156,9 +155,7 @@ class OptimizedGestureDetector extends StatelessWidget { _isSingleTap = false; _isDoubleTap = false; _cancelAndResetSingleTapTimer(); - if (_tapCancelCallback != null) { - _tapCancelCallback(); - } + _tapCancelCallback?.call(); }, onLongPressStart: (details) { Util.L1("onLongPressStart", details); @@ -187,14 +184,14 @@ class OptimizedGestureDetector extends StatelessWidget { _isRealScale = !(details.verticalScale == 1.0 && details.horizontalScale == 1.0 && details.rotation == 0.0); - if (_isRealScale) { + if (_isRealScale!) { _moveCancel(); } else { _scaleCancel(); } } - if (_isRealScale) { + if (_isRealScale!) { _scaleUpdate(details); } else { _moveUpdate(details); @@ -217,64 +214,48 @@ class OptimizedGestureDetector extends StatelessWidget { void _singleTap(TapUpDetails details) { Util.L1("_singleTap", details); - if (_singleTapCallback != null) { - _singleTapCallback(details); - } + _singleTapCallback?.call(details); } void _doubleTap(TapUpDetails details) { Util.L1("_doubleTap", details); - if (_doubleTapCallback != null) { - _doubleTapCallback(details); - } + _doubleTapCallback?.call(details); } /// _drag* methods means long press then move void _dragStart(LongPressStartDetails details) { Util.L1("_dragStart", details); - if (_dragStartCallback != null) { - _dragStartCallback(details); - } + _dragStartCallback?.call(details); } void _dragUpdate(LongPressMoveUpdateDetails details) { Util.L1("_dragUpdate", details); - if (_dragUpdateCallback != null) { - _dragUpdateCallback(details); - } + _dragUpdateCallback?.call(details); } void _dragEnd(LongPressEndDetails details) { Util.L1("_dragEnd", details); - if (_dragEndCallback != null) { - _dragEndCallback(details); - } + _dragEndCallback?.call(details); } /// _move* methods means tap then move void _moveStart(scale.OpsSStartDetails details) { Util.L1("_moveStart", details); _resetLastMoveUpdatePos(); - if (_moveStartCallback != null) { - _moveStartCallback(DetailsUtils.toOpsMoveStartDetails(details)); - } + _moveStartCallback?.call(DetailsUtils.toOpsMoveStartDetails(details)); } void _moveUpdate(scale.OpsSUpdateDetails details) { Util.L1("_moveUpdate", details); - if (_moveUpdateCallback != null) { - _moveUpdateCallback(DetailsUtils.toOpsMoveUpdateDetails(details)); - } + _moveUpdateCallback?.call(DetailsUtils.toOpsMoveUpdateDetails(details)); _lastMoveUpdateGolbalPos = details.focalPoint; _lastMoveUpdateLocalPos = details.localFocalPoint; } void _moveEnd(scale.OpsSEndDetails details) { Util.L1("_moveEnd", details); - if (_moveEndCallback != null) { - _moveEndCallback(DetailsUtils.toOpsMoveEndDetails(details, - _lastMoveUpdateGolbalPos ?? ZERO, _lastMoveUpdateLocalPos ?? ZERO)); - } + _moveEndCallback?.call(DetailsUtils.toOpsMoveEndDetails(details, + _lastMoveUpdateGolbalPos ?? ZERO, _lastMoveUpdateLocalPos ?? ZERO)); _resetLastMoveUpdatePos(); } @@ -282,9 +263,7 @@ class OptimizedGestureDetector extends StatelessWidget { Util.L2("_moveCancel"); _isMoveCancel = true; _resetLastMoveUpdatePos(); - if (_moveCancelCallback != null) { - _moveCancelCallback(); - } + _moveCancelCallback?.call(); } /// _scale* methods means zoom then move @@ -292,17 +271,15 @@ class OptimizedGestureDetector extends StatelessWidget { Util.L1("_scaleStart", details); _resetScaleDirection(); _resetLastScaleUpdatePos(); - if (_scaleStartCallback != null) { - _scaleStartCallback(DetailsUtils.toOpsScaleStartDetails(details)); - } + _scaleStartCallback?.call(DetailsUtils.toOpsScaleStartDetails(details)); } void _scaleUpdate(scale.OpsSUpdateDetails details) { Util.L1("_scaleUpdate", details); - if (details.globalPointerLocations.length >= 2) { + if (details.globalPointerLocations!.length >= 2) { if (_scaleTwoKeys.isEmpty) { - details.globalPointerLocations.forEach((k, v) { + details.globalPointerLocations!.forEach((k, v) { if (_scaleTwoKeys.length < 2) { _scaleTwoKeys.add(k); } @@ -312,15 +289,13 @@ class OptimizedGestureDetector extends StatelessWidget { if (_scaleTwoKeys.length >= 2) { if (_scaleMainDirection == null) { _scaleMainDirection = getCurrentDirection( - details.globalPointerLocations[_scaleTwoKeys[0]], - details.globalPointerLocations[_scaleTwoKeys[1]]); + details.globalPointerLocations![_scaleTwoKeys[0]]!, + details.globalPointerLocations![_scaleTwoKeys[1]]!); } Util.L2("direction $_scaleMainDirection"); - if (_scaleUpdateCallback != null) { - _scaleUpdateCallback(DetailsUtils.toOpsScaleUpdateDetails( - details, _scaleMainDirection)); - } + _scaleUpdateCallback?.call( + DetailsUtils.toOpsScaleUpdateDetails(details, _scaleMainDirection)); } } _lastScaleUpdateGolbalPos = details.focalPoint; @@ -330,10 +305,8 @@ class OptimizedGestureDetector extends StatelessWidget { void _scaleEnd(scale.OpsSEndDetails details) { Util.L1("_scaleEnd", details); _resetScaleDirection(); - if (_scaleEndCallback != null) { - _scaleEndCallback(DetailsUtils.toOpsScaleEndDetails(details, - _lastScaleUpdateGolbalPos ?? ZERO, _lastScaleUpdateLocalPos ?? ZERO)); - } + _scaleEndCallback?.call(DetailsUtils.toOpsScaleEndDetails(details, + _lastScaleUpdateGolbalPos ?? ZERO, _lastScaleUpdateLocalPos ?? ZERO)); _resetLastScaleUpdatePos(); } @@ -342,9 +315,7 @@ class OptimizedGestureDetector extends StatelessWidget { _isScaleCancel = true; _resetScaleDirection(); _resetLastScaleUpdatePos(); - if (_scaleCancelCallback != null) { - _scaleCancelCallback(); - } + _scaleCancelCallback?.call(); } void _resetLastMoveUpdatePos() { diff --git a/lib/scale.dart b/lib/scale.dart index dc25087..9dabef2 100644 --- a/lib/scale.dart +++ b/lib/scale.dart @@ -1,5 +1,4 @@ import 'package:flutter/gestures.dart'; -import 'package:flutter/widgets.dart'; import 'dart:math' as math; /// Signature for when the pointers in contact with the screen have established @@ -42,12 +41,11 @@ class OpsSStartDetails { this.globalPointerLocations, this.localPointerLocations, this.focalPoint = Offset.zero, - Offset localFocalPoint, - }) : assert(focalPoint != null), - localFocalPoint = localFocalPoint ?? focalPoint; + Offset? localFocalPoint, + }) : localFocalPoint = localFocalPoint ?? focalPoint; - final Map globalPointerLocations; - final Map localPointerLocations; + final Map? globalPointerLocations; + final Map? localPointerLocations; final Offset focalPoint; final Offset localFocalPoint; @@ -67,20 +65,18 @@ class OpsSUpdateDetails { this.globalPointerLocations, this.localPointerLocations, this.focalPoint = Offset.zero, - Offset localFocalPoint, + Offset? localFocalPoint, this.scale = 1.0, this.horizontalScale = 1.0, this.verticalScale = 1.0, this.rotation = 0.0, - }) : assert(focalPoint != null), - assert(scale != null && scale >= 0.0), - assert(horizontalScale != null && horizontalScale >= 0.0), - assert(verticalScale != null && verticalScale >= 0.0), - assert(rotation != null), + }) : assert(scale >= 0.0), + assert(horizontalScale >= 0.0), + assert(verticalScale >= 0.0), localFocalPoint = localFocalPoint ?? focalPoint; - final Map globalPointerLocations; - final Map localPointerLocations; + final Map? globalPointerLocations; + final Map? localPointerLocations; final Offset focalPoint; final Offset localFocalPoint; final double scale; @@ -101,11 +97,10 @@ class OpsSEndDetails { OpsSEndDetails( {this.globalPointerLocations, this.localPointerLocations, - this.velocity = Velocity.zero}) - : assert(velocity != null); + this.velocity = Velocity.zero}); - final Map globalPointerLocations; - final Map localPointerLocations; + final Map? globalPointerLocations; + final Map? localPointerLocations; /// The velocity of the last pointer to be lifted off of the screen. final Velocity velocity; @@ -116,7 +111,6 @@ class OpsSEndDetails { } bool _isFlingGesture(Velocity velocity) { - assert(velocity != null); final double speedSquared = velocity.pixelsPerSecond.distanceSquared; return speedSquared > kMinFlingVelocity * kMinFlingVelocity; } @@ -135,15 +129,14 @@ class _LineBetweenPointers { this.pointerEndLocation = Offset.zero, this.pointerEndId = 1, }) : assert(pointerStartLocation != null && pointerEndLocation != null), - assert(pointerStartId != null && pointerEndId != null), assert(pointerStartId != pointerEndId); // The location and the id of the pointer that marks the start of the line. - final Offset pointerStartLocation; + final Offset? pointerStartLocation; final int pointerStartId; // The location and the id of the pointer that marks the end of the line. - final Offset pointerEndLocation; + final Offset? pointerEndLocation; final int pointerEndId; } @@ -159,63 +152,63 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { /// /// {@macro flutter.gestures.gestureRecognizer.kind} OpsScaleGestureRecognizer({ - Object debugOwner, - PointerDeviceKind kind, - }) : super(debugOwner: debugOwner, kind: kind); + Object? debugOwner, + PointerDeviceKind? kind, + }) : super(debugOwner: debugOwner); /// The pointers in contact with the screen have established a focal point and /// initial scale of 1.0. - GestureScaleStartCallback onStart; + GestureScaleStartCallback? onStart; /// The pointers in contact with the screen have indicated a new focal point /// and/or scale. - GestureScaleUpdateCallback onUpdate; + GestureScaleUpdateCallback? onUpdate; /// The pointers are no longer in contact with the screen. - GestureScaleEndCallback onEnd; + GestureScaleEndCallback? onEnd; _ScaleState _state = _ScaleState.ready; - Matrix4 _lastTransform; - - Offset _initialFocalPoint; - Offset _currentFocalPoint; - double _initialSpan; - double _currentSpan; - double _initialHorizontalSpan; - double _currentHorizontalSpan; - double _initialVerticalSpan; - double _currentVerticalSpan; - _LineBetweenPointers _initialLine; - _LineBetweenPointers _currentLine; - Map _pointerLocations; - List _pointerQueue; // A queue to sort pointers in order of entrance + Matrix4? _lastTransform; + + Offset? _initialFocalPoint; + Offset? _currentFocalPoint; + double? _initialSpan; + double? _currentSpan; + double? _initialHorizontalSpan; + double? _currentHorizontalSpan; + double? _initialVerticalSpan; + double? _currentVerticalSpan; + _LineBetweenPointers? _initialLine; + _LineBetweenPointers? _currentLine; + Map? _pointerLocations; + late List _pointerQueue; // A queue to sort pointers in order of entrance final Map _velocityTrackers = {}; double get _scaleFactor => - _initialSpan > 0.0 ? _currentSpan / _initialSpan : 1.0; + _initialSpan! > 0.0 ? _currentSpan! / _initialSpan! : 1.0; - double get _horizontalScaleFactor => _initialHorizontalSpan > 0.0 - ? _currentHorizontalSpan / _initialHorizontalSpan + double get _horizontalScaleFactor => _initialHorizontalSpan! > 0.0 + ? _currentHorizontalSpan! / _initialHorizontalSpan! : 1.0; - double get _verticalScaleFactor => _initialVerticalSpan > 0.0 - ? _currentVerticalSpan / _initialVerticalSpan + double get _verticalScaleFactor => _initialVerticalSpan! > 0.0 + ? _currentVerticalSpan! / _initialVerticalSpan! : 1.0; double _computeRotationFactor() { if (_initialLine == null || _currentLine == null) { return 0.0; } - final double fx = _initialLine.pointerStartLocation.dx; - final double fy = _initialLine.pointerStartLocation.dy; - final double sx = _initialLine.pointerEndLocation.dx; - final double sy = _initialLine.pointerEndLocation.dy; + final double fx = _initialLine!.pointerStartLocation!.dx; + final double fy = _initialLine!.pointerStartLocation!.dy; + final double sx = _initialLine!.pointerEndLocation!.dx; + final double sy = _initialLine!.pointerEndLocation!.dy; - final double nfx = _currentLine.pointerStartLocation.dx; - final double nfy = _currentLine.pointerStartLocation.dy; - final double nsx = _currentLine.pointerEndLocation.dx; - final double nsy = _currentLine.pointerEndLocation.dy; + final double nfx = _currentLine!.pointerStartLocation!.dx; + final double nfy = _currentLine!.pointerStartLocation!.dy; + final double nsx = _currentLine!.pointerEndLocation!.dx; + final double nsy = _currentLine!.pointerEndLocation!.dy; final double angle1 = math.atan2(fy - sy, fx - sx); final double angle2 = math.atan2(nfy - nsy, nfx - nsx); @@ -226,7 +219,7 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { @override void addAllowedPointer(PointerEvent event) { startTrackingPointer(event.pointer, event.transform); - _velocityTrackers[event.pointer] = VelocityTracker(event.kind); + _velocityTrackers[event.pointer] = VelocityTracker.withKind(event.kind); if (_state == _ScaleState.ready) { _state = _ScaleState.possible; _initialSpan = 0.0; @@ -246,21 +239,20 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { bool didChangeConfiguration = false; bool shouldStartIfAccepted = false; if (event is PointerMoveEvent) { - final VelocityTracker tracker = _velocityTrackers[event.pointer]; - assert(tracker != null); + final VelocityTracker tracker = _velocityTrackers[event.pointer]!; if (!event.synthesized) tracker.addPosition(event.timeStamp, event.position); - _pointerLocations[event.pointer] = event.position; + _pointerLocations![event.pointer] = event.position; shouldStartIfAccepted = true; _lastTransform = event.transform; } else if (event is PointerDownEvent) { - _pointerLocations[event.pointer] = event.position; + _pointerLocations![event.pointer] = event.position; _pointerQueue.add(event.pointer); didChangeConfiguration = true; shouldStartIfAccepted = true; _lastTransform = event.transform; } else if (event is PointerUpEvent || event is PointerCancelEvent) { - _pointerLocations.remove(event.pointer); + _pointerLocations!.remove(event.pointer); _pointerQueue.remove(event.pointer); didChangeConfiguration = true; _lastTransform = event.transform; @@ -275,12 +267,12 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { } void _update() { - final int count = _pointerLocations.keys.length; + final int count = _pointerLocations!.keys.length; // Compute the focal point Offset focalPoint = Offset.zero; - for (int pointer in _pointerLocations.keys) { - focalPoint += _pointerLocations[pointer]; + for (int pointer in _pointerLocations!.keys) { + focalPoint += _pointerLocations![pointer]!; } _currentFocalPoint = count > 0 ? focalPoint / count.toDouble() : Offset.zero; @@ -291,13 +283,13 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { double totalDeviation = 0.0; double totalHorizontalDeviation = 0.0; double totalVerticalDeviation = 0.0; - for (int pointer in _pointerLocations.keys) { + for (int pointer in _pointerLocations!.keys) { totalDeviation += - (_currentFocalPoint - _pointerLocations[pointer]).distance; + (_currentFocalPoint! - _pointerLocations![pointer]!).distance; totalHorizontalDeviation += - (_currentFocalPoint.dx - _pointerLocations[pointer].dx).abs(); + (_currentFocalPoint!.dx - _pointerLocations![pointer]!.dx).abs(); totalVerticalDeviation += - (_currentFocalPoint.dy - _pointerLocations[pointer].dy).abs(); + (_currentFocalPoint!.dy - _pointerLocations![pointer]!.dy).abs(); } _currentSpan = count > 0 ? totalDeviation / count : 0.0; _currentHorizontalSpan = count > 0 ? totalHorizontalDeviation / count : 0.0; @@ -307,29 +299,29 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { /// Updates [_initialLine] and [_currentLine] accordingly to the situation of /// the registered pointers void _updateLines() { - final int count = _pointerLocations.keys.length; + final int count = _pointerLocations!.keys.length; assert(_pointerQueue.length >= count); /// In case of just one pointer registered, reconfigure [_initialLine] if (count < 2) { _initialLine = _currentLine; } else if (_initialLine != null && - _initialLine.pointerStartId == _pointerQueue[0] && - _initialLine.pointerEndId == _pointerQueue[1]) { + _initialLine!.pointerStartId == _pointerQueue[0] && + _initialLine!.pointerEndId == _pointerQueue[1]) { /// Rotation updated, set the [_currentLine] _currentLine = _LineBetweenPointers( pointerStartId: _pointerQueue[0], - pointerStartLocation: _pointerLocations[_pointerQueue[0]], + pointerStartLocation: _pointerLocations![_pointerQueue[0]], pointerEndId: _pointerQueue[1], - pointerEndLocation: _pointerLocations[_pointerQueue[1]], + pointerEndLocation: _pointerLocations![_pointerQueue[1]], ); } else { /// A new rotation process is on the way, set the [_initialLine] _initialLine = _LineBetweenPointers( pointerStartId: _pointerQueue[0], - pointerStartLocation: _pointerLocations[_pointerQueue[0]], + pointerStartLocation: _pointerLocations![_pointerQueue[0]], pointerEndId: _pointerQueue[1], - pointerEndLocation: _pointerLocations[_pointerQueue[1]], + pointerEndLocation: _pointerLocations![_pointerQueue[1]], ); _currentLine = null; } @@ -343,8 +335,7 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { _initialVerticalSpan = _currentVerticalSpan; if (_state == _ScaleState.started) { if (onEnd != null) { - final VelocityTracker tracker = _velocityTrackers[pointer]; - assert(tracker != null); + final VelocityTracker tracker = _velocityTrackers[pointer]!; Velocity velocity = tracker.getVelocity(); if (_isFlingGesture(velocity)) { @@ -356,16 +347,16 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { kMaxFlingVelocity); invokeCallback( 'onEnd', - () => onEnd(OpsSEndDetails( + () => onEnd!(OpsSEndDetails( globalPointerLocations: _pointerLocations, - localPointerLocations: toLocalLocations(_pointerLocations), + localPointerLocations: toLocalLocations(_pointerLocations!), velocity: velocity))); } else { invokeCallback( 'onEnd', - () => onEnd(OpsSEndDetails( + () => onEnd!(OpsSEndDetails( globalPointerLocations: _pointerLocations, - localPointerLocations: toLocalLocations(_pointerLocations), + localPointerLocations: toLocalLocations(_pointerLocations!), velocity: Velocity.zero))); } } @@ -379,9 +370,9 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { if (_state == _ScaleState.ready) _state = _ScaleState.possible; if (_state == _ScaleState.possible) { - final double spanDelta = (_currentSpan - _initialSpan).abs(); + final double spanDelta = (_currentSpan! - _initialSpan!).abs(); final double focalPointDelta = - (_currentFocalPoint - _initialFocalPoint).distance; + (_currentFocalPoint! - _initialFocalPoint!).distance; if (spanDelta > kScaleSlop || focalPointDelta > kPanSlop) resolve(GestureDisposition.accepted); } else if (_state.index >= _ScaleState.accepted.index) { @@ -395,15 +386,15 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { if (_state == _ScaleState.started && onUpdate != null) invokeCallback('onUpdate', () { - onUpdate(OpsSUpdateDetails( + onUpdate!(OpsSUpdateDetails( globalPointerLocations: _pointerLocations, - localPointerLocations: toLocalLocations(_pointerLocations), + localPointerLocations: toLocalLocations(_pointerLocations!), scale: _scaleFactor, horizontalScale: _horizontalScaleFactor, verticalScale: _verticalScaleFactor, - focalPoint: _currentFocalPoint, + focalPoint: _currentFocalPoint!, localFocalPoint: PointerEvent.transformPosition( - _lastTransform, _currentFocalPoint), + _lastTransform, _currentFocalPoint!), rotation: _computeRotationFactor(), )); }); @@ -413,12 +404,12 @@ class OpsScaleGestureRecognizer extends OneSequenceGestureRecognizer { assert(_state == _ScaleState.started); if (onStart != null) invokeCallback('onStart', () { - onStart(OpsSStartDetails( + onStart!(OpsSStartDetails( globalPointerLocations: _pointerLocations, - localPointerLocations: toLocalLocations(_pointerLocations), - focalPoint: _currentFocalPoint, + localPointerLocations: toLocalLocations(_pointerLocations!), + focalPoint: _currentFocalPoint!, localFocalPoint: PointerEvent.transformPosition( - _lastTransform, _currentFocalPoint), + _lastTransform, _currentFocalPoint!), )); }); } diff --git a/lib/utils.dart b/lib/utils.dart index 8e20a75..857a6ad 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -28,7 +28,7 @@ class DetailsUtils { } static OpsScaleUpdateDetails toOpsScaleUpdateDetails( - OpsSUpdateDetails details, Direction mainDirection) { + OpsSUpdateDetails details, Direction? mainDirection) { return OpsScaleUpdateDetails( globalFocalPoint: details.focalPoint, localFocalPoint: details.localFocalPoint, diff --git a/pubspec.lock b/pubspec.lock index c84e218..4dd7081 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,51 +5,50 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + url: "https://pub.dev" source: hosted - version: "2.5.0-nullsafety" + version: "2.13.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" + url: "https://pub.dev" source: hosted - version: "2.1.0-nullsafety" + version: "2.1.2" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 + url: "https://pub.dev" source: hosted - version: "1.1.0-nullsafety.2" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0-nullsafety" + version: "1.4.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" source: hosted - version: "1.1.0-nullsafety" + version: "1.1.2" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" source: hosted - version: "1.15.0-nullsafety.2" + version: "1.19.1" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" + url: "https://pub.dev" source: hosted - version: "1.1.0-nullsafety" + version: "1.3.3" flutter: dependency: "direct main" description: flutter @@ -60,88 +59,131 @@ packages: description: flutter source: sdk version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" + url: "https://pub.dev" + source: hosted + version: "11.0.2" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" + url: "https://pub.dev" + source: hosted + version: "3.0.10" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" + url: "https://pub.dev" + source: hosted + version: "3.0.2" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 + url: "https://pub.dev" + source: hosted + version: "0.12.17" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + url: "https://pub.dev" source: hosted - version: "0.12.10-nullsafety" + version: "0.11.1" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" source: hosted - version: "1.3.0-nullsafety.2" + version: "1.17.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" source: hosted - version: "1.8.0-nullsafety" + version: "1.9.1" sky_engine: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_span: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" source: hosted - version: "1.8.0-nullsafety" + version: "1.10.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" + url: "https://pub.dev" source: hosted - version: "1.10.0-nullsafety" + version: "1.12.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" source: hosted - version: "2.1.0-nullsafety" + version: "2.1.4" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" source: hosted - version: "1.1.0-nullsafety" + version: "1.4.1" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" source: hosted - version: "1.2.0-nullsafety" + version: "1.2.2" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55 + url: "https://pub.dev" source: hosted - version: "0.2.19-nullsafety" - typed_data: + version: "0.7.7" + vector_math: dependency: transitive description: - name: typed_data - url: "https://pub.dartlang.org" + name: vector_math + sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b + url: "https://pub.dev" source: hosted - version: "1.3.0-nullsafety.2" - vector_math: + version: "2.2.0" + vm_service: dependency: transitive description: - name: vector_math - url: "https://pub.dartlang.org" + name: vm_service + sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02 + url: "https://pub.dev" source: hosted - version: "2.1.0-nullsafety.2" + version: "15.0.0" sdks: - dart: ">=2.10.0-0.0.dev <2.10.0" - flutter: ">1.21.0" + dart: ">=3.10.8 <4.0.0" + flutter: ">=3.35.0" diff --git a/pubspec.yaml b/pubspec.yaml index aa4ef47..56c7206 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,11 @@ name: optimized_gesture_detector -description: a optimized class on flutter GestureDector -version: 0.0.6 -author: SunPointed<410338643@qq.com> +description: An optimized class on flutter GestureDetector +version: 1.4.0 homepage: https://github.com/SunPointed/OptimizedGestureDetector environment: - sdk: ">=2.1.0 <3.0.0" - flutter: ">1.21.0" + sdk: '>=3.10.8 <4.0.0' + flutter: ">=3.35.0" dependencies: flutter: @@ -15,40 +14,3 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter. -flutter: - - # To add assets to your package, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - # - # For details regarding assets in packages, see - # https://flutter.dev/assets-and-images/#from-packages - # - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware. - - # To add custom fonts to your package, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts in packages, see - # https://flutter.dev/custom-fonts/#from-packages