|
|
@ -14,6 +14,7 @@ class RefreshFutureBuilder<T> extends StatefulWidget { |
|
|
|
class _RefreshFutureBuilderState<T> extends State<RefreshFutureBuilder<T>> { |
|
|
|
class _RefreshFutureBuilderState<T> extends State<RefreshFutureBuilder<T>> { |
|
|
|
late RefreshFutureBuilderSnapshot<T> snapshot; |
|
|
|
late RefreshFutureBuilderSnapshot<T> snapshot; |
|
|
|
Future<T> Function()? futureCreator; |
|
|
|
Future<T> Function()? futureCreator; |
|
|
|
|
|
|
|
bool _disposed = false; |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
void initState() { |
|
|
@ -61,11 +62,17 @@ class _RefreshFutureBuilderState<T> extends State<RefreshFutureBuilder<T>> { |
|
|
|
}); |
|
|
|
}); |
|
|
|
try { |
|
|
|
try { |
|
|
|
final data = await futureCreator!(); |
|
|
|
final data = await futureCreator!(); |
|
|
|
|
|
|
|
if (_disposed) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
setState(() { |
|
|
|
setState(() { |
|
|
|
snapshot = RefreshFutureBuilderSnapshot.withData(data); |
|
|
|
snapshot = RefreshFutureBuilderSnapshot.withData(data); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (e, st) { |
|
|
|
catch (e, st) { |
|
|
|
|
|
|
|
if (_disposed) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
setState(() { |
|
|
|
setState(() { |
|
|
|
if (snapshot.state == RefreshFutureBuilderState.waiting) { |
|
|
|
if (snapshot.state == RefreshFutureBuilderState.waiting) { |
|
|
|
snapshot = RefreshFutureBuilderSnapshot.withError(e, st); |
|
|
|
snapshot = RefreshFutureBuilderSnapshot.withError(e, st); |
|
|
@ -77,6 +84,12 @@ class _RefreshFutureBuilderState<T> extends State<RefreshFutureBuilder<T>> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
|
|
void dispose() { |
|
|
|
|
|
|
|
_disposed = true; |
|
|
|
|
|
|
|
super.dispose(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return widget.builder( |
|
|
|
return widget.builder( |
|
|
|