crasowas / easy_sticky_header Goto Github PK
View Code? Open in Web Editor NEWAn easy-to-use and powerful sticky header for any widget that supports scrolling.
Home Page: https://pub.dev/packages/easy_sticky_header
License: MIT License
An easy-to-use and powerful sticky header for any widget that supports scrolling.
Home Page: https://pub.dev/packages/easy_sticky_header
License: MIT License
header里是个横向滑动列表,在顶部时滑动到一半,纵向列表滑动上去之后,顶部sticky_header效果显露,stickey_header内的横向列表就自动滑回初始状态了,这个要怎么处理
很强大的库,但是没找到合适的api可以不静止状态去刷新StickyHeaderWidget,我尝试过重新实例StickyHeaderController(),但是有肉眼可见的闪烁。
WidgetsBinding?.instance.addPostFrameCallback((timeStamp) {
_controller?.scrollListener();
});
使用setState(() {});发现StickyContainerWidget的child部件里面的text部件内容变量不变化,得在StickyHeader随意滑动后才变化,就很奇怪,麻烦看下这个问题
Scroll content with items and headers to bottom of ListView
using maxScrollExtent
of ScrollController
or getMaxScrollExtent
of StickyHeaderController.
Content should be scrolled down without jerking up and the last element should be visible
Sometimes the content doesn't make it to the end, sometimes it tries to go higher than the last element
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,
),
),
);
}
}
[√] 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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.