0

我在实现以下代码时收到错误消息:“期望一个方法、getter、setter 或运算符声明”。

它包括提供者、消费者和 StreamBuilder。下面的实现有什么我做错了吗?我已经检查过,我相信我包括了上述所有错误状态。

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    final _width = MediaQuery.of(context).size.width;
    final _height = MediaQuery.of(context).size.height;
    return Consumer<UserModel>(
        builder: (context, userModel, child) {
    return StreamBuilder<DocumentSnapshot>(
        stream: Firestore.instance
            .collection(Provider.of<UserModel>(context).uid)
            .document(Provider.of<UserModel>(context).uid)
            .snapshots(),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
             return Stack(
              children: <Widget>[
                new Container(
                  color: Colors.blue,
                ),
                new Image.network(
                  snapshot.data['photourl'].toString(),
                  fit: BoxFit.fill,
                ),
                new BackdropFilter(
                    filter: new ui.ImageFilter.blur(
                      sigmaX: 6.0,
                      sigmaY: 6.0,
                    ),
                    child: new Container(
                      decoration: BoxDecoration(
                        color: Colors.blue.withOpacity(0.9),
                        borderRadius: BorderRadius.all(Radius.circular(50.0)),
                      ),
                    )),
                new Scaffold(
                    appBar: new AppBar(
                      title: new Text(widget.title),
                      centerTitle: false,
                      elevation: 0.0,
                      backgroundColor: Colors.transparent,
                    ),
                    drawer: new Drawer(
                      child: new Container(),
                    ),
                    backgroundColor: Colors.transparent,
                    body: new Center(
                      child: new Column(
                        children: <Widget>[
                          new SizedBox(
                            height: _height / 12,
                          ),
                          new CircleAvatar(
                            radius: _width < _height ? _width / 4 : _height / 4,
                            backgroundImage: NetworkImage(snapshot.data['photourl']),
                          ),
                          new SizedBox(
                            height: _height / 25.0,
                          ),
                          new Text(
                            snapshot.data['name'],
                            style: new TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: _width / 15,
                                color: Colors.white),
                          ),
                          new Padding(
                            padding: new EdgeInsets.only(
                                top: _height / 30,
                                left: _width / 8,
                                right: _width / 8),
                          ),
                          new Divider(
                            height: _height / 15,
                            color: Colors.white,
                          ),
                          new Row(
                            children: <Widget>[
                              rowCell(
                                  snapshot.data['totalquestions'], 'Answers'),
                              rowCell(
                                  '£ ${int.parse(snapshot.data['totalquestions']) * 2}', 'Earned'),
                            ],
                          ),
                          new Divider(
                              height: _height / 15, color: Colors.white),
                        ],
                      ),
                    ),
                ),
          ],
                    );
          );
            }
          );
        } else {
            return CircularProgressIndicator();
          }
        });
  }
4

1 回答 1

1

我不确定我是否正确地得到了你。试试这个代码。

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    final _width = MediaQuery.of(context).size.width;
    final _height = MediaQuery.of(context).size.height;
    return Consumer<UserModel>(builder: (context, userModel, child) {
      return StreamBuilder<DocumentSnapshot>(
        stream: Firestore.instance.collection(Provider.of<UserModel>(context).uid).document(Provider.of<UserModel>(context).uid).snapshots(),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return Stack(
              children: <Widget>[
                new Container(
                  color: Colors.blue,
                ),
                new Image.network(
                  snapshot.data['photourl'].toString(),
                  fit: BoxFit.fill,
                ),
                new BackdropFilter(
                    filter: new ui.ImageFilter.blur(
                      sigmaX: 6.0,
                      sigmaY: 6.0,
                    ),
                    child: new Container(
                      decoration: BoxDecoration(
                        color: Colors.blue.withOpacity(0.9),
                        borderRadius: BorderRadius.all(Radius.circular(50.0)),
                      ),
                    )),
                new Scaffold(
                  appBar: new AppBar(
                    title: new Text(widget.title),
                    centerTitle: false,
                    elevation: 0.0,
                    backgroundColor: Colors.transparent,
                  ),
                  drawer: new Drawer(
                    child: new Container(),
                  ),
                  backgroundColor: Colors.transparent,
                  body: new Center(
                    child: new Column(
                      children: <Widget>[
                        new SizedBox(
                          height: _height / 12,
                        ),
                        new CircleAvatar(
                          radius: _width < _height ? _width / 4 : _height / 4,
                          backgroundImage: NetworkImage(snapshot.data['photourl']),
                        ),
                        new SizedBox(
                          height: _height / 25.0,
                        ),
                        new Text(
                          snapshot.data['name'],
                          style: new TextStyle(fontWeight: FontWeight.bold, fontSize: _width / 15, color: Colors.white),
                        ),
                        new Padding(
                          padding: new EdgeInsets.only(top: _height / 30, left: _width / 8, right: _width / 8),
                        ),
                        new Divider(
                          height: _height / 15,
                          color: Colors.white,
                        ),
                        new Row(
                          children: <Widget>[
                            rowCell(snapshot.data['totalquestions'], 'Answers'),
                            rowCell('£ ${int.parse(snapshot.data['totalquestions']) * 2}', 'Earned'),
                          ],
                        ),
                        new Divider(height: _height / 15, color: Colors.white),
                      ],
                    ),
                  ),
                ),
              ],
            );
          } else {
            return CircularProgressIndicator();
          }
        },
      );
    });
  }
}
于 2019-09-14T16:30:28.787 回答