diff --git a/example/.gitignore b/example/.gitignore index dee655c..0fa6b67 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,9 +1,46 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp .DS_Store -.dart_tool/ +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies .packages +.pub-cache/ .pub/ +/build/ -build/ +# Web related +lib/generated_plugin_registrant.dart -.flutter-plugins +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/example/.metadata b/example/.metadata index 8cab361..fd70cab 100644 --- a/example/.metadata +++ b/example/.metadata @@ -4,5 +4,7 @@ # This file should be version controlled and should not be manually edited. version: - revision: 44b7e7d3f42f050a79712daab253af06e9daf530 - channel: beta + revision: 77d935af4db863f6abd0b9c31c7e6df2a13de57b + channel: stable + +project_type: app diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml new file mode 100644 index 0000000..61b6c4d --- /dev/null +++ b/example/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/example/android/.gitignore b/example/android/.gitignore index 65b7315..6f56801 100644 --- a/example/android/.gitignore +++ b/example/android/.gitignore @@ -1,10 +1,13 @@ -*.iml -*.class -.gradle +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat /local.properties -/.idea/workspace.xml -/.idea/libraries -.DS_Store -/build -/captures GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties +**/*.keystore +**/*.jks diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 595a771..5fe3c92 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -11,24 +11,43 @@ 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' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +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 27 + compileSdkVersion flutter.compileSdkVersion + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } - lintOptions { - disable 'InvalidPackage' + sourceSets { + main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.example" - minSdkVersion 16 - targetSdkVersion 27 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName } buildTypes { @@ -45,7 +64,5 @@ flutter { } dependencies { - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.1' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000..c208884 --- /dev/null +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 1b515f8..3f41384 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,39 +1,34 @@ - - - - - - - + + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" + /> + + diff --git a/example/android/app/src/main/java/com/example/example/MainActivity.java b/example/android/app/src/main/java/com/example/example/MainActivity.java deleted file mode 100644 index a313e78..0000000 --- a/example/android/app/src/main/java/com/example/example/MainActivity.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.example.example; - -import android.os.Bundle; - -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; - -public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } -} diff --git a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt new file mode 100644 index 0000000..e793a00 --- /dev/null +++ b/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt @@ -0,0 +1,6 @@ +package com.example.example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/example/android/app/src/main/res/drawable-v21/launch_background.xml b/example/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 0000000..f74085f --- /dev/null +++ b/example/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/example/android/app/src/main/res/values-night/styles.xml b/example/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 0000000..3db14bb --- /dev/null +++ b/example/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml index 00fa441..d460d1e 100644 --- a/example/android/app/src/main/res/values/styles.xml +++ b/example/android/app/src/main/res/values/styles.xml @@ -1,8 +1,18 @@ - + + diff --git a/example/android/app/src/profile/AndroidManifest.xml b/example/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 0000000..c208884 --- /dev/null +++ b/example/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/example/android/build.gradle b/example/android/build.gradle index 4476887..24047dc 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,18 +1,20 @@ buildscript { + ext.kotlin_version = '1.3.50' repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:4.1.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { google() - jcenter() + mavenCentral() } } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 8bd86f6..94adc3a 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1 +1,3 @@ org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index aa901e1..bc6a58a 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.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 5a2f14f..44e62bc 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,15 +1,11 @@ include ':app' -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } -} +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":$name" - project(":$name").projectDir = pluginDirectory -} +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/example/ios/.gitignore b/example/ios/.gitignore index 2a8c8b6..7a7f987 100644 --- a/example/ios/.gitignore +++ b/example/ios/.gitignore @@ -1,44 +1,34 @@ -.idea/ -.vagrant/ -.sconsign.dblite -.svn/ - -.DS_Store -*.swp -profile - -DerivedData/ -build/ -GeneratedPluginRegistrant.h -GeneratedPluginRegistrant.m - -.generated/ - -*.pbxuser +**/dgph *.mode1v3 *.mode2v3 +*.moved-aside +*.pbxuser *.perspectivev3 - -!default.pbxuser +**/*sync/ +.sconsign.dblite +.tags* +**/.vagrant/ +**/DerivedData/ +Icon? +**/Pods/ +**/.symlinks/ +profile +xcuserdata +**/.generated/ +Flutter/App.framework +Flutter/Flutter.framework +Flutter/Flutter.podspec +Flutter/Generated.xcconfig +Flutter/ephemeral/ +Flutter/app.flx +Flutter/app.zip +Flutter/flutter_assets/ +Flutter/flutter_export_environment.sh +ServiceDefinitions.json +Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. !default.mode1v3 !default.mode2v3 +!default.pbxuser !default.perspectivev3 - -xcuserdata - -*.moved-aside - -*.pyc -*sync/ -Icon? -.tags* - -/Flutter/app.flx -/Flutter/app.zip -/Flutter/flutter_assets/ -/Flutter/App.framework -/Flutter/Flutter.framework -/Flutter/Generated.xcconfig -/ServiceDefinitions.json - -Pods/ diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 6c2de80..8d4492f 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -20,11 +20,7 @@ ???? CFBundleVersion 1.0 - UIRequiredDeviceCapabilities - - arm64 - MinimumOSVersion - 8.0 + 9.0 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index fd76eac..6edd238 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,25 +3,16 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 50; objects = { /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 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, ); }; }; - 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 */; }; - 9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB31CF90195004384FC /* Generated.xcconfig */; }; - 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; - 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; - D57DA1A0215230B4005D4B7F /* MyLaunch.jpg in Resources */ = {isa = PBXBuildFile; fileRef = D57DA19F215230B4005D4B7F /* MyLaunch.jpg */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -31,8 +22,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -42,22 +31,17 @@ /* Begin PBXFileReference section */ 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 = ""; }; - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 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 = ""; }; - 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; 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; }; - 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 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 = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - D57DA19F215230B4005D4B7F /* MyLaunch.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = MyLaunch.jpg; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -65,8 +49,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -76,10 +58,7 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, - 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, - 9740EEBA1CF902C7004384FC /* Flutter.framework */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 9740EEB31CF90195004384FC /* Generated.xcconfig */, @@ -90,7 +69,6 @@ 97C146E51CF9000F007C117D = { isa = PBXGroup; children = ( - D57DA19F215230B4005D4B7F /* MyLaunch.jpg */, 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, @@ -108,27 +86,18 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( - 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, - 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, 97C146FA1CF9000F007C117D /* Main.storyboard */, 97C146FD1CF9000F007C117D /* Assets.xcassets */, 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 97C147021CF9000F007C117D /* Info.plist */, - 97C146F11CF9000F007C117D /* Supporting Files */, 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, ); path = Runner; sourceTree = ""; }; - 97C146F11CF9000F007C117D /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 97C146F21CF9000F007C117D /* main.m */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -158,18 +127,18 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0910; - ORGANIZATIONNAME = "The Chromium Authors"; + LastUpgradeCheck = 1300; + ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; - DevelopmentTeam = 23T2HFANR5; + LastSwiftMigration = 1100; }; }; }; buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -191,12 +160,8 @@ buildActionMask = 2147483647; files = ( 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, - 9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */, 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, - 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, - D57DA1A0215230B4005D4B7F /* MyLaunch.jpg in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -216,7 +181,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; @@ -239,8 +204,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, - 97C146F31CF9000F007C117D /* main.m in Sources */, + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -267,9 +231,79 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 249021D3217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Profile; + }; + 249021D4217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.example; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Profile; + }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -281,12 +315,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -313,7 +349,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; @@ -323,7 +359,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -335,12 +370,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -361,9 +398,12 @@ 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; + SUPPORTED_PLATFORMS = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -373,24 +413,20 @@ isa = XCBuildConfiguration; baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { - ARCHS = arm64; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = 23T2HFANR5; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; ENABLE_BITCODE = NO; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Flutter", - ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - LIBRARY_SEARCH_PATHS = ( + LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Flutter", + "@executable_path/Frameworks", ); PRODUCT_BUNDLE_IDENTIFIER = com.example.example; PRODUCT_NAME = "$(TARGET_NAME)"; - TARGETED_DEVICE_FAMILY = 1; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -399,24 +435,19 @@ isa = XCBuildConfiguration; baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { - ARCHS = arm64; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CURRENT_PROJECT_VERSION = 1; - DEVELOPMENT_TEAM = 23T2HFANR5; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; ENABLE_BITCODE = NO; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Flutter", - ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - LIBRARY_SEARCH_PATHS = ( + LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", - "$(PROJECT_DIR)/Flutter", + "@executable_path/Frameworks", ); PRODUCT_BUNDLE_IDENTIFIER = com.example.example; PRODUCT_NAME = "$(TARGET_NAME)"; - TARGETED_DEVICE_FAMILY = 1; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; @@ -429,6 +460,7 @@ buildConfigurations = ( 97C147031CF9000F007C117D /* Debug */, 97C147041CF9000F007C117D /* Release */, + 249021D3217E4FDB00AE95B9 /* Profile */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; @@ -438,6 +470,7 @@ buildConfigurations = ( 97C147061CF9000F007C117D /* Debug */, 97C147071CF9000F007C117D /* Release */, + 249021D4217E4FDB00AE95B9 /* Profile */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; 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/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f9b0d7c --- /dev/null +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 1263ac8..c87d15a 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ - - - - + + - - - BuildSystemType - Original + PreviewsEnabled + diff --git a/example/ios/Runner/AppDelegate.h b/example/ios/Runner/AppDelegate.h deleted file mode 100644 index cf210d2..0000000 --- a/example/ios/Runner/AppDelegate.h +++ /dev/null @@ -1,6 +0,0 @@ -#import -#import - -@interface AppDelegate : FlutterAppDelegate - -@end diff --git a/example/ios/Runner/AppDelegate.m b/example/ios/Runner/AppDelegate.m deleted file mode 100644 index 112becd..0000000 --- a/example/ios/Runner/AppDelegate.m +++ /dev/null @@ -1,12 +0,0 @@ -#include "AppDelegate.h" -#include "GeneratedPluginRegistrant.h" - -@implementation AppDelegate - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [GeneratedPluginRegistrant registerWithRegistry:self]; - // Override point for customization after application launch. - return [super application:application didFinishLaunchingWithOptions:launchOptions]; -} - -@end diff --git a/example/ios/Runner/AppDelegate.swift b/example/ios/Runner/AppDelegate.swift new file mode 100644 index 0000000..70693e4 --- /dev/null +++ b/example/ios/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +import UIKit +import Flutter + +@UIApplicationMain +@objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +} diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png index 3d43d11..dc9ada4 100644 Binary files a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png differ diff --git a/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/example/ios/Runner/Base.lproj/LaunchScreen.storyboard index e30dfce..f2e259c 100644 --- a/example/ios/Runner/Base.lproj/LaunchScreen.storyboard +++ b/example/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -1,12 +1,8 @@ - - - - - + + - - + @@ -18,19 +14,15 @@ - - - + - - - - + + @@ -40,6 +32,6 @@ - + diff --git a/example/ios/Runner/Base.lproj/Main.storyboard b/example/ios/Runner/Base.lproj/Main.storyboard index 5e371ac..f3c2851 100644 --- a/example/ios/Runner/Base.lproj/Main.storyboard +++ b/example/ios/Runner/Base.lproj/Main.storyboard @@ -1,12 +1,8 @@ - - - - - + + - - + @@ -18,9 +14,9 @@ - + - + diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index ccd04df..27491e8 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -3,7 +3,9 @@ CFBundleDevelopmentRegion - en + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Example CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier @@ -15,24 +17,22 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + $(FLUTTER_BUILD_NAME) CFBundleSignature ???? CFBundleVersion - 1 + $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS UILaunchStoryboardName LaunchScreen UIMainStoryboardFile Main - UIRequiredDeviceCapabilities - - arm64 - UISupportedInterfaceOrientations UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight UISupportedInterfaceOrientations~ipad @@ -42,6 +42,6 @@ UIInterfaceOrientationLandscapeRight UIViewControllerBasedStatusBarAppearance - + diff --git a/example/ios/Runner/Runner-Bridging-Header.h b/example/ios/Runner/Runner-Bridging-Header.h new file mode 100644 index 0000000..308a2a5 --- /dev/null +++ b/example/ios/Runner/Runner-Bridging-Header.h @@ -0,0 +1 @@ +#import "GeneratedPluginRegistrant.h" diff --git a/example/ios/Runner/main.m b/example/ios/Runner/main.m deleted file mode 100644 index 0ccc450..0000000 --- a/example/ios/Runner/main.m +++ /dev/null @@ -1,9 +0,0 @@ -#import -#import -#import "AppDelegate.h" - -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); - } -} diff --git a/example/lib/InnerSwiper.dart b/example/lib/InnerSwiper.dart index ccf32a6..23641c7 100644 --- a/example/lib/InnerSwiper.dart +++ b/example/lib/InnerSwiper.dart @@ -20,23 +20,14 @@ class InnerSwiper extends StatefulWidget { } class _InnerSwiperState extends State { - SwiperController controller; + SwiperController controller = new SwiperController(); - List autoplayes; - - List controllers; - - @override - void initState() { - controller = new SwiperController(); - autoplayes = new List() - ..length = 10 - ..fillRange(0, 10, false); - controllers = new List() - ..length = 10 - ..fillRange(0, 10, new SwiperController()); - super.initState(); - } + List autoplayes = [] + ..length = 10 + ..fillRange(0, 10, false); + List controllers = [] + ..length = 10 + ..fillRange(0, 10, new SwiperController()); @override Widget build(BuildContext context) { diff --git a/example/lib/listener_test.dart b/example/lib/listener_test.dart index a81ca60..2ff0ab7 100644 --- a/example/lib/listener_test.dart +++ b/example/lib/listener_test.dart @@ -1,11 +1,5 @@ import 'package:flutter/material.dart'; - import 'package:flutter_swiper/flutter_swiper.dart'; -import 'src/ExampleCustom.dart'; -import 'src/config.dart'; -import 'src/ExampleSwiperInScrollView.dart'; - -import 'package:flutter/cupertino.dart'; void main() => runApp(new MyApp()); @@ -24,7 +18,7 @@ class MyApp extends StatelessWidget { } class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); + MyHomePage({Key? key, required this.title}) : super(key: key); final String title; diff --git a/example/lib/main.dart b/example/lib/main.dart index 6f05be1..3e7f1d4 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,12 +1,9 @@ import 'package:flutter/material.dart'; -import 'package:flutter_page_indicator/flutter_page_indicator.dart'; - import 'package:flutter_swiper/flutter_swiper.dart'; + import 'src/ExampleCustom.dart'; -import 'src/config.dart'; import 'src/ExampleSwiperInScrollView.dart'; - -import 'package:flutter/cupertino.dart'; +import 'src/config.dart'; void main() => runApp(new MyApp()); @@ -39,7 +36,7 @@ class MyApp extends StatelessWidget { } class MyHomePage extends StatefulWidget { - MyHomePage({Key key, this.title}) : super(key: key); + MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @@ -318,11 +315,11 @@ class ExamplePhone extends StatelessWidget { } class ScaffoldWidget extends StatelessWidget { - final Widget child; + final Widget? child; final String title; final List actions; - ScaffoldWidget({this.child, this.title, this.actions}); + ScaffoldWidget({this.child, required this.title, this.actions = const []}); @override Widget build(BuildContext context) { diff --git a/example/lib/src/ExampleCustom.dart b/example/lib/src/ExampleCustom.dart index 3b65a43..c41fb45 100644 --- a/example/lib/src/ExampleCustom.dart +++ b/example/lib/src/ExampleCustom.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter_page_indicator/flutter_page_indicator.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; import 'config.dart'; import 'forms/form_widget.dart'; @@ -13,37 +12,42 @@ class ExampleCustom extends StatefulWidget { class _ExampleCustomState extends State { //properties want to custom - int _itemCount; + int _itemCount = 3; - bool _loop; + bool _loop = true; - bool _autoplay; + bool _autoplay = false; - int _autoplayDely; + int _autoplayDely = 3000; - double _padding; + double _padding = 0.0; - bool _outer; + bool _outer = false; - double _radius; + double _radius = 10.0; - double _viewportFraction; + double _viewportFraction = 0.8; - SwiperLayout _layout; + SwiperLayout _layout = SwiperLayout.TINDER; - int _currentIndex; + int _currentIndex = 0; - double _scale; + double _scale = 0.8; - Axis _scrollDirection; + Axis _scrollDirection = Axis.horizontal; - Curve _curve; + Curve _curve = Curves.ease; - double _fade; + double _fade = 1; - bool _autoplayDisableOnInteraction; + bool _autoplayDisableOnInteraction = false; - CustomLayoutOption customLayoutOption; + CustomLayoutOption customLayoutOption = new CustomLayoutOption(startIndex: -1, stateCount: 3) + .addRotate([-25.0 / 180, 0.0, 25.0 / 180]).addTranslate([ + new Offset(-350.0, 0.0), + new Offset(0.0, 0.0), + new Offset(350.0, 0.0) + ]); Widget _buildItem(BuildContext context, int index) { return ClipRRect( @@ -66,33 +70,6 @@ class _ExampleCustomState extends State { super.didUpdateWidget(oldWidget); } - @override - void initState() { - customLayoutOption = new CustomLayoutOption(startIndex: -1, stateCount: 3) - .addRotate([-25.0 / 180, 0.0, 25.0 / 180]).addTranslate([ - new Offset(-350.0, 0.0), - new Offset(0.0, 0.0), - new Offset(350.0, 0.0) - ]); - _fade = 1.0; - _currentIndex = 0; - _curve = Curves.ease; - _scale = 0.8; - _controller = new SwiperController(); - _layout = SwiperLayout.TINDER; - _radius = 10.0; - _padding = 0.0; - _loop = true; - _itemCount = 3; - _autoplay = false; - _autoplayDely = 3000; - _viewportFraction = 0.8; - _outer = false; - _scrollDirection = Axis.horizontal; - _autoplayDisableOnInteraction = false; - super.initState(); - } - // maintain the index Widget buildSwiper() { @@ -138,7 +115,7 @@ class _ExampleCustomState extends State { ); } - SwiperController _controller; + SwiperController _controller = new SwiperController(); TextEditingController numberController = new TextEditingController(); @override Widget build(BuildContext context) { @@ -183,7 +160,7 @@ class _ExampleCustomState extends State { ), new FormWidget( label: "layout", - child: new FormSelect( + child: new FormSelect( placeholder: "Select layout", value: _layout, values: [ @@ -314,7 +291,7 @@ class _ExampleCustomState extends State { new FormWidget( label: "curve", - child: new FormSelect( + child: new FormSelect( placeholder: "Select curve", value: _layout, values: [ diff --git a/example/lib/src/ExampleSwiperInScrollView.dart b/example/lib/src/ExampleSwiperInScrollView.dart index e15339f..8fc14e4 100644 --- a/example/lib/src/ExampleSwiperInScrollView.dart +++ b/example/lib/src/ExampleSwiperInScrollView.dart @@ -10,11 +10,11 @@ class ExampleSwiperInScrollView extends StatefulWidget { class _ExampleState extends State with TickerProviderStateMixin { - AnimationController controller; - Animation _animation10; - Animation _animation11; - Animation _animation12; - Animation _animation13; + late AnimationController controller; + late Animation _animation10; + late Animation _animation11; + late Animation _animation12; + late Animation _animation13; _ExampleState(); @@ -114,7 +114,6 @@ class _ExampleState extends State @override Widget build(BuildContext context) { - double screenWidth = MediaQuery.of(context).size.width; return new Container( color: Theme.of(context).primaryColorLight, child: CustomScrollView( diff --git a/example/lib/src/forms/form_widget.dart b/example/lib/src/forms/form_widget.dart index 2cba7de..6869292 100644 --- a/example/lib/src/forms/form_widget.dart +++ b/example/lib/src/forms/form_widget.dart @@ -4,9 +4,9 @@ import 'package:flutter/cupertino.dart'; class FormWidget extends StatelessWidget { final String label; - final Widget child; + final Widget? child; - FormWidget({this.label, this.child}); + FormWidget({required this.label, this.child}); @override Widget build(BuildContext context) { @@ -29,7 +29,7 @@ class FormSelect extends StatefulWidget { final List values; final dynamic value; - FormSelect({this.placeholder, this.valueChanged, this.value, this.values}); + FormSelect({required this.placeholder, required this.valueChanged, this.value, this.values = const []}); @override State createState() { @@ -116,7 +116,7 @@ class NumberPad extends StatelessWidget { final num min; final ValueChanged onChangeValue; - NumberPad({this.number, this.step, this.onChangeValue, this.max, this.min}); + NumberPad({required this.number, required this.step, required this.onChangeValue, required this.max, required this.min}); void onAdd() { onChangeValue(number + step > max ? max : number + step); diff --git a/example/pubspec.lock b/example/pubspec.lock index 5aa195f..128d5b6 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,60 +1,74 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: async: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.8.2" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.1.2" + version: "0.1.3" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" - flutter_page_indicator: - dependency: transitive - description: - name: flutter_page_indicator - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.0.3" flutter_swiper: dependency: "direct main" description: path: ".." relative: true source: path - version: "1.1.5" + version: "1.1.6" flutter_test: dependency: "direct dev" description: flutter @@ -64,37 +78,30 @@ packages: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.11" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.7.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.8.0" percent_indicator: dependency: "direct main" description: name: percent_indicator - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.0.9" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "4.0.0" sky_engine: dependency: transitive description: flutter @@ -104,65 +111,58 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.6.8" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.2.1" - transformer_page_view: - dependency: transitive - description: - name: transformer_page_view - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.1.5" + version: "0.4.3" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.1" sdks: - dart: ">=2.0.0 <3.0.0" - flutter: ">=0.1.4 <3.0.0" + dart: ">=2.14.0 <3.0.0" + flutter: ">=0.1.4" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 48d87fa..6018618 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,9 @@ name: example description: A new Flutter project. +environment: + sdk: '>=2.12.0 <3.0.0' + dependencies: flutter: sdk: flutter diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 63d397c..a466b0f 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -1,29 +1,29 @@ -// This is a basic Flutter widget test. -// To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter -// provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to -// find child widgets in the widget tree, read text, and verify that the values of widget properties -// are correct. +// // This is a basic Flutter widget test. +// // To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter +// // provides. For example, you can send tap and scroll gestures. You can also use WidgetTester to +// // find child widgets in the widget tree, read text, and verify that the values of widget properties +// // are correct. -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutter_test/flutter_test.dart'; -import 'package:example/main.dart'; +// import 'package:example/main.dart'; -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(new MyApp()); +// void main() { +// testWidgets('Counter increments smoke test', (WidgetTester tester) async { +// // Build our app and trigger a frame. +// await tester.pumpWidget(new MyApp()); - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); +// // Verify that our counter starts at 0. +// expect(find.text('0'), findsOneWidget); +// expect(find.text('1'), findsNothing); - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); +// // Tap the '+' icon and trigger a frame. +// await tester.tap(find.byIcon(Icons.add)); +// await tester.pump(); - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -} +// // Verify that our counter has incremented. +// expect(find.text('0'), findsNothing); +// expect(find.text('1'), findsOneWidget); +// }); +// } diff --git a/example/web/favicon.png b/example/web/favicon.png new file mode 100644 index 0000000..8aaa46a Binary files /dev/null and b/example/web/favicon.png differ diff --git a/example/web/icons/Icon-192.png b/example/web/icons/Icon-192.png new file mode 100644 index 0000000..b749bfe Binary files /dev/null and b/example/web/icons/Icon-192.png differ diff --git a/example/web/icons/Icon-512.png b/example/web/icons/Icon-512.png new file mode 100644 index 0000000..88cfd48 Binary files /dev/null and b/example/web/icons/Icon-512.png differ diff --git a/example/web/icons/Icon-maskable-192.png b/example/web/icons/Icon-maskable-192.png new file mode 100644 index 0000000..eb9b4d7 Binary files /dev/null and b/example/web/icons/Icon-maskable-192.png differ diff --git a/example/web/icons/Icon-maskable-512.png b/example/web/icons/Icon-maskable-512.png new file mode 100644 index 0000000..d69c566 Binary files /dev/null and b/example/web/icons/Icon-maskable-512.png differ diff --git a/example/web/index.html b/example/web/index.html new file mode 100644 index 0000000..b6b9dd2 --- /dev/null +++ b/example/web/index.html @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + example + + + + + + + diff --git a/example/web/manifest.json b/example/web/manifest.json new file mode 100644 index 0000000..096edf8 --- /dev/null +++ b/example/web/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "example", + "short_name": "example", + "start_url": ".", + "display": "standalone", + "background_color": "#0175C2", + "theme_color": "#0175C2", + "description": "A new Flutter project.", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ] +} diff --git a/lib/flutter_swiper.dart b/lib/flutter_swiper.dart index 5f19cad..e5cb768 100644 --- a/lib/flutter_swiper.dart +++ b/lib/flutter_swiper.dart @@ -5,3 +5,5 @@ export 'src/swiper_pagination.dart'; export 'src/swiper_control.dart'; export 'src/swiper_controller.dart'; export 'src/swiper_plugin.dart'; +export 'src/flutter_page_indicator/flutter_page_indicator.dart'; +export 'src/transformer_page_view/transformer_page_view.dart'; diff --git a/lib/src/custom_layout.dart b/lib/src/custom_layout.dart index 8ce77f2..e417fb0 100644 --- a/lib/src/custom_layout.dart +++ b/lib/src/custom_layout.dart @@ -2,12 +2,12 @@ part of 'swiper.dart'; abstract class _CustomLayoutStateBase extends State with SingleTickerProviderStateMixin { - double _swiperWidth; - double _swiperHeight; - Animation _animation; - AnimationController _animationController; - int _startIndex; - int _animationCount; + late double _swiperWidth; + late double _swiperHeight; + late Animation _animation; + late AnimationController _animationController; + late int _startIndex; + int? _animationCount; @override void initState() { @@ -17,7 +17,7 @@ abstract class _CustomLayoutStateBase extends State } _createAnimationController(); - widget.controller.addListener(_onController); + widget.controller?.addListener(_onController); super.initState(); } @@ -29,7 +29,7 @@ abstract class _CustomLayoutStateBase extends State @override void didChangeDependencies() { - WidgetsBinding.instance.addPostFrameCallback(_getSize); + WidgetsBinding.instance?.addPostFrameCallback(_getSize); super.didChangeDependencies(); } @@ -39,8 +39,8 @@ abstract class _CustomLayoutStateBase extends State @mustCallSuper void afterRender() { - RenderObject renderObject = context.findRenderObject(); - Size size = renderObject.paintBounds.size; + RenderObject? renderObject = context.findRenderObject(); + Size size = renderObject!.paintBounds.size; _swiperWidth = size.width; _swiperHeight = size.height; setState(() {}); @@ -49,8 +49,8 @@ abstract class _CustomLayoutStateBase extends State @override void didUpdateWidget(T oldWidget) { if (widget.controller != oldWidget.controller) { - oldWidget.controller.removeListener(_onController); - widget.controller.addListener(_onController); + oldWidget.controller?.removeListener(_onController); + widget.controller?.addListener(_onController); } if (widget.loop != oldWidget.loop) { @@ -72,8 +72,8 @@ abstract class _CustomLayoutStateBase extends State @override void dispose() { - widget.controller.removeListener(_onController); - _animationController?.dispose(); + widget.controller?.removeListener(_onController); + _animationController.dispose(); super.dispose(); } @@ -85,12 +85,12 @@ abstract class _CustomLayoutStateBase extends State ); } - Widget _buildAnimation(BuildContext context, Widget w) { + Widget _buildAnimation(BuildContext context, Widget? w) { List list = []; double animationValue = _animation.value; - for (int i = 0; i < _animationCount; ++i) { + for (int i = 0; i < (_animationCount ?? 0); ++i) { int realIndex = _currentIndex + i + _startIndex; realIndex = realIndex % widget.itemCount; if (realIndex < 0) { @@ -115,19 +115,16 @@ abstract class _CustomLayoutStateBase extends State @override Widget build(BuildContext context) { - if (_animationCount == null) { - return new Container(); - } return new AnimatedBuilder( animation: _animationController, builder: _buildAnimation); } - double _currentValue; - double _currentPos; + late double _currentValue; + late double _currentPos; bool _lockScroll = false; - void _move(double position, {int nextIndex}) async { + void _move(double position, {int? nextIndex}) async { if (_lockScroll) return; try { _lockScroll = true; @@ -170,7 +167,7 @@ abstract class _CustomLayoutStateBase extends State } void _onController() { - switch (widget.controller.event) { + switch (widget.controller?.event) { case IndexController.PREVIOUS: int prevIndex = _prevIndex(); if (prevIndex == _currentIndex) return; @@ -282,13 +279,13 @@ Offset _getOffsetValue(List values, double animationValue, int index) { abstract class TransformBuilder { List values; - TransformBuilder({this.values}); + TransformBuilder({this.values = const []}); Widget build(int i, double animationValue, Widget widget); } class ScaleTransformBuilder extends TransformBuilder { final Alignment alignment; - ScaleTransformBuilder({List values, this.alignment: Alignment.center}) + ScaleTransformBuilder({List values = const [], this.alignment: Alignment.center}) : super(values: values); Widget build(int i, double animationValue, Widget widget) { @@ -298,7 +295,7 @@ class ScaleTransformBuilder extends TransformBuilder { } class OpacityTransformBuilder extends TransformBuilder { - OpacityTransformBuilder({List values}) : super(values: values); + OpacityTransformBuilder({List values = const []}) : super(values: values); Widget build(int i, double animationValue, Widget widget) { double v = _getValue(values, animationValue, i); @@ -310,7 +307,7 @@ class OpacityTransformBuilder extends TransformBuilder { } class RotateTransformBuilder extends TransformBuilder { - RotateTransformBuilder({List values}) : super(values: values); + RotateTransformBuilder({List values = const []}) : super(values: values); Widget build(int i, double animationValue, Widget widget) { double v = _getValue(values, animationValue, i); @@ -322,7 +319,7 @@ class RotateTransformBuilder extends TransformBuilder { } class TranslateTransformBuilder extends TransformBuilder { - TranslateTransformBuilder({List values}) : super(values: values); + TranslateTransformBuilder({List values = const []}) : super(values: values); @override Widget build(int i, double animationValue, Widget widget) { @@ -339,8 +336,7 @@ class CustomLayoutOption { final int startIndex; final int stateCount; - CustomLayoutOption({this.stateCount, this.startIndex}) - : assert(startIndex != null, stateCount != null); + CustomLayoutOption({required this.stateCount, required this.startIndex}); CustomLayoutOption addOpacity(List values) { builders.add(new OpacityTransformBuilder(values: values)); @@ -368,21 +364,20 @@ class _CustomLayoutSwiper extends _SubSwiper { final CustomLayoutOption option; _CustomLayoutSwiper( - {this.option, - double itemWidth, - bool loop, - double itemHeight, - ValueChanged onIndexChanged, - Key key, - IndexedWidgetBuilder itemBuilder, - Curve curve, - int duration, - int index, - int itemCount, - Axis scrollDirection, - SwiperController controller}) - : assert(option != null), - super( + {required this.option, + double? itemWidth, + required bool loop, + double? itemHeight, + required ValueChanged onIndexChanged, + Key? key, + required IndexedWidgetBuilder itemBuilder, + required Curve curve, + required int duration, + required int index, + required int itemCount, + required Axis scrollDirection, + required SwiperController? controller}) + : super( loop: loop, onIndexChanged: onIndexChanged, itemWidth: itemWidth, @@ -424,7 +419,7 @@ class _CustomLayoutState extends _CustomLayoutStateBase<_CustomLayoutSwiper> { Widget child = new SizedBox( width: widget.itemWidth ?? double.infinity, height: widget.itemHeight ?? double.infinity, - child: widget.itemBuilder(context, realIndex)); + child: widget.itemBuilder?.call(context, realIndex)); for (int i = builders.length - 1; i >= 0; --i) { TransformBuilder builder = builders[i]; diff --git a/lib/src/flutter_page_indicator/flutter_page_indicator.dart b/lib/src/flutter_page_indicator/flutter_page_indicator.dart new file mode 100644 index 0000000..d7b61af --- /dev/null +++ b/lib/src/flutter_page_indicator/flutter_page_indicator.dart @@ -0,0 +1,349 @@ +library flutter_page_indicator; + +import 'package:flutter/material.dart'; + +class _WarmPainter extends _BasePainter { + _WarmPainter(PageIndicator widget, double page, int index, Paint paint) + : super(widget, page, index, paint); + + void draw(Canvas canvas, double space, double size, double radius) { + double progress = page - index; + double distance = size + space; + double start = index * (size + space); + + if (progress > 0.5) { + double right = start + size + distance; + //progress=>0.5-1.0 + //left:0.0=>distance + + double left = index * distance + distance * (progress - 0.5) * 2; + canvas.drawRRect( + new RRect.fromLTRBR( + left, 0.0, right, size, new Radius.circular(radius)), + _paint); + } else { + double right = start + size + distance * progress * 2; + + canvas.drawRRect( + new RRect.fromLTRBR( + start, 0.0, right, size, new Radius.circular(radius)), + _paint); + } + } +} + +class _DropPainter extends _BasePainter { + _DropPainter(PageIndicator widget, double page, int index, Paint paint) + : super(widget, page, index, paint); + + @override + void draw(Canvas canvas, double space, double size, double radius) { + double progress = page - index; + double dropHeight = widget.dropHeight; + double rate = (0.5 - progress).abs() * 2; + double scale = widget.scale; + + //lerp(begin, end, progress) + + canvas.drawCircle( + new Offset(radius + ((page) * (size + space)), + radius - dropHeight * (1 - rate)), + radius * (scale + rate * (1.0 - scale)), + _paint); + } +} + +class _NonePainter extends _BasePainter { + _NonePainter(PageIndicator widget, double page, int index, Paint paint) + : super(widget, page, index, paint); + + @override + void draw(Canvas canvas, double space, double size, double radius) { + double progress = page - index; + double secondOffset = index == widget.count - 1 + ? radius + : radius + ((index + 1) * (size + space)); + + if (progress > 0.5) { + canvas.drawCircle(new Offset(secondOffset, radius), radius, _paint); + } else { + canvas.drawCircle(new Offset(radius + (index * (size + space)), radius), + radius, _paint); + } + } +} + +class _SlidePainter extends _BasePainter { + _SlidePainter(PageIndicator widget, double page, int index, Paint paint) + : super(widget, page, index, paint); + + @override + void draw(Canvas canvas, double space, double size, double radius) { + canvas.drawCircle( + new Offset(radius + (page * (size + space)), radius), radius, _paint); + } +} + +class _ScalePainter extends _BasePainter { + _ScalePainter(PageIndicator widget, double page, int index, Paint paint) + : super(widget, page, index, paint); + + // 连续的两个点,含有最后一个和第一个 + @override + bool _shouldSkip(int i) { + if (index == widget.count - 1) { + return i == 0 || i == index; + } + return (i == index || i == index + 1); + } + + @override + void paint(Canvas canvas, Size size) { + _paint.color = widget.color; + double space = widget.space; + double size = widget.size; + double radius = size / 2; + for (int i = 0, c = widget.count; i < c; ++i) { + if (_shouldSkip(i)) { + continue; + } + canvas.drawCircle(new Offset(i * (size + space) + radius, radius), + radius * widget.scale, _paint); + } + + _paint.color = widget.activeColor; + draw(canvas, space, size, radius); + } + + @override + void draw(Canvas canvas, double space, double size, double radius) { + double secondOffset = index == widget.count - 1 + ? radius + : radius + ((index + 1) * (size + space)); + + double progress = page - index; + _paint.color = Color.lerp(widget.activeColor, widget.color, progress)!; + //last + canvas.drawCircle(new Offset(radius + (index * (size + space)), radius), + lerp(radius, radius * widget.scale, progress), _paint); + //first + _paint.color = Color.lerp(widget.color, widget.activeColor, progress)!; + canvas.drawCircle(new Offset(secondOffset, radius), + lerp(radius * widget.scale, radius, progress), _paint); + } +} + +class _ColorPainter extends _BasePainter { + _ColorPainter(PageIndicator widget, double page, int index, Paint paint) + : super(widget, page, index, paint); + + // 连续的两个点,含有最后一个和第一个 + @override + bool _shouldSkip(int i) { + if (index == widget.count - 1) { + return i == 0 || i == index; + } + return (i == index || i == index + 1); + } + + @override + void draw(Canvas canvas, double space, double size, double radius) { + double progress = page - index; + double secondOffset = index == widget.count - 1 + ? radius + : radius + ((index + 1) * (size + space)); + + _paint.color = Color.lerp(widget.activeColor, widget.color, progress)!; + //left + canvas.drawCircle( + new Offset(radius + (index * (size + space)), radius), radius, _paint); + //right + _paint.color = Color.lerp(widget.color, widget.activeColor, progress)!; + canvas.drawCircle(new Offset(secondOffset, radius), radius, _paint); + } +} + +abstract class _BasePainter extends CustomPainter { + final PageIndicator widget; + final double page; + final int index; + final Paint _paint; + + double lerp(double begin, double end, double progress) { + return begin + (end - begin) * progress; + } + + _BasePainter(this.widget, this.page, this.index, this._paint); + + void draw(Canvas canvas, double space, double size, double radius); + + bool _shouldSkip(int index) { + return false; + } + //double secondOffset = index == widget.count-1 ? radius : radius + ((index + 1) * (size + space)); + + @override + void paint(Canvas canvas, Size size) { + _paint.color = widget.color; + double space = widget.space; + double size = widget.size; + double radius = size / 2; + for (int i = 0, c = widget.count; i < c; ++i) { + if (_shouldSkip(i)) { + continue; + } + canvas.drawCircle( + new Offset(i * (size + space) + radius, radius), radius, _paint); + } + + double page = this.page; + if (page < index) { + page = 0.0; + } + _paint.color = widget.activeColor; + draw(canvas, space, size, radius); + } + + @override + bool shouldRepaint(_BasePainter oldDelegate) { + return oldDelegate.page != page; + } +} + +class _PageIndicatorState extends State { + int index = 0; + Paint _paint = new Paint(); + + _BasePainter _createPainer() { + switch (widget.layout) { + case PageIndicatorLayout.NONE: + return new _NonePainter( + widget, widget.controller?.page ?? 0.0, index, _paint); + case PageIndicatorLayout.SLIDE: + return new _SlidePainter( + widget, widget.controller?.page ?? 0.0, index, _paint); + case PageIndicatorLayout.WARM: + return new _WarmPainter( + widget, widget.controller?.page ?? 0.0, index, _paint); + case PageIndicatorLayout.COLOR: + return new _ColorPainter( + widget, widget.controller?.page ?? 0.0, index, _paint); + case PageIndicatorLayout.SCALE: + return new _ScalePainter( + widget, widget.controller?.page ?? 0.0, index, _paint); + case PageIndicatorLayout.DROP: + return new _DropPainter( + widget, widget.controller?.page ?? 0.0, index, _paint); + default: + throw new Exception("Not a valid layout"); + } + } + + @override + Widget build(BuildContext context) { + Widget child = new SizedBox( + width: widget.count * widget.size + (widget.count - 1) * widget.space, + height: widget.size, + child: new CustomPaint( + painter: _createPainer(), + ), + ); + + if (widget.layout == PageIndicatorLayout.SCALE || + widget.layout == PageIndicatorLayout.COLOR) { + child = new ClipRect( + child: child, + ); + } + + return new IgnorePointer( + child: child, + ); + } + + void _onController() { + double page = widget.controller?.page ?? 0.0; + index = page.floor(); + + setState(() {}); + } + + @override + void initState() { + widget.controller?.addListener(_onController); + super.initState(); + } + + @override + void didUpdateWidget(PageIndicator oldWidget) { + if (widget.controller != oldWidget.controller) { + oldWidget.controller?.removeListener(_onController); + widget.controller?.addListener(_onController); + } + super.didUpdateWidget(oldWidget); + } + + @override + void dispose() { + widget.controller?.removeListener(_onController); + super.dispose(); + } +} + +enum PageIndicatorLayout { + NONE, + SLIDE, + WARM, + COLOR, + SCALE, + DROP, +} + +class PageIndicator extends StatefulWidget { + /// size of the dots + final double size; + + /// space between dots. + final double space; + + /// count of dots + final int count; + + /// active color + final Color activeColor; + + /// normal color + final Color color; + + /// layout of the dots,default is [PageIndicatorLayout.SLIDE] + final PageIndicatorLayout layout; + + // Only valid when layout==PageIndicatorLayout.scale + final double scale; + + // Only valid when layout==PageIndicatorLayout.drop + final double dropHeight; + + final PageController? controller; + + final double activeSize; + + PageIndicator( + {Key? key, + this.size: 20.0, + this.space: 5.0, + required this.count, + this.activeSize: 20.0, + this.controller, + this.color: Colors.white30, + this.layout: PageIndicatorLayout.SLIDE, + this.activeColor: Colors.white, + this.scale: 0.6, + this.dropHeight: 20.0}) + : super(key: key); + + @override + State createState() { + return new _PageIndicatorState(); + } +} \ No newline at end of file diff --git a/lib/src/swiper.dart b/lib/src/swiper.dart index 9783740..5ea0ff8 100644 --- a/lib/src/swiper.dart +++ b/lib/src/swiper.dart @@ -1,10 +1,7 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; -import 'package:flutter_page_indicator/flutter_page_indicator.dart'; -import 'package:flutter_swiper/flutter_swiper.dart'; import 'dart:async'; -import 'package:transformer_page_view/transformer_page_view.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_swiper/flutter_swiper.dart'; part 'custom_layout.dart'; @@ -18,9 +15,6 @@ const int kDefaultAutoplayDelayMs = 3000; /// Default auto play transition duration (in millisecond) const int kDefaultAutoplayTransactionDuration = 300; -const int kMaxValue = 2000000000; -const int kMiddleValue = 1000000000; - enum SwiperLayout { DEFAULT, STACK, TINDER, CUSTOM } class Swiper extends StatefulWidget { @@ -28,27 +22,27 @@ class Swiper extends StatefulWidget { final bool outer; /// Inner item height, this property is valid if layout=STACK or layout=TINDER or LAYOUT=CUSTOM, - final double itemHeight; + final double? itemHeight; /// Inner item width, this property is valid if layout=STACK or layout=TINDER or LAYOUT=CUSTOM, - final double itemWidth; + final double? itemWidth; // height of the inside container,this property is valid when outer=true,otherwise the inside container size is controlled by parent widget - final double containerHeight; + final double? containerHeight; // width of the inside container,this property is valid when outer=true,otherwise the inside container size is controlled by parent widget - final double containerWidth; + final double? containerWidth; /// Build item on index - final IndexedWidgetBuilder itemBuilder; + final IndexedWidgetBuilder? itemBuilder; /// Support transform like Android PageView did /// `itemBuilder` and `transformItemBuilder` must have one not null - final PageTransformer transformer; + final PageTransformer? transformer; /// count of the display items final int itemCount; - final ValueChanged onIndexChanged; + final ValueChanged? onIndexChanged; ///auto play config final bool autoplay; @@ -74,24 +68,24 @@ class Swiper extends StatefulWidget { ///Index number of initial slide. ///If not set , the `Swiper` is 'uncontrolled', which means manage index by itself ///If set , the `Swiper` is 'controlled', which means the index is fully managed by parent widget. - final int index; + final int? index; ///Called when tap - final SwiperOnTap onTap; + final SwiperOnTap? onTap; ///The swiper pagination plugin - final SwiperPlugin pagination; + final SwiperPlugin? pagination; ///the swiper control button plugin - final SwiperPlugin control; + final SwiperPlugin? control; ///other plugins, you can custom your own plugin final List plugins; /// - final SwiperController controller; + final SwiperController? controller; - final ScrollPhysics physics; + final ScrollPhysics? physics; /// final double viewportFraction; @@ -100,13 +94,13 @@ class Swiper extends StatefulWidget { final SwiperLayout layout; /// this value is valid when layout == SwiperLayout.CUSTOM - final CustomLayoutOption customLayoutOption; + final CustomLayoutOption? customLayoutOption; // This value is valid when viewportFraction is set and < 1.0 - final double scale; + final double? scale; // This value is valid when viewportFraction is set and < 1.0 - final double fade; + final double? fade; final PageIndicatorLayout indicatorLayout; @@ -116,7 +110,7 @@ class Swiper extends StatefulWidget { /// this.transformer, - @required this.itemCount, + required this.itemCount, this.autoplay: false, this.layout: SwiperLayout.DEFAULT, this.autoplayDelay: kDefaultAutoplayDelayMs, @@ -130,9 +124,9 @@ class Swiper extends StatefulWidget { this.curve: Curves.ease, this.scrollDirection: Axis.horizontal, this.pagination, - this.plugins, + this.plugins: const [], this.physics, - Key key, + Key? key, this.controller, this.customLayoutOption, @@ -159,36 +153,34 @@ class Swiper extends StatefulWidget { super(key: key); factory Swiper.children({ - List children, + required List children, bool autoplay: false, - PageTransformer transformer, + PageTransformer? transformer, int autoplayDelay: kDefaultAutoplayDelayMs, bool reverse: false, bool autoplayDisableOnInteraction: true, int duration: kDefaultAutoplayTransactionDuration, - ValueChanged onIndexChanged, - int index, - SwiperOnTap onTap, + ValueChanged? onIndexChanged, + int? index, + SwiperOnTap? onTap, bool loop: true, Curve curve: Curves.ease, Axis scrollDirection: Axis.horizontal, - SwiperPlugin pagination, - SwiperPlugin control, - List plugins, - SwiperController controller, - Key key, - CustomLayoutOption customLayoutOption, - ScrollPhysics physics, - double containerHeight, - double containerWidth, + SwiperPlugin? pagination, + SwiperPlugin? control, + List plugins = const [], + SwiperController? controller, + Key? key, + CustomLayoutOption? customLayoutOption, + ScrollPhysics? physics, + double? containerHeight, + double? containerWidth, double viewportFraction: 1.0, - double itemHeight, - double itemWidth, + double? itemHeight, + double? itemWidth, bool outer: false, double scale: 1.0, }) { - assert(children != null, "children must not be null"); - return new Swiper( transformer: transformer, customLayoutOption: customLayoutOption, @@ -222,32 +214,32 @@ class Swiper extends StatefulWidget { } factory Swiper.list({ - PageTransformer transformer, - List list, - CustomLayoutOption customLayoutOption, - SwiperDataBuilder builder, + PageTransformer? transformer, + required List list, + CustomLayoutOption? customLayoutOption, + required SwiperDataBuilder builder, bool autoplay: false, int autoplayDelay: kDefaultAutoplayDelayMs, bool reverse: false, bool autoplayDisableOnInteraction: true, int duration: kDefaultAutoplayTransactionDuration, - ValueChanged onIndexChanged, - int index, - SwiperOnTap onTap, + ValueChanged? onIndexChanged, + int? index, + SwiperOnTap? onTap, bool loop: true, Curve curve: Curves.ease, Axis scrollDirection: Axis.horizontal, - SwiperPlugin pagination, - SwiperPlugin control, - List plugins, - SwiperController controller, - Key key, - ScrollPhysics physics, - double containerHeight, - double containerWidth, + SwiperPlugin? pagination, + SwiperPlugin? control, + List plugins: const [], + SwiperController? controller, + Key? key, + ScrollPhysics? physics, + double? containerHeight, + double? containerWidth, double viewportFraction: 1.0, - double itemHeight, - double itemWidth, + double? itemHeight, + double? itemWidth, bool outer: false, double scale: 1.0, }) { @@ -290,23 +282,22 @@ class Swiper extends StatefulWidget { } abstract class _SwiperTimerMixin extends State { - Timer _timer; + Timer? _timer; - SwiperController _controller; + SwiperController? _controller; @override void initState() { - _controller = widget.controller; - if (_controller == null) { + if (widget.controller == null) { _controller = new SwiperController(); } - _controller.addListener(_onController); + _controller?.addListener(_onController); _handleAutoplay(); super.initState(); } void _onController() { - switch (_controller.event) { + switch (_controller?.event) { case SwiperController.START_AUTOPLAY: { if (_timer == null) { @@ -328,9 +319,9 @@ abstract class _SwiperTimerMixin extends State { void didUpdateWidget(Swiper oldWidget) { if (_controller != oldWidget.controller) { if (oldWidget.controller != null) { - oldWidget.controller.removeListener(_onController); - _controller = oldWidget.controller; - _controller.addListener(_onController); + oldWidget.controller!.removeListener(_onController); + _controller = oldWidget.controller!; + _controller?.addListener(_onController); } } _handleAutoplay(); @@ -339,17 +330,15 @@ abstract class _SwiperTimerMixin extends State { @override void dispose() { - if (_controller != null) { - _controller.removeListener(_onController); - // _controller.dispose(); - } + _controller?.removeListener(_onController); + // _controller?.dispose(); _stopAutoplay(); super.dispose(); } bool _autoplayEnabled() { - return _controller.autoplay ?? widget.autoplay; + return _controller?.autoplay ?? false; } void _handleAutoplay() { @@ -367,29 +356,29 @@ abstract class _SwiperTimerMixin extends State { } void _onTimer(Timer timer) { - _controller.next(animation: true); + _controller?.next(animation: true); } void _stopAutoplay() { if (_timer != null) { - _timer.cancel(); + _timer!.cancel(); _timer = null; } } } class _SwiperState extends _SwiperTimerMixin { - int _activeIndex; + late int _activeIndex; - TransformerPageController _pageController; + TransformerPageController? _pageController; Widget _wrapTap(BuildContext context, int index) { return new GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { - this.widget.onTap(index); + widget.onTap?.call(index); }, - child: widget.itemBuilder(context, index), + child: widget.itemBuilder?.call(context, index), ); } @@ -398,18 +387,18 @@ class _SwiperState extends _SwiperTimerMixin { _activeIndex = widget.index ?? 0; if (_isPageViewLayout()) { _pageController = new TransformerPageController( - initialPage: widget.index, + initialPage: widget.index ?? 0, loop: widget.loop, itemCount: widget.itemCount, reverse: - widget.transformer == null ? false : widget.transformer.reverse, + widget.transformer == null ? false : widget.transformer!.reverse, viewportFraction: widget.viewportFraction); } super.initState(); } bool _isPageViewLayout() { - return widget.layout == null || widget.layout == SwiperLayout.DEFAULT; + return widget.layout == SwiperLayout.DEFAULT; } @override @@ -418,20 +407,19 @@ class _SwiperState extends _SwiperTimerMixin { } bool _getReverse(Swiper widget) => - widget.transformer == null ? false : widget.transformer.reverse; + widget.transformer == null ? false : widget.transformer!.reverse; @override void didUpdateWidget(Swiper oldWidget) { super.didUpdateWidget(oldWidget); if (_isPageViewLayout()) { - if (_pageController == null || - (widget.index != oldWidget.index || + if ((widget.index != oldWidget.index || widget.loop != oldWidget.loop || widget.itemCount != oldWidget.itemCount || widget.viewportFraction != oldWidget.viewportFraction || _getReverse(widget) != _getReverse(oldWidget))) { _pageController = new TransformerPageController( - initialPage: widget.index, + initialPage: widget.index ?? 0, loop: widget.loop, itemCount: widget.itemCount, reverse: _getReverse(widget), @@ -440,14 +428,12 @@ class _SwiperState extends _SwiperTimerMixin { } else { scheduleMicrotask(() { // So that we have a chance to do `removeListener` in child widgets. - if (_pageController != null) { - _pageController.dispose(); - _pageController = null; - } + _pageController?.dispose(); + _pageController = null; }); } if (widget.index != null && widget.index != _activeIndex) { - _activeIndex = widget.index; + _activeIndex = widget.index!; } } @@ -456,12 +442,12 @@ class _SwiperState extends _SwiperTimerMixin { _activeIndex = index; }); if (widget.onIndexChanged != null) { - widget.onIndexChanged(index); + widget.onIndexChanged!(index); } } Widget _buildSwiper() { - IndexedWidgetBuilder itemBuilder; + IndexedWidgetBuilder? itemBuilder; if (widget.onTap != null) { itemBuilder = _wrapTap; } else { @@ -483,7 +469,7 @@ class _SwiperState extends _SwiperTimerMixin { scrollDirection: widget.scrollDirection, ); } else if (_isPageViewLayout()) { - PageTransformer transformer = widget.transformer; + PageTransformer? transformer = widget.transformer; if (widget.scale != null || widget.fade != null) { transformer = new ScaleAndFadeTransformer(scale: widget.scale, fade: widget.fade); @@ -527,9 +513,9 @@ class _SwiperState extends _SwiperTimerMixin { return new _TinderSwiper( loop: widget.loop, itemWidth: widget.itemWidth, - itemHeight: widget.itemHeight, + itemHeight: widget.itemHeight!, itemCount: widget.itemCount, - itemBuilder: itemBuilder, + itemBuilder: itemBuilder!, index: _activeIndex, curve: widget.curve, duration: widget.duration, @@ -540,11 +526,11 @@ class _SwiperState extends _SwiperTimerMixin { } else if (widget.layout == SwiperLayout.CUSTOM) { return new _CustomLayoutSwiper( loop: widget.loop, - option: widget.customLayoutOption, + option: widget.customLayoutOption!, itemWidth: widget.itemWidth, itemHeight: widget.itemHeight, itemCount: widget.itemCount, - itemBuilder: itemBuilder, + itemBuilder: itemBuilder!, index: _activeIndex, curve: widget.curve, duration: widget.duration, @@ -557,7 +543,7 @@ class _SwiperState extends _SwiperTimerMixin { } } - SwiperPluginConfig _ensureConfig(SwiperPluginConfig config) { + SwiperPluginConfig _ensureConfig(SwiperPluginConfig? config) { if (config == null) { config = new SwiperPluginConfig( outer: widget.outer, @@ -574,7 +560,7 @@ class _SwiperState extends _SwiperTimerMixin { } List _ensureListForStack( - Widget swiper, List listForStack, Widget widget) { + Widget swiper, List? listForStack, Widget widget) { if (listForStack == null) { listForStack = [swiper, widget]; } else { @@ -586,46 +572,40 @@ class _SwiperState extends _SwiperTimerMixin { @override Widget build(BuildContext context) { Widget swiper = _buildSwiper(); - List listForStack; - SwiperPluginConfig config; + List? listForStack; + SwiperPluginConfig? config; if (widget.control != null) { //Stack config = _ensureConfig(config); listForStack = _ensureListForStack( - swiper, listForStack, widget.control.build(context, config)); + swiper, listForStack, widget.control!.build(context, config)); } - if (widget.plugins != null) { - config = _ensureConfig(config); - for (SwiperPlugin plugin in widget.plugins) { - listForStack = _ensureListForStack( - swiper, listForStack, plugin.build(context, config)); - } + config = _ensureConfig(config); + for (SwiperPlugin plugin in widget.plugins) { + listForStack = _ensureListForStack( + swiper, listForStack, plugin.build(context, config)); } if (widget.pagination != null) { config = _ensureConfig(config); if (widget.outer) { return _buildOuterPagination( - widget.pagination, + widget.pagination!, listForStack == null ? swiper : new Stack(children: listForStack), config); } else { listForStack = _ensureListForStack( - swiper, listForStack, widget.pagination.build(context, config)); + swiper, listForStack, widget.pagination!.build(context, config)); } } - if (listForStack != null) { - return new Stack( - children: listForStack, - ); - } - - return swiper; + return new Stack( + children: listForStack ?? [], + ); } Widget _buildOuterPagination( - SwiperPagination pagination, Widget swiper, SwiperPluginConfig config) { + SwiperPlugin pagination, Widget swiper, SwiperPluginConfig config) { List list = []; //Only support bottom yet! if (widget.containerHeight != null || widget.containerWidth != null) { @@ -648,31 +628,31 @@ class _SwiperState extends _SwiperTimerMixin { } abstract class _SubSwiper extends StatefulWidget { - final IndexedWidgetBuilder itemBuilder; + final IndexedWidgetBuilder? itemBuilder; final int itemCount; final int index; final ValueChanged onIndexChanged; - final SwiperController controller; + final SwiperController? controller; final int duration; final Curve curve; - final double itemWidth; - final double itemHeight; + final double? itemWidth; + final double? itemHeight; final bool loop; final Axis scrollDirection; _SubSwiper( - {Key key, - this.loop, + {Key? key, + required this.loop, this.itemHeight, this.itemWidth, - this.duration, - this.curve, + required this.duration, + required this.curve, this.itemBuilder, - this.controller, - this.index, - this.itemCount, + required this.controller, + required this.index, + required this.itemCount, this.scrollDirection: Axis.horizontal, - this.onIndexChanged}) + required this.onIndexChanged}) : super(key: key); @override @@ -690,20 +670,19 @@ abstract class _SubSwiper extends StatefulWidget { class _TinderSwiper extends _SubSwiper { _TinderSwiper({ - Key key, - Curve curve, - int duration, - SwiperController controller, - ValueChanged onIndexChanged, - double itemHeight, - double itemWidth, - IndexedWidgetBuilder itemBuilder, - int index, - bool loop, - int itemCount, - Axis scrollDirection, - }) : assert(itemWidth != null && itemHeight != null), - super( + Key? key, + required Curve curve, + required int duration, + required SwiperController? controller, + required ValueChanged onIndexChanged, + required double itemHeight, + double? itemWidth, + required IndexedWidgetBuilder itemBuilder, + required int index, + required bool loop, + required int itemCount, + required Axis scrollDirection, + }) : super( loop: loop, key: key, itemWidth: itemWidth, @@ -725,18 +704,18 @@ class _TinderSwiper extends _SubSwiper { class _StackSwiper extends _SubSwiper { _StackSwiper({ - Key key, - Curve curve, - int duration, - SwiperController controller, - ValueChanged onIndexChanged, - double itemHeight, - double itemWidth, - IndexedWidgetBuilder itemBuilder, - int index, - bool loop, - int itemCount, - Axis scrollDirection, + Key? key, + required Curve curve, + required int duration, + required SwiperController? controller, + required ValueChanged onIndexChanged, + double? itemHeight, + double? itemWidth, + IndexedWidgetBuilder? itemBuilder, + required int index, + required bool loop, + required int itemCount, + required Axis scrollDirection, }) : super( loop: loop, key: key, @@ -758,14 +737,14 @@ class _StackSwiper extends _SubSwiper { } class _TinderState extends _CustomLayoutStateBase<_TinderSwiper> { - List scales; - List offsetsX; - List offsetsY; - List opacity; - List rotates; + late List scales; + late List offsetsX; + late List offsetsY; + late List opacity; + late List rotates; double getOffsetY(double scale) { - return widget.itemHeight - widget.itemHeight * scale; + return widget.itemHeight! - widget.itemHeight! * scale; } @override @@ -841,7 +820,7 @@ class _TinderState extends _CustomLayoutStateBase<_TinderSwiper> { child: new SizedBox( width: widget.itemWidth ?? double.infinity, height: widget.itemHeight ?? double.infinity, - child: widget.itemBuilder(context, realIndex), + child: widget.itemBuilder?.call(context, realIndex), ), ), ), @@ -851,9 +830,9 @@ class _TinderState extends _CustomLayoutStateBase<_TinderSwiper> { } class _StackViewState extends _CustomLayoutStateBase<_StackSwiper> { - List scales; - List offsets; - List opacity; + late List scales; + late List offsets; + late List opacity; @override void didChangeDependencies() { super.didChangeDependencies(); @@ -861,10 +840,10 @@ class _StackViewState extends _CustomLayoutStateBase<_StackSwiper> { void _updateValues() { if (widget.scrollDirection == Axis.horizontal) { - double space = (_swiperWidth - widget.itemWidth) / 2; + double space = (_swiperWidth - widget.itemWidth!) / 2; offsets = [-space, -space / 3 * 2, -space / 3, 0.0, _swiperWidth]; } else { - double space = (_swiperHeight - widget.itemHeight) / 2; + double space = (_swiperHeight - widget.itemHeight!) / 2; offsets = [-space, -space / 3 * 2, -space / 3, 0.0, _swiperHeight]; } } @@ -915,7 +894,7 @@ class _StackViewState extends _CustomLayoutStateBase<_StackSwiper> { child: new SizedBox( width: widget.itemWidth ?? double.infinity, height: widget.itemHeight ?? double.infinity, - child: widget.itemBuilder(context, realIndex), + child: widget.itemBuilder?.call(context, realIndex), ), ), ), @@ -927,32 +906,28 @@ class ScaleAndFadeTransformer extends PageTransformer { final double _scale; final double _fade; - ScaleAndFadeTransformer({double fade: 0.3, double scale: 0.8}) - : _fade = fade, - _scale = scale; + ScaleAndFadeTransformer({double? fade: 0.3, double? scale: 0.8}) + : _fade = fade ?? 0.3, + _scale = scale ?? 0.8; @override Widget transform(Widget item, TransformInfo info) { double position = info.position; Widget child = item; - if (_scale != null) { - double scaleFactor = (1 - position.abs()) * (1 - _scale); - double scale = _scale + scaleFactor; + double scaleFactor = (1 - position.abs()) * (1 - _scale); + double scale = _scale + scaleFactor; - child = new Transform.scale( - scale: scale, - child: item, - ); - } + child = new Transform.scale( + scale: scale, + child: item, + ); - if (_fade != null) { - double fadeFactor = (1 - position.abs()) * (1 - _fade); - double opacity = _fade + fadeFactor; - child = new Opacity( - opacity: opacity, - child: child, - ); - } + double fadeFactor = (1 - position.abs()) * (1 - _fade); + double opacity = _fade + fadeFactor; + child = new Opacity( + opacity: opacity, + child: child, + ); return child; } diff --git a/lib/src/swiper_control.dart b/lib/src/swiper_control.dart index 158b460..239395b 100644 --- a/lib/src/swiper_control.dart +++ b/lib/src/swiper_control.dart @@ -12,15 +12,15 @@ class SwiperControl extends SwiperPlugin { final double size; ///Icon normal color, The theme's [ThemeData.primaryColor] by default. - final Color color; + final Color? color; ///if set loop=false on Swiper, this color will be used when swiper goto the last slide. ///The theme's [ThemeData.disabledColor] by default. - final Color disableColor; + final Color? disableColor; final EdgeInsetsGeometry padding; - final Key key; + final Key? key; const SwiperControl( {this.iconPrevious: Icons.arrow_back_ios, @@ -37,9 +37,9 @@ class SwiperControl extends SwiperPlugin { behavior: HitTestBehavior.opaque, onTap: () { if (previous) { - config.controller.previous(animation: true); + config.controller?.previous(animation: true); } else { - config.controller.next(animation: true); + config.controller?.next(animation: true); } }, child: Padding( @@ -64,7 +64,7 @@ class SwiperControl extends SwiperPlugin { Color prevColor; Color nextColor; - if (config.loop) { + if (config.loop ?? false) { prevColor = nextColor = color; } else { bool next = config.activeIndex < config.itemCount - 1; diff --git a/lib/src/swiper_controller.dart b/lib/src/swiper_controller.dart index a659500..dc178fe 100644 --- a/lib/src/swiper_controller.dart +++ b/lib/src/swiper_controller.dart @@ -1,5 +1,5 @@ import 'package:flutter_swiper/src/swiper_plugin.dart'; -import 'package:transformer_page_view/transformer_page_view.dart'; +import 'package:flutter_swiper/src/transformer_page_view/transformer_page_view.dart'; class SwiperController extends IndexController { // Autoplay is started @@ -16,15 +16,13 @@ class SwiperController extends IndexController { static const int BUILD = 5; // available when `event` == SwiperController.BUILD - SwiperPluginConfig config; + SwiperPluginConfig? config; // available when `event` == SwiperController.SWIPE // this value is PageViewController.pos - double pos; + double? pos; - int index; - bool animation; - bool autoplay; + bool autoplay = false; SwiperController(); diff --git a/lib/src/swiper_pagination.dart b/lib/src/swiper_pagination.dart index a866de2..5b929ea 100644 --- a/lib/src/swiper_pagination.dart +++ b/lib/src/swiper_pagination.dart @@ -1,15 +1,12 @@ import 'package:flutter/material.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; -import 'package:flutter_page_indicator/flutter_page_indicator.dart'; - class FractionPaginationBuilder extends SwiperPlugin { ///color ,if set null , will be Theme.of(context).scaffoldBackgroundColor - final Color color; + final Color? color; ///color when active,if set null , will be Theme.of(context).primaryColor - final Color activeColor; + final Color? activeColor; ////font size final double fontSize; @@ -17,7 +14,7 @@ class FractionPaginationBuilder extends SwiperPlugin { ///font size when active final double activeFontSize; - final Key key; + final Key? key; const FractionPaginationBuilder( {this.color, @@ -72,10 +69,10 @@ class FractionPaginationBuilder extends SwiperPlugin { class RectSwiperPaginationBuilder extends SwiperPlugin { ///color when current index,if set null , will be Theme.of(context).primaryColor - final Color activeColor; + final Color? activeColor; ///,if set null , will be Theme.of(context).scaffoldBackgroundColor - final Color color; + final Color? color; ///Size of the rect when activate final Size activeSize; @@ -86,7 +83,7 @@ class RectSwiperPaginationBuilder extends SwiperPlugin { /// Space between rects final double space; - final Key key; + final Key? key; const RectSwiperPaginationBuilder( {this.activeColor, @@ -144,10 +141,10 @@ class RectSwiperPaginationBuilder extends SwiperPlugin { class DotSwiperPaginationBuilder extends SwiperPlugin { ///color when current index,if set null , will be Theme.of(context).primaryColor - final Color activeColor; + final Color? activeColor; ///,if set null , will be Theme.of(context).scaffoldBackgroundColor - final Color color; + final Color? color; ///Size of the dot when activate final double activeSize; @@ -158,7 +155,7 @@ class DotSwiperPaginationBuilder extends SwiperPlugin { /// Space between dots final double space; - final Key key; + final Key? key; const DotSwiperPaginationBuilder( {this.activeColor, @@ -174,8 +171,8 @@ class DotSwiperPaginationBuilder extends SwiperPlugin { print( "The itemCount is too big, we suggest use FractionPaginationBuilder instead of DotSwiperPaginationBuilder in this sitituation"); } - Color activeColor = this.activeColor; - Color color = this.color; + Color? activeColor = this.activeColor; + Color? color = this.color; if (activeColor == null || color == null) { ThemeData themeData = Theme.of(context); @@ -188,7 +185,7 @@ class DotSwiperPaginationBuilder extends SwiperPlugin { return new PageIndicator( count: config.itemCount, controller: config.pageController, - layout: config.indicatorLayout, + layout: config.indicatorLayout ?? PageIndicatorLayout.SLIDE, size: size, activeColor: activeColor, color: color, @@ -238,7 +235,7 @@ typedef Widget SwiperPaginationBuilder( class SwiperCustomPagination extends SwiperPlugin { final SwiperPaginationBuilder builder; - SwiperCustomPagination({@required this.builder}) : assert(builder != null); + SwiperCustomPagination({required this.builder}); @override Widget build(BuildContext context, SwiperPluginConfig config) { @@ -257,7 +254,7 @@ class SwiperPagination extends SwiperPlugin { /// Alignment.bottomCenter by default when scrollDirection== Axis.horizontal /// Alignment.centerRight by default when scrollDirection== Axis.vertical - final Alignment alignment; + final Alignment? alignment; /// Distance between pagination and the container final EdgeInsetsGeometry margin; @@ -265,7 +262,7 @@ class SwiperPagination extends SwiperPlugin { /// Build the widet final SwiperPlugin builder; - final Key key; + final Key? key; const SwiperPagination( {this.alignment, @@ -282,7 +279,7 @@ class SwiperPagination extends SwiperPlugin { margin: margin, child: this.builder.build(context, config), ); - if (!config.outer) { + if (!(config.outer ?? false)) { child = new Align( key: key, alignment: alignment, diff --git a/lib/src/swiper_plugin.dart b/lib/src/swiper_plugin.dart index 5c9fb9a..562ef7d 100644 --- a/lib/src/swiper_plugin.dart +++ b/lib/src/swiper_plugin.dart @@ -1,5 +1,4 @@ import 'package:flutter/widgets.dart'; -import 'package:flutter_page_indicator/flutter_page_indicator.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; /// plugin to display swiper components @@ -13,26 +12,24 @@ abstract class SwiperPlugin { class SwiperPluginConfig { final int activeIndex; final int itemCount; - final PageIndicatorLayout indicatorLayout; + final PageIndicatorLayout? indicatorLayout; final Axis scrollDirection; - final bool loop; - final bool outer; - final PageController pageController; - final SwiperController controller; - final SwiperLayout layout; + final bool? loop; + final bool? outer; + final PageController? pageController; + final SwiperController? controller; + final SwiperLayout? layout; const SwiperPluginConfig( - {this.activeIndex, - this.itemCount, + {required this.activeIndex, + required this.itemCount, this.indicatorLayout, this.outer, - this.scrollDirection, - this.controller, + required this.scrollDirection, + required this.controller, this.pageController, this.layout, - this.loop}) - : assert(scrollDirection != null), - assert(controller != null); + this.loop}); } class SwiperPluginView extends StatelessWidget { diff --git a/lib/src/transformer_page_view/index_controller.dart b/lib/src/transformer_page_view/index_controller.dart new file mode 100644 index 0000000..1896ccb --- /dev/null +++ b/lib/src/transformer_page_view/index_controller.dart @@ -0,0 +1,47 @@ +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/widgets.dart'; + +class IndexController extends ChangeNotifier { + static const int NEXT = 1; + static const int PREVIOUS = -1; + static const int MOVE = 0; + + late Completer _completer; + + late int index; + late bool animation; + late int event; + + Future move(int index, {bool? animation: true}) { + this.animation = animation ?? true; + this.index = index; + this.event = MOVE; + _completer = new Completer(); + notifyListeners(); + return _completer.future; + } + + Future next({bool? animation: true}) { + this.event = NEXT; + this.animation = animation ?? true; + _completer = new Completer(); + notifyListeners(); + return _completer.future; + } + + Future previous({bool? animation: true}) { + this.event = PREVIOUS; + this.animation = animation ?? true; + _completer = new Completer(); + notifyListeners(); + return _completer.future; + } + + void complete() { + if (!_completer.isCompleted) { + _completer.complete(); + } + } +} \ No newline at end of file diff --git a/lib/src/transformer_page_view/parallax.dart b/lib/src/transformer_page_view/parallax.dart new file mode 100644 index 0000000..2ea5f75 --- /dev/null +++ b/lib/src/transformer_page_view/parallax.dart @@ -0,0 +1,142 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_swiper/src/transformer_page_view/transformer_page_view.dart'; + +typedef void PaintCallback(Canvas canvas, Size siz); + +class ColorPainter extends CustomPainter { + final Paint _paint; + final TransformInfo info; + final List colors; + + ColorPainter(this._paint, this.info, this.colors); + + @override + void paint(Canvas canvas, Size size) { + int index = info.fromIndex; + _paint.color = colors[index]; + canvas.drawRect( + new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _paint); + if (info.done) { + return; + } + int alpha; + int color; + double opacity; + double position = info.position; + if (info.forward) { + if (index < colors.length - 1) { + color = colors[index + 1].value & 0x00ffffff; + opacity = (position <= 0 + ? (-position / info.viewportFraction) + : 1 - position / info.viewportFraction); + if (opacity > 1) { + opacity -= 1.0; + } + if (opacity < 0) { + opacity += 1.0; + } + alpha = (0xff * opacity).toInt(); + + _paint.color = new Color((alpha << 24) | color); + canvas.drawRect( + new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _paint); + } + } else { + if (index > 0) { + color = colors[index - 1].value & 0x00ffffff; + opacity = (position > 0 + ? position / info.viewportFraction + : (1 + position / info.viewportFraction)); + if (opacity > 1) { + opacity -= 1.0; + } + if (opacity < 0) { + opacity += 1.0; + } + alpha = (0xff * opacity).toInt(); + + _paint.color = new Color((alpha << 24) | color); + canvas.drawRect( + new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _paint); + } + } + } + + @override + bool shouldRepaint(ColorPainter oldDelegate) { + return oldDelegate.info != info; + } +} + +class _ParallaxColorState extends State { + Paint paint = new Paint(); + + @override + Widget build(BuildContext context) { + return new CustomPaint( + painter: new ColorPainter(paint, widget.info, widget.colors), + child: widget.child, + ); + } +} + +class ParallaxColor extends StatefulWidget { + final Widget child; + + final List colors; + + final TransformInfo info; + + ParallaxColor({ + required this.colors, + required this.info, + required this.child, + }); + + @override + State createState() { + return new _ParallaxColorState(); + } +} + +class ParallaxContainer extends StatelessWidget { + final Widget? child; + final double position; + final double translationFactor; + final double opacityFactor; + + ParallaxContainer( + {this.child, + required this.position, + this.translationFactor: 100.0, + this.opacityFactor: 1.0}); + + @override + Widget build(BuildContext context) { + return Opacity( + opacity: (1 - position.abs()).clamp(0.0, 1.0) * opacityFactor, + child: new Transform.translate( + offset: new Offset(position * translationFactor, 0.0), + child: child, + ), + ); + } +} + +class ParallaxImage extends StatelessWidget { + final Image image; + final double imageFactor; + + ParallaxImage.asset(String name, {required double position, this.imageFactor: 0.3}) + : image = Image.asset(name, + fit: BoxFit.cover, + alignment: FractionalOffset( + 0.5 + position * imageFactor, + 0.5, + )); + + @override + Widget build(BuildContext context) { + return image; + } +} \ No newline at end of file diff --git a/lib/src/transformer_page_view/transformer_page_view.dart b/lib/src/transformer_page_view/transformer_page_view.dart new file mode 100644 index 0000000..1508969 --- /dev/null +++ b/lib/src/transformer_page_view/transformer_page_view.dart @@ -0,0 +1,597 @@ +library transformer_page_view; + +import 'package:flutter/widgets.dart'; +import 'package:flutter_swiper/src/transformer_page_view/index_controller.dart'; +export 'package:flutter_swiper/src/transformer_page_view/index_controller.dart'; +export 'package:flutter_swiper/src/transformer_page_view/parallax.dart'; + +/// +/// NOTICE:: +/// +/// In order to make package smaller,currently we're not supporting any build-in page transformers +/// You can find build in transforms here: +/// +/// +/// +const int kMaxValue = 2000000000; +const int kMiddleValue = 1000000000; + +/// Default auto play transition duration (in millisecond) +const int kDefaultTransactionDuration = 300; + +class TransformInfo { + /// The `width` of the `TransformerPageView` + final double width; + + /// The `height` of the `TransformerPageView` + final double height; + + /// The `position` of the widget pass to [PageTransformer.transform] + /// A `position` describes how visible the widget is. + /// The widget in the center of the screen' which is full visible, position is 0.0. + /// The widge in the left ,may be hidden, of the screen's position is less than 0.0, -1.0 when out of the screen. + /// The widge in the right ,may be hidden, of the screen's position is greater than 0.0, 1.0 when out of the screen + /// + /// + final double position; + + /// The `index` of the widget pass to [PageTransformer.transform] + final int index; + + /// The `activeIndex` of the PageView + final int activeIndex; + + /// The `activeIndex` of the PageView, from user start to swipe + /// It will change when user end drag + final int fromIndex; + + /// Next `index` is greater than this `index` + final bool forward; + + /// User drag is done. + final bool done; + + /// Same as [TransformerPageView.viewportFraction] + final double viewportFraction; + + /// Copy from [TransformerPageView.scrollDirection] + final Axis scrollDirection; + + TransformInfo( + {required this.index, + required this.position, + required this.width, + required this.height, + required this.activeIndex, + required this.fromIndex, + required this.forward, + required this.done, + required this.viewportFraction, + required this.scrollDirection}); +} + +abstract class PageTransformer { + /// + final bool reverse; + + PageTransformer({this.reverse: false}); + + /// Return a transformed widget, based on child and TransformInfo + Widget transform(Widget child, TransformInfo info); +} + +typedef Widget PageTransformerBuilderCallback(Widget child, TransformInfo info); + +class PageTransformerBuilder extends PageTransformer { + final PageTransformerBuilderCallback builder; + + PageTransformerBuilder({bool reverse: false, required this.builder}) + : super(reverse: reverse); + + @override + Widget transform(Widget child, TransformInfo info) { + return builder(child, info); + } +} + +class TransformerPageController extends PageController { + final bool loop; + final int itemCount; + final bool reverse; + + TransformerPageController({ + int initialPage = 0, + bool keepPage = true, + double viewportFraction = 1.0, + this.loop: false, + required this.itemCount, + this.reverse: false, + }) : super( + initialPage: TransformerPageController._getRealIndexFromRenderIndex( + initialPage, loop, itemCount, reverse), + keepPage: keepPage, + viewportFraction: viewportFraction); + + int getRenderIndexFromRealIndex(int index) { + return _getRenderIndexFromRealIndex(index, loop, itemCount, reverse); + } + + int getRealItemCount() { + if (itemCount == 0) return 0; + return loop ? itemCount + kMaxValue : itemCount; + } + + static _getRenderIndexFromRealIndex( + int index, bool loop, int itemCount, bool reverse) { + if (itemCount == 0) return 0; + int renderIndex; + if (loop) { + renderIndex = index - kMiddleValue; + renderIndex = renderIndex % itemCount; + if (renderIndex < 0) { + renderIndex += itemCount; + } + } else { + renderIndex = index; + } + if (reverse) { + renderIndex = itemCount - renderIndex - 1; + } + + return renderIndex; + } + + double? get realPage { + return super.page; + } + + static _getRenderPageFromRealPage( + double? page, bool loop, int itemCount, bool reverse) { + double renderPage; + page ??= 0; + if (loop) { + renderPage = page - kMiddleValue; + renderPage = renderPage % itemCount; + if (renderPage < 0) { + renderPage += itemCount; + } + } else { + renderPage = page; + } + if (reverse) { + renderPage = itemCount - renderPage - 1; + } + + return renderPage; + } + + double get page { + return loop + ? _getRenderPageFromRealPage(realPage, loop, itemCount, reverse) + : realPage; + } + + int getRealIndexFromRenderIndex(int index) { + return _getRealIndexFromRenderIndex(index, loop, itemCount, reverse); + } + + static int _getRealIndexFromRenderIndex( + int index, bool loop, int itemCount, bool reverse) { + int result = reverse ? (itemCount - index - 1) : index; + if (loop) { + result += kMiddleValue; + } + return result; + } +} + +class TransformerPageView extends StatefulWidget { + /// Create a `transformed` widget base on the widget that has been passed to the [PageTransformer.transform]. + /// See [TransformInfo] + /// + final PageTransformer? transformer; + + /// Same as [PageView.scrollDirection] + /// + /// Defaults to [Axis.horizontal]. + final Axis scrollDirection; + + /// Same as [PageView.physics] + final ScrollPhysics? physics; + + /// Set to false to disable page snapping, useful for custom scroll behavior. + /// Same as [PageView.pageSnapping] + final bool pageSnapping; + + /// Called whenever the page in the center of the viewport changes. + /// Same as [PageView.onPageChanged] + final ValueChanged? onPageChanged; + + final IndexedWidgetBuilder? itemBuilder; + + // See [IndexController.mode],[IndexController.next],[IndexController.previous] + final IndexController? controller; + + /// Animation duration + final Duration duration; + + /// Animation curve + final Curve curve; + + final TransformerPageController? pageController; + + /// Set true to open infinity loop mode. + final bool loop; + + /// This value is only valid when `pageController` is not set, + final int itemCount; + + /// This value is only valid when `pageController` is not set, + final double viewportFraction; + + /// If not set, it is controlled by this widget. + final int? index; + + /// Creates a scrollable list that works page by page using widgets that are + /// created on demand. + /// + /// This constructor is appropriate for page views with a large (or infinite) + /// number of children because the builder is called only for those children + /// that are actually visible. + /// + /// Providing a non-null [itemCount] lets the [PageView] compute the maximum + /// scroll extent. + /// + /// [itemBuilder] will be called only with indices greater than or equal to + /// zero and less than [itemCount]. + TransformerPageView({ + Key? key, + this.index, + this.duration: const Duration(milliseconds: kDefaultTransactionDuration), + this.curve: Curves.ease, + this.viewportFraction: 1.0, + this.loop: false, + this.scrollDirection = Axis.horizontal, + this.physics, + this.pageSnapping = true, + this.onPageChanged, + required this.controller, + this.transformer, + this.itemBuilder, + this.pageController, + required this.itemCount, + }) : assert(itemCount == 0 || itemBuilder != null || transformer != null), + super(key: key); + + factory TransformerPageView.children( + {Key? key, + int? index, + Duration? duration, + Curve curve: Curves.ease, + double viewportFraction: 1.0, + bool loop: false, + Axis scrollDirection = Axis.horizontal, + ScrollPhysics? physics, + bool pageSnapping = true, + ValueChanged? onPageChanged, + required IndexController controller, + PageTransformer? transformer, + required List children, + TransformerPageController? pageController}) { + return new TransformerPageView( + itemCount: children.length, + itemBuilder: (BuildContext context, int index) { + return children[index]; + }, + pageController: pageController, + transformer: transformer, + pageSnapping: pageSnapping, + key: key, + index: index, + duration: duration ?? const Duration(milliseconds: kDefaultTransactionDuration), + curve: curve, + viewportFraction: viewportFraction, + scrollDirection: scrollDirection, + physics: physics, + onPageChanged: onPageChanged, + controller: controller, + ); + } + + @override + State createState() { + return new _TransformerPageViewState(); + } + + static int getRealIndexFromRenderIndex( + {required bool reverse, required int index, required int itemCount, required bool loop}) { + int initPage = reverse ? (itemCount - index - 1) : index; + if (loop) { + initPage += kMiddleValue; + } + return initPage; + } + + static PageController createPageController( + {required bool reverse, + required int index, + required int itemCount, + required bool loop, + required double viewportFraction}) { + return new PageController( + initialPage: getRealIndexFromRenderIndex( + reverse: reverse, index: index, itemCount: itemCount, loop: loop), + viewportFraction: viewportFraction); + } +} + +class _TransformerPageViewState extends State { + Size? _size; + late int _activeIndex; + late double _currentPixels; + bool _done = false; + + ///This value will not change until user end drag. + late int _fromIndex; + + PageTransformer? _transformer; + + late TransformerPageController _pageController; + + Widget _buildItemNormal(BuildContext context, int index) { + int renderIndex = _pageController.getRenderIndexFromRealIndex(index); + Widget? child = widget.itemBuilder?.call(context, renderIndex); + return child ?? Container(); + } + + Widget _buildItem(BuildContext context, int index) { + return new AnimatedBuilder( + animation: _pageController, + builder: (BuildContext c, Widget? w) { + int renderIndex = _pageController.getRenderIndexFromRealIndex(index); + late Widget child; + if (widget.itemBuilder != null) { + child = widget.itemBuilder?.call(context, renderIndex) ?? Container(); + } + if (_size == null) { + return child; + } + + double position; + + double page = _pageController.realPage ?? 0; + + if (_transformer!.reverse) { + position = page - index; + } else { + position = index - page; + } + position *= widget.viewportFraction; + + TransformInfo info = new TransformInfo( + index: renderIndex, + width: _size!.width, + height: _size!.height, + position: position.clamp(-1.0, 1.0), + activeIndex: + _pageController.getRenderIndexFromRealIndex(_activeIndex), + fromIndex: _fromIndex, + forward: _pageController.position.pixels - _currentPixels >= 0, + done: _done, + scrollDirection: widget.scrollDirection, + viewportFraction: widget.viewportFraction); + return _transformer!.transform(child, info); + }); + } + + double _calcCurrentPixels() { + _currentPixels = _pageController.getRenderIndexFromRealIndex(_activeIndex) * + _pageController.position.viewportDimension * + widget.viewportFraction; + + // print("activeIndex:$_activeIndex , pix:$_currentPixels"); + + return _currentPixels; + } + + @override + Widget build(BuildContext context) { + IndexedWidgetBuilder builder = + _transformer == null ? _buildItemNormal : _buildItem; + Widget child = new PageView.builder( + itemBuilder: builder, + itemCount: _pageController.getRealItemCount(), + onPageChanged: _onIndexChanged, + controller: _pageController, + scrollDirection: widget.scrollDirection, + physics: widget.physics, + pageSnapping: widget.pageSnapping, + reverse: _pageController.reverse, + ); + if (_transformer == null) { + return child; + } + return new NotificationListener( + onNotification: (ScrollNotification notification) { + if (notification is ScrollStartNotification) { + _calcCurrentPixels(); + _done = false; + _fromIndex = _activeIndex; + } else if (notification is ScrollEndNotification) { + _calcCurrentPixels(); + _fromIndex = _activeIndex; + _done = true; + } + + return false; + }, + child: child); + } + + void _onIndexChanged(int index) { + _activeIndex = index; + widget.onPageChanged?.call(_pageController.getRenderIndexFromRealIndex(index)); + } + + void _onGetSize(_) { + Size? size; + RenderObject? renderObject = context.findRenderObject(); + if (renderObject != null) { + Rect bounds = renderObject.paintBounds; + size = bounds.size; + } + _calcCurrentPixels(); + onGetSize(size); + } + + void onGetSize(Size? size) { + if(mounted){ + setState(() { + _size = size; + }); + } + + } + + @override + void initState() { + _transformer = widget.transformer; + // int index = widget.index ?? 0; + _pageController = widget.pageController ??TransformerPageController( + initialPage: widget.index ?? 0, + itemCount: widget.itemCount, + loop: widget.loop, + reverse: + widget.transformer == null ? false : widget.transformer!.reverse); + // int initPage = _getRealIndexFromRenderIndex(index); + // _pageController = new PageController(initialPage: initPage,viewportFraction: widget.viewportFraction); + _fromIndex = _activeIndex = _pageController.initialPage; + + _controller = getNotifier(); + if (_controller != null) { + _controller!.addListener(onChangeNotifier); + } + super.initState(); + } + + @override + void didUpdateWidget(TransformerPageView oldWidget) { + _transformer = widget.transformer; + int index = widget.index ?? 0; + bool created = false; + if (_pageController != widget.pageController) { + if (widget.pageController != null) { + _pageController = widget.pageController!; + } else { + created = true; + _pageController = new TransformerPageController( + initialPage: widget.index ?? 0, + itemCount: widget.itemCount, + loop: widget.loop, + reverse: widget.transformer == null + ? false + : widget.transformer!.reverse); + } + } + + if (_pageController.getRenderIndexFromRealIndex(_activeIndex) != index) { + _fromIndex = _activeIndex = _pageController.initialPage; + if (!created) { + int initPage = _pageController.getRealIndexFromRenderIndex(index); + _pageController.animateToPage(initPage, + duration: widget.duration, curve: widget.curve); + } + } + if (_transformer != null) + WidgetsBinding.instance?.addPostFrameCallback(_onGetSize); + + if (_controller != getNotifier()) { + if (_controller != null) { + _controller!.removeListener(onChangeNotifier); + } + _controller = getNotifier(); + if (_controller != null) { + _controller!.addListener(onChangeNotifier); + } + } + super.didUpdateWidget(oldWidget); + } + + @override + void didChangeDependencies() { + if (_transformer != null) + WidgetsBinding.instance?.addPostFrameCallback(_onGetSize); + super.didChangeDependencies(); + } + + ChangeNotifier? getNotifier() { + return widget.controller; + } + + int _calcNextIndex(bool next) { + int currentIndex = _activeIndex; + if (_pageController.reverse) { + if (next) { + currentIndex--; + } else { + currentIndex++; + } + } else { + if (next) { + currentIndex++; + } else { + currentIndex--; + } + } + + if (!_pageController.loop) { + if (currentIndex >= _pageController.itemCount) { + currentIndex = 0; + } else if (currentIndex < 0) { + currentIndex = _pageController.itemCount - 1; + } + } + + return currentIndex; + } + + void onChangeNotifier() { + int? event = widget.controller?.event; + int index; + switch (event) { + case IndexController.MOVE: + { + index = _pageController + .getRealIndexFromRenderIndex(widget.controller!.index); + } + break; + case IndexController.PREVIOUS: + case IndexController.NEXT: + { + index = _calcNextIndex(event == IndexController.NEXT); + } + break; + default: + //ignore this event + return; + } + if (widget.controller?.animation ?? false) { + _pageController + .animateToPage(index, + duration: widget.duration, curve: widget.curve) + .whenComplete(widget.controller!.complete); + } else { + _pageController.jumpToPage(index); + widget.controller?.complete(); + } + } + + ChangeNotifier? _controller; + + void dispose() { + super.dispose(); + if (_controller != null) { + _controller?.removeListener(onChangeNotifier); + } + } +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 86f253d..3a832ae 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,46 +1,60 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: async: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.8.2" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.3.1" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" + source: hosted + version: "1.15.0" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.2.0" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" - flutter_page_indicator: - dependency: "direct main" - description: - name: flutter_page_indicator - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.0.3" flutter_test: dependency: "direct dev" description: flutter @@ -50,30 +64,23 @@ packages: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.11" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.7.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.0.1" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -83,65 +90,58 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.6.8" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.2.1" - transformer_page_view: - dependency: "direct main" - description: - name: transformer_page_view - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.1.5" + version: "0.4.3" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.1" sdks: - dart: ">=2.0.0 <3.0.0" - flutter: ">=0.1.4 <3.0.0" + dart: ">=2.14.0 <3.0.0" + flutter: ">=0.1.4" diff --git a/pubspec.yaml b/pubspec.yaml index 17ed711..6a8c35e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,11 +8,8 @@ dependencies: flutter: sdk: flutter - transformer_page_view: ^0.1.6 - flutter_page_indicator: ^0.0.3 - environment: - sdk: ">=2.0.0-dev.48.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=0.1.4 <3.0.0" dev_dependencies: