Skip to content

CupertinoSliverRefreshControl hangs if onRefresh completes with error #31382

@edwardez

Description

@edwardez

Steps to Reproduce

  1. Run code below
  2. Pull to refresh
  3. RefreshIndicator completes even if the future returns an exception, while CupertinoSliverRefreshControl hangs in RefreshIndicatorMode.refresh

I think the reason is CupertinoSliverRefreshControl completes future with widget.onRefresh()..then while RefreshIndicator completes future with refreshResult.whenComplete

https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/cupertino/refresh.dart#L457

https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/refresh_indicator.dart#L372

Cupertino

Material

Code

Change _testCupertino to _testMaterial to check the difference

import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
  MyApp();
}

class MyApp extends StatefulWidget {
  MyApp();

  @override
  State<StatefulWidget> createState() {
    return _MyAppState();
  }
}

class _MyAppState extends State<MyApp> {
  Future<void> onRefresh() {
    Completer completer = Completer();
    Future.delayed(Duration(seconds: 1), () {
      completer.completeError('test error');
    });
    return completer.future;
  }

  CustomScrollView _testCupertino() {
    return CustomScrollView(
      slivers: <Widget>[
        CupertinoSliverRefreshControl(
          onRefresh: onRefresh,
        ),
        SliverList(delegate: SliverChildBuilderDelegate((context, index) {
          return Padding(
            padding: const EdgeInsets.all(16.0),
            child: Text('demo'),
          );
        }))
      ],
    );
  }

  RefreshIndicator _testMaterial() {
    return RefreshIndicator(
      child: CustomScrollView(
        slivers: <Widget>[
          SliverList(delegate: SliverChildBuilderDelegate((context, index) {
            return Padding(
              padding: const EdgeInsets.all(16.0),
              child: Text('demo'),
            );
          }))
        ],
      ),
      onRefresh: onRefresh,
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: _testCupertino(),
        ),
      ),
    );
  }
}

flutter doctor -v
[✓] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.4 18E226, locale en-US)
• Flutter version 1.2.1 at /Users/edward/dev/flutter
• Framework revision 8661d8a (8 weeks ago), 2019-02-14 19:19:53 -0800
• Engine revision 3757390
• Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/edward/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 10.2, Build version 10E125
• ios-deploy 1.9.4
• CocoaPods version 1.6.1

[!] Android Studio (version 3.3)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[✓] IntelliJ IDEA Ultimate Edition (version 2019.1)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 34.0.4
• Dart plugin version 191.6183.88

[!] VS Code (version 1.33.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
✗ Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (1 available)
• iPhone Xs • ios • com.apple.CoreSimulator.SimRuntime.iOS-12-2 (simulator)

! Doctor found issues in 2 categories.

Metadata

Metadata

Labels

f: cupertinoflutter/packages/flutter/cupertino repositoryframeworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions