Flutter:如何在屏幕之间传递视频流

时间:2020-07-16 10:14:33

标签: flutter dart

这是我下面用于初始化流的代码:

Stream userStream;

  @override
  void initState() {
    userStream = Firestore.instance
        .collection('rooms')
        .document(widget.gameID)
        .collection('users')
        .orderBy('timestamp')
        .snapshots()
        .asBroadcastStream();
    super.initState();
  }

这是我要在其中传递流的小部件:

class WaitForSubmissions extends StatelessWidget {
  WaitForSubmissions({ 
    @required this.userStream,
  });

  final Stream userStream; 

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      builder: (context, snap) {
          if (!snap.hasData) {
            return Scaffold();
          }
        return Scaffold(
          body: Center(
            child: Text(snap.data.documents[0]['username']),
          ),
        );
      },
      stream: userStream,
    );
  }

但是此StreamBuilder在传递流时未返回任何内容:

Navigator.pushReplacement(
  context,
  MaterialPageRoute(
    builder: (BuildContext context) =>
      WaitForSubmissions(
        userStream: userStream,
     ),
  ),
);

什么也没回来。我发现该流没有数据。但是,为什么即使在通过流时也没有数据?

Blank scaffold is returned

0 个答案:

没有答案