एक बढ़ाया हुआ NestedScrollView जो नेस्टेड और पैरेंट स्क्रॉल व्यू में ओवरस्क्रॉल सपोर्ट प्रदान करता है, जिससे एक सुचारू स्क्रॉलिंग अनुभव सुनिश्चित होता है।
सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
Flutter के NestedScrollView का एक सुधारित संस्करण जो नेस्टेड और पैरेंट स्क्रॉल व्यू के लिए ओवरस्क्रॉल समर्थन प्रदान करता है, जिससे सभी प्लेटफॉर्मों पर चिकनी और स्थिर स्क्रॉलिंग अनुभव सुनिश्चित होता है। इसके द्वारा मानक व्यवहार में सुधार किया गया है, जिससे दोनों परतों में प्राकृतिक ओवरस्क्रॉल प्रभाव संभव होते हैं, जो ऐप बार के साथ नीचे छलकने वाली सामग्री जैसे जटिल स्क्रॉल करने योग्य लेआउट के लिए आदर्श है। पैकेज को सक्रिय रूप से बनाए रखा जाता है और Android, iOS, Web, macOS, Windows और Linux के साथ संगत है।
उपयोग
जटिल एप्प बार लेआउट
ओवरस्क्रॉल के साथ नेस्टेड स्क्रॉल कंटेंट
पैरलैक्स प्रभाव के साथ स्क्रॉलिंग
परतदार स्क्रोलिंग के साथ अनुकूल उपयोगकर्ता इंटरफेस
हाइब्रिड स्क्रॉल करने योग्य इंटरफेस
मुख्य विशेषताएँ
नेस्टेड और पैरेंट स्क्रॉल व्यू के लिए ओवरस्क्रॉल समर्थन
अनुभव बिना स्क्रॉल करें
क्रॉस-प्लेटफ़ॉर्म संगतता
सुधारित स्क्रॉल भौतिकी
कस्टम स्क्रॉल व्यवहार का समर्थन
सक्रिय रूप से रखरखाव और अद्यतन
इनके लिए उपयुक्त
उन्नत स्क्रॉल करने योग्य 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.