Created
February 12, 2020 04:56
-
-
Save thetrav/58be79efc5438ef85026a4e65a939603 to your computer and use it in GitHub Desktop.
Combine navigation on error with FutureBuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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