如果您不需要渲染任何东西,请不要使用
StreamBuilder。
StreamBuilder是用于显示内容的帮助小部件
Stream。
您想要的是不同的。因此,您可以简单地
Stream手动听。
将执行以下操作:
class Foo<T> extends StatefulWidget { Stream<T> stream; Foo({this.stream}); @override _FooState createState() => _FooState<T>();}class _FooState<T> extends State<Foo<T>> { StreamSubscription streamSubscription; @override void initState() { streamSubscription = widget.stream.listen(onNewValue); super.initState(); } void onNewValue(T event) { Navigator.of(context).pushNamed("my/new/route"); } @override void dispose() { streamSubscription.cancel(); super.dispose(); } @override Widget build(BuildContext context) { return Container(); }}


