Unverified Commit 47f12cae authored by Casey Rogers's avatar Casey Rogers Committed by GitHub

made top level if checks gaurd clauses (#135070)

This is a tiny tweak to replace some top level if clauses with guard clauses in `FutureBuilder`. I find the resultant code much more readable, but this is a matter of taste and I didn't see any info one way or another on it in the style guide so let me know if this is not to your all's preference.
parent 433bca5e
......@@ -595,14 +595,15 @@ class _FutureBuilderState<T> extends State<FutureBuilder<T>> {
@override
void didUpdateWidget(FutureBuilder<T> oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.future != widget.future) {
if (oldWidget.future == widget.future) {
return;
}
if (_activeCallbackIdentity != null) {
_unsubscribe();
_snapshot = _snapshot.inState(ConnectionState.none);
}
_subscribe();
}
}
@override
Widget build(BuildContext context) => widget.builder(context, _snapshot);
......@@ -614,7 +615,10 @@ class _FutureBuilderState<T> extends State<FutureBuilder<T>> {
}
void _subscribe() {
if (widget.future != null) {
if (widget.future == null) {
// There is no future to subscribe to, do nothing.
return;
}
final Object callbackIdentity = Object();
_activeCallbackIdentity = callbackIdentity;
widget.future!.then<void>((T data) {
......@@ -642,7 +646,6 @@ class _FutureBuilderState<T> extends State<FutureBuilder<T>> {
_snapshot = _snapshot.inState(ConnectionState.waiting);
}
}
}
void _unsubscribe() {
_activeCallbackIdentity = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment