Flutter의 NestedScrollView를 개선한 버전으로, 중첩된 스크롤 뷰와 부모 스크롤 뷰 모두에 오버스크롤 지원을 제공하여 모든 플랫폼에서 부드럽고 일관된 스크롤 경험을 보장합니다. 기본 동작을 향상시켜 두 계층 모두 자연스러운 오버스크롤 효과를 가능하게 하여 앱 바 아래에 스크롤 가능한 콘텐츠가 있는 복잡한 스크롤 레이아웃에 이상적입니다. 이 패키지는 지속적으로 유지 관리되며 Android, iOS, Web, macOS, Windows, Linux와 호환됩니다.
사용 사례
복잡한 앱 바 레이아웃
오버스크롤이 있는 중첩 스크롤 가능한 콘텐츠
파라랙스 효과가 있는 스크롤
계층적 스크롤링을 갖춘 반응형 UI
하이브리드 스크롤 가능한 인터페이스
주요 기능
중첩 및 부모 스크롤 뷰에 대한 오버스크롤 지원
원활한 스크롤 경험
크로스 플랫폼 호환성
개선된 스크롤 물리
사용자 정의 스크롤 동작 지원
활동적인 유지보수 및 업데이트
적합한 대상
고급 스크롤 가능한 UI를 구축하는 개발자
시각적 피드백이 있는 계층적 스크롤링을 필요로 하는 앱
일관된 오버스크롤 동작이 필요한 프로젝트
다양한 플랫폼을 대상으로 하는 팀
동적 스크롤 효과를 구현하는 UI 디자이너
고려 사항
간단한 스크롤 레이아웃의 복잡성을 증가시킬 수 있습니다
스크롤 컨트롤러의 주의 깊은 조작이 필요합니다
깊이 중첩된 스크롤로 인한 성능 영향 가능성
기본 스크롤 가능한 위젯에는 필요하지 않음
표준 NestedScrollView 대신 고급 사용 사례에 가장 적합
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
NestedScrollViewPlus
An enhanced NestedScrollView offering overscroll support for both the nested and parent scroll views, ensuring a seamless scrolling experience.
Install NestedScrollViewPlus by running the following command:
flutter pub add nested_scroll_view_plus
Here’s a basic example:
import'package:nested_scroll_view_plus/nested_scroll_view_plus.dart';
// Step 1: Replace `NestedScrollView` with `NestedScrollViewPlus`NestedScrollViewPlus(
headerSliverBuilder: (context, innerScrolled) => <Widget>[
// ... insert your header sliver widgets here
],
body: CustomScrollView(
// Step 2: [🚨IMPORTANT] Set the physics of `CustomScrollView` to `AlwaysScrollableScrollPhysics`
physics: constBouncingScrollPhysics(
parent: AlwaysScrollableScrollPhysics(),
),
slivers: <Widget>[
// ... insert your body sliver widgets here
],
),
);
For additional examples, please visit the scroll_master repository. It includes features such as pull-to-refresh for NestedScrollView, combined scrolling for scrollview and tabview, and more.
🚗 Examples
1. Loading Indicator
NestedScrollViewPlus(
overscrollBehavior: OverscrollBehavior.outer,
headerSliverBuilder: (context, innerScrolled) => <Widget>[
// Place the refresh indicator at the top of the header sliversCupertinoSliverRefreshControl(
onRefresh: () async {
// fetching data
},
),
// Add your custom AppBar or other header sliver widgets here.
],
// ...
)
2. Accessing the Inner or Outer Scroll Controller
To access the inner or outer scroll controller of a NestedScrollViewPlus, you can use a GlobalKey<NestedScrollViewStatePlus> to get its state.
👉 Example
class_ExampleStateextendsState<Example> {
// 1. Create a GlobalKeyfinalGlobalKey<NestedScrollViewStatePlus> myKey = GlobalKey();
@overrideWidgetbuild(BuildContext context) {
returnNestedScrollViewPlus(
// 2. Set the key to NestedScrollViewStatePlus
key: myKey,
// ...,
);
}
@overridevoidinitState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
// 3. Access the inner or outer scroll controller using GlobalKey<NestedScrollViewStatePlus>
myKey.currentState!.innerController.addListener(_handleInnerScroll);
myKey.currentState!.outerController.addListener(_handleOuterScroll);
});
}
void_handleInnerScroll() {
final innerController = myKey.currentState!.innerController;
if (innerController.positions.length == 1) {
print('Scrolling inner nested scrollview: ${innerController.offset}');
}
}
void_handleOuterScroll() {
final outerController = myKey.currentState!.outerController;
if (outerController.positions.length == 1) {
print('Scrolling outer nested scrollview: ${outerController.offset}');
}
}
}
3. Preserve Scroll Positions of Inner CustomScrollViews
To preserve the scroll positions of inner CustomScrollViews, you can add a PageStorageKey to the CustomScrollView widget. Here's an example:
By assigning a unique key to the CustomScrollView, Flutter's PageStorage mechanism will store and restore the scroll position of the inner CustomScrollViews, allowing you to maintain the scroll positions even when the widget tree is rebuilt.
⭕️ For Older Flutter Versions
If you are using an older version of Flutter, please follow these steps to install the appropriate branch from the old git repository.
dependencies:
custom_nested_scroll_view:
git:
url: https://github.com/idootop/custom_nested_scroll_view.git
# Choose the branch based on your local Flutter version
ref: flutter-3.7
The different branches support the following Flutter versions:
Git branch
Supported flutter versions
flutter-3.7
>=3.7.0-13.0.pre
flutter-3.4
>=3.4.0-27.0.pre <3.7.0-13.0.pre
flutter-3.4-pre
>=3.4.0-17.0.pre <3.4.0-27.0.pre
flutter-3.0
>=2.12.0-4.0.pre <3.4.0-17.0.pre
flutter-2.x
<2.12.0-4.0.pre
For more details, please visit the old documentation for CustomNestedScrollView.