简体   繁体   English

运行flutter应用程序时出错

[英]Error while running flutter app

This is the error message which I am getting:这是我收到的错误消息:

Please do look at it below is my code:请看下面是我的代码:

  void main(){
  runApp(HomePage());
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage("assets/dotbg.jpg"),
              fit: BoxFit.cover,
            ),
          ),
          child: Row(
            children: <Widget>[
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[
                    Text(
                      'Welcome!',
                      style: TextStyle(
                          fontSize: 30.0,
                          color: Colors.black,
                          fontWeight: FontWeight.bold),
                    ),
                    Container(height: 10.0),
                    RaisedButton(
                        padding: EdgeInsets.symmetric(
                            horizontal: 50.0, vertical: 15.0),
                        textColor: Colors.black,
                        child: Text(
                          'Play Online',
                          style: TextStyle(
                            fontSize: 20.0,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        onPressed: () {
                    },
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(50.0))),
                    Container(
                      height: 30.0,
                    ),
                    RaisedButton(
                        padding: EdgeInsets.symmetric(
                            horizontal: 50.0, vertical: 15.0),
                        textColor: Colors.black,
                        child: Text(
                          'Play Offline',
                          style: TextStyle(
                            fontSize: 20.0,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        onPressed: () {
                          Navigator.push(context, MaterialPageRoute(builder:(context)=> OfflinePage()),);
                        },
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(50.0))),
                    Container(height: 70.0),
                    Text(
                      'Copyright@2019 DotsNBoxes',
                      style: TextStyle(fontSize: 20.0),
                    ),
                  ],
                ),
              )
            ],
          )),
    );
  }
}

This problem is solved by adding MaterialApp :这个问题通过添加 MaterialApp 来解决:


void main()
runApp(
  MaterialApp(home: HomePage()),
);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM