Code Monkey home page Code Monkey logo

easy_sticky_header's Introduction

easy_sticky_header

platform pub license issues commits

English | 中文

An easy-to-use and powerful sticky header for any widget that supports scrolling.

Features

  • Support widget for horizontal or vertical scrolling
  • Support widget for reverse scrolling
  • Allow dynamic building of header widget and support custom transition animation
  • Header widget can dynamically change stickiness
  • Support jumping to the header widget of the specified index
  • Support header widget grouping
  • Support infinite list

Usage

Add dependency:

dependencies:
  easy_sticky_header: ^1.1.1

Import package:

import 'package:easy_sticky_header/easy_sticky_header.dart';

Example:

class Example extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return StickyHeader(
      child: ListView.builder(
        itemCount: 100,
        itemBuilder: (context, index) {
          // Custom header widget.
          if (index % 3 == 0) {
            return StickyContainerWidget(
              index: index,
              child: Container(
                color: Color.fromRGBO(Random().nextInt(256),
                    Random().nextInt(256), Random().nextInt(256), 1),
                padding: const EdgeInsets.only(left: 16.0),
                alignment: Alignment.centerLeft,
                width: double.infinity,
                height: 50,
                child: Text(
                  'Header #$index',
                  style: const TextStyle(
                    color: Colors.white,
                    fontSize: 16,
                  ),
                ),
              ),
            );
          }
          // Custom item widget.
          return Container(
            width: double.infinity,
            height: 80,
            color: Colors.white,
          );
        },
      ),
    );
  }
}

For more features, please go to the example project to see the details.

Screenshots

screenshot1 screenshot2 screenshot3
screenshot4 screenshot5 screenshot6
screenshot7 screenshot8 screenshot9

Contribution

You are welcome to contribute here 😄!

You can open an issue, if you find a bug, or want a new feature.

You can open up a PR, if you fixed a bug or implemented a new feature.

License

MIT License

Copyright (c) 2022 crasowas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

easy_sticky_header's People

Contributors

crasowas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

easy_sticky_header's Issues

StickyContainerWidget的child内容不刷新

使用setState(() {});发现StickyContainerWidget的child部件里面的text部件内容变量不变化,得在StickyHeader随意滑动后才变化,就很奇怪,麻烦看下这个问题

Incorrectly calculated maxScrollExtent/getMaxScrollExtent

Steps to reproduce

Scroll content with items and headers to bottom of ListView using maxScrollExtent of ScrollController or getMaxScrollExtent of StickyHeaderController.

Expected results

Content should be scrolled down without jerking up and the last element should be visible

Actual results

Sometimes the content doesn't make it to the end, sometimes it tries to go higher than the last element

Code sample

Example
import 'dart:math';

import 'package:flutter/material.dart';

import 'package:easy_sticky_header/easy_sticky_header.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Sticky Header Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _stickyController = StickyHeaderController();
  final _scrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: StickyHeader(
        controller: _stickyController,
        child: ListView.builder(
          itemCount: 100,
          controller: _scrollController,
          itemBuilder: (context, index) {
            // Custom header widget.
            // If you set 20 here instead of 3 than content will not full scroll down
            if (index % 3 == 0) {
              return StickyContainerWidget(
                index: index,
                child: Container(
                  color: Color.fromRGBO(
                      Random().nextInt(256), Random().nextInt(256), Random().nextInt(256), 1),
                  padding: const EdgeInsets.only(left: 16.0),
                  alignment: Alignment.centerLeft,
                  width: double.infinity,
                  height: 50,
                  child: Text(
                    'Header #$index',
                    style: const TextStyle(
                      color: Colors.white,
                      fontSize: 16,
                    ),
                  ),
                ),
              );
            }
            // Custom item widget.
            return Container(
              width: double.infinity,
              height: 80,
              color: Colors.grey,
              child: Text(
                'item #$index',
                style: const TextStyle(
                  color: Colors.white,
                  fontSize: 16,
                ),
              ),
            );
          },
        ),
      ),
      floatingActionButton: FloatingActionButton(
        backgroundColor: Colors.black,
        onPressed: () {
          debugPrint(
              '_stickyController.getMaxScrollExtent: ${_stickyController.getMaxScrollExtent}');
          debugPrint(
              '_scrollController.position.maxScrollExtent: ${_scrollController.position.maxScrollExtent}');
          _scrollController.animateTo(
            _scrollController.position.maxScrollExtent,
            duration: const Duration(milliseconds: 100),
            curve: Curves.linear,
          );
        },
        child: const Icon(
          Icons.download_for_offline_sharp,
          color: Colors.white,
        ),
      ),
    );
  }
}

Screenshots or Video

Screenrecorder-2024-02-22-12-57-50-352.mp4
Screenrecorder-2024-02-22-12-57-22-273.mp4

Flutter Doctor output

flutter doctor -v

[√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [Version
10.0.19045.4046], locale en-US)
• Flutter version 3.16.9 on channel stable at D:\FRAMEWORKS\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 41456452f2 (4 weeks ago), 2024-01-25 10:06:23 -0800
• Engine revision f40e976bed
• Dart version 3.2.6
• DevTools version 2.28.5

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at D:\ENVIRONMENT\Android\sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = D:\ENVIRONMENT\Android
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
• Java version OpenJDK Runtime Environment (build
17.0.7+0-b2043.56-10550314)
• All Android licenses accepted.

[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.6.4)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.6.33815.320
• Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2023.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build
17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.86.2)
• VS Code at C:\Users\Nikita\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.82.0

[√] Connected device (5 available)
• M2007J17G (mobile) • 3cd17780 • android-arm64 • Android 12
(API 31)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 14
(API 34) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft
Windows [Version 10.0.19045.4046]
• Chrome (web) • chrome • web-javascript • Google
Chrome 122.0.6261.57
• Edge (web) • edge • web-javascript • Microsoft
Edge 120.0.2210.121

[√] Network resources
• All expected network resources are available.

• No issues found!

header横向滑动列表异常

header里是个横向滑动列表,在顶部时滑动到一半,纵向列表滑动上去之后,顶部sticky_header效果显露,stickey_header内的横向列表就自动滑回初始状态了,这个要怎么处理

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.