├── test
└── easy_sticky_header_test.dart
├── example
├── README.md
├── ios
│ ├── Runner
│ │ ├── Runner-Bridging-Header.h
│ │ ├── Assets.xcassets
│ │ │ ├── LaunchImage.imageset
│ │ │ │ ├── LaunchImage.png
│ │ │ │ ├── LaunchImage@2x.png
│ │ │ │ ├── LaunchImage@3x.png
│ │ │ │ ├── README.md
│ │ │ │ └── Contents.json
│ │ │ └── AppIcon.appiconset
│ │ │ │ ├── Icon-App-20x20@1x.png
│ │ │ │ ├── Icon-App-20x20@2x.png
│ │ │ │ ├── Icon-App-20x20@3x.png
│ │ │ │ ├── Icon-App-29x29@1x.png
│ │ │ │ ├── Icon-App-29x29@2x.png
│ │ │ │ ├── Icon-App-29x29@3x.png
│ │ │ │ ├── Icon-App-40x40@1x.png
│ │ │ │ ├── Icon-App-40x40@2x.png
│ │ │ │ ├── Icon-App-40x40@3x.png
│ │ │ │ ├── Icon-App-60x60@2x.png
│ │ │ │ ├── Icon-App-60x60@3x.png
│ │ │ │ ├── Icon-App-76x76@1x.png
│ │ │ │ ├── Icon-App-76x76@2x.png
│ │ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ │ ├── Icon-App-83.5x83.5@2x.png
│ │ │ │ └── Contents.json
│ │ ├── AppDelegate.swift
│ │ ├── Base.lproj
│ │ │ ├── Main.storyboard
│ │ │ └── LaunchScreen.storyboard
│ │ └── Info.plist
│ ├── Flutter
│ │ ├── Debug.xcconfig
│ │ ├── Release.xcconfig
│ │ └── AppFrameworkInfo.plist
│ ├── Runner.xcodeproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ ├── WorkspaceSettings.xcsettings
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ ├── xcshareddata
│ │ │ └── xcschemes
│ │ │ │ └── Runner.xcscheme
│ │ └── project.pbxproj
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ ├── WorkspaceSettings.xcsettings
│ │ │ └── IDEWorkspaceChecks.plist
│ ├── .gitignore
│ └── Podfile
├── android
│ ├── gradle.properties
│ ├── app
│ │ ├── src
│ │ │ ├── main
│ │ │ │ ├── res
│ │ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── drawable
│ │ │ │ │ │ └── launch_background.xml
│ │ │ │ │ ├── drawable-v21
│ │ │ │ │ │ └── launch_background.xml
│ │ │ │ │ ├── values
│ │ │ │ │ │ └── styles.xml
│ │ │ │ │ └── values-night
│ │ │ │ │ │ └── styles.xml
│ │ │ │ ├── kotlin
│ │ │ │ │ └── dev
│ │ │ │ │ │ └── crasowas
│ │ │ │ │ │ └── easy_sticky_header_example
│ │ │ │ │ │ └── MainActivity.kt
│ │ │ │ └── AndroidManifest.xml
│ │ │ ├── debug
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── profile
│ │ │ │ └── AndroidManifest.xml
│ │ └── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ ├── .gitignore
│ ├── settings.gradle
│ └── build.gradle
├── lib
│ ├── test_config.dart
│ ├── examples
│ │ ├── example12.dart
│ │ ├── example7.dart
│ │ ├── example9.dart
│ │ ├── example2.dart
│ │ ├── example11.dart
│ │ ├── example1.dart
│ │ ├── example4.dart
│ │ ├── example3.dart
│ │ ├── example10.dart
│ │ ├── example8.dart
│ │ ├── example0.dart
│ │ ├── example5.dart
│ │ └── example6.dart
│ └── main.dart
├── test
│ └── widget_test.dart
├── .gitignore
├── .metadata
├── analysis_options.yaml
├── pubspec.yaml
└── pubspec.lock
├── screenshots
├── screenshot1.gif
├── screenshot2.gif
├── screenshot3.gif
├── screenshot4.gif
├── screenshot5.gif
├── screenshot6.gif
├── screenshot7.gif
├── screenshot8.gif
└── screenshot9.gif
├── analysis_options.yaml
├── .metadata
├── lib
├── easy_sticky_header.dart
└── src
│ ├── sticky_header_info.dart
│ ├── render_sticky_container.dart
│ ├── sticky_header_widget.dart
│ ├── sticky_header.dart
│ ├── sticky_header_controller.dart
│ └── sticky_container_widget.dart
├── .gitignore
├── .github
└── workflows
│ └── publish.yml
├── CHANGELOG.md
├── LICENSE
├── pubspec.yaml
├── README-CN.md
└── README.md
/test/easy_sticky_header_test.dart:
--------------------------------------------------------------------------------
1 | void main() {}
2 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # example
2 |
3 | An example project of Easy Sticky Header.
4 |
--------------------------------------------------------------------------------
/example/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 |
--------------------------------------------------------------------------------
/screenshots/screenshot1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/screenshots/screenshot1.gif
--------------------------------------------------------------------------------
/screenshots/screenshot2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/screenshots/screenshot2.gif
--------------------------------------------------------------------------------
/screenshots/screenshot3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/screenshots/screenshot3.gif
--------------------------------------------------------------------------------
/screenshots/screenshot4.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/screenshots/screenshot4.gif
--------------------------------------------------------------------------------
/screenshots/screenshot5.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/screenshots/screenshot5.gif
--------------------------------------------------------------------------------
/screenshots/screenshot6.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/screenshots/screenshot6.gif
--------------------------------------------------------------------------------
/screenshots/screenshot7.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/screenshots/screenshot7.gif
--------------------------------------------------------------------------------
/screenshots/screenshot8.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/screenshots/screenshot8.gif
--------------------------------------------------------------------------------
/screenshots/screenshot9.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/screenshots/screenshot9.gif
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/example/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | include: package:flutter_lints/flutter.yaml
2 |
3 | # Additional information about this file can be found at
4 | # https://dart.dev/guides/language/analysis-options
5 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/lib/test_config.dart:
--------------------------------------------------------------------------------
1 | /// Test Configuration.
2 | class TestConfig {
3 | /// Used to quickly test reverse scroll direction when [reverse] is true.
4 | static const reverse = false;
5 | }
6 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/crasowas/easy_sticky_header/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/android/app/src/main/kotlin/dev/crasowas/easy_sticky_header_example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package dev.crasowas.easy_sticky_header_example
2 |
3 | import io.flutter.embedding.android.FlutterActivity
4 |
5 | class MainActivity: FlutterActivity() {
6 | }
7 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 23 08:50:38 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
7 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: f1875d570e39de09040c8f79aa13cc56baab8db1
8 | channel: stable
9 |
10 | project_type: package
11 |
--------------------------------------------------------------------------------
/example/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 |
9 | # Remember to never publicly share your keystore.
10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11 | key.properties
12 | **/*.keystore
13 | **/*.jks
14 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/example/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // This is a basic Flutter widget test.
2 | //
3 | // To perform an interaction with a widget in your test, use the WidgetTester
4 | // utility in the flutter_test package. For example, you can send tap and scroll
5 | // gestures. You can also use WidgetTester to find child widgets in the widget
6 | // tree, read text, and verify that the values of widget properties are correct.
7 |
8 | void main() {}
9 |
--------------------------------------------------------------------------------
/lib/easy_sticky_header.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, crasowas.
2 | //
3 | // Use of this source code is governed by a MIT-style license
4 | // that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | library easy_sticky_header;
8 |
9 | export 'src/sticky_container_widget.dart';
10 | export 'src/sticky_header.dart';
11 | export 'src/sticky_header_controller.dart';
12 | export 'src/sticky_header_info.dart';
13 |
--------------------------------------------------------------------------------
/example/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4 | def properties = new Properties()
5 |
6 | assert localPropertiesFile.exists()
7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
8 |
9 | def flutterSdkPath = properties.getProperty("flutter.sdk")
10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
12 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable-v21/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchImage@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "LaunchImage@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 | migrate_working_dir/
12 |
13 | # IntelliJ related
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea/
18 |
19 | # The .vscode folder contains launch configuration and tasks you configure in
20 | # VS Code which you may wish to be included in version control, so this line
21 | # is commented out by default.
22 | #.vscode/
23 |
24 | # Flutter/Dart/Pub related
25 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26 | /pubspec.lock
27 | **/doc/api/
28 | .dart_tool/
29 | .packages
30 | build/
31 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish to pub.dev
2 |
3 | on:
4 | push:
5 | tags:
6 | - 'v[0-9]+.[0-9]+.[0-9]+*'
7 |
8 | jobs:
9 | publish:
10 | runs-on: ubuntu-latest
11 | permissions:
12 | id-token: write
13 |
14 | steps:
15 | - name: Clone repository
16 | uses: actions/checkout@v4
17 |
18 | - name: Install Dart
19 | uses: dart-lang/setup-dart@v1
20 | with:
21 | sdk: stable
22 |
23 | - name: Install Flutter
24 | uses: subosito/flutter-action@v2
25 | with:
26 | channel: 'stable'
27 |
28 | - name: Publish to pub.dev
29 | run: flutter pub publish --force
30 |
--------------------------------------------------------------------------------
/example/ios/.gitignore:
--------------------------------------------------------------------------------
1 | **/dgph
2 | *.mode1v3
3 | *.mode2v3
4 | *.moved-aside
5 | *.pbxuser
6 | *.perspectivev3
7 | **/*sync/
8 | .sconsign.dblite
9 | .tags*
10 | **/.vagrant/
11 | **/DerivedData/
12 | Icon?
13 | **/Pods/
14 | **/.symlinks/
15 | profile
16 | xcuserdata
17 | **/.generated/
18 | Flutter/App.framework
19 | Flutter/Flutter.framework
20 | Flutter/Flutter.podspec
21 | Flutter/Generated.xcconfig
22 | Flutter/ephemeral/
23 | Flutter/app.flx
24 | Flutter/app.zip
25 | Flutter/flutter_assets/
26 | Flutter/flutter_export_environment.sh
27 | ServiceDefinitions.json
28 | Runner/GeneratedPluginRegistrant.*
29 |
30 | # Exceptions to above rules.
31 | !default.mode1v3
32 | !default.mode2v3
33 | !default.pbxuser
34 | !default.perspectivev3
35 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.7.10'
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:7.1.2'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | mavenCentral()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | }
25 | subprojects {
26 | project.evaluationDependsOn(':app')
27 | }
28 |
29 | task clean(type: Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/example/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 12.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 | migrate_working_dir/
12 |
13 | # IntelliJ related
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea/
18 |
19 | # The .vscode folder contains launch configuration and tasks you configure in
20 | # VS Code which you may wish to be included in version control, so this line
21 | # is commented out by default.
22 | #.vscode/
23 |
24 | # Flutter/Dart/Pub related
25 | **/doc/api/
26 | **/ios/Flutter/.last_build_id
27 | .dart_tool/
28 | .flutter-plugins
29 | .flutter-plugins-dependencies
30 | .packages
31 | .pub-cache/
32 | .pub/
33 | /build/
34 |
35 | # Web related
36 | lib/generated_plugin_registrant.dart
37 |
38 | # Symbolication related
39 | app.*.symbols
40 |
41 | # Obfuscation related
42 | app.*.map.json
43 |
44 | # Android Studio will place build artifacts here
45 | /android/app/debug
46 | /android/app/profile
47 | /android/app/release
48 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 1.1.1
2 | * Fix scroll position issue in `animateTo()` method ([#4](https://github.com/crasowas/easy_sticky_header/issues/4)).
3 | * Remove invalid null aware operator.
4 |
5 | ## 1.1.0
6 | * Add `ScrollableStickyContainerBuilder` for building scrollable header widget ([#3](https://github.com/crasowas/easy_sticky_header/issues/3)).
7 | * Update README and examples.
8 |
9 | ## 1.0.5
10 | * Fix an issue caused by optimizing performance.
11 |
12 | ## 1.0.4
13 | * Optimize performance.
14 |
15 | ## 1.0.3
16 | * Improve debugging properties.
17 | * Fix the problem of pixels being inaccurate in some cases.
18 | * Update the feature of jumping to the specified header widget.
19 | * Add the grouping feature of the header widget.
20 | * Remove scrollController property.
21 | * Fix the problem that stickyAmount is invalid.
22 | * Update README and examples.
23 |
24 | ## 1.0.2
25 | * Update README.
26 |
27 | ## 1.0.1
28 | * Support for earlier version of dart sdk.
29 | * Update README and examples.
30 |
31 | ## 1.0.0
32 | * Initial version.
33 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 crasowas
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/example/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled.
5 |
6 | version:
7 | revision: f1875d570e39de09040c8f79aa13cc56baab8db1
8 | channel: stable
9 |
10 | project_type: app
11 |
12 | # Tracks metadata for the flutter migrate command
13 | migration:
14 | platforms:
15 | - platform: root
16 | create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
17 | base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
18 | - platform: android
19 | create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
20 | base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
21 | - platform: ios
22 | create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
23 | base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
24 |
25 | # User provided section
26 |
27 | # List of Local paths (relative to this file) that should be
28 | # ignored by the migrate tool.
29 | #
30 | # Files that are not part of the templates will be ignored by default.
31 | unmanaged_files:
32 | - 'lib/main.dart'
33 | - 'ios/Runner.xcodeproj/project.pbxproj'
34 |
--------------------------------------------------------------------------------
/example/ios/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | # platform :ios, '12.0'
3 |
4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6 |
7 | project 'Runner', {
8 | 'Debug' => :debug,
9 | 'Profile' => :release,
10 | 'Release' => :release,
11 | }
12 |
13 | def flutter_root
14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15 | unless File.exist?(generated_xcode_build_settings_path)
16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
17 | end
18 |
19 | File.foreach(generated_xcode_build_settings_path) do |line|
20 | matches = line.match(/FLUTTER_ROOT\=(.*)/)
21 | return matches[1].strip if matches
22 | end
23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
24 | end
25 |
26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27 |
28 | flutter_ios_podfile_setup
29 |
30 | target 'Runner' do
31 | use_frameworks!
32 | use_modular_headers!
33 |
34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
35 | end
36 |
37 | post_install do |installer|
38 | installer.pods_project.targets.each do |target|
39 | flutter_additional_ios_build_settings(target)
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/example/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | # This file configures the analyzer, which statically analyzes Dart code to
2 | # check for errors, warnings, and lints.
3 | #
4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6 | # invoked from the command line by running `flutter analyze`.
7 |
8 | # The following line activates a set of recommended lints for Flutter apps,
9 | # packages, and plugins designed to encourage good coding practices.
10 | include: package:flutter_lints/flutter.yaml
11 |
12 | linter:
13 | # The lint rules applied to this project can be customized in the
14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml`
15 | # included above or to enable additional rules. A list of all available lints
16 | # and their documentation is published at
17 | # https://dart-lang.github.io/linter/lints/index.html.
18 | #
19 | # Instead of disabling a lint rule for the entire project in the
20 | # section below, it can also be suppressed for a single line of code
21 | # or a specific dart file by using the `// ignore: name_of_lint` and
22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file
23 | # producing the lint.
24 | rules:
25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule
26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27 |
28 | # Additional information about this file can be found at
29 | # https://dart.dev/guides/language/analysis-options
30 |
--------------------------------------------------------------------------------
/lib/src/sticky_header_info.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, crasowas.
2 | //
3 | // Use of this source code is governed by a MIT-style license
4 | // that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | import 'package:flutter/material.dart';
8 |
9 | /// Sticky Header Info.
10 | ///
11 | /// See also:
12 | ///
13 | /// * [RenderStickyContainer], which creates a [StickyHeaderInfo] in callback.
14 | ///
15 | /// * [StickyHeaderController], which handles the [StickyHeaderInfo] list.
16 | class StickyHeaderInfo {
17 | int index;
18 |
19 | bool visible;
20 |
21 | Size size;
22 |
23 | double pixels;
24 |
25 | Offset offset;
26 |
27 | double stickyAmount;
28 |
29 | int? parentIndex;
30 |
31 | bool overlapParent;
32 |
33 | Widget widget;
34 |
35 | StickyHeaderInfo({
36 | required this.index,
37 | required this.visible,
38 | required this.size,
39 | required this.pixels,
40 | required this.offset,
41 | this.stickyAmount = 0.0,
42 | this.parentIndex,
43 | this.overlapParent = false,
44 | required this.widget,
45 | });
46 |
47 | @override
48 | String toString() {
49 | final List description = [
50 | 'index: $index',
51 | 'visible: $visible',
52 | 'size: $size',
53 | 'pixels: $pixels',
54 | 'offset: $offset',
55 | 'stickyAmount: $stickyAmount',
56 | if (parentIndex != null) 'parentIndex: $parentIndex',
57 | if (parentIndex != null) 'overlapParent: $overlapParent',
58 | ];
59 | return 'StickyHeaderInfo(${description.join(', ')})';
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
15 |
19 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: easy_sticky_header
2 | description: An easy-to-use and powerful sticky header for any widget that supports scrolling.
3 | version: 1.1.1
4 | homepage: https://github.com/crasowas/easy_sticky_header
5 |
6 | environment:
7 | sdk: '>=2.12.0 <4.0.0'
8 | flutter: '>=2.0.0'
9 |
10 | dependencies:
11 | flutter:
12 | sdk: flutter
13 |
14 | dev_dependencies:
15 | flutter_test:
16 | sdk: flutter
17 | flutter_lints: ^3.0.0
18 |
19 | # For information on the generic Dart part of this file, see the
20 | # following page: https://dart.dev/tools/pub/pubspec
21 |
22 | # The following section is specific to Flutter packages.
23 | flutter:
24 |
25 | # To add assets to your package, add an assets section, like this:
26 | # assets:
27 | # - images/a_dot_burr.jpeg
28 | # - images/a_dot_ham.jpeg
29 | #
30 | # For details regarding assets in packages, see
31 | # https://flutter.dev/assets-and-images/#from-packages
32 | #
33 | # An image asset can refer to one or more resolution-specific "variants", see
34 | # https://flutter.dev/assets-and-images/#resolution-aware
35 |
36 | # To add custom fonts to your package, add a fonts section here,
37 | # in this "flutter" section. Each entry in this list should have a
38 | # "family" key with the font family name, and a "fonts" key with a
39 | # list giving the asset and other descriptors for the font. For
40 | # example:
41 | # fonts:
42 | # - family: Schyler
43 | # fonts:
44 | # - asset: fonts/Schyler-Regular.ttf
45 | # - asset: fonts/Schyler-Italic.ttf
46 | # style: italic
47 | # - family: Trajan Pro
48 | # fonts:
49 | # - asset: fonts/TrajanPro.ttf
50 | # - asset: fonts/TrajanPro_Bold.ttf
51 | # weight: 700
52 | #
53 | # For details regarding fonts in packages, see
54 | # https://flutter.dev/custom-fonts/#from-packages
55 |
--------------------------------------------------------------------------------
/example/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CADisableMinimumFrameDurationOnPhone
6 |
7 | CFBundleDevelopmentRegion
8 | $(DEVELOPMENT_LANGUAGE)
9 | CFBundleDisplayName
10 | Example
11 | CFBundleExecutable
12 | $(EXECUTABLE_NAME)
13 | CFBundleIdentifier
14 | $(PRODUCT_BUNDLE_IDENTIFIER)
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | example
19 | CFBundlePackageType
20 | APPL
21 | CFBundleShortVersionString
22 | $(FLUTTER_BUILD_NAME)
23 | CFBundleSignature
24 | ????
25 | CFBundleVersion
26 | $(FLUTTER_BUILD_NUMBER)
27 | LSRequiresIPhoneOS
28 |
29 | UIApplicationSupportsIndirectInputEvents
30 |
31 | UILaunchStoryboardName
32 | LaunchScreen
33 | UIMainStoryboardFile
34 | Main
35 | UISupportedInterfaceOrientations
36 |
37 | UIInterfaceOrientationPortrait
38 | UIInterfaceOrientationLandscapeLeft
39 | UIInterfaceOrientationLandscapeRight
40 |
41 | UISupportedInterfaceOrientations~ipad
42 |
43 | UIInterfaceOrientationPortrait
44 | UIInterfaceOrientationPortraitUpsideDown
45 | UIInterfaceOrientationLandscapeLeft
46 | UIInterfaceOrientationLandscapeRight
47 |
48 | UIViewControllerBasedStatusBarAppearance
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | def localProperties = new Properties()
2 | def localPropertiesFile = rootProject.file('local.properties')
3 | if (localPropertiesFile.exists()) {
4 | localPropertiesFile.withReader('UTF-8') { reader ->
5 | localProperties.load(reader)
6 | }
7 | }
8 |
9 | def flutterRoot = localProperties.getProperty('flutter.sdk')
10 | if (flutterRoot == null) {
11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12 | }
13 |
14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15 | if (flutterVersionCode == null) {
16 | flutterVersionCode = '1'
17 | }
18 |
19 | def flutterVersionName = localProperties.getProperty('flutter.versionName')
20 | if (flutterVersionName == null) {
21 | flutterVersionName = '1.0'
22 | }
23 |
24 | apply plugin: 'com.android.application'
25 | apply plugin: 'kotlin-android'
26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27 |
28 | android {
29 | compileSdkVersion flutter.compileSdkVersion
30 | ndkVersion flutter.ndkVersion
31 |
32 | compileOptions {
33 | sourceCompatibility JavaVersion.VERSION_1_8
34 | targetCompatibility JavaVersion.VERSION_1_8
35 | }
36 |
37 | kotlinOptions {
38 | jvmTarget = '1.8'
39 | }
40 |
41 | sourceSets {
42 | main.java.srcDirs += 'src/main/kotlin'
43 | }
44 |
45 | defaultConfig {
46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
47 | applicationId "dev.crasowas.easy_sticky_header_example"
48 | // You can update the following values to match your application needs.
49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
50 | minSdkVersion flutter.minSdkVersion
51 | targetSdkVersion flutter.targetSdkVersion
52 | versionCode flutterVersionCode.toInteger()
53 | versionName flutterVersionName
54 | }
55 |
56 | buildTypes {
57 | release {
58 | // TODO: Add your own signing config for the release build.
59 | // Signing with the debug keys for now, so `flutter run --release` works.
60 | signingConfig signingConfigs.debug
61 | }
62 | }
63 | }
64 |
65 | flutter {
66 | source '../..'
67 | }
68 |
69 | dependencies {
70 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
71 | }
72 |
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/example/lib/examples/example12.dart:
--------------------------------------------------------------------------------
1 | import 'package:easy_sticky_header/easy_sticky_header.dart';
2 | import 'package:flutter/material.dart';
3 |
4 | import '../test_config.dart';
5 |
6 | class Example12 extends StatelessWidget {
7 | const Example12({Key? key}) : super(key: key);
8 |
9 | @override
10 | Widget build(BuildContext context) {
11 | return Scaffold(
12 | backgroundColor: Colors.white,
13 | appBar: AppBar(
14 | shadowColor: Colors.transparent,
15 | backgroundColor: Colors.black,
16 | foregroundColor: Colors.white,
17 | title: const Text('Infinite list'),
18 | ),
19 | body: StickyHeader(
20 | child: ListView.builder(
21 | reverse: TestConfig.reverse,
22 | physics: const AlwaysScrollableScrollPhysics(
23 | parent: BouncingScrollPhysics(),
24 | ),
25 | itemBuilder: (context, index) {
26 | if (index % 3 == 0 && index < 6) {
27 | return StickyContainerWidget(
28 | index: index,
29 | child: Container(
30 | color: const Color.fromRGBO(255, 105, 0, 1.0),
31 | padding: const EdgeInsets.only(left: 16.0),
32 | alignment: Alignment.centerLeft,
33 | width: double.infinity,
34 | height: 50,
35 | child: Text(
36 | 'Header #$index',
37 | style: const TextStyle(
38 | color: Colors.white,
39 | fontSize: 16,
40 | ),
41 | ),
42 | ),
43 | );
44 | }
45 | return Column(
46 | children: [
47 | Container(
48 | width: double.infinity,
49 | height: 80,
50 | color: Colors.white,
51 | padding: const EdgeInsets.only(left: 16),
52 | alignment: Alignment.centerLeft,
53 | child: Text(
54 | 'Item #$index',
55 | style: const TextStyle(
56 | color: Colors.black,
57 | fontSize: 16,
58 | ),
59 | ),
60 | ),
61 | Divider(
62 | height: 1.0,
63 | thickness: 1.0,
64 | color: Colors.grey.shade200,
65 | indent: 16.0,
66 | ),
67 | ],
68 | );
69 | },
70 | ),
71 | ),
72 | );
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/example/lib/examples/example7.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 |
3 | import 'package:easy_sticky_header/easy_sticky_header.dart';
4 | import 'package:flutter/material.dart';
5 |
6 | import '../test_config.dart';
7 |
8 | class Example7 extends StatelessWidget {
9 | const Example7({Key? key}) : super(key: key);
10 |
11 | @override
12 | Widget build(BuildContext context) {
13 | return Scaffold(
14 | backgroundColor: Colors.white,
15 | appBar: AppBar(
16 | shadowColor: Colors.transparent,
17 | backgroundColor: Colors.black,
18 | foregroundColor: Colors.white,
19 | title: const Text('GridView'),
20 | ),
21 | body: StickyHeader(
22 | child: CustomScrollView(
23 | reverse: TestConfig.reverse,
24 | physics: const AlwaysScrollableScrollPhysics(
25 | parent: BouncingScrollPhysics()),
26 | slivers: [
27 | _buildHeader(0),
28 | _buildSliverGrid(0),
29 | _buildHeader(1),
30 | _buildSliverGrid(1),
31 | _buildHeader(2),
32 | _buildSliverGrid(2),
33 | ],
34 | ),
35 | ),
36 | );
37 | }
38 |
39 | Widget _buildHeader(int index) => SliverToBoxAdapter(
40 | child: StickyContainerWidget(
41 | index: index,
42 | child: Container(
43 | color: const Color.fromRGBO(255, 105, 0, 1.0),
44 | padding: const EdgeInsets.only(left: 16.0),
45 | alignment: Alignment.centerLeft,
46 | width: double.infinity,
47 | height: 50,
48 | child: Text(
49 | 'Header #$index',
50 | style: const TextStyle(
51 | color: Colors.white,
52 | fontSize: 16,
53 | ),
54 | ),
55 | ),
56 | ),
57 | );
58 |
59 | Widget _buildSliverGrid(int section) => SliverGrid(
60 | gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
61 | crossAxisCount: 2,
62 | mainAxisSpacing: 10,
63 | crossAxisSpacing: 10,
64 | ),
65 | delegate: SliverChildBuilderDelegate(
66 | (context, index) {
67 | return Container(
68 | width: double.infinity,
69 | height: 80,
70 | color: Color.fromRGBO(Random().nextInt(256),
71 | Random().nextInt(256), Random().nextInt(256), 1),
72 | padding: const EdgeInsets.only(left: 16),
73 | alignment: Alignment.centerLeft,
74 | child: Text(
75 | 'Item #$section-$index',
76 | style: const TextStyle(
77 | color: Colors.black,
78 | fontSize: 16,
79 | ),
80 | ),
81 | );
82 | },
83 | childCount: 4,
84 | ),
85 | );
86 | }
87 |
--------------------------------------------------------------------------------
/example/lib/examples/example9.dart:
--------------------------------------------------------------------------------
1 | import 'package:easy_sticky_header/easy_sticky_header.dart';
2 | import 'package:flutter/material.dart';
3 |
4 | import '../test_config.dart';
5 |
6 | class Example9 extends StatelessWidget {
7 | const Example9({Key? key}) : super(key: key);
8 |
9 | @override
10 | Widget build(BuildContext context) {
11 | return Scaffold(
12 | backgroundColor: Colors.white,
13 | appBar: AppBar(
14 | shadowColor: Colors.transparent,
15 | backgroundColor: Colors.black,
16 | foregroundColor: Colors.white,
17 | title: const Text('SingleChildScrollView'),
18 | ),
19 | body: StickyHeader(
20 | child: SingleChildScrollView(
21 | reverse: TestConfig.reverse,
22 | physics: const AlwaysScrollableScrollPhysics(
23 | parent: BouncingScrollPhysics()),
24 | child: Column(
25 | children: [
26 | _buildHeader(0),
27 | _buildItem(0, 0),
28 | _buildItem(0, 1),
29 | _buildHeader(1),
30 | _buildItem(1, 0),
31 | _buildItem(1, 1),
32 | _buildItem(1, 2),
33 | _buildItem(1, 3),
34 | _buildItem(1, 4),
35 | _buildHeader(2),
36 | _buildItem(2, 0),
37 | _buildItem(2, 1),
38 | _buildItem(2, 2),
39 | _buildItem(2, 3),
40 | _buildItem(2, 4),
41 | _buildItem(2, 5),
42 | ],
43 | ),
44 | ),
45 | ),
46 | );
47 | }
48 |
49 | Widget _buildHeader(int index) => StickyContainerWidget(
50 | index: index,
51 | child: Container(
52 | color: const Color.fromRGBO(255, 105, 0, 1.0),
53 | padding: const EdgeInsets.only(left: 16.0),
54 | alignment: Alignment.centerLeft,
55 | width: double.infinity,
56 | height: 50,
57 | child: Text(
58 | 'Header #$index',
59 | style: const TextStyle(
60 | color: Colors.white,
61 | fontSize: 16,
62 | ),
63 | ),
64 | ),
65 | );
66 |
67 | Widget _buildItem(int section, int index) => Column(
68 | children: [
69 | Container(
70 | width: double.infinity,
71 | height: 80,
72 | color: Colors.white,
73 | padding: const EdgeInsets.only(left: 16),
74 | alignment: Alignment.centerLeft,
75 | child: Text(
76 | 'Item #$section-$index',
77 | style: const TextStyle(
78 | color: Colors.black,
79 | fontSize: 16,
80 | ),
81 | ),
82 | ),
83 | Divider(
84 | height: 1.0,
85 | thickness: 1.0,
86 | color: Colors.grey.shade200,
87 | indent: 16.0,
88 | ),
89 | ],
90 | );
91 | }
92 |
--------------------------------------------------------------------------------
/example/lib/examples/example2.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 |
3 | import 'package:easy_sticky_header/easy_sticky_header.dart';
4 | import 'package:flutter/material.dart';
5 |
6 | import '../test_config.dart';
7 |
8 | class Example2 extends StatefulWidget {
9 | const Example2({Key? key}) : super(key: key);
10 |
11 | @override
12 | State createState() => _Example2State();
13 | }
14 |
15 | class _Example2State extends State {
16 | final ScrollController _scrollController =
17 | ScrollController(initialScrollOffset: 520);
18 |
19 | @override
20 | Widget build(BuildContext context) {
21 | return Scaffold(
22 | backgroundColor: Colors.white,
23 | appBar: AppBar(
24 | shadowColor: Colors.transparent,
25 | backgroundColor: Colors.black,
26 | foregroundColor: Colors.white,
27 | title: const Text('ScrollController with initialScrollOffset'),
28 | ),
29 | body: StickyHeader(
30 | child: ListView.builder(
31 | reverse: TestConfig.reverse,
32 | physics: const AlwaysScrollableScrollPhysics(
33 | parent: BouncingScrollPhysics(),
34 | ),
35 | controller: _scrollController,
36 | itemCount: 100,
37 | itemBuilder: (context, index) {
38 | if (index % 3 == 0) {
39 | return StickyContainerWidget(
40 | index: index,
41 | child: Container(
42 | color: Color.fromRGBO(Random().nextInt(256),
43 | Random().nextInt(256), Random().nextInt(256), 1),
44 | padding: const EdgeInsets.only(left: 16.0),
45 | alignment: Alignment.centerLeft,
46 | width: double.infinity,
47 | height: 50,
48 | child: Text(
49 | 'Header #$index',
50 | style: const TextStyle(
51 | color: Colors.white,
52 | fontSize: 16,
53 | ),
54 | ),
55 | ),
56 | );
57 | }
58 | return Column(
59 | children: [
60 | Container(
61 | width: double.infinity,
62 | height: 80,
63 | color: Colors.white,
64 | padding: const EdgeInsets.only(left: 16),
65 | alignment: Alignment.centerLeft,
66 | child: Text(
67 | 'Item #$index',
68 | style: const TextStyle(
69 | color: Colors.black,
70 | fontSize: 16,
71 | ),
72 | ),
73 | ),
74 | Divider(
75 | height: 1.0,
76 | thickness: 1.0,
77 | color: Colors.grey.shade200,
78 | indent: 16.0,
79 | ),
80 | ],
81 | );
82 | },
83 | ),
84 | ),
85 | );
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/example/lib/examples/example11.dart:
--------------------------------------------------------------------------------
1 | import 'package:easy_sticky_header/easy_sticky_header.dart';
2 | import 'package:flutter/material.dart';
3 |
4 | import '../test_config.dart';
5 |
6 | class Example11 extends StatelessWidget {
7 | const Example11({Key? key}) : super(key: key);
8 |
9 | @override
10 | Widget build(BuildContext context) {
11 | return Scaffold(
12 | backgroundColor: Colors.white,
13 | appBar: AppBar(
14 | shadowColor: Colors.transparent,
15 | backgroundColor: Colors.black,
16 | foregroundColor: Colors.white,
17 | title: const Text('Multiple SliverList'),
18 | ),
19 | body: StickyHeader(
20 | child: CustomScrollView(
21 | reverse: TestConfig.reverse,
22 | physics: const AlwaysScrollableScrollPhysics(
23 | parent: BouncingScrollPhysics()),
24 | slivers: [
25 | _buildSliverList(0),
26 | _buildSliverList(1),
27 | _buildSliverList(2),
28 | _buildSliverList(3),
29 | ],
30 | ),
31 | ),
32 | );
33 | }
34 |
35 | Widget _buildSliverList(int section) {
36 | return SliverList(
37 | delegate: SliverChildBuilderDelegate(
38 | (context, index) {
39 | if (index % 3 == 0) {
40 | return StickyContainerWidget(
41 | // Index must be unique.
42 | index: section * 100 + index,
43 | // If you have problems with inaccurate position of sticky
44 | // header, please try without performance priority.
45 | performancePriority: false,
46 | child: Container(
47 | color: Color.fromRGBO(255 - (section * 60), 105, 0, 1.0),
48 | padding: const EdgeInsets.only(left: 16.0),
49 | alignment: Alignment.centerLeft,
50 | width: double.infinity,
51 | height: 50,
52 | child: Text(
53 | 'Header #$section-$index',
54 | style: const TextStyle(
55 | color: Colors.white,
56 | fontSize: 16,
57 | ),
58 | ),
59 | ),
60 | );
61 | }
62 | return Column(
63 | children: [
64 | Container(
65 | width: double.infinity,
66 | height: 80,
67 | color: Colors.white,
68 | padding: const EdgeInsets.only(left: 16),
69 | alignment: Alignment.centerLeft,
70 | child: Text(
71 | 'Item #$section-$index',
72 | style: const TextStyle(
73 | color: Colors.black,
74 | fontSize: 16,
75 | ),
76 | ),
77 | ),
78 | Divider(
79 | height: 1.0,
80 | thickness: 1.0,
81 | color: Colors.grey.shade200,
82 | indent: 16.0,
83 | ),
84 | ],
85 | );
86 | },
87 | childCount: 8,
88 | ),
89 | );
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/example/lib/examples/example1.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 |
3 | import 'package:easy_sticky_header/easy_sticky_header.dart';
4 | import 'package:flutter/material.dart';
5 |
6 | class Example1 extends StatelessWidget {
7 | const Example1({Key? key}) : super(key: key);
8 |
9 | @override
10 | Widget build(BuildContext context) {
11 | return Scaffold(
12 | backgroundColor: Colors.white,
13 | appBar: AppBar(
14 | shadowColor: Colors.transparent,
15 | backgroundColor: Colors.black,
16 | foregroundColor: Colors.white,
17 | title: const Text('Horizontal scroll axis'),
18 | ),
19 | body: Column(
20 | mainAxisAlignment: MainAxisAlignment.spaceEvenly,
21 | children: [
22 | _buildListView(),
23 | _buildListView(reverse: true),
24 | ],
25 | ),
26 | );
27 | }
28 |
29 | Widget _buildListView({
30 | bool reverse = false,
31 | }) =>
32 | Container(
33 | width: double.infinity,
34 | height: 200,
35 | color: Colors.grey.shade100,
36 | child: StickyHeader(
37 | child: ListView.builder(
38 | physics: const AlwaysScrollableScrollPhysics(
39 | parent: BouncingScrollPhysics(),
40 | ),
41 | scrollDirection: Axis.horizontal,
42 | reverse: reverse,
43 | itemCount: 100,
44 | itemBuilder: (context, index) {
45 | if (index % 3 == 0) {
46 | return StickyContainerWidget(
47 | index: index,
48 | child: Container(
49 | color: Color.fromRGBO(Random().nextInt(256),
50 | Random().nextInt(256), Random().nextInt(256), 1),
51 | padding: const EdgeInsets.symmetric(horizontal: 4),
52 | alignment: Alignment.centerLeft,
53 | width: 50,
54 | child: Text(
55 | 'Header #$index',
56 | style: const TextStyle(
57 | color: Colors.white,
58 | fontSize: 16,
59 | ),
60 | ),
61 | ),
62 | );
63 | }
64 | return Row(
65 | children: [
66 | Container(
67 | width: 80,
68 | height: 200,
69 | color: Colors.white,
70 | padding: const EdgeInsets.only(top: 16),
71 | alignment: Alignment.topCenter,
72 | child: Text(
73 | 'Item #$index',
74 | style: const TextStyle(
75 | color: Colors.black,
76 | fontSize: 16,
77 | ),
78 | ),
79 | ),
80 | VerticalDivider(
81 | width: 1.0,
82 | thickness: 1.0,
83 | color: Colors.grey.shade200,
84 | ),
85 | ],
86 | );
87 | },
88 | ),
89 | ),
90 | );
91 | }
92 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/lib/src/render_sticky_container.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, crasowas.
2 | //
3 | // Use of this source code is governed by a MIT-style license
4 | // that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | import 'package:flutter/material.dart';
8 | import 'package:flutter/rendering.dart';
9 |
10 | import 'sticky_header_controller.dart';
11 | import 'sticky_header_info.dart';
12 |
13 | /// RenderObject for StickyContainer widget.
14 | ///
15 | /// When the page is scrolled, the [StickyHeaderController] will get the header
16 | /// widget information through callback.
17 | class RenderStickyContainer extends RenderProxyBox {
18 | StickyHeaderController? _controller;
19 | double? _pixelsCache;
20 |
21 | int index;
22 | bool visible;
23 | double? pixels;
24 | bool performancePriority;
25 | int? parentIndex;
26 | bool overlapParent;
27 | Widget widget;
28 |
29 | RenderStickyContainer({
30 | required StickyHeaderController? controller,
31 | required this.index,
32 | required this.visible,
33 | this.pixels,
34 | required this.performancePriority,
35 | this.parentIndex,
36 | required this.overlapParent,
37 | required this.widget,
38 | }) : _controller = controller;
39 |
40 | set controller(StickyHeaderController? newController) {
41 | if (newController != null && _controller != newController) {
42 | StickyHeaderController? oldController = _controller;
43 | _controller = newController;
44 | oldController?.removeCallback(_callback);
45 | newController.addCallback(_callback);
46 | }
47 | }
48 |
49 | @override
50 | void attach(PipelineOwner owner) {
51 | super.attach(owner);
52 | _controller?.addCallback(_callback);
53 | }
54 |
55 | @override
56 | void detach() {
57 | _controller?.removeCallback(_callback);
58 | super.detach();
59 | }
60 |
61 | @override
62 | void performLayout() {
63 | // Layout header widget.
64 | final childConstraints = constraints.loosen();
65 | child?.layout(childConstraints, parentUsesSize: true);
66 | size = child?.size ?? Size.zero;
67 | }
68 |
69 | double get _pixels {
70 | if (pixels != null) {
71 | return pixels ?? 0.0;
72 | } else {
73 | if (_pixelsCache == null || !performancePriority) {
74 | _pixelsCache = RenderAbstractViewport.of(this)
75 | .getOffsetToReveal(this, 0.0)
76 | .offset;
77 | }
78 | return _pixelsCache ?? 0.0;
79 | }
80 | }
81 |
82 | Offset get _offset {
83 | var controller = _controller;
84 | if (controller != null) {
85 | var d = _pixels - controller.currentPixels;
86 | return controller.isHorizontalAxis ? Offset(d, 0.0) : Offset(0.0, d);
87 | }
88 | return Offset.zero;
89 | }
90 |
91 | int? get _parentIndex =>
92 | (parentIndex != null && (parentIndex ?? 0) < index) ? parentIndex : null;
93 |
94 | StickyHeaderInfo _callback() => StickyHeaderInfo(
95 | index: index,
96 | visible: visible,
97 | size: size,
98 | pixels: _pixels,
99 | offset: _offset,
100 | parentIndex: _parentIndex,
101 | overlapParent: overlapParent,
102 | widget: widget,
103 | );
104 | }
105 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/example/lib/examples/example4.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 |
3 | import 'package:easy_sticky_header/easy_sticky_header.dart';
4 | import 'package:flutter/material.dart';
5 |
6 | import '../test_config.dart';
7 |
8 | class Example4 extends StatefulWidget {
9 | const Example4({Key? key}) : super(key: key);
10 |
11 | @override
12 | State createState() => _Example4State();
13 | }
14 |
15 | class _Example4State extends State {
16 | late final StickyHeaderController _controller;
17 |
18 | @override
19 | void initState() {
20 | super.initState();
21 | _controller = StickyHeaderController();
22 | }
23 |
24 | @override
25 | void dispose() {
26 | _controller.dispose();
27 | super.dispose();
28 | }
29 |
30 | @override
31 | Widget build(BuildContext context) {
32 | return Scaffold(
33 | backgroundColor: Colors.white,
34 | appBar: AppBar(
35 | shadowColor: Colors.transparent,
36 | backgroundColor: Colors.black,
37 | foregroundColor: Colors.white,
38 | title:
39 | const Text('Scrolls to the top after the header widget is tapped'),
40 | ),
41 | body: StickyHeader(
42 | controller: _controller,
43 | child: ListView.builder(
44 | reverse: TestConfig.reverse,
45 | physics: const AlwaysScrollableScrollPhysics(
46 | parent: BouncingScrollPhysics(),
47 | ),
48 | itemCount: 100,
49 | itemBuilder: (context, index) {
50 | if (index % 6 == 0) {
51 | return StickyContainerWidget(
52 | index: index,
53 | child: GestureDetector(
54 | onTap: () {
55 | // Jumps without animation.
56 | // _controller.jumpTo(index);
57 | _controller.animateTo(index);
58 | },
59 | child: Container(
60 | color: Color.fromRGBO(Random().nextInt(256),
61 | Random().nextInt(256), Random().nextInt(256), 1),
62 | padding: const EdgeInsets.only(left: 16.0),
63 | alignment: Alignment.centerLeft,
64 | width: double.infinity,
65 | height: 50,
66 | child: Text(
67 | 'Header #$index',
68 | style: const TextStyle(
69 | color: Colors.white,
70 | fontSize: 16,
71 | ),
72 | ),
73 | ),
74 | ),
75 | );
76 | }
77 | return Column(
78 | children: [
79 | Container(
80 | width: double.infinity,
81 | height: 80,
82 | color: Colors.white,
83 | padding: const EdgeInsets.only(left: 16),
84 | alignment: Alignment.centerLeft,
85 | child: Text(
86 | 'Item #$index',
87 | style: const TextStyle(
88 | color: Colors.black,
89 | fontSize: 16,
90 | ),
91 | ),
92 | ),
93 | Divider(
94 | height: 1.0,
95 | thickness: 1.0,
96 | color: Colors.grey.shade200,
97 | indent: 16.0,
98 | ),
99 | ],
100 | );
101 | },
102 | ),
103 | ),
104 | );
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/example/lib/examples/example3.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 |
3 | import 'package:easy_sticky_header/easy_sticky_header.dart';
4 | import 'package:flutter/material.dart';
5 |
6 | import '../test_config.dart';
7 |
8 | class Example3 extends StatelessWidget {
9 | const Example3({Key? key}) : super(key: key);
10 |
11 | @override
12 | Widget build(BuildContext context) {
13 | return Scaffold(
14 | backgroundColor: Colors.white,
15 | appBar: AppBar(
16 | shadowColor: Colors.transparent,
17 | backgroundColor: Colors.black,
18 | foregroundColor: Colors.white,
19 | title: const Text('Building header widget by sticky amount'),
20 | ),
21 | body: StickyHeader(
22 | child: ListView.builder(
23 | reverse: TestConfig.reverse,
24 | physics: const AlwaysScrollableScrollPhysics(
25 | parent: BouncingScrollPhysics(),
26 | ),
27 | itemCount: 100,
28 | itemBuilder: (context, index) {
29 | if (index % 3 == 0) {
30 | if (index == 6) {
31 | return StickyContainerWidget(
32 | index: index,
33 | child: Container(
34 | color: const Color.fromRGBO(155, 105, 0, 1),
35 | padding: const EdgeInsets.only(left: 16.0),
36 | alignment: Alignment.centerLeft,
37 | width: double.infinity,
38 | height: min(100, 50 + 5.0 * index),
39 | child: Text(
40 | 'Header #$index, not using stickyAmount',
41 | style: const TextStyle(
42 | color: Colors.white,
43 | fontSize: 16,
44 | ),
45 | ),
46 | ),
47 | );
48 | } else {
49 | return StickyContainerBuilder(
50 | index: index,
51 | builder: (context, stickyAmount) => Container(
52 | color: Color.fromRGBO(
53 | 155 + (100 * stickyAmount).toInt(), 105, 0, 1.0),
54 | padding: const EdgeInsets.only(left: 16.0),
55 | alignment: Alignment.centerLeft,
56 | width: double.infinity,
57 | height: min(100, 50 + 5.0 * index),
58 | child: Text(
59 | 'Header #$index stickyAmount:${stickyAmount.toStringAsFixed(2)}',
60 | style: const TextStyle(
61 | color: Colors.white,
62 | fontSize: 16,
63 | ),
64 | ),
65 | ),
66 | );
67 | }
68 | }
69 | return Column(
70 | children: [
71 | Container(
72 | width: double.infinity,
73 | height: 80,
74 | color: Colors.white,
75 | padding: const EdgeInsets.only(left: 16),
76 | alignment: Alignment.centerLeft,
77 | child: Text(
78 | 'Item #$index',
79 | style: const TextStyle(
80 | color: Colors.black,
81 | fontSize: 16,
82 | ),
83 | ),
84 | ),
85 | Divider(
86 | height: 1.0,
87 | thickness: 1.0,
88 | color: Colors.grey.shade200,
89 | indent: 16.0,
90 | ),
91 | ],
92 | );
93 | },
94 | ),
95 | ),
96 | );
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/example/lib/examples/example10.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 |
3 | import 'package:easy_sticky_header/easy_sticky_header.dart';
4 | import 'package:flutter/material.dart';
5 |
6 | import '../test_config.dart';
7 |
8 | class Example10 extends StatelessWidget {
9 | const Example10({Key? key}) : super(key: key);
10 |
11 | @override
12 | Widget build(BuildContext context) {
13 | return Scaffold(
14 | backgroundColor: Colors.white,
15 | appBar: AppBar(
16 | shadowColor: Colors.transparent,
17 | backgroundColor: Colors.black,
18 | foregroundColor: Colors.white,
19 | title: const Text('SliverPersistentHeader'),
20 | ),
21 | body: StickyHeader(
22 | spacing: 50,
23 | child: CustomScrollView(
24 | reverse: TestConfig.reverse,
25 | physics: const AlwaysScrollableScrollPhysics(
26 | parent: BouncingScrollPhysics()),
27 | slivers: [
28 | SliverPersistentHeader(
29 | pinned: true,
30 | delegate: CustomDelegate(),
31 | ),
32 | // Temporarily only supports the layout of a header widget.
33 | _buildHeader(1),
34 | _buildSliverGrid(1),
35 | ],
36 | ),
37 | ),
38 | );
39 | }
40 |
41 | Widget _buildHeader(int index) => SliverToBoxAdapter(
42 | child: StickyContainerWidget(
43 | index: index,
44 | child: Container(
45 | color: const Color.fromRGBO(255, 105, 0, 1.0),
46 | padding: const EdgeInsets.only(left: 16.0),
47 | alignment: Alignment.centerLeft,
48 | width: double.infinity,
49 | height: 50,
50 | child: Text(
51 | 'Header #$index',
52 | style: const TextStyle(
53 | color: Colors.white,
54 | fontSize: 16,
55 | ),
56 | ),
57 | ),
58 | ),
59 | );
60 |
61 | Widget _buildSliverGrid(int section) => SliverGrid(
62 | gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
63 | crossAxisCount: 2,
64 | mainAxisSpacing: 10,
65 | crossAxisSpacing: 10,
66 | ),
67 | delegate: SliverChildBuilderDelegate(
68 | (context, index) {
69 | return Container(
70 | width: double.infinity,
71 | height: 80,
72 | color: Color.fromRGBO(Random().nextInt(256),
73 | Random().nextInt(256), Random().nextInt(256), 1),
74 | padding: const EdgeInsets.only(left: 16),
75 | alignment: Alignment.centerLeft,
76 | child: Text(
77 | 'Item #$section-$index',
78 | style: const TextStyle(
79 | color: Colors.black,
80 | fontSize: 16,
81 | ),
82 | ),
83 | );
84 | },
85 | childCount: 10,
86 | ),
87 | );
88 | }
89 |
90 | class CustomDelegate extends SliverPersistentHeaderDelegate {
91 | @override
92 | double get maxExtent => 200;
93 |
94 | @override
95 | double get minExtent => 50;
96 |
97 | @override
98 | Widget build(
99 | BuildContext context, double shrinkOffset, bool overlapsContent) =>
100 | Container(
101 | color: const Color.fromRGBO(0, 128, 255, 1.0),
102 | padding: const EdgeInsets.only(left: 16.0),
103 | alignment: Alignment.centerLeft,
104 | child: const Text(
105 | 'SliverPersistentHeader',
106 | style: TextStyle(
107 | color: Colors.white,
108 | fontSize: 18,
109 | ),
110 | ),
111 | );
112 |
113 | @override
114 | bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
115 | return maxExtent != oldDelegate.maxExtent ||
116 | minExtent != oldDelegate.minExtent;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/example/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: example
2 | description: An example project of Easy Sticky Header.
3 |
4 | # The following line prevents the package from being accidentally published to
5 | # pub.dev using `flutter pub publish`. This is preferred for private packages.
6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev
7 |
8 | # The following defines the version and build number for your application.
9 | # A version number is three numbers separated by dots, like 1.2.43
10 | # followed by an optional build number separated by a +.
11 | # Both the version and the builder number may be overridden in flutter
12 | # build by specifying --build-name and --build-number, respectively.
13 | # In Android, build-name is used as versionName while build-number used as versionCode.
14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
16 | # Read more about iOS versioning at
17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18 | version: 1.0.0+1
19 |
20 | environment:
21 | sdk: '>=2.12.0 <4.0.0'
22 |
23 | # Dependencies specify other packages that your package needs in order to work.
24 | # To automatically upgrade your package dependencies to the latest versions
25 | # consider running `flutter pub upgrade --major-versions`. Alternatively,
26 | # dependencies can be manually updated by changing the version numbers below to
27 | # the latest version available on pub.dev. To see which dependencies have newer
28 | # versions available, run `flutter pub outdated`.
29 | dependencies:
30 | flutter:
31 | sdk: flutter
32 |
33 | easy_sticky_header:
34 | path: ../
35 |
36 | # The following adds the Cupertino Icons font to your application.
37 | # Use with the CupertinoIcons class for iOS style icons.
38 | cupertino_icons: ^1.0.2
39 |
40 | dev_dependencies:
41 | flutter_test:
42 | sdk: flutter
43 |
44 | # The "flutter_lints" package below contains a set of recommended lints to
45 | # encourage good coding practices. The lint set provided by the package is
46 | # activated in the `analysis_options.yaml` file located at the root of your
47 | # package. See that file for information about deactivating specific lint
48 | # rules and activating additional ones.
49 | flutter_lints: ^3.0.0
50 |
51 | # For information on the generic Dart part of this file, see the
52 | # following page: https://dart.dev/tools/pub/pubspec
53 |
54 | # The following section is specific to Flutter packages.
55 | flutter:
56 |
57 | # The following line ensures that the Material Icons font is
58 | # included with your application, so that you can use the icons in
59 | # the material Icons class.
60 | uses-material-design: true
61 |
62 | # To add assets to your application, add an assets section, like this:
63 | # assets:
64 | # - images/a_dot_burr.jpeg
65 | # - images/a_dot_ham.jpeg
66 |
67 | # An image asset can refer to one or more resolution-specific "variants", see
68 | # https://flutter.dev/assets-and-images/#resolution-aware
69 |
70 | # For details regarding adding assets from package dependencies, see
71 | # https://flutter.dev/assets-and-images/#from-packages
72 |
73 | # To add custom fonts to your application, add a fonts section here,
74 | # in this "flutter" section. Each entry in this list should have a
75 | # "family" key with the font family name, and a "fonts" key with a
76 | # list giving the asset and other descriptors for the font. For
77 | # example:
78 | # fonts:
79 | # - family: Schyler
80 | # fonts:
81 | # - asset: fonts/Schyler-Regular.ttf
82 | # - asset: fonts/Schyler-Italic.ttf
83 | # style: italic
84 | # - family: Trajan Pro
85 | # fonts:
86 | # - asset: fonts/TrajanPro.ttf
87 | # - asset: fonts/TrajanPro_Bold.ttf
88 | # weight: 700
89 | #
90 | # For details regarding fonts from package dependencies,
91 | # see https://flutter.dev/custom-fonts/#from-packages
92 |
--------------------------------------------------------------------------------
/example/lib/examples/example8.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 |
3 | import 'package:easy_sticky_header/easy_sticky_header.dart';
4 | import 'package:flutter/material.dart';
5 |
6 | import '../test_config.dart';
7 |
8 | class Example8 extends StatelessWidget {
9 | const Example8({Key? key}) : super(key: key);
10 |
11 | @override
12 | Widget build(BuildContext context) {
13 | return Scaffold(
14 | backgroundColor: Colors.white,
15 | appBar: AppBar(
16 | shadowColor: Colors.transparent,
17 | backgroundColor: Colors.black,
18 | foregroundColor: Colors.white,
19 | title: const Text('CustomScrollView'),
20 | ),
21 | body: StickyHeader(
22 | child: CustomScrollView(
23 | reverse: TestConfig.reverse,
24 | physics: const AlwaysScrollableScrollPhysics(
25 | parent: BouncingScrollPhysics()),
26 | slivers: [
27 | _buildHeader(0),
28 | _buildSliverGrid(0),
29 | _buildHeader(1),
30 | _buildSliverGrid(1),
31 | _buildSliverList(1),
32 | ],
33 | ),
34 | ),
35 | );
36 | }
37 |
38 | Widget _buildHeader(int index) => SliverToBoxAdapter(
39 | child: StickyContainerWidget(
40 | index: index,
41 | child: Container(
42 | color: const Color.fromRGBO(255, 105, 0, 1.0),
43 | padding: const EdgeInsets.only(left: 16.0),
44 | alignment: Alignment.centerLeft,
45 | width: double.infinity,
46 | height: 50,
47 | child: Text(
48 | 'Header #$index',
49 | style: const TextStyle(
50 | color: Colors.white,
51 | fontSize: 16,
52 | ),
53 | ),
54 | ),
55 | ),
56 | );
57 |
58 | Widget _buildSliverList(int section) {
59 | return SliverList(
60 | delegate: SliverChildBuilderDelegate(
61 | (context, index) {
62 | return Column(
63 | children: [
64 | Container(
65 | width: double.infinity,
66 | height: 80,
67 | color: Color.fromRGBO(Random().nextInt(256),
68 | Random().nextInt(256), Random().nextInt(256), 1),
69 | padding: const EdgeInsets.only(left: 16),
70 | alignment: Alignment.centerLeft,
71 | child: Text(
72 | 'List Item #$section-$index',
73 | style: const TextStyle(
74 | color: Colors.black,
75 | fontSize: 16,
76 | ),
77 | ),
78 | ),
79 | Divider(
80 | height: 1.0,
81 | thickness: 1.0,
82 | color: Colors.grey.shade200,
83 | indent: 16.0,
84 | ),
85 | ],
86 | );
87 | },
88 | childCount: 8,
89 | ),
90 | );
91 | }
92 |
93 | Widget _buildSliverGrid(int section) => SliverGrid(
94 | gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
95 | crossAxisCount: 2,
96 | mainAxisSpacing: 10,
97 | crossAxisSpacing: 10,
98 | ),
99 | delegate: SliverChildBuilderDelegate(
100 | (context, index) {
101 | return Container(
102 | width: double.infinity,
103 | height: 80,
104 | color: Color.fromRGBO(Random().nextInt(256),
105 | Random().nextInt(256), Random().nextInt(256), 1),
106 | padding: const EdgeInsets.only(left: 16),
107 | alignment: Alignment.centerLeft,
108 | child: Text(
109 | 'Grid Item #$section-$index',
110 | style: const TextStyle(
111 | color: Colors.black,
112 | fontSize: 16,
113 | ),
114 | ),
115 | );
116 | },
117 | childCount: 4,
118 | ),
119 | );
120 | }
121 |
--------------------------------------------------------------------------------
/README-CN.md:
--------------------------------------------------------------------------------
1 | # easy_sticky_header
2 |
3 | [](https://flutter.dev)
4 | [](https://pub.dev/packages/easy_sticky_header)
5 | [](https://opensource.org/licenses/MIT)
6 | [](https://github.com/crasowas/easy_sticky_header/issues)
7 | [](https://github.com/crasowas/easy_sticky_header/commits)
8 |
9 | ## [English](https://github.com/crasowas/easy_sticky_header/blob/main/README.md) | 中文
10 |
11 | 一个易用且功能强大的粘性头部组件库,适用于任何支持滚动的组件。
12 |
13 | ## 介绍
14 |
15 | * [博客](https://blog.csdn.net/crasowas/article/details/126838153)
16 |
17 | ## 特性
18 |
19 | * 支持水平或垂直方向滚动的组件
20 | * 支持反向滚动的组件
21 | * 允许动态构建头部组件,支持自定义过渡动画
22 | * 头部组件可以动态改变粘性
23 | * 支持跳转到指定索引的头部组件
24 | * 支持头部组件分组
25 | * 支持无限列表
26 |
27 | ## 用法
28 |
29 | 添加依赖:
30 |
31 | ```yaml
32 | dependencies:
33 | easy_sticky_header: ^1.1.1
34 | ```
35 |
36 | 导入包:
37 |
38 | ```dart
39 | import 'package:easy_sticky_header/easy_sticky_header.dart';
40 | ```
41 |
42 | 示例:
43 |
44 | ```dart
45 | class Example extends StatelessWidget {
46 | @override
47 | Widget build(BuildContext context) {
48 | return StickyHeader(
49 | child: ListView.builder(
50 | itemCount: 100,
51 | itemBuilder: (context, index) {
52 | // Custom header widget.
53 | if (index % 3 == 0) {
54 | return StickyContainerWidget(
55 | index: index,
56 | child: Container(
57 | color: Color.fromRGBO(Random().nextInt(256),
58 | Random().nextInt(256), Random().nextInt(256), 1),
59 | padding: const EdgeInsets.only(left: 16.0),
60 | alignment: Alignment.centerLeft,
61 | width: double.infinity,
62 | height: 50,
63 | child: Text(
64 | 'Header #$index',
65 | style: const TextStyle(
66 | color: Colors.white,
67 | fontSize: 16,
68 | ),
69 | ),
70 | ),
71 | );
72 | }
73 | // Custom item widget.
74 | return Container(
75 | width: double.infinity,
76 | height: 80,
77 | color: Colors.white,
78 | );
79 | },
80 | ),
81 | );
82 | }
83 | }
84 | ```
85 |
86 | 想了解更多功能请前往[示例项目](https://github.com/crasowas/easy_sticky_header/blob/main/example)查看详情。
87 |
88 | ## 截图
89 |
90 | ||||
91 | |:---:|:---:|:---:|
92 | ||||
93 | ||||
94 |
95 | ## 贡献
96 |
97 | 欢迎你来为这里做出贡献 😄!
98 |
99 | 如果你发现bug或者想要新功能,可以提[issue](https://github.com/crasowas/easy_sticky_header/issues)。
100 |
101 | 如果你修复了bug或者实现了新功能,可以提PR。
102 |
103 | ## 许可协议
104 |
105 | ```
106 | MIT License
107 |
108 | Copyright (c) 2022 crasowas
109 |
110 | Permission is hereby granted, free of charge, to any person obtaining a copy
111 | of this software and associated documentation files (the "Software"), to deal
112 | in the Software without restriction, including without limitation the rights
113 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
114 | copies of the Software, and to permit persons to whom the Software is
115 | furnished to do so, subject to the following conditions:
116 |
117 | The above copyright notice and this permission notice shall be included in all
118 | copies or substantial portions of the Software.
119 |
120 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
121 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
122 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
123 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
124 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
125 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
126 | SOFTWARE.
127 | ```
--------------------------------------------------------------------------------
/example/lib/examples/example0.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 |
3 | import 'package:easy_sticky_header/easy_sticky_header.dart';
4 | import 'package:flutter/material.dart';
5 |
6 | class Example0 extends StatefulWidget {
7 | const Example0({Key? key}) : super(key: key);
8 |
9 | @override
10 | State createState() => _Example0State();
11 | }
12 |
13 | class _Example0State extends State {
14 | bool _reverse = false;
15 |
16 | @override
17 | Widget build(BuildContext context) {
18 | return Scaffold(
19 | backgroundColor: Colors.white,
20 | appBar: AppBar(
21 | shadowColor: Colors.transparent,
22 | backgroundColor: Colors.black,
23 | foregroundColor: Colors.white,
24 | title: const Text('Vertical scroll axis'),
25 | ),
26 | body: StickyHeader(
27 | // Not required, it only needs to be set when the [reverse] parameter
28 | // needs to be dynamically changed.
29 | reverse: _reverse,
30 | child: ListView.builder(
31 | physics: const AlwaysScrollableScrollPhysics(
32 | parent: BouncingScrollPhysics(),
33 | ),
34 | reverse: _reverse,
35 | itemCount: 100,
36 | itemBuilder: (context, index) {
37 | if (index % 3 == 0) {
38 | if (index == 3) {
39 | return ScrollableStickyContainerBuilder(
40 | index: index,
41 | builder: (context, scrollController) {
42 | return Container(
43 | color: Color.fromRGBO(Random().nextInt(256),
44 | Random().nextInt(256), Random().nextInt(256), 1),
45 | padding: const EdgeInsets.only(left: 16.0),
46 | alignment: Alignment.centerLeft,
47 | width: double.infinity,
48 | height: 50,
49 | child: ListView.builder(
50 | controller: scrollController,
51 | scrollDirection: Axis.horizontal,
52 | itemCount: 10,
53 | itemBuilder: (context, index) {
54 | return Container(
55 | height: 50,
56 | alignment: Alignment.center,
57 | child: Text('Header #3-$index | ',
58 | style: const TextStyle(
59 | color: Colors.white,
60 | fontSize: 16,
61 | )),
62 | );
63 | },
64 | ),
65 | );},
66 | );
67 | }
68 | return StickyContainerWidget(
69 | index: index,
70 | visible: index != 6,
71 | child: Container(
72 | color: Color.fromRGBO(Random().nextInt(256),
73 | Random().nextInt(256), Random().nextInt(256), 1),
74 | padding: const EdgeInsets.only(left: 16.0),
75 | alignment: Alignment.centerLeft,
76 | width: double.infinity,
77 | height: 50,
78 | child: Text(
79 | index == 6
80 | ? 'Header #$index, non-sticky'
81 | : 'Header #$index',
82 | style: const TextStyle(
83 | color: Colors.white,
84 | fontSize: 16,
85 | ),
86 | ),
87 | ),
88 | );
89 | }
90 | return Column(
91 | children: [
92 | Container(
93 | width: double.infinity,
94 | height: 80,
95 | color: Colors.white,
96 | padding: const EdgeInsets.only(left: 16),
97 | alignment: Alignment.centerLeft,
98 | child: Text(
99 | 'Item #$index',
100 | style: const TextStyle(
101 | color: Colors.black,
102 | fontSize: 16,
103 | ),
104 | ),
105 | ),
106 | Divider(
107 | height: 1.0,
108 | thickness: 1.0,
109 | color: Colors.grey.shade200,
110 | indent: 16.0,
111 | ),
112 | ],
113 | );
114 | },
115 | ),
116 | ),
117 | floatingActionButton: FloatingActionButton(
118 | backgroundColor: Colors.blue,
119 | shape: const CircleBorder(),
120 | onPressed: () {
121 | setState(() {
122 | _reverse = !_reverse;
123 | });
124 | },
125 | child: const Text(
126 | 'Reverse',
127 | style: TextStyle(
128 | color: Colors.white,
129 | fontSize: 10,
130 | ),
131 | ),
132 | ),
133 | );
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # easy_sticky_header
2 |
3 | [](https://flutter.dev)
4 | [](https://pub.dev/packages/easy_sticky_header)
5 | [](https://opensource.org/licenses/MIT)
6 | [](https://github.com/crasowas/easy_sticky_header/issues)
7 | [](https://github.com/crasowas/easy_sticky_header/commits)
8 |
9 | ## English | [中文](https://github.com/crasowas/easy_sticky_header/blob/main/README-CN.md)
10 |
11 | An easy-to-use and powerful sticky header for any widget that supports scrolling.
12 |
13 | ## Features
14 |
15 | * Support widget for horizontal or vertical scrolling
16 | * Support widget for reverse scrolling
17 | * Allow dynamic building of header widget and support custom transition animation
18 | * Header widget can dynamically change stickiness
19 | * Support jumping to the header widget of the specified index
20 | * Support header widget grouping
21 | * Support infinite list
22 |
23 | ## Usage
24 |
25 | Add dependency:
26 |
27 | ```yaml
28 | dependencies:
29 | easy_sticky_header: ^1.1.1
30 | ```
31 |
32 | Import package:
33 |
34 | ```dart
35 | import 'package:easy_sticky_header/easy_sticky_header.dart';
36 | ```
37 |
38 | Example:
39 |
40 | ```dart
41 | class Example extends StatelessWidget {
42 | @override
43 | Widget build(BuildContext context) {
44 | return StickyHeader(
45 | child: ListView.builder(
46 | itemCount: 100,
47 | itemBuilder: (context, index) {
48 | // Custom header widget.
49 | if (index % 3 == 0) {
50 | return StickyContainerWidget(
51 | index: index,
52 | child: Container(
53 | color: Color.fromRGBO(Random().nextInt(256),
54 | Random().nextInt(256), Random().nextInt(256), 1),
55 | padding: const EdgeInsets.only(left: 16.0),
56 | alignment: Alignment.centerLeft,
57 | width: double.infinity,
58 | height: 50,
59 | child: Text(
60 | 'Header #$index',
61 | style: const TextStyle(
62 | color: Colors.white,
63 | fontSize: 16,
64 | ),
65 | ),
66 | ),
67 | );
68 | }
69 | // Custom item widget.
70 | return Container(
71 | width: double.infinity,
72 | height: 80,
73 | color: Colors.white,
74 | );
75 | },
76 | ),
77 | );
78 | }
79 | }
80 | ```
81 |
82 | For more features, please go to the [example project](https://github.com/crasowas/easy_sticky_header/blob/main/example) to see the details.
83 |
84 | ## Screenshots
85 |
86 | ||||
87 | |:---:|:---:|:---:|
88 | ||||
89 | ||||
90 |
91 | ## Contribution
92 |
93 | You are welcome to contribute here 😄!
94 |
95 | You can open an [issue](https://github.com/crasowas/easy_sticky_header/issues), if you find a bug,
96 | or want a new feature.
97 |
98 | You can open up a PR, if you fixed a bug or implemented a new feature.
99 |
100 | ## License
101 |
102 | ```
103 | MIT License
104 |
105 | Copyright (c) 2022 crasowas
106 |
107 | Permission is hereby granted, free of charge, to any person obtaining a copy
108 | of this software and associated documentation files (the "Software"), to deal
109 | in the Software without restriction, including without limitation the rights
110 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
111 | copies of the Software, and to permit persons to whom the Software is
112 | furnished to do so, subject to the following conditions:
113 |
114 | The above copyright notice and this permission notice shall be included in all
115 | copies or substantial portions of the Software.
116 |
117 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
118 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
119 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
120 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
121 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
122 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
123 | SOFTWARE.
124 | ```
--------------------------------------------------------------------------------
/lib/src/sticky_header_widget.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, crasowas.
2 | //
3 | // Use of this source code is governed by a MIT-style license
4 | // that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | import 'package:flutter/foundation.dart';
8 | import 'package:flutter/material.dart';
9 |
10 | import 'sticky_header_controller.dart';
11 | import 'sticky_header_info.dart';
12 |
13 | /// Sticky Header Widget.
14 | ///
15 | /// Adjusts the position and visibility of the widget in real time according to
16 | /// the scrolling changes, while covering the lower widget to achieve the effect
17 | /// of sticky header.
18 | class StickyHeaderWidget extends StatefulWidget {
19 | final StickyHeaderController controller;
20 |
21 | final double spacing;
22 |
23 | const StickyHeaderWidget({
24 | Key? key,
25 | required this.controller,
26 | required this.spacing,
27 | }) : super(key: key);
28 |
29 | @override
30 | State createState() => _StickyHeaderWidgetState();
31 |
32 | @override
33 | void debugFillProperties(DiagnosticPropertiesBuilder properties) {
34 | super.debugFillProperties(properties);
35 | properties.add(DiagnosticsProperty(
36 | 'pixels', controller.currentPixels,
37 | defaultValue: 0.0));
38 | properties.add(DiagnosticsProperty(
39 | 'offset', controller.currentOffset,
40 | defaultValue: Offset.zero));
41 | properties.add(DiagnosticsProperty(
42 | 'stickyHeaderInfo', controller.currentStickyHeaderInfo,
43 | defaultValue: null));
44 | properties.add(DiagnosticsProperty(
45 | 'childStickyHeaderInfo', controller.currentChildStickyHeaderInfo,
46 | defaultValue: null));
47 | }
48 | }
49 |
50 | class _StickyHeaderWidgetState extends State
51 | with SingleTickerProviderStateMixin {
52 | late AnimationController _animationController;
53 |
54 | @override
55 | void initState() {
56 | super.initState();
57 | _animationController = AnimationController.unbounded(vsync: this);
58 | _animationController.addListener(() {
59 | widget.controller.scrollPosition?.jumpTo(_animationController.value);
60 | });
61 | widget.controller.addListener(_update);
62 | }
63 |
64 | @override
65 | void didUpdateWidget(covariant StickyHeaderWidget oldWidget) {
66 | super.didUpdateWidget(oldWidget);
67 | if (widget.controller != oldWidget.controller) {
68 | oldWidget.controller.removeListener(_update);
69 | widget.controller.addListener(_update);
70 | }
71 | }
72 |
73 | @override
74 | void dispose() {
75 | widget.controller.removeListener(_update);
76 | _animationController.dispose();
77 | super.dispose();
78 | }
79 |
80 | @override
81 | Widget build(BuildContext context) {
82 | var stickyHeaderInfo = widget.controller.currentStickyHeaderInfo;
83 | return GestureDetector(
84 | onPanUpdate: _onPanUpdate,
85 | onPanEnd: _onPanEnd,
86 | child: Visibility(
87 | visible: stickyHeaderInfo != null && stickyHeaderInfo.visible,
88 | child: _buildStickyHeader(stickyHeaderInfo),
89 | ),
90 | );
91 | }
92 |
93 | Widget _buildStickyHeader(StickyHeaderInfo? stickyHeaderInfo) {
94 | if (stickyHeaderInfo != null) {
95 | var isHorizontalAxis = widget.controller.isHorizontalAxis;
96 | var spacing = (widget.controller.isReverse ? -1 : 1) * widget.spacing;
97 | return Stack(
98 | children: [
99 | Positioned(
100 | left: widget.controller.currentOffset.dx +
101 | (isHorizontalAxis ? spacing : 0.0),
102 | top: widget.controller.currentOffset.dy +
103 | (isHorizontalAxis ? 0.0 : spacing),
104 | right: isHorizontalAxis ? null : 0.0,
105 | bottom: isHorizontalAxis ? 0.0 : null,
106 | child: stickyHeaderInfo.widget,
107 | ),
108 | ],
109 | );
110 | }
111 | return Container();
112 | }
113 |
114 | void _update() {
115 | setState(() {});
116 | }
117 |
118 | /// The sticky header widget should be scrollable, and the scrolling widget
119 | /// scrolls in sync when the sticky header widget scrolls,
120 | /// it feels like part of the scrolling widget.
121 | void _onPanUpdate(DragUpdateDetails details) {
122 | widget.controller.scrollPosition?.jumpTo(widget.controller.currentPixels +
123 | (widget.controller.isReverse ? 1.0 : -1.0) *
124 | widget.controller.getComponent(details.delta));
125 | }
126 |
127 | /// After the user stops dragging the sticky header widget, keep the same
128 | /// physics animation as the scrolling widget.
129 | void _onPanEnd(DragEndDetails details) {
130 | var scrollPosition = widget.controller.scrollPosition;
131 | if (scrollPosition != null) {
132 | // Velocity limit.
133 | var velocity = (widget.controller.isReverse ? 1.0 : -1.0) *
134 | widget.controller.getComponent(
135 | details.velocity.clampMagnitude(0, 1000).pixelsPerSecond);
136 | var simulation = scrollPosition.physics
137 | .createBallisticSimulation(scrollPosition, velocity);
138 | // In some cases, physical animation is not required, for example,
139 | // the velocity is already 0.0 at this time.
140 | if (simulation != null) {
141 | _animationController.animateWith(simulation);
142 | }
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/lib/src/sticky_header.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, crasowas.
2 | //
3 | // Use of this source code is governed by a MIT-style license
4 | // that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | import 'package:flutter/foundation.dart';
8 | import 'package:flutter/material.dart';
9 |
10 | import 'sticky_header_controller.dart';
11 | import 'sticky_header_widget.dart';
12 |
13 | /// Sticky Header.
14 | ///
15 | /// Wraps a [ListView], [GridView], [CustomScrollView], [SingleChildScrollView]
16 | /// or similar with this widget. Usually, as long as the wrapped widget is a
17 | /// scrolling widget, it can be used normally.
18 | ///
19 | /// {@tool snippet}
20 | ///
21 | /// This example shows how to easily create a [ListView] with a sticky header.
22 | /// For more usage details, please refer to the example project.
23 | ///
24 | /// ```dart
25 | /// StickyHeader(
26 | /// child: ListView.builder(
27 | /// itemCount: 100,
28 | /// itemBuilder: (context, index) {
29 | /// // Custom header widget.
30 | /// if (index % 3 == 0) {
31 | /// return StickyContainerWidget(
32 | /// index: index,
33 | /// child: Container(
34 | /// color: Color.fromRGBO(Random().nextInt(256),
35 | /// Random().nextInt(256), Random().nextInt(256), 1),
36 | /// padding: const EdgeInsets.only(left: 16.0),
37 | /// alignment: Alignment.centerLeft,
38 | /// width: double.infinity,
39 | /// height: 50,
40 | /// child: Text(
41 | /// 'Header #$index',
42 | /// style: const TextStyle(
43 | /// color: Colors.white,
44 | /// fontSize: 16,
45 | /// ),
46 | /// ),
47 | /// ),
48 | /// );
49 | /// }
50 | /// // Custom item widget.
51 | /// return Container(
52 | /// width: double.infinity,
53 | /// height: 80,
54 | /// color: Colors.white,
55 | /// );
56 | /// },
57 | /// ),
58 | /// );
59 | /// ```
60 | /// {@end-tool}
61 | class StickyHeader extends StatefulWidget {
62 | /// Optional [StickyHeaderController].
63 | ///
64 | /// One controller will be maintained by default,
65 | /// if no other features are required, then there is no need to create
66 | /// a new controller.
67 | final StickyHeaderController? controller;
68 |
69 | /// This property must be set if the value of the [reverse] property
70 | /// needs to be changed dynamically. Usually set to null by default.
71 | final bool? reverse;
72 |
73 | /// Spacing between sticky header and start position.
74 | final double spacing;
75 |
76 | /// Widget that support scrolling.
77 | final Widget child;
78 |
79 | const StickyHeader({
80 | Key? key,
81 | this.controller,
82 | this.reverse,
83 | this.spacing = 0.0,
84 | required this.child,
85 | }) : super(key: key);
86 |
87 | @override
88 | State createState() => _StickyHeaderState();
89 |
90 | @override
91 | void debugFillProperties(DiagnosticPropertiesBuilder properties) {
92 | super.debugFillProperties(properties);
93 | properties
94 | .add(DiagnosticsProperty('reverse', reverse, defaultValue: null));
95 | properties.add(
96 | DiagnosticsProperty('spacing', spacing, defaultValue: 0.0));
97 | }
98 |
99 | static StickyHeaderController? of(BuildContext? context) => context
100 | ?.dependOnInheritedWidgetOfExactType<_StickyHeaderControllerWidget>()
101 | ?.controller;
102 | }
103 |
104 | class _StickyHeaderState extends State {
105 | StickyHeaderController? _controller;
106 |
107 | @override
108 | void initState() {
109 | super.initState();
110 | _controller = widget.controller ?? StickyHeaderController();
111 | }
112 |
113 | @override
114 | void didUpdateWidget(covariant StickyHeader oldWidget) {
115 | super.didUpdateWidget(oldWidget);
116 | if (widget.controller != oldWidget.controller &&
117 | widget.controller != null) {
118 | _controller?.dispose();
119 | _controller = widget.controller;
120 | } else if (widget.reverse != null &&
121 | widget.reverse != _controller?.isReverse) {
122 | _controller?.clearStickyHeaderInfo();
123 | WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
124 | _controller?.scrollListener();
125 | });
126 | }
127 | }
128 |
129 | @override
130 | void dispose() {
131 | if (widget.controller == null) {
132 | _controller?.dispose();
133 | }
134 | super.dispose();
135 | }
136 |
137 | @override
138 | Widget build(BuildContext context) {
139 | var controller = _controller;
140 | if (controller != null) {
141 | return _StickyHeaderControllerWidget(
142 | controller: controller,
143 | child: Stack(
144 | children: [
145 | NotificationListener(
146 | onNotification: (notification) {
147 | // Abort if jumping to the header widget at the specified index
148 | // is in progress.
149 | controller.isJumping = false;
150 | return false;
151 | },
152 | child: widget.child,
153 | ),
154 | StickyHeaderWidget(
155 | controller: controller,
156 | spacing: widget.spacing,
157 | ),
158 | ],
159 | ),
160 | );
161 | } else {
162 | // Ignore this return, this line of code will not be executed.
163 | return const _NullWidget();
164 | }
165 | }
166 | }
167 |
168 | /// Sticky Header Controller Widget.
169 | ///
170 | /// This is an [InheritedWidget], which is convenient for
171 | /// [StickyContainerWidget] to get the controller.
172 | class _StickyHeaderControllerWidget extends InheritedWidget {
173 | const _StickyHeaderControllerWidget({
174 | Key? key,
175 | required this.controller,
176 | required Widget child,
177 | }) : super(key: key, child: child);
178 |
179 | final StickyHeaderController controller;
180 |
181 | @override
182 | bool updateShouldNotify(_StickyHeaderControllerWidget oldWidget) =>
183 | controller != oldWidget.controller;
184 | }
185 |
186 | class _NullWidget extends Widget {
187 | const _NullWidget();
188 |
189 | @override
190 | Element createElement() => throw UnimplementedError();
191 | }
192 |
--------------------------------------------------------------------------------
/example/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:easy_sticky_header/easy_sticky_header.dart';
2 | import 'package:flutter/material.dart';
3 |
4 | import 'examples/example0.dart';
5 | import 'examples/example1.dart';
6 | import 'examples/example10.dart';
7 | import 'examples/example11.dart';
8 | import 'examples/example12.dart';
9 | import 'examples/example2.dart';
10 | import 'examples/example3.dart';
11 | import 'examples/example4.dart';
12 | import 'examples/example5.dart';
13 | import 'examples/example6.dart';
14 | import 'examples/example7.dart';
15 | import 'examples/example8.dart';
16 | import 'examples/example9.dart';
17 |
18 | void main() {
19 | runApp(const MyApp());
20 | }
21 |
22 | class MyApp extends StatelessWidget {
23 | const MyApp({Key? key}) : super(key: key);
24 |
25 | @override
26 | Widget build(BuildContext context) {
27 | return MaterialApp(
28 | title: 'Easy Sticky Header Demo',
29 | theme: ThemeData(
30 | primarySwatch: Colors.blue,
31 | ),
32 | home: const MyHomePage(title: 'Easy Sticky Header Demo'),
33 | // showPerformanceOverlay: true,
34 | );
35 | }
36 | }
37 |
38 | class MyHomePage extends StatefulWidget {
39 | const MyHomePage({Key? key, required this.title}) : super(key: key);
40 |
41 | final String title;
42 |
43 | @override
44 | State createState() => _MyHomePageState();
45 | }
46 |
47 | class _MyHomePageState extends State {
48 | @override
49 | Widget build(BuildContext context) {
50 | return Scaffold(
51 | backgroundColor: Colors.white,
52 | appBar: AppBar(
53 | shadowColor: Colors.transparent,
54 | backgroundColor: Colors.black,
55 | foregroundColor: Colors.white,
56 | title: Text(widget.title),
57 | ),
58 | body: StickyHeader(
59 | child: ListView.builder(
60 | physics: const AlwaysScrollableScrollPhysics(
61 | parent: BouncingScrollPhysics(),
62 | ),
63 | itemCount: 15,
64 | itemBuilder: (context, index) {
65 | if (index == 0) {
66 | return _buildHeader(index, 'Getting Started');
67 | } else if (index == 1) {
68 | return _buildItem(index, 'Example 0 - Vertical scroll axis',
69 | () => _push(context, const Example0()));
70 | } else if (index == 2) {
71 | return _buildItem(index, 'Example 1 - Horizontal scroll axis',
72 | () => _push(context, const Example1()));
73 | } else if (index == 3) {
74 | return _buildItem(
75 | index,
76 | 'Example 2 - ScrollController with initialScrollOffset',
77 | () => _push(context, const Example2()));
78 | } else if (index == 4) {
79 | return _buildItem(
80 | index,
81 | 'Example 3 - Building header widget by sticky amount',
82 | () => _push(context, const Example3()));
83 | } else if (index == 5) {
84 | return _buildItem(
85 | index,
86 | 'Example 4 - Scrolls to the top after the header widget is tapped',
87 | () => _push(context, const Example4()));
88 | } else if (index == 6) {
89 | return _buildItem(
90 | index,
91 | 'Example 5 - Jumps to the header widget of the specified index',
92 | () => _push(context, const Example5()));
93 | } else if (index == 7) {
94 | return _buildItem(
95 | index,
96 | 'Example 6 - Building header widget by group',
97 | () => _push(context, const Example6()));
98 | } else if (index == 8) {
99 | return _buildHeader(index, 'More features');
100 | } else if (index == 9) {
101 | return _buildItem(index, 'Example 7 - GridView',
102 | () => _push(context, const Example7()));
103 | } else if (index == 10) {
104 | return _buildItem(index, 'Example 8 - CustomScrollView',
105 | () => _push(context, const Example8()));
106 | } else if (index == 11) {
107 | return _buildItem(index, 'Example 9 - SingleChildScrollView',
108 | () => _push(context, const Example9()));
109 | } else if (index == 12) {
110 | return _buildItem(index, 'Example 10 - SliverPersistentHeader',
111 | () => _push(context, const Example10()));
112 | } else if (index == 13) {
113 | return _buildItem(index, 'Example 11 - Multiple SliverList',
114 | () => _push(context, const Example11()));
115 | } else if (index == 14) {
116 | return _buildItem(index, 'Example 12 - Infinite list',
117 | () => _push(context, const Example12()));
118 | }
119 | return Container();
120 | },
121 | ),
122 | ),
123 | );
124 | }
125 |
126 | Widget _buildHeader(int index, String title) => StickyContainerWidget(
127 | index: index,
128 | child: Container(
129 | color: Colors.grey.shade600,
130 | padding: const EdgeInsets.only(left: 16.0),
131 | alignment: Alignment.centerLeft,
132 | width: double.infinity,
133 | height: 50,
134 | child: Text(
135 | title,
136 | style: const TextStyle(
137 | color: Colors.white,
138 | fontSize: 18,
139 | ),
140 | ),
141 | ),
142 | );
143 |
144 | Widget _buildItem(int index, String title, GestureTapCallback? onTap) =>
145 | Column(
146 | children: [
147 | ListTile(
148 | tileColor: Colors.white,
149 | title: Text(
150 | title,
151 | style: const TextStyle(
152 | color: Colors.black,
153 | fontSize: 16,
154 | ),
155 | ),
156 | visualDensity: const VisualDensity(vertical: 2),
157 | onTap: onTap,
158 | ),
159 | Divider(
160 | height: 1.0,
161 | thickness: 1.0,
162 | color: Colors.grey.shade200,
163 | indent: 16.0,
164 | ),
165 | ],
166 | );
167 |
168 | void _push(BuildContext context, Widget widget) {
169 | Navigator.of(context).push(MaterialPageRoute(
170 | builder: (context) => widget,
171 | ));
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/example/lib/examples/example5.dart:
--------------------------------------------------------------------------------
1 | import 'dart:math';
2 |
3 | import 'package:easy_sticky_header/easy_sticky_header.dart';
4 | import 'package:flutter/material.dart';
5 |
6 | import '../test_config.dart';
7 |
8 | class Example5 extends StatefulWidget {
9 | const Example5({Key? key}) : super(key: key);
10 |
11 | @override
12 | State createState() => _Example5State();
13 | }
14 |
15 | class _Example5State extends State {
16 | late final StickyHeaderController _controller;
17 | final ScrollController _scrollController =
18 | ScrollController(initialScrollOffset: 1200);
19 |
20 | @override
21 | void initState() {
22 | super.initState();
23 | _controller = StickyHeaderController();
24 | }
25 |
26 | @override
27 | void dispose() {
28 | _controller.dispose();
29 | _scrollController.dispose();
30 | super.dispose();
31 | }
32 |
33 | @override
34 | Widget build(BuildContext context) {
35 | return Scaffold(
36 | backgroundColor: Colors.white,
37 | appBar: AppBar(
38 | shadowColor: Colors.transparent,
39 | backgroundColor: Colors.black,
40 | foregroundColor: Colors.white,
41 | title: const Text('Jumps to the header of the specified index'),
42 | ),
43 | body: Column(
44 | children: [
45 | Expanded(
46 | child: StickyHeader(
47 | controller: _controller,
48 | child: ListView.builder(
49 | reverse: TestConfig.reverse,
50 | controller: _scrollController,
51 | itemCount: 100,
52 | itemBuilder: (context, index) {
53 | if (index % 3 == 0) {
54 | return StickyContainerWidget(
55 | index: index,
56 | child: Container(
57 | color: Color.fromRGBO(Random().nextInt(256),
58 | Random().nextInt(256), Random().nextInt(256), 1),
59 | padding: const EdgeInsets.only(left: 16.0),
60 | alignment: Alignment.centerLeft,
61 | width: double.infinity,
62 | height: 50,
63 | child: Text(
64 | 'Header #$index',
65 | style: const TextStyle(
66 | color: Colors.white,
67 | fontSize: 16,
68 | ),
69 | ),
70 | ),
71 | );
72 | }
73 | return Column(
74 | children: [
75 | Container(
76 | width: double.infinity,
77 | height: 80,
78 | color: Colors.white,
79 | padding: const EdgeInsets.only(left: 16),
80 | alignment: Alignment.centerLeft,
81 | child: Text(
82 | 'Item #$index',
83 | style: const TextStyle(
84 | color: Colors.black,
85 | fontSize: 16,
86 | ),
87 | ),
88 | ),
89 | Divider(
90 | height: 1.0,
91 | thickness: 1.0,
92 | color: Colors.grey.shade200,
93 | indent: 16.0,
94 | ),
95 | ],
96 | );
97 | },
98 | ),
99 | ),
100 | ),
101 | Container(
102 | padding: const EdgeInsets.symmetric(vertical: 10),
103 | child: Row(
104 | mainAxisAlignment: MainAxisAlignment.spaceAround,
105 | children: [
106 | _buildFloatingActionButton(0),
107 | _buildFloatingActionButton(33),
108 | TextWidget(controller: _controller),
109 | _buildFloatingActionButton(72),
110 | _buildFloatingActionButton(99),
111 | ],
112 | ),
113 | ),
114 | ],
115 | ),
116 | );
117 | }
118 |
119 | Widget _buildFloatingActionButton(int index) => FloatingActionButton(
120 | heroTag: index,
121 | backgroundColor: Colors.blue,
122 | shape: const CircleBorder(),
123 | onPressed: () {
124 | // If this just happens to jump to the header widget of
125 | // the specified index, the header widget doesn't become
126 | // a sticky header at this point, which is why you need
127 | // to set a little offset.
128 | _controller.animateTo(
129 | index,
130 | offset: 0.5,
131 | velocity: 5,
132 | );
133 | },
134 | child: Text(
135 | '$index',
136 | style: const TextStyle(
137 | color: Colors.white,
138 | fontSize: 16,
139 | ),
140 | ),
141 | );
142 | }
143 |
144 | class TextWidget extends StatefulWidget {
145 | final StickyHeaderController controller;
146 |
147 | const TextWidget({
148 | Key? key,
149 | required this.controller,
150 | }) : super(key: key);
151 |
152 | @override
153 | State createState() => _TextWidgetState();
154 | }
155 |
156 | class _TextWidgetState extends State {
157 | int? _index;
158 |
159 | @override
160 | void initState() {
161 | super.initState();
162 | widget.controller.addListener(_update);
163 | }
164 |
165 | @override
166 | void dispose() {
167 | widget.controller.removeListener(_update);
168 | super.dispose();
169 | }
170 |
171 | @override
172 | Widget build(BuildContext context) => Container(
173 | width: 50,
174 | height: 50,
175 | alignment: Alignment.center,
176 | decoration: const BoxDecoration(
177 | color: Colors.green,
178 | borderRadius: BorderRadius.all(
179 | Radius.circular(25),
180 | ),
181 | ),
182 | child: Text(
183 | '$_index',
184 | style: const TextStyle(
185 | color: Colors.white,
186 | fontSize: 16,
187 | ),
188 | ),
189 | );
190 |
191 | void _update() {
192 | var index = widget.controller.currentStickyHeaderInfo?.index;
193 | if (index != _index) {
194 | setState(() {
195 | _index = index;
196 | });
197 | }
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/example/pubspec.lock:
--------------------------------------------------------------------------------
1 | # Generated by pub
2 | # See https://dart.dev/tools/pub/glossary#lockfile
3 | packages:
4 | async:
5 | dependency: transitive
6 | description:
7 | name: async
8 | sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
9 | url: "https://pub.dev"
10 | source: hosted
11 | version: "2.11.0"
12 | boolean_selector:
13 | dependency: transitive
14 | description:
15 | name: boolean_selector
16 | sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
17 | url: "https://pub.dev"
18 | source: hosted
19 | version: "2.1.1"
20 | characters:
21 | dependency: transitive
22 | description:
23 | name: characters
24 | sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
25 | url: "https://pub.dev"
26 | source: hosted
27 | version: "1.3.0"
28 | clock:
29 | dependency: transitive
30 | description:
31 | name: clock
32 | sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
33 | url: "https://pub.dev"
34 | source: hosted
35 | version: "1.1.1"
36 | collection:
37 | dependency: transitive
38 | description:
39 | name: collection
40 | sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
41 | url: "https://pub.dev"
42 | source: hosted
43 | version: "1.18.0"
44 | cupertino_icons:
45 | dependency: "direct main"
46 | description:
47 | name: cupertino_icons
48 | sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
49 | url: "https://pub.dev"
50 | source: hosted
51 | version: "1.0.6"
52 | easy_sticky_header:
53 | dependency: "direct main"
54 | description:
55 | path: ".."
56 | relative: true
57 | source: path
58 | version: "1.1.1"
59 | fake_async:
60 | dependency: transitive
61 | description:
62 | name: fake_async
63 | sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
64 | url: "https://pub.dev"
65 | source: hosted
66 | version: "1.3.1"
67 | flutter:
68 | dependency: "direct main"
69 | description: flutter
70 | source: sdk
71 | version: "0.0.0"
72 | flutter_lints:
73 | dependency: "direct dev"
74 | description:
75 | name: flutter_lints
76 | sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
77 | url: "https://pub.dev"
78 | source: hosted
79 | version: "3.0.1"
80 | flutter_test:
81 | dependency: "direct dev"
82 | description: flutter
83 | source: sdk
84 | version: "0.0.0"
85 | leak_tracker:
86 | dependency: transitive
87 | description:
88 | name: leak_tracker
89 | sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
90 | url: "https://pub.dev"
91 | source: hosted
92 | version: "10.0.0"
93 | leak_tracker_flutter_testing:
94 | dependency: transitive
95 | description:
96 | name: leak_tracker_flutter_testing
97 | sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
98 | url: "https://pub.dev"
99 | source: hosted
100 | version: "2.0.1"
101 | leak_tracker_testing:
102 | dependency: transitive
103 | description:
104 | name: leak_tracker_testing
105 | sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
106 | url: "https://pub.dev"
107 | source: hosted
108 | version: "2.0.1"
109 | lints:
110 | dependency: transitive
111 | description:
112 | name: lints
113 | sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
114 | url: "https://pub.dev"
115 | source: hosted
116 | version: "3.0.0"
117 | matcher:
118 | dependency: transitive
119 | description:
120 | name: matcher
121 | sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
122 | url: "https://pub.dev"
123 | source: hosted
124 | version: "0.12.16+1"
125 | material_color_utilities:
126 | dependency: transitive
127 | description:
128 | name: material_color_utilities
129 | sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
130 | url: "https://pub.dev"
131 | source: hosted
132 | version: "0.8.0"
133 | meta:
134 | dependency: transitive
135 | description:
136 | name: meta
137 | sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
138 | url: "https://pub.dev"
139 | source: hosted
140 | version: "1.11.0"
141 | path:
142 | dependency: transitive
143 | description:
144 | name: path
145 | sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
146 | url: "https://pub.dev"
147 | source: hosted
148 | version: "1.9.0"
149 | sky_engine:
150 | dependency: transitive
151 | description: flutter
152 | source: sdk
153 | version: "0.0.99"
154 | source_span:
155 | dependency: transitive
156 | description:
157 | name: source_span
158 | sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
159 | url: "https://pub.dev"
160 | source: hosted
161 | version: "1.10.0"
162 | stack_trace:
163 | dependency: transitive
164 | description:
165 | name: stack_trace
166 | sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
167 | url: "https://pub.dev"
168 | source: hosted
169 | version: "1.11.1"
170 | stream_channel:
171 | dependency: transitive
172 | description:
173 | name: stream_channel
174 | sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
175 | url: "https://pub.dev"
176 | source: hosted
177 | version: "2.1.2"
178 | string_scanner:
179 | dependency: transitive
180 | description:
181 | name: string_scanner
182 | sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
183 | url: "https://pub.dev"
184 | source: hosted
185 | version: "1.2.0"
186 | term_glyph:
187 | dependency: transitive
188 | description:
189 | name: term_glyph
190 | sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
191 | url: "https://pub.dev"
192 | source: hosted
193 | version: "1.2.1"
194 | test_api:
195 | dependency: transitive
196 | description:
197 | name: test_api
198 | sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
199 | url: "https://pub.dev"
200 | source: hosted
201 | version: "0.6.1"
202 | vector_math:
203 | dependency: transitive
204 | description:
205 | name: vector_math
206 | sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
207 | url: "https://pub.dev"
208 | source: hosted
209 | version: "2.1.4"
210 | vm_service:
211 | dependency: transitive
212 | description:
213 | name: vm_service
214 | sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
215 | url: "https://pub.dev"
216 | source: hosted
217 | version: "13.0.0"
218 | sdks:
219 | dart: ">=3.2.0-0 <4.0.0"
220 | flutter: ">=2.0.0"
221 |
--------------------------------------------------------------------------------
/example/lib/examples/example6.dart:
--------------------------------------------------------------------------------
1 | import 'package:easy_sticky_header/easy_sticky_header.dart';
2 | import 'package:flutter/material.dart';
3 |
4 | import '../test_config.dart';
5 |
6 | class Example6 extends StatefulWidget {
7 | const Example6({Key? key}) : super(key: key);
8 |
9 | @override
10 | State createState() => _Example6State();
11 | }
12 |
13 | class _Example6State extends State
14 | with SingleTickerProviderStateMixin {
15 | final int parentIndex = 2;
16 | final List _groupedIndexList = [3, 6, 15, 26];
17 | late final StickyHeaderController _controller;
18 | late final TabController _tabController;
19 |
20 | @override
21 | void initState() {
22 | super.initState();
23 | _controller = StickyHeaderController();
24 | _tabController = TabController(
25 | length: _groupedIndexList.length,
26 | vsync: this,
27 | );
28 | }
29 |
30 | @override
31 | void dispose() {
32 | _controller.dispose();
33 | _tabController.dispose();
34 | super.dispose();
35 | }
36 |
37 | @override
38 | Widget build(BuildContext context) {
39 | return Scaffold(
40 | backgroundColor: Colors.white,
41 | appBar: AppBar(
42 | shadowColor: Colors.transparent,
43 | backgroundColor: Colors.black,
44 | foregroundColor: Colors.white,
45 | title: const Text('Building header widget by group'),
46 | ),
47 | body: StickyHeader(
48 | controller: _controller,
49 | child: ListView.builder(
50 | reverse: TestConfig.reverse,
51 | physics: const AlwaysScrollableScrollPhysics(
52 | parent: BouncingScrollPhysics(),
53 | ),
54 | itemCount: 50,
55 | itemBuilder: (context, index) {
56 | if (index == parentIndex) {
57 | return _buildParentHeader1(index);
58 | // return _buildParentHeader2(index);
59 | } else if (_groupedIndexList.contains(index)) {
60 | return _buildChildHeader1(index, parentIndex);
61 | // return _buildChildHeader2(index, parentIndex);
62 | }
63 | return _buildItem(index);
64 | },
65 | ),
66 | ),
67 | );
68 | }
69 |
70 | /// Building parent header widget is not limited to using
71 | /// [ParentStickyContainerBuilder], [StickyContainerWidget] or
72 | /// [StickyContainerBuilder] can also be used.
73 | Widget _buildParentHeader1(int index) => ParentStickyContainerBuilder(
74 | index: index,
75 | onUpdate: (childStickyHeaderInfo) {
76 | if (childStickyHeaderInfo != null &&
77 | _groupedIndexList.indexOf(childStickyHeaderInfo.index) !=
78 | _tabController.index) {
79 | _tabController.animateTo(
80 | _groupedIndexList.indexOf(childStickyHeaderInfo.index));
81 | }
82 | // There is no need to rebuild the [TabBar] here, so return false.
83 | return false;
84 | },
85 | builder: (context, childStickyHeaderInfo) {
86 | return Container(
87 | color: Colors.purple,
88 | width: double.infinity,
89 | height: 80,
90 | child: TabBar(
91 | controller: _tabController,
92 | tabs: _groupedIndexList
93 | .map(
94 | (e) => GestureDetector(
95 | onTap: () {
96 | // If this just happens to jump to the header widget of
97 | // the specified index, the header widget doesn't become
98 | // a sticky header at this point, which is why you need
99 | // to set a little offset.
100 | _controller.animateTo(e, offset: 0.5);
101 | },
102 | child: Text(
103 | 'Header #$e',
104 | style: const TextStyle(
105 | color: Colors.white,
106 | fontSize: 16,
107 | ),
108 | ),
109 | ),
110 | )
111 | .toList(),
112 | indicatorPadding: const EdgeInsets.symmetric(horizontal: 10),
113 | indicator: const UnderlineTabIndicator(
114 | borderSide: BorderSide(
115 | color: Colors.white,
116 | width: 2.0,
117 | ),
118 | ),
119 | ),
120 | );
121 | },
122 | );
123 |
124 | Widget _buildParentHeader2(int index) => ParentStickyContainerBuilder(
125 | index: index,
126 | builder: (context, childStickyHeaderInfo) {
127 | return Container(
128 | color: Colors.purple,
129 | width: double.infinity,
130 | height: 80,
131 | child: Row(
132 | mainAxisAlignment: MainAxisAlignment.spaceAround,
133 | children: _groupedIndexList.map(
134 | (e) {
135 | return GestureDetector(
136 | onTap: () {
137 | _controller.animateTo(e, offset: 0.5);
138 | },
139 | child: Column(
140 | children: [
141 | Expanded(
142 | child: Container(
143 | alignment: Alignment.center,
144 | child: Text(
145 | 'Header #$e',
146 | style: const TextStyle(
147 | color: Colors.white,
148 | fontSize: 16,
149 | ),
150 | ),
151 | ),
152 | ),
153 | Container(
154 | width: 60,
155 | padding: const EdgeInsets.symmetric(horizontal: 5),
156 | child: Divider(
157 | height: 2,
158 | thickness: 2,
159 | color: (childStickyHeaderInfo?.index == e)
160 | ? Colors.white
161 | : Colors.transparent,
162 | ),
163 | ),
164 | ],
165 | ),
166 | );
167 | },
168 | ).toList(),
169 | ),
170 | );
171 | },
172 | );
173 |
174 | Widget _buildChildHeader1(int index, int parentIndex) =>
175 | StickyContainerWidget(
176 | index: index,
177 | parentIndex: parentIndex,
178 | // It is recommended to use the default value, which is more in line
179 | // with usage habits.
180 | overlapParent: false,
181 | child: Container(
182 | color: Colors.green,
183 | padding: const EdgeInsets.only(left: 16.0),
184 | alignment: Alignment.centerLeft,
185 | width: double.infinity,
186 | height: 50,
187 | child: Text(
188 | 'Header #$index',
189 | style: const TextStyle(
190 | color: Colors.white,
191 | fontSize: 16,
192 | ),
193 | ),
194 | ),
195 | );
196 |
197 | Widget _buildChildHeader2(int index, int parentIndex) =>
198 | StickyContainerBuilder(
199 | index: index,
200 | parentIndex: parentIndex,
201 | builder: (context, stickyAmount) => Container(
202 | color: Colors.green,
203 | padding: const EdgeInsets.only(left: 16.0),
204 | alignment: Alignment.centerLeft,
205 | width: double.infinity,
206 | height: 50,
207 | child: Text(
208 | 'Header #$index stickyAmount: ${stickyAmount.toStringAsFixed(2)}',
209 | style: const TextStyle(
210 | color: Colors.white,
211 | fontSize: 16,
212 | ),
213 | ),
214 | ),
215 | );
216 |
217 | Widget _buildItem(int index) => Column(
218 | children: [
219 | Container(
220 | width: double.infinity,
221 | height: 80,
222 | color: Colors.white,
223 | padding: const EdgeInsets.only(left: 16),
224 | alignment: Alignment.centerLeft,
225 | child: Text(
226 | 'Item #$index',
227 | style: const TextStyle(
228 | color: Colors.black,
229 | fontSize: 16,
230 | ),
231 | ),
232 | ),
233 | Divider(
234 | height: 1.0,
235 | thickness: 1.0,
236 | color: Colors.grey.shade200,
237 | indent: 16.0,
238 | ),
239 | ],
240 | );
241 | }
242 |
--------------------------------------------------------------------------------
/lib/src/sticky_header_controller.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, crasowas.
2 | //
3 | // Use of this source code is governed by a MIT-style license
4 | // that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | import 'dart:math' show min, max;
8 |
9 | import 'package:flutter/material.dart';
10 |
11 | import 'sticky_header_info.dart';
12 |
13 | /// When the page is scrolled, information such as the position of the sticky
14 | /// header widget will be obtained through this callback.
15 | typedef StickyHeaderInfoCallback = StickyHeaderInfo Function();
16 |
17 | /// Sticky Header Controller.
18 | ///
19 | /// [StickyHeaderController] is the core of the library, its main feature is to
20 | /// monitor the scroll changes and calculate the sticky header. In addition to
21 | /// this, it also supports jumping the header widget of the specified index,
22 | /// see also [animateTo].
23 | class StickyHeaderController extends ChangeNotifier {
24 | ScrollPosition? _scrollPosition;
25 | bool _isJumping = false;
26 | _FindingTargetInfo? _findingTargetInfo;
27 |
28 | /// Cache of sticky headers information.
29 | ///
30 | /// With the help of the existing sticky header information, you can
31 | /// jump to the header widget of the specified index.
32 | final Map _stickyHeaderInfoMap =
33 | {};
34 |
35 | /// Cache of sticky header information callbacks.
36 | final List _stickyHeaderInfoCallbackList =
37 | [];
38 |
39 | /// When the value of the [useStickyAmount] property is set to true, the
40 | /// sticky amount of the header widget will be automatically calculated.
41 | ///
42 | /// This property is automatically set to true if [StickyContainerBuilder] is
43 | /// used.
44 | bool useStickyAmount = false;
45 |
46 | /// Cache of pixel values for the current scroll position
47 | double currentPixels = 0.0;
48 |
49 | /// Current sticky header information.
50 | ///
51 | /// See also:
52 | ///
53 | /// * [StickyHeaderWidget], which uses this build sticky header.
54 | StickyHeaderInfo? currentStickyHeaderInfo;
55 |
56 | /// Current child sticky header information.
57 | ///
58 | /// See also:
59 | ///
60 | /// * [StickyContainerGroupBuilder], which uses this to build parent header
61 | /// widget.
62 | StickyHeaderInfo? currentChildStickyHeaderInfo;
63 |
64 | /// Current sticky header offset.
65 | ///
66 | /// See also:
67 | ///
68 | /// * [StickyHeaderWidget], which uses this to determine the sticky header
69 | /// position.
70 | Offset currentOffset = Offset.zero;
71 |
72 | set scrollPosition(ScrollPosition? newScrollPosition) {
73 | if (newScrollPosition != null && _scrollPosition != newScrollPosition) {
74 | ScrollPosition? oldScrollPosition = _scrollPosition;
75 | _scrollPosition = newScrollPosition;
76 | oldScrollPosition?.removeListener(scrollListener);
77 | newScrollPosition.addListener(scrollListener);
78 | }
79 | }
80 |
81 | ScrollPosition? get scrollPosition => _scrollPosition;
82 |
83 | set isJumping(bool newValue) {
84 | _isJumping = newValue;
85 | if (!newValue) {
86 | _findingTargetInfo = null;
87 | }
88 | }
89 |
90 | bool get isJumping => _isJumping;
91 |
92 | bool get isReverse =>
93 | _scrollPosition?.axisDirection == AxisDirection.up ||
94 | _scrollPosition?.axisDirection == AxisDirection.left;
95 |
96 | bool get isHorizontalAxis => _scrollPosition?.axis == Axis.horizontal;
97 |
98 | double get getViewportDimension => _scrollPosition?.viewportDimension ?? 0.0;
99 |
100 | double get getMaxScrollExtent => _scrollPosition?.maxScrollExtent ?? 0.0;
101 |
102 | double get getMinScrollExtent => _scrollPosition?.minScrollExtent ?? 0.0;
103 |
104 | @override
105 | void dispose() {
106 | _scrollPosition?.removeListener(scrollListener);
107 | super.dispose();
108 | }
109 |
110 | /// Monitors scroll changes and control the position and visibility of
111 | /// the sticky header widget based on the scroll position.
112 | void scrollListener() {
113 | currentPixels = _scrollPosition?.pixels ?? 0.0;
114 | for (var callback in _stickyHeaderInfoCallbackList) {
115 | var stickyHeaderInfo = callback();
116 | _stickyHeaderInfoMap[stickyHeaderInfo.index] = stickyHeaderInfo;
117 | }
118 | var stickyHeaderInfoList = _stickyHeaderInfoMap.values.toList();
119 | // Sort by index.
120 | stickyHeaderInfoList.sort((a, b) => a.index.compareTo(b.index));
121 | // Clear cache.
122 | currentStickyHeaderInfo = null;
123 | currentChildStickyHeaderInfo = null;
124 | currentOffset = Offset.zero;
125 | // Find current sticky header and calculate offset.
126 | if (stickyHeaderInfoList.isNotEmpty &&
127 | _isNeedsStickyHeader(stickyHeaderInfoList)) {
128 | for (var i = 0; i < stickyHeaderInfoList.length; i++) {
129 | var stickyHeaderInfo = stickyHeaderInfoList[i];
130 | if (_isValidStickyHeader(stickyHeaderInfo)) {
131 | var parentIndex = stickyHeaderInfo.parentIndex;
132 | if (i == stickyHeaderInfoList.length - 1) {
133 | if (parentIndex != null) {
134 | currentStickyHeaderInfo = _stickyHeaderInfoMap[parentIndex];
135 | currentChildStickyHeaderInfo = stickyHeaderInfo;
136 | } else {
137 | currentStickyHeaderInfo = stickyHeaderInfo;
138 | }
139 | break;
140 | } else {
141 | var nextStickyHeaderInfo = stickyHeaderInfoList[i + 1];
142 | if (!_isValidStickyHeader(nextStickyHeaderInfo)) {
143 | if (parentIndex != null) {
144 | currentStickyHeaderInfo = _stickyHeaderInfoMap[parentIndex];
145 | currentChildStickyHeaderInfo = stickyHeaderInfo;
146 | if (stickyHeaderInfo.parentIndex !=
147 | nextStickyHeaderInfo.parentIndex) {
148 | currentOffset =
149 | _calculateOffset(stickyHeaderInfo, nextStickyHeaderInfo);
150 | }
151 | } else {
152 | currentStickyHeaderInfo = stickyHeaderInfo;
153 | if (stickyHeaderInfo.index !=
154 | nextStickyHeaderInfo.parentIndex) {
155 | currentOffset =
156 | _calculateOffset(stickyHeaderInfo, nextStickyHeaderInfo);
157 | }
158 | }
159 | break;
160 | }
161 | }
162 | }
163 | }
164 | }
165 | _handleReverse();
166 | if (useStickyAmount) {
167 | _calculateStickyAmount(stickyHeaderInfoList);
168 | }
169 | _findHeaderWidget();
170 | // Update sticky header.
171 | notifyListeners();
172 | }
173 |
174 | /// In some cases sticky header is not required,
175 | /// e.g. scroll events triggered by [BouncingScrollPhysics].
176 | bool _isNeedsStickyHeader(List stickyHeaderInfoList) =>
177 | getComponent(stickyHeaderInfoList.first.offset) < 0;
178 |
179 | /// Returns true if the header widget is partially or completely invisible
180 | /// on the screen, false otherwise.
181 | ///
182 | /// For grouped header widgets, additional processing is required if the child
183 | /// header widget and parent header widget do not overlap.
184 | bool _isValidStickyHeader(StickyHeaderInfo stickyHeaderInfo) {
185 | var value = 0.0;
186 | var parentIndex = stickyHeaderInfo.parentIndex;
187 | if (parentIndex != null && !stickyHeaderInfo.overlapParent) {
188 | value = getDimension(getStickyHeaderInfo(parentIndex)?.size);
189 | }
190 | return getComponent(stickyHeaderInfo.offset) < value;
191 | }
192 |
193 | /// Calculates the offset at which the header widget should stuck to
194 | /// the starting position.
195 | Offset _calculateOffset(StickyHeaderInfo stickyHeaderInfo,
196 | StickyHeaderInfo nextStickyHeaderInfo) {
197 | var d = 0.0;
198 | // ±0.2: Which to reduce fluctuations and optimize the scrolling experience.
199 | if (isReverse) {
200 | d = getViewportDimension - getComponent(nextStickyHeaderInfo.offset);
201 | d = d - 0.2;
202 | d = max(getViewportDimension - getDimension(stickyHeaderInfo.size), d);
203 | } else {
204 | d = getComponent(nextStickyHeaderInfo.offset) -
205 | getDimension(stickyHeaderInfo.size);
206 | d = d + 0.2;
207 | d = min(0.0, d);
208 | }
209 | return isHorizontalAxis ? Offset(d, 0.0) : Offset(0.0, d);
210 | }
211 |
212 | /// When the scroll direction is reversed, the default offset cannot be zero,
213 | /// and additional processing is required.
214 | void _handleReverse() {
215 | if (isReverse &&
216 | currentStickyHeaderInfo != null &&
217 | currentOffset == Offset.zero) {
218 | var d =
219 | getViewportDimension - getDimension(currentStickyHeaderInfo?.size);
220 | currentOffset = isHorizontalAxis ? Offset(d, 0.0) : Offset(0.0, d);
221 | }
222 | }
223 |
224 | /// The `stickyAmount` is used to create header widget with varying styles.
225 | void _calculateStickyAmount(List stickyHeaderInfoList) {
226 | int? nextStickyHeaderIndex;
227 | for (var i = 0; i < stickyHeaderInfoList.length; i++) {
228 | var stickyHeaderInfo = stickyHeaderInfoList[i];
229 | var stickyAmount = 0.0;
230 | if (!_isValidStickyHeader(stickyHeaderInfo)) {
231 | var value = 0.0;
232 | if (stickyHeaderInfo.parentIndex != null &&
233 | !stickyHeaderInfo.overlapParent) {
234 | value = getDimension(currentStickyHeaderInfo?.size);
235 | }
236 | stickyAmount = (getComponent(stickyHeaderInfo.offset) - value) /
237 | getDimension(stickyHeaderInfo.size);
238 | stickyAmount = (1.0 - stickyAmount).clamp(0.0, 1.0);
239 | } else if ((currentChildStickyHeaderInfo == null &&
240 | stickyHeaderInfo == currentStickyHeaderInfo) ||
241 | stickyHeaderInfo == currentChildStickyHeaderInfo) {
242 | nextStickyHeaderIndex =
243 | i < stickyHeaderInfoList.length - 1 ? i + 1 : null;
244 | stickyAmount = 1.0;
245 | }
246 | stickyHeaderInfo.stickyAmount = stickyAmount;
247 | }
248 | if (nextStickyHeaderIndex != null) {
249 | var stickyAmount =
250 | stickyHeaderInfoList[nextStickyHeaderIndex].stickyAmount;
251 | if (currentChildStickyHeaderInfo != null) {
252 | currentChildStickyHeaderInfo?.stickyAmount -= stickyAmount;
253 | } else {
254 | currentStickyHeaderInfo?.stickyAmount -= stickyAmount;
255 | }
256 | }
257 | }
258 |
259 | /// Gets the horizontal or vertical component based on the scroll view's
260 | /// scroll axis.
261 | double getComponent(Offset offset) =>
262 | _scrollPosition?.axis == Axis.horizontal ? offset.dx : offset.dy;
263 |
264 | /// Gets the width or height based on scroll view's scroll axis.
265 | double getDimension(Size? size) {
266 | size ??= Size.zero;
267 | return _scrollPosition?.axis == Axis.horizontal ? size.width : size.height;
268 | }
269 |
270 | /// When the header widget is attached to the widget tree, which will execute
271 | /// this method to add its own callback to the list. When the page is
272 | /// scrolled, a callback will be executed to get [StickyHeaderInfo] to
273 | /// determine the position of [StickyHeaderWidget].
274 | ///
275 | /// See also:
276 | ///
277 | /// * [RenderStickyContainer], which automatically adds and removes callback
278 | /// based on lifecycle.
279 | void addCallback(StickyHeaderInfoCallback callback) {
280 | _stickyHeaderInfoCallbackList.add(callback);
281 | }
282 |
283 | /// When the header widget is detached from the widget tree, which will
284 | /// execute this method to remove its own callback to the list.
285 | void removeCallback(StickyHeaderInfoCallback callback) {
286 | _stickyHeaderInfoCallbackList.remove(callback);
287 | }
288 |
289 | /// Gets sticky header information from cache.
290 | StickyHeaderInfo? getStickyHeaderInfo(int index) =>
291 | _stickyHeaderInfoMap[index];
292 |
293 | /// Clears the cache, please call when needed.
294 | void clearStickyHeaderInfo() => _stickyHeaderInfoMap.clear();
295 |
296 | /// Jumps to the header widget of the specified index. Compared with [jumpTo],
297 | /// a transition animation is added and it supports jumping to the header
298 | /// widget that has not yet appeared.
299 | ///
300 | /// The find operation will be performed when the header widget of the
301 | /// specified index has not yet appeared.
302 | ///
303 | /// The `velocity` parameter indicates how many pixels to scroll per
304 | /// millisecond and is used to calculate the default animation duration.
305 | /// This parameter has no effect if a duration is specified. The value of
306 | /// `velocity` must be greater than 0.0, else equal to 1.0.
307 | ///
308 | /// For a better user experience, it is recommended to set finding animation
309 | /// curves in pairs. For example [Curves.easeIn] and [Curves.easeOut] are a
310 | /// pair of animation curves that can be combined into a coherent animation
311 | /// curve.
312 | void animateTo(
313 | int index, {
314 | double offset = 0.0,
315 | double velocity = 1.0,
316 | Duration? duration,
317 | Curve? curve,
318 | Duration? findingStartDuration,
319 | Curve? findingStartCurve,
320 | Duration? findingEndDuration,
321 | Curve? findingEndCurve,
322 | }) {
323 | var stickyHeaderInfo = getStickyHeaderInfo(index);
324 | if (stickyHeaderInfo != null) {
325 | var pixels = min(getMaxScrollExtent, _calculatePixels(stickyHeaderInfo, offset));
326 | if (currentPixels != pixels) {
327 | isJumping = true;
328 | _scrollPosition?.animateTo(
329 | pixels,
330 | duration: duration ?? _getDefaultDuration(pixels, velocity),
331 | curve: curve ?? Curves.ease,
332 | );
333 | }
334 | } else {
335 | _findingTargetInfo = _FindingTargetInfo(
336 | index: index,
337 | offset: offset,
338 | velocity: velocity,
339 | duration: findingEndDuration,
340 | curve: findingEndCurve ?? Curves.easeOut,
341 | );
342 | var isForward = true;
343 | // Note that if [_stickyHeaderInfoMap] is empty, the current scrolling
344 | // widget is considered to be at the starting position. When the [reverse]
345 | // property of [StickyHeader] is updated, the [_stickyHeaderInfoMap] will
346 | // be cleared, which may cause the jump to fail.
347 | if (_stickyHeaderInfoMap.isNotEmpty) {
348 | var stickyHeaderInfoList = _stickyHeaderInfoMap.values.toList();
349 | stickyHeaderInfoList.sort((a, b) => a.index.compareTo(b.index));
350 | if (stickyHeaderInfoList.first.index > index) {
351 | isForward = false;
352 | }
353 | }
354 | var pixels = isForward ? getMaxScrollExtent : getMinScrollExtent;
355 | if (currentPixels != pixels) {
356 | isJumping = true;
357 | _scrollPosition?.animateTo(
358 | pixels,
359 | duration:
360 | findingStartDuration ?? _getDefaultDuration(pixels, velocity),
361 | curve: findingStartCurve ?? Curves.easeIn,
362 | );
363 | }
364 | }
365 | }
366 |
367 | /// Duration is calculated based on the number of pixels to scroll and
368 | /// the scroll velocity.
369 | Duration _getDefaultDuration(double pixels, double velocity) {
370 | if (velocity <= 0.0) {
371 | velocity = 1.0;
372 | }
373 | return Duration(
374 | milliseconds: ((pixels - currentPixels).abs() / velocity).floor(),
375 | );
376 | }
377 |
378 | /// Finds header widget.
379 | void _findHeaderWidget() {
380 | var target = _findingTargetInfo;
381 | if (target != null && getStickyHeaderInfo(target.index) != null) {
382 | animateTo(
383 | target.index,
384 | offset: target.offset,
385 | duration: target.duration,
386 | curve: target.curve,
387 | );
388 | _findingTargetInfo = null;
389 | }
390 | }
391 |
392 | /// Jumps to the header widget of the specified index.
393 | ///
394 | /// Note that this jump operation is based on the [_stickyHeaderInfoMap]
395 | /// cache. If the header widget information of the specified index is not
396 | /// in the cache, no operation will be performed and false will be returned.
397 | ///
398 | /// It is recommended to use [animateTo].
399 | bool jumpTo(
400 | int index, {
401 | double offset = 0.0,
402 | }) {
403 | var stickyHeaderInfo = getStickyHeaderInfo(index);
404 | if (stickyHeaderInfo != null) {
405 | var pixels = _calculatePixels(stickyHeaderInfo, offset);
406 | if (currentPixels != pixels) {
407 | _scrollPosition?.jumpTo(pixels);
408 | WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
409 | scrollListener();
410 | });
411 | }
412 | return true;
413 | }
414 | return false;
415 | }
416 |
417 | /// Calculates the scroll position.
418 | double _calculatePixels(StickyHeaderInfo stickyHeaderInfo, double offset) {
419 | var pixels = stickyHeaderInfo.pixels + offset;
420 | var parentIndex = stickyHeaderInfo.parentIndex;
421 | if (parentIndex != null && !stickyHeaderInfo.overlapParent) {
422 | pixels -= getDimension(getStickyHeaderInfo(parentIndex)?.size);
423 | }
424 | return pixels;
425 | }
426 | }
427 |
428 | /// Finding Target Info.
429 | class _FindingTargetInfo {
430 | int index;
431 | double offset;
432 | double velocity;
433 | Duration? duration;
434 | Curve? curve;
435 |
436 | _FindingTargetInfo({
437 | required this.index,
438 | required this.offset,
439 | required this.velocity,
440 | this.duration,
441 | this.curve,
442 | });
443 | }
444 |
--------------------------------------------------------------------------------
/lib/src/sticky_container_widget.dart:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2022, crasowas.
2 | //
3 | // Use of this source code is governed by a MIT-style license
4 | // that can be found in the LICENSE file or at
5 | // https://opensource.org/licenses/MIT.
6 |
7 | import 'package:flutter/foundation.dart';
8 | import 'package:flutter/material.dart';
9 |
10 | import 'render_sticky_container.dart';
11 | import 'sticky_header.dart';
12 | import 'sticky_header_controller.dart';
13 | import 'sticky_header_info.dart';
14 |
15 | /// Building header widget by sticky amount.
16 | ///
17 | /// The value of `stickyAmount` is in the range 0.0 to 1.0.
18 | ///
19 | /// When the value of `stickyAmount` grows from 0.0 to 1.0, the header widget
20 | /// is about to become a sticky header. When the value of `stickyAmount` value
21 | /// is reduced from 1.0 to 0.0, the header widget is about to stop being a
22 | /// sticky header. In other cases, the value of `stickyAmount` is 0.0.
23 | typedef HeaderWidgetBuilder = Widget Function(
24 | BuildContext context, double stickyAmount);
25 |
26 | /// Building scrollable header widget.
27 | ///
28 | /// The header widget and the sticky header synchronize the scroll position
29 | /// through [ScrollController].
30 | typedef ScrollableHeaderWidgetBuilder = Widget Function(
31 | BuildContext context, ScrollController scrollController);
32 |
33 | /// Parent header update callback.
34 | ///
35 | /// Uses this callback when the content of the parent header widget changes. If
36 | /// the callback result is true, call [ParentHeaderWidgetBuilder] to rebuild the
37 | /// parent header widget.
38 | ///
39 | /// This callback is used to reduce unnecessary rebuilds of the parent header
40 | /// widget and optimize performance.
41 | typedef ParentHeaderUpdateCallback = bool Function(
42 | StickyHeaderInfo? childStickyHeaderInfo);
43 |
44 | /// Building header widget by group.
45 | ///
46 | /// The widget created by this builder is the parent header widget, which is
47 | /// used to provide content for the sticky header.
48 | typedef ParentHeaderWidgetBuilder = Widget Function(
49 | BuildContext context, StickyHeaderInfo? childStickyHeaderInfo);
50 |
51 | /// Sticky Container widget.
52 | ///
53 | /// Wraps a header widget with this widget to make the sticky effect take effect.
54 | class StickyContainerWidget extends SingleChildRenderObjectWidget {
55 | /// The index of the header widget, which requires a unique index and is
56 | /// sorted from small to large, can be discontinuous.
57 | ///
58 | /// It is recommended to use the index provided by the scroll widget.
59 | final int index;
60 |
61 | /// If [visible] is false, the header widget will not be visible
62 | /// when it is the current sticky header widget.
63 | ///
64 | /// The use of this property is that non-sticky header widgets
65 | /// can be inserted between header widgets.
66 | final bool visible;
67 |
68 | /// The exact pixels of the header widget.
69 | ///
70 | /// In the presence of exact pixels, setting this property can
71 | /// optimize performance.
72 | final double? pixels;
73 |
74 | /// In some special usage scenarios, the offset obtained through
75 | /// [getOffsetToReveal] has errors. If this property is set to false,
76 | /// the offset will be obtained in real time without caching.
77 | ///
78 | /// Note that if it is not necessary, please use the default value of true,
79 | /// otherwise the frame rate will be reduced. Also, if [pixels] is not null,
80 | /// this property has no effect.
81 | final bool performancePriority;
82 |
83 | /// If the [parentIndex] property is not null, the current header widget will
84 | /// be bound to the parent header widget, and the content of the sticky header
85 | /// will be provided by the bound parent header widget.
86 | ///
87 | /// Note that the value of [parentIndex] must be less than the value of
88 | /// [index], otherwise it is invalid.
89 | final int? parentIndex;
90 |
91 | /// The [overlapParent] property is used to determine how the sticky
92 | /// header is calculated when the header widgets are grouped.
93 | ///
94 | /// The default value of this property is false, which may be more in line
95 | /// with usage habits.
96 | final bool overlapParent;
97 |
98 | const StickyContainerWidget({
99 | Key? key,
100 | required this.index,
101 | this.visible = true,
102 | this.pixels,
103 | this.performancePriority = true,
104 | this.parentIndex,
105 | this.overlapParent = false,
106 | required Widget child,
107 | }) : super(key: key, child: child);
108 |
109 | @override
110 | RenderStickyContainer createRenderObject(BuildContext context) {
111 | return RenderStickyContainer(
112 | controller: _getController(context),
113 | index: index,
114 | visible: visible,
115 | pixels: pixels,
116 | performancePriority: performancePriority,
117 | parentIndex: parentIndex,
118 | overlapParent: overlapParent,
119 | widget: child ?? Container(),
120 | );
121 | }
122 |
123 | @override
124 | void updateRenderObject(
125 | BuildContext context, RenderStickyContainer renderObject) {
126 | renderObject
127 | ..controller = _getController(context)
128 | ..index = index
129 | ..visible = visible
130 | ..pixels = pixels
131 | ..performancePriority = performancePriority
132 | ..parentIndex = parentIndex
133 | ..overlapParent = overlapParent
134 | ..widget = child ?? Container();
135 | }
136 |
137 | @override
138 | void debugFillProperties(DiagnosticPropertiesBuilder properties) {
139 | super.debugFillProperties(properties);
140 | properties.add(DiagnosticsProperty('index', index, defaultValue: 0));
141 | properties
142 | .add(DiagnosticsProperty('visible', visible, defaultValue: true));
143 | properties
144 | .add(DiagnosticsProperty('pixels', pixels, defaultValue: null));
145 | properties.add(DiagnosticsProperty(
146 | 'performancePriority', performancePriority,
147 | defaultValue: true));
148 | properties.add(DiagnosticsProperty('parentIndex', parentIndex,
149 | defaultValue: null));
150 | properties.add(DiagnosticsProperty('overlapParent', overlapParent,
151 | defaultValue: false));
152 | }
153 |
154 | StickyHeaderController? _getController(BuildContext context) {
155 | var controller = StickyHeader.of(context);
156 | assert(
157 | controller != null,
158 | 'Sticky header controller instance must not be null, '
159 | 'confirm whether to use [StickyHeader] to wrap the widget.');
160 | var scrollPosition = Scrollable.of(context).position;
161 | if (controller?.scrollPosition != scrollPosition) {
162 | controller?.scrollPosition = scrollPosition;
163 | WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
164 | controller?.scrollListener();
165 | });
166 | }
167 | return controller;
168 | }
169 | }
170 |
171 | /// Sticky Container Builder.
172 | ///
173 | /// An extension of [StickyContainerWidget] that supports dynamically building
174 | /// header widget by sticky amount.
175 | ///
176 | /// If you find problems in use, please first confirm whether the
177 | /// [addAutomaticKeepAlives] property of the scroll widget has been set to true.
178 | class StickyContainerBuilder extends StatefulWidget {
179 | /// Mirror to [StickyContainerWidget.index]
180 | final int index;
181 |
182 | /// Mirror to [StickyContainerWidget.visible]
183 | final bool visible;
184 |
185 | /// Mirror to [StickyContainerWidget.pixels]
186 | final double? pixels;
187 |
188 | /// Mirror to [StickyContainerWidget.performancePriority]
189 | final bool performancePriority;
190 |
191 | /// Mirror to [StickyContainerWidget.parentIndex]
192 | final int? parentIndex;
193 |
194 | /// Mirror to [StickyContainerWidget.overlapParent]
195 | final bool overlapParent;
196 |
197 | /// The builder that creates a child to display in this widget, which will use
198 | /// the provided `stickyAmount` to build the header widget.
199 | final HeaderWidgetBuilder builder;
200 |
201 | const StickyContainerBuilder({
202 | Key? key,
203 | required this.index,
204 | this.visible = true,
205 | this.pixels,
206 | this.performancePriority = true,
207 | this.parentIndex,
208 | this.overlapParent = false,
209 | required this.builder,
210 | }) : super(key: key);
211 |
212 | @override
213 | State createState() => _StickyContainerBuilderState();
214 | }
215 |
216 | class _StickyContainerBuilderState extends State
217 | with AutomaticKeepAliveClientMixin {
218 | StickyHeaderController? _controller;
219 | double _stickyAmount = 0.0;
220 |
221 | @override
222 | void dispose() {
223 | _controller?.removeListener(_update);
224 | super.dispose();
225 | }
226 |
227 | @override
228 | Widget build(BuildContext context) {
229 | super.build(context);
230 | var controller = StickyHeader.of(context);
231 | if (controller != null && _controller != controller) {
232 | controller.useStickyAmount = true;
233 | _controller?.removeListener(_update);
234 | _controller = controller;
235 | _controller?.addListener(_update);
236 | }
237 | return StickyContainerWidget(
238 | index: widget.index,
239 | visible: widget.visible,
240 | pixels: widget.pixels,
241 | performancePriority: widget.performancePriority,
242 | parentIndex: widget.parentIndex,
243 | overlapParent: widget.overlapParent,
244 | child: widget.builder(context, _stickyAmount),
245 | );
246 | }
247 |
248 | /// If there is too much spacing between the header widgets, the header widget
249 | /// may be disposed prematurely, making it impossible to rebuild the header
250 | /// widget with `stickyAmount`, so keep it active to avoid problems.
251 | @override
252 | bool get wantKeepAlive => true;
253 |
254 | void _update() {
255 | var stickyAmount =
256 | _controller?.getStickyHeaderInfo(widget.index)?.stickyAmount ?? 0.0;
257 | if (stickyAmount != _stickyAmount) {
258 | _stickyAmount = stickyAmount;
259 | setState(() {});
260 | }
261 | }
262 | }
263 |
264 | /// Sticky Container Scrollable Builder.
265 | ///
266 | /// An extension of [StickyContainerWidget] that supports building scrollable
267 | /// header widget.
268 | ///
269 | /// If you find problems in use, please first confirm whether the
270 | /// [addAutomaticKeepAlives] property of the scroll widget has been set to true.
271 | class ScrollableStickyContainerBuilder extends StatefulWidget {
272 | /// Mirror to [StickyContainerWidget.index]
273 | final int index;
274 |
275 | /// Mirror to [StickyContainerWidget.visible]
276 | final bool visible;
277 |
278 | /// Mirror to [StickyContainerWidget.pixels]
279 | final double? pixels;
280 |
281 | /// Mirror to [StickyContainerWidget.performancePriority]
282 | final bool performancePriority;
283 |
284 | /// Mirror to [StickyContainerWidget.parentIndex]
285 | final int? parentIndex;
286 |
287 | /// Mirror to [StickyContainerWidget.overlapParent]
288 | final bool overlapParent;
289 |
290 | /// See also [ScrollController.initialScrollOffset].
291 | final double initialScrollOffset;
292 |
293 | /// See also [ScrollController.keepScrollOffset].
294 | final bool keepScrollOffset;
295 |
296 | /// See also [ScrollController.debugLabel].
297 | final String? debugLabel;
298 |
299 | /// See also [ScrollController.onAttach].
300 | final ScrollControllerCallback? onAttach;
301 |
302 | /// See also [ScrollController.onDetach].
303 | final ScrollControllerCallback? onDetach;
304 |
305 | /// The builder that creates a child to display in this widget, which will use
306 | /// the provided [ScrollController] to build the header widget.
307 | final ScrollableHeaderWidgetBuilder builder;
308 |
309 | const ScrollableStickyContainerBuilder({
310 | Key? key,
311 | required this.index,
312 | this.visible = true,
313 | this.pixels,
314 | this.performancePriority = true,
315 | this.parentIndex,
316 | this.overlapParent = false,
317 | this.initialScrollOffset = 0.0,
318 | this.keepScrollOffset = true,
319 | this.debugLabel,
320 | this.onAttach,
321 | this.onDetach,
322 | required this.builder,
323 | }) : super(key: key);
324 |
325 | @override
326 | State createState() =>
327 | _ScrollableStickyContainerBuilderState();
328 | }
329 |
330 | class _ScrollableStickyContainerBuilderState
331 | extends State
332 | with AutomaticKeepAliveClientMixin {
333 | bool _isSticking = false;
334 | late ScrollController _scrollController;
335 |
336 | Iterable get _positions => _scrollController.positions;
337 |
338 | @override
339 | void initState() {
340 | super.initState();
341 | _scrollController = ScrollController(
342 | initialScrollOffset: widget.initialScrollOffset,
343 | keepScrollOffset: widget.keepScrollOffset,
344 | debugLabel: widget.debugLabel,
345 | onAttach: (position) {
346 | assert(_positions.length <= 2,
347 | 'ScrollController attached to multiple scroll views.');
348 | _isSticking = _positions.length == 2;
349 | if (_isSticking) {
350 | position.correctPixels(_positions.first.pixels);
351 | }
352 | widget.onAttach?.call(position);
353 | },
354 | onDetach: (position) {
355 | if (_isSticking) {
356 | _positions.first.jumpTo(position.pixels);
357 | }
358 | _isSticking = false;
359 | widget.onDetach?.call(position);
360 | },
361 | );
362 | }
363 |
364 | @override
365 | void dispose() {
366 | _scrollController.dispose();
367 | super.dispose();
368 | }
369 |
370 | @override
371 | Widget build(BuildContext context) {
372 | super.build(context);
373 | return StickyContainerWidget(
374 | index: widget.index,
375 | visible: widget.visible,
376 | pixels: widget.pixels,
377 | performancePriority: widget.performancePriority,
378 | parentIndex: widget.parentIndex,
379 | overlapParent: widget.overlapParent,
380 | child: widget.builder(context, _scrollController),
381 | );
382 | }
383 |
384 | /// If there is too much spacing between the header widgets, the header widget
385 | /// may be disposed prematurely, resulting in failure to synchronize the scroll
386 | /// position, so keep it active to avoid problems.
387 | @override
388 | bool get wantKeepAlive => true;
389 | }
390 |
391 | /// Sticky Container Parent Builder.
392 | ///
393 | /// An extension of [StickyContainerWidget] for building parent header widget.
394 | ///
395 | /// [ParentStickyContainerBuilder] is not necessary to build the parent header
396 | /// widget, [StickyContainerWidget] or [StickyContainerBuilder] are equally
397 | /// fine. It's just that [ParentStickyContainerBuilder] can build a sticky
398 | /// header based on the changes of the child header widgets.
399 | ///
400 | /// If you find problems in use, please first confirm whether the
401 | /// [addAutomaticKeepAlives] property of the scroll widget has been set to true.
402 | class ParentStickyContainerBuilder extends StatefulWidget {
403 | /// Mirror to [StickyContainerWidget.index]
404 | final int index;
405 |
406 | /// Mirror to [StickyContainerWidget.visible]
407 | final bool visible;
408 |
409 | /// Mirror to [StickyContainerWidget.pixels]
410 | final double? pixels;
411 |
412 | /// Mirror to [StickyContainerWidget.performancePriority]
413 | final bool performancePriority;
414 |
415 | /// The callback should return false if the parent header widget does not
416 | /// need to be rebuild.
417 | final ParentHeaderUpdateCallback? onUpdate;
418 |
419 | /// The builder that creates a child to display in this widget, which will use
420 | /// the provided [StickyHeaderInfo] to build the parent header widget.
421 | final ParentHeaderWidgetBuilder builder;
422 |
423 | const ParentStickyContainerBuilder({
424 | Key? key,
425 | required this.index,
426 | this.visible = true,
427 | this.pixels,
428 | this.performancePriority = true,
429 | this.onUpdate,
430 | required this.builder,
431 | }) : super(key: key);
432 |
433 | @override
434 | State createState() =>
435 | _ParentStickyContainerBuilderState();
436 | }
437 |
438 | class _ParentStickyContainerBuilderState
439 | extends State
440 | with AutomaticKeepAliveClientMixin {
441 | StickyHeaderController? _controller;
442 | StickyHeaderInfo? _childStickyHeaderInfo;
443 | double _stickyAmount = 0.0;
444 |
445 | @override
446 | void dispose() {
447 | _controller?.removeListener(_update);
448 | super.dispose();
449 | }
450 |
451 | @override
452 | Widget build(BuildContext context) {
453 | super.build(context);
454 | var controller = StickyHeader.of(context);
455 | if (controller != null && _controller != controller) {
456 | _controller?.removeListener(_update);
457 | _controller = controller;
458 | _controller?.addListener(_update);
459 | }
460 | return StickyContainerWidget(
461 | index: widget.index,
462 | visible: widget.visible,
463 | pixels: widget.pixels,
464 | performancePriority: widget.performancePriority,
465 | child: widget.builder(context, _childStickyHeaderInfo),
466 | );
467 | }
468 |
469 | /// If there is too much spacing between the parent header widget and the
470 | /// associated child header widget, the parent header widget may be disposed
471 | /// prematurely, so keep it alive to avoid problems.
472 | @override
473 | bool get wantKeepAlive => true;
474 |
475 | void _update() {
476 | var childStickyHeaderInfo = _controller?.currentChildStickyHeaderInfo;
477 | var needsUpdate = false;
478 | if (childStickyHeaderInfo == null) {
479 | if (_childStickyHeaderInfo != null) {
480 | _childStickyHeaderInfo = null;
481 | _stickyAmount = 0.0;
482 | needsUpdate = true;
483 | }
484 | } else {
485 | if (childStickyHeaderInfo.parentIndex == widget.index &&
486 | (childStickyHeaderInfo.index != _childStickyHeaderInfo?.index ||
487 | childStickyHeaderInfo.stickyAmount != _stickyAmount)) {
488 | _childStickyHeaderInfo = childStickyHeaderInfo;
489 | _stickyAmount = childStickyHeaderInfo.stickyAmount;
490 | needsUpdate = true;
491 | }
492 | }
493 | if (needsUpdate &&
494 | (widget.onUpdate?.call(_childStickyHeaderInfo) ?? true)) {
495 | setState(() {});
496 | }
497 | }
498 | }
499 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 54;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
11 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
12 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
13 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
14 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
15 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
16 | /* End PBXBuildFile section */
17 |
18 | /* Begin PBXCopyFilesBuildPhase section */
19 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = {
20 | isa = PBXCopyFilesBuildPhase;
21 | buildActionMask = 2147483647;
22 | dstPath = "";
23 | dstSubfolderSpec = 10;
24 | files = (
25 | );
26 | name = "Embed Frameworks";
27 | runOnlyForDeploymentPostprocessing = 0;
28 | };
29 | /* End PBXCopyFilesBuildPhase section */
30 |
31 | /* Begin PBXFileReference section */
32 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; };
33 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; };
34 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; };
35 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; };
36 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
37 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; };
38 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; };
39 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; };
40 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
41 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
42 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
43 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
44 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
45 | /* End PBXFileReference section */
46 |
47 | /* Begin PBXFrameworksBuildPhase section */
48 | 97C146EB1CF9000F007C117D /* Frameworks */ = {
49 | isa = PBXFrameworksBuildPhase;
50 | buildActionMask = 2147483647;
51 | files = (
52 | );
53 | runOnlyForDeploymentPostprocessing = 0;
54 | };
55 | /* End PBXFrameworksBuildPhase section */
56 |
57 | /* Begin PBXGroup section */
58 | 9740EEB11CF90186004384FC /* Flutter */ = {
59 | isa = PBXGroup;
60 | children = (
61 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
62 | 9740EEB21CF90195004384FC /* Debug.xcconfig */,
63 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
64 | 9740EEB31CF90195004384FC /* Generated.xcconfig */,
65 | );
66 | name = Flutter;
67 | sourceTree = "";
68 | };
69 | 97C146E51CF9000F007C117D = {
70 | isa = PBXGroup;
71 | children = (
72 | 9740EEB11CF90186004384FC /* Flutter */,
73 | 97C146F01CF9000F007C117D /* Runner */,
74 | 97C146EF1CF9000F007C117D /* Products */,
75 | );
76 | sourceTree = "";
77 | };
78 | 97C146EF1CF9000F007C117D /* Products */ = {
79 | isa = PBXGroup;
80 | children = (
81 | 97C146EE1CF9000F007C117D /* Runner.app */,
82 | );
83 | name = Products;
84 | sourceTree = "";
85 | };
86 | 97C146F01CF9000F007C117D /* Runner */ = {
87 | isa = PBXGroup;
88 | children = (
89 | 97C146FA1CF9000F007C117D /* Main.storyboard */,
90 | 97C146FD1CF9000F007C117D /* Assets.xcassets */,
91 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */,
92 | 97C147021CF9000F007C117D /* Info.plist */,
93 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */,
94 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
95 | 74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
96 | 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
97 | );
98 | path = Runner;
99 | sourceTree = "";
100 | };
101 | /* End PBXGroup section */
102 |
103 | /* Begin PBXNativeTarget section */
104 | 97C146ED1CF9000F007C117D /* Runner */ = {
105 | isa = PBXNativeTarget;
106 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
107 | buildPhases = (
108 | 9740EEB61CF901F6004384FC /* Run Script */,
109 | 97C146EA1CF9000F007C117D /* Sources */,
110 | 97C146EB1CF9000F007C117D /* Frameworks */,
111 | 97C146EC1CF9000F007C117D /* Resources */,
112 | 9705A1C41CF9048500538489 /* Embed Frameworks */,
113 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */,
114 | );
115 | buildRules = (
116 | );
117 | dependencies = (
118 | );
119 | name = Runner;
120 | productName = Runner;
121 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */;
122 | productType = "com.apple.product-type.application";
123 | };
124 | /* End PBXNativeTarget section */
125 |
126 | /* Begin PBXProject section */
127 | 97C146E61CF9000F007C117D /* Project object */ = {
128 | isa = PBXProject;
129 | attributes = {
130 | LastUpgradeCheck = 1510;
131 | ORGANIZATIONNAME = "";
132 | TargetAttributes = {
133 | 97C146ED1CF9000F007C117D = {
134 | CreatedOnToolsVersion = 7.3.1;
135 | LastSwiftMigration = 1100;
136 | };
137 | };
138 | };
139 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */;
140 | compatibilityVersion = "Xcode 9.3";
141 | developmentRegion = en;
142 | hasScannedForEncodings = 0;
143 | knownRegions = (
144 | en,
145 | Base,
146 | );
147 | mainGroup = 97C146E51CF9000F007C117D;
148 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
149 | projectDirPath = "";
150 | projectRoot = "";
151 | targets = (
152 | 97C146ED1CF9000F007C117D /* Runner */,
153 | );
154 | };
155 | /* End PBXProject section */
156 |
157 | /* Begin PBXResourcesBuildPhase section */
158 | 97C146EC1CF9000F007C117D /* Resources */ = {
159 | isa = PBXResourcesBuildPhase;
160 | buildActionMask = 2147483647;
161 | files = (
162 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */,
163 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
164 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
165 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
166 | );
167 | runOnlyForDeploymentPostprocessing = 0;
168 | };
169 | /* End PBXResourcesBuildPhase section */
170 |
171 | /* Begin PBXShellScriptBuildPhase section */
172 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
173 | isa = PBXShellScriptBuildPhase;
174 | alwaysOutOfDate = 1;
175 | buildActionMask = 2147483647;
176 | files = (
177 | );
178 | inputPaths = (
179 | "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
180 | );
181 | name = "Thin Binary";
182 | outputPaths = (
183 | );
184 | runOnlyForDeploymentPostprocessing = 0;
185 | shellPath = /bin/sh;
186 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
187 | };
188 | 9740EEB61CF901F6004384FC /* Run Script */ = {
189 | isa = PBXShellScriptBuildPhase;
190 | alwaysOutOfDate = 1;
191 | buildActionMask = 2147483647;
192 | files = (
193 | );
194 | inputPaths = (
195 | );
196 | name = "Run Script";
197 | outputPaths = (
198 | );
199 | runOnlyForDeploymentPostprocessing = 0;
200 | shellPath = /bin/sh;
201 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
202 | };
203 | /* End PBXShellScriptBuildPhase section */
204 |
205 | /* Begin PBXSourcesBuildPhase section */
206 | 97C146EA1CF9000F007C117D /* Sources */ = {
207 | isa = PBXSourcesBuildPhase;
208 | buildActionMask = 2147483647;
209 | files = (
210 | 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
211 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
212 | );
213 | runOnlyForDeploymentPostprocessing = 0;
214 | };
215 | /* End PBXSourcesBuildPhase section */
216 |
217 | /* Begin PBXVariantGroup section */
218 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = {
219 | isa = PBXVariantGroup;
220 | children = (
221 | 97C146FB1CF9000F007C117D /* Base */,
222 | );
223 | name = Main.storyboard;
224 | sourceTree = "";
225 | };
226 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = {
227 | isa = PBXVariantGroup;
228 | children = (
229 | 97C147001CF9000F007C117D /* Base */,
230 | );
231 | name = LaunchScreen.storyboard;
232 | sourceTree = "";
233 | };
234 | /* End PBXVariantGroup section */
235 |
236 | /* Begin XCBuildConfiguration section */
237 | 249021D3217E4FDB00AE95B9 /* Profile */ = {
238 | isa = XCBuildConfiguration;
239 | buildSettings = {
240 | ALWAYS_SEARCH_USER_PATHS = NO;
241 | CLANG_ANALYZER_NONNULL = YES;
242 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
243 | CLANG_CXX_LIBRARY = "libc++";
244 | CLANG_ENABLE_MODULES = YES;
245 | CLANG_ENABLE_OBJC_ARC = YES;
246 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
247 | CLANG_WARN_BOOL_CONVERSION = YES;
248 | CLANG_WARN_COMMA = YES;
249 | CLANG_WARN_CONSTANT_CONVERSION = YES;
250 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
251 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
252 | CLANG_WARN_EMPTY_BODY = YES;
253 | CLANG_WARN_ENUM_CONVERSION = YES;
254 | CLANG_WARN_INFINITE_RECURSION = YES;
255 | CLANG_WARN_INT_CONVERSION = YES;
256 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
257 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
258 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
259 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
260 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
261 | CLANG_WARN_STRICT_PROTOTYPES = YES;
262 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
263 | CLANG_WARN_UNREACHABLE_CODE = YES;
264 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
265 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
266 | COPY_PHASE_STRIP = NO;
267 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
268 | ENABLE_NS_ASSERTIONS = NO;
269 | ENABLE_STRICT_OBJC_MSGSEND = YES;
270 | GCC_C_LANGUAGE_STANDARD = gnu99;
271 | GCC_NO_COMMON_BLOCKS = YES;
272 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
273 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
274 | GCC_WARN_UNDECLARED_SELECTOR = YES;
275 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
276 | GCC_WARN_UNUSED_FUNCTION = YES;
277 | GCC_WARN_UNUSED_VARIABLE = YES;
278 | IPHONEOS_DEPLOYMENT_TARGET = 12.0;
279 | MTL_ENABLE_DEBUG_INFO = NO;
280 | SDKROOT = iphoneos;
281 | SUPPORTED_PLATFORMS = iphoneos;
282 | TARGETED_DEVICE_FAMILY = "1,2";
283 | VALIDATE_PRODUCT = YES;
284 | };
285 | name = Profile;
286 | };
287 | 249021D4217E4FDB00AE95B9 /* Profile */ = {
288 | isa = XCBuildConfiguration;
289 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
290 | buildSettings = {
291 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
292 | CLANG_ENABLE_MODULES = YES;
293 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
294 | DEVELOPMENT_TEAM = 2D45M65AUG;
295 | ENABLE_BITCODE = NO;
296 | INFOPLIST_FILE = Runner/Info.plist;
297 | LD_RUNPATH_SEARCH_PATHS = (
298 | "$(inherited)",
299 | "@executable_path/Frameworks",
300 | );
301 | PRODUCT_BUNDLE_IDENTIFIER = dev.crasowas.easyStickyHeaderExample;
302 | PRODUCT_NAME = "$(TARGET_NAME)";
303 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
304 | SWIFT_VERSION = 5.0;
305 | VERSIONING_SYSTEM = "apple-generic";
306 | };
307 | name = Profile;
308 | };
309 | 97C147031CF9000F007C117D /* Debug */ = {
310 | isa = XCBuildConfiguration;
311 | buildSettings = {
312 | ALWAYS_SEARCH_USER_PATHS = NO;
313 | CLANG_ANALYZER_NONNULL = YES;
314 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
315 | CLANG_CXX_LIBRARY = "libc++";
316 | CLANG_ENABLE_MODULES = YES;
317 | CLANG_ENABLE_OBJC_ARC = YES;
318 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
319 | CLANG_WARN_BOOL_CONVERSION = YES;
320 | CLANG_WARN_COMMA = YES;
321 | CLANG_WARN_CONSTANT_CONVERSION = YES;
322 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
323 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
324 | CLANG_WARN_EMPTY_BODY = YES;
325 | CLANG_WARN_ENUM_CONVERSION = YES;
326 | CLANG_WARN_INFINITE_RECURSION = YES;
327 | CLANG_WARN_INT_CONVERSION = YES;
328 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
329 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
330 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
331 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
332 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
333 | CLANG_WARN_STRICT_PROTOTYPES = YES;
334 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
335 | CLANG_WARN_UNREACHABLE_CODE = YES;
336 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
337 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
338 | COPY_PHASE_STRIP = NO;
339 | DEBUG_INFORMATION_FORMAT = dwarf;
340 | ENABLE_STRICT_OBJC_MSGSEND = YES;
341 | ENABLE_TESTABILITY = YES;
342 | GCC_C_LANGUAGE_STANDARD = gnu99;
343 | GCC_DYNAMIC_NO_PIC = NO;
344 | GCC_NO_COMMON_BLOCKS = YES;
345 | GCC_OPTIMIZATION_LEVEL = 0;
346 | GCC_PREPROCESSOR_DEFINITIONS = (
347 | "DEBUG=1",
348 | "$(inherited)",
349 | );
350 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
351 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
352 | GCC_WARN_UNDECLARED_SELECTOR = YES;
353 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
354 | GCC_WARN_UNUSED_FUNCTION = YES;
355 | GCC_WARN_UNUSED_VARIABLE = YES;
356 | IPHONEOS_DEPLOYMENT_TARGET = 12.0;
357 | MTL_ENABLE_DEBUG_INFO = YES;
358 | ONLY_ACTIVE_ARCH = YES;
359 | SDKROOT = iphoneos;
360 | TARGETED_DEVICE_FAMILY = "1,2";
361 | };
362 | name = Debug;
363 | };
364 | 97C147041CF9000F007C117D /* Release */ = {
365 | isa = XCBuildConfiguration;
366 | buildSettings = {
367 | ALWAYS_SEARCH_USER_PATHS = NO;
368 | CLANG_ANALYZER_NONNULL = YES;
369 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
370 | CLANG_CXX_LIBRARY = "libc++";
371 | CLANG_ENABLE_MODULES = YES;
372 | CLANG_ENABLE_OBJC_ARC = YES;
373 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
374 | CLANG_WARN_BOOL_CONVERSION = YES;
375 | CLANG_WARN_COMMA = YES;
376 | CLANG_WARN_CONSTANT_CONVERSION = YES;
377 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
378 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
379 | CLANG_WARN_EMPTY_BODY = YES;
380 | CLANG_WARN_ENUM_CONVERSION = YES;
381 | CLANG_WARN_INFINITE_RECURSION = YES;
382 | CLANG_WARN_INT_CONVERSION = YES;
383 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
384 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
385 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
386 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
387 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
388 | CLANG_WARN_STRICT_PROTOTYPES = YES;
389 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
390 | CLANG_WARN_UNREACHABLE_CODE = YES;
391 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
392 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
393 | COPY_PHASE_STRIP = NO;
394 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
395 | ENABLE_NS_ASSERTIONS = NO;
396 | ENABLE_STRICT_OBJC_MSGSEND = YES;
397 | GCC_C_LANGUAGE_STANDARD = gnu99;
398 | GCC_NO_COMMON_BLOCKS = YES;
399 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
400 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
401 | GCC_WARN_UNDECLARED_SELECTOR = YES;
402 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
403 | GCC_WARN_UNUSED_FUNCTION = YES;
404 | GCC_WARN_UNUSED_VARIABLE = YES;
405 | IPHONEOS_DEPLOYMENT_TARGET = 12.0;
406 | MTL_ENABLE_DEBUG_INFO = NO;
407 | SDKROOT = iphoneos;
408 | SUPPORTED_PLATFORMS = iphoneos;
409 | SWIFT_COMPILATION_MODE = wholemodule;
410 | SWIFT_OPTIMIZATION_LEVEL = "-O";
411 | TARGETED_DEVICE_FAMILY = "1,2";
412 | VALIDATE_PRODUCT = YES;
413 | };
414 | name = Release;
415 | };
416 | 97C147061CF9000F007C117D /* Debug */ = {
417 | isa = XCBuildConfiguration;
418 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
419 | buildSettings = {
420 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
421 | CLANG_ENABLE_MODULES = YES;
422 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
423 | DEVELOPMENT_TEAM = 2D45M65AUG;
424 | ENABLE_BITCODE = NO;
425 | INFOPLIST_FILE = Runner/Info.plist;
426 | LD_RUNPATH_SEARCH_PATHS = (
427 | "$(inherited)",
428 | "@executable_path/Frameworks",
429 | );
430 | PRODUCT_BUNDLE_IDENTIFIER = dev.crasowas.easyStickyHeaderExample;
431 | PRODUCT_NAME = "$(TARGET_NAME)";
432 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
433 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
434 | SWIFT_VERSION = 5.0;
435 | VERSIONING_SYSTEM = "apple-generic";
436 | };
437 | name = Debug;
438 | };
439 | 97C147071CF9000F007C117D /* Release */ = {
440 | isa = XCBuildConfiguration;
441 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
442 | buildSettings = {
443 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
444 | CLANG_ENABLE_MODULES = YES;
445 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
446 | DEVELOPMENT_TEAM = 2D45M65AUG;
447 | ENABLE_BITCODE = NO;
448 | INFOPLIST_FILE = Runner/Info.plist;
449 | LD_RUNPATH_SEARCH_PATHS = (
450 | "$(inherited)",
451 | "@executable_path/Frameworks",
452 | );
453 | PRODUCT_BUNDLE_IDENTIFIER = dev.crasowas.easyStickyHeaderExample;
454 | PRODUCT_NAME = "$(TARGET_NAME)";
455 | SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
456 | SWIFT_VERSION = 5.0;
457 | VERSIONING_SYSTEM = "apple-generic";
458 | };
459 | name = Release;
460 | };
461 | /* End XCBuildConfiguration section */
462 |
463 | /* Begin XCConfigurationList section */
464 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = {
465 | isa = XCConfigurationList;
466 | buildConfigurations = (
467 | 97C147031CF9000F007C117D /* Debug */,
468 | 97C147041CF9000F007C117D /* Release */,
469 | 249021D3217E4FDB00AE95B9 /* Profile */,
470 | );
471 | defaultConfigurationIsVisible = 0;
472 | defaultConfigurationName = Release;
473 | };
474 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = {
475 | isa = XCConfigurationList;
476 | buildConfigurations = (
477 | 97C147061CF9000F007C117D /* Debug */,
478 | 97C147071CF9000F007C117D /* Release */,
479 | 249021D4217E4FDB00AE95B9 /* Profile */,
480 | );
481 | defaultConfigurationIsVisible = 0;
482 | defaultConfigurationName = Release;
483 | };
484 | /* End XCConfigurationList section */
485 | };
486 | rootObject = 97C146E61CF9000F007C117D /* Project object */;
487 | }
488 |
--------------------------------------------------------------------------------