Last active
February 21, 2020 09:17
-
-
Save hayribakici/b7aa6486aec9aa947ce9432c3de13c13 to your computer and use it in GitHub Desktop.
Extended FutureProvider, that displays an additional child while the Future operation is running.
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/widgets.dart'; | |
import 'package:provider/provider.dart'; | |
class FutureProvider2<T> extends FutureProvider<T> { | |
final Widget _childOnFutureBusy; | |
FutureProvider2.value({ | |
Key key, | |
@required Future<T> value, | |
T initialData, | |
Widget childOnFutureBusy, | |
ErrorBuilder<T> catchError, | |
UpdateShouldNotify<T> updateShouldNotify, | |
Widget child, | |
}) : _childOnFutureBusy = childOnFutureBusy, | |
super.value( | |
key: key, | |
value: value, | |
initialData: initialData, | |
catchError: catchError, | |
updateShouldNotify: updateShouldNotify, | |
child: child); | |
@override | |
Widget build(BuildContext context) { | |
return FutureBuilder<T>( | |
future: delegate.value, | |
initialData: initialData, | |
builder: (_, snapshot) { | |
return snapshot.connectionState == ConnectionState.waiting | |
? _childOnFutureBusy | |
: super.build(context); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment