Created
August 28, 2019 09:07
-
-
Save rrousselGit/7a305c00fd6556f5da34cf7ddd726fe8 to your computer and use it in GitHub Desktop.
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
class ProviderToStream<T> extends StatefulWidget | |
implements SingleChildCloneableWidget { | |
const ProviderToStream({Key key, this.builder, this.child}) : super(key: key); | |
final ValueWidgetBuilder<Stream<T>> builder; | |
final Widget child; | |
@override | |
_ProviderToStreamState<T> createState() => _ProviderToStreamState<T>(); | |
@override | |
ProviderToStream<T> cloneWithChild(Widget child) { | |
return ProviderToStream( | |
key: key, | |
builder: builder, | |
child: child, | |
); | |
} | |
} | |
class _ProviderToStreamState<T> extends State<ProviderToStream> { | |
final StreamController<T> controller = StreamController<T>(); | |
@override | |
void dispose() { | |
controller.close(); | |
super.dispose(); | |
} | |
@override | |
void didChangeDependencies() { | |
super.didChangeDependencies(); | |
controller.add(Provider.of<T>(context)); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return widget.builder(context, controller.stream, widget.child); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment