NestedScrollView in the drop-down refresh commonly used NestedScrollViewRefreshIndicator controls,

Project, using NestedScrollViewRefreshIndicator appeared some problems in the record, the hope can help some people. The problem we ran into was that when using headerSliverBuilder in NestedScrollView the method would be called multiple times per drag, resulting in each drag. If there was a widget with state in the headerSliverBuilder, the state would be flushed back to the beginning Statuses, such as a rolling AD banner, can also pose problems with screen freezes and frequent refreshes. The problem caused by NestedScrollViewRefreshIndicator controls the refresh. View NestedScrollViewRefreshIndicator build code:

Widget build(BuildContext context) {
  assert(debugCheckHasMaterialLocalizations(context));
  final Widget child = NotificationListener<ScrollNotification>(
    key: _key,
    onNotification: _handleScrollNotification,
    child: NotificationListener<OverscrollIndicatorNotification>(
      onNotification: _handleGlowNotification,
      child: widget.child,
    ),
  );
Copy the code

It turns out that the build builds itself a Widget that wraps the widget.child we passed in with multiple calls to the setState method. This method refreshes the entire control, which contains widget.child, so our widget will also be called multiple times to refresh. Among them

_handleScrollNotification
Copy the code

In the method

Notification. The metrics. ExtentBefore = = 0.0 && _mode = = null && _start (notification. The metrics. AxisDirection)) {setState (() {  _mode = _RefreshIndicatorMode.drag; }); return false; }Copy the code

Is the key refresh problem. Once the problem is found, the solution is easy to solve. Make the control refresh only itself, that is, the drop-down load diagram. The main idea is to extract the loading control and refresh it separately. Adjust the code more, the need of the students can download the use or view. The use mode is the same as the original method. The attachment cannot be uploaded, and the github address is attached: github.com/190709670/h…