被调用的构造函数不是 const 构造函数。尝试从构造函数调用中删除“const”,Flutter dart。怎么解决?

问题描述 投票:0回答:1

容器总是显示这样的错误

class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: Container( padding:  EdgeInsets.symmetric(vertical: 30), width: double.infinity, decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, colors: [ Color.fromARGB(255, 9, 106, 185), Color.fromARGB(255, 56, 145, 217), Color.fromARGB(255, 66, 161, 239), Color.fromARGB(255, 109, 179, 237) ] ) ), child: const Column( crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[ SizedBox(height: 80,), Padding( padding: EdgeInsets.all(20), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[ Text("Login", style: TextStyle(color: Colors.white, fontSize: 40),), SizedBox(height: 5,), Text("Welcome Back", style: TextStyle(color: Colors.white, fontSize: 18),) ], ),       ), Expanded( child: Container( decoration:  BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only(topLeft: Radius.circular(50), topRight: Radius.circular(50)) ), child: Padding( padding: EdgeInsets.all(20), child: Column( children: <Widget>[ Container( decoration: BoxDecoration( boxShadow:  [BoxShadow( color:  Color.fromARGB(255, 5, 97, 173), blurRadius: 20, offset: Offset(0,10) )] ), ) ], ), ), )); ], ) ), ); } }
而我已经删除了 const

flutter dart constructor containers
1个回答
0
投票

我修复了你的代码,看看吧

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
          padding:  EdgeInsets.symmetric(vertical: 30),
          width: double.infinity,
          decoration: const BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  colors: [
                    Color.fromARGB(255, 9, 106, 185),
                    Color.fromARGB(255, 56, 145, 217),
                    Color.fromARGB(255, 66, 161, 239),
                    Color.fromARGB(255, 109, 179, 237)
                  ]
              )
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
            SizedBox(height: 80,),
          Padding(
            padding: EdgeInsets.all(20),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text("Login", style: TextStyle(color: Colors.white, fontSize: 40),),
                SizedBox(height: 5,),
                Text("Welcome Back", style: TextStyle(color: Colors.white, fontSize: 18),)
              ],
            ),
          ),
          Expanded(
              child: Container(
                decoration:  BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(topLeft: Radius.circular(50), topRight: Radius.circular(50))
                ),
                child: Padding(
                  padding: EdgeInsets.all(20),
                  child: Column(
                    children: <Widget>[
                      Container(
                        decoration: BoxDecoration(
                            boxShadow:  [BoxShadow(
                                color:  Color.fromARGB(255, 5, 97, 173),
                                blurRadius: 20,
                                offset: Offset(0,10)
                            )]
                        ),
                      )
                    ],
                  ),
                ),
              )
          )
          ],
        )
    ),
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.