New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RefreshIndicator does not disappear when refreshed in background #14619
Comments
might be the same underlying cause as #13818 |
This is my workaround: import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
class MyRefreshIndicator extends StatefulWidget {
const MyRefreshIndicator({
Key key,
@required this.child,
this.displacement: 40.0,
@required this.onRefresh,
this.color,
this.backgroundColor,
this.notificationPredicate: defaultScrollNotificationPredicate,
}) : assert(child != null),
assert(onRefresh != null),
assert(notificationPredicate != null),
super(key: key);
final Widget child;
final double displacement;
final RefreshCallback onRefresh;
final Color color;
final Color backgroundColor;
final ScrollNotificationPredicate notificationPredicate;
@override
State<StatefulWidget> createState() {
return new MyRefreshIndicatorState();
}
}
class MyRefreshIndicatorState extends State<MyRefreshIndicator> with WidgetsBindingObserver {
Completer<Null> completer;
bool foreground = true;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
foreground = (state == AppLifecycleState.resumed);
if (foreground && completer != null) {
//debugPrint("complete on didChangeAppLifecycleState");
completer.complete();
completer = null;
}
}
@override
Widget build(BuildContext context) {
return new RefreshIndicator(
child: widget.child,
onRefresh: _onRefresh,
displacement: widget.displacement,
color: widget.color,
backgroundColor: widget.backgroundColor,
notificationPredicate: widget.notificationPredicate,
);
}
Future<Null> _onRefresh() {
final Completer<Null> completer = new Completer<Null>();
widget.onRefresh().then((_) {
if (foreground) {
//debugPrint("complete on original future");
completer.complete();
} else {
this.completer = completer;
}
});
return completer.future;
}
} |
I can't reproduce this on 1.12.13+hotfix.5. Closing. If it's still an issue, please reopen. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
The
RefreshIndicator#show
's future is completed but indicator does not disappear.See: https://youtu.be/Ns8yRhq65wM
Logs
No error logs.
Flutter Doctor
The text was updated successfully, but these errors were encountered: