Skip to content

Instantly share code, notes, and snippets.

@thetrav
Created February 12, 2020 04:56
Show Gist options
  • Save thetrav/58be79efc5438ef85026a4e65a939603 to your computer and use it in GitHub Desktop.
Save thetrav/58be79efc5438ef85026a4e65a939603 to your computer and use it in GitHub Desktop.
Combine navigation on error with FutureBuilder
import 'package:flutter/material.dart';
class FancyFutureBuilder<T> extends StatelessWidget {
final Future<T> future;
final Widget Function (BuildContext , AsyncSnapshot<T>) builder;
final Function doNavigation;
final bool Function(Object) shouldNavigate;
FancyFutureBuilder({
@required this.future,
@required this.builder,
@required this.doNavigation,
@required this.shouldNavigate
});
@override
Widget build(BuildContext context) => FutureBuilder<T>(
future: future.catchError(doNavigation, test: shouldNavigate),
builder: builder
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment