Skip to content

Solution to SmartRefresh looking like it is hanged or bugged after refresh #663

Description

@stefan-ma22

Hello all, I spent few days debugging why is my SmartRefresher stuck when I pulldown and do refresh. The issue is related to flutter_bloc package. What I do, I have SmartRefresh inside BlocBuilder. When I do refresh no data comes as it is the same state with same data. The SmartRefresh recognizes this as no data has come. There is a default option enableLoadingWhenNoData: false, you have to set it to true otherwise it will be stuck forever.

Here is my solution:

          child: RefreshConfiguration(
            headerBuilder: () => WaterDropHeader(), // Configure the default header indicator. If you have the same header indicator for each page, you need to set this
            footerBuilder: () => ClassicFooter(), // Configure default bottom indicator
            headerTriggerDistance: 100.0, // header trigger refresh trigger distance
            springDescription: SpringDescription(stiffness: 170, damping: 16, mass: 1.9), // custom spring back animate,the props meaning see the flutter api
            maxOverScrollExtent: 100, //The maximum dragging range of the head. Set this property if a rush out of the view area occurs
            maxUnderScrollExtent: 0, // Maximum dragging range at the bottom
            enableScrollWhenRefreshCompleted: true, //This property is incompatible with PageView and TabBarView. If you need TabBarView to slide left and right, you need to set it to true.
            **enableLoadingWhenNoData: true,**
            enableLoadingWhenFailed: true, //In the case of load failure, users can still trigger more loads by gesture pull-up.
            hideFooterWhenNotFull: false, // Disable pull-up to load more functionality when Viewport is less than one screen
            enableBallisticLoad: true, // trigger load more by BallisticScrollActivity
            child: SmartRefresher(
              enablePullDown: true,
              enablePullUp: true,
              header: WaterDropHeader(
                complete: Text(context.localize('refreshDone'), style: TextStyle(color: Colors.white)),
              ),
              footer: CustomFooter(
                builder: (BuildContext context, LoadStatus? mode) {
                  String footerMessage;
                  if (widget.state.thereAreNoMoreRecords) {
                    footerMessage = context.localize('noMoreRecords');
                  } else {
                    footerMessage = context.localize('pullToLoadMore');
                  }

                  return Container(
                    child: Center(
                      child: Text(footerMessage, style: TextStyle(color: Colors.white)),
                    ),
                  );
                },
              ),
              controller: _refreshController,
              onRefresh: () async {
                await widget.cubit.refresh();
                _refreshController.refreshCompleted();
              },
              onLoading: () async {
                if (widget.state.thereAreNoMoreRecords == false) {
                  await widget.cubit.loadMore();
                  _refreshController.loadComplete();
                } else {
                  _refreshController.loadNoData();
                }
              },
              child: showRecordListBody(widget),
            ),
          ),
        ),

Flutter doctor for info

    • Flutter version 3.38.5 on channel stable at D:\SideProjects\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f6ff1529fd (9 weeks ago), 2025-12-11 11:50:07 -0500
    • Engine revision 1527ae0ec5
    • Dart version 3.10.4
    • DevTools version 2.51.1
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging

[√] Windows Version (11 Pro 64-bit, 24H2, 2009) [1 718ms]

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [3,7s]
    • Android SDK at C:\Users\stefa\AppData\Local\Android\sdk
    • Emulator version 35.2.10.0 (build_id 12414864) (CL:N/A)
    • Platform android-36, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    • All Android licenses accepted.

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

[X] Visual Studio - develop Windows apps [440ms]
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Connected device (4 available) [591ms]
    • M2012K11AG (mobile) • 192.168.0.219:42643 • android-arm64  • Android 13 (API 33)
    • Windows (desktop)   • windows             • windows-x64    • Microsoft Windows [Version 10.0.26100.7623]
    • Chrome (web)        • chrome              • web-javascript • Google Chrome 144.0.7559.133
    • Edge (web)          • edge                • web-javascript • Microsoft Edge 145.0.3800.58

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

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions