无效常量 value.dart(invalid_constant)

Invalid constant value.dart(invalid_constant)

在下面的代码中,我在“controller: urlController”这一行得到了错误

      var url;
      final urlController = TextEditingController();
    
      @override
      void dispose() {
        urlController.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            backgroundColor: const Color(0xff16352A),
            title: const Text(
              'Downloader',
              style: TextStyle(color: Color(0xffEDAB24)),
            ),
          ),
          body: Container(
            padding: const EdgeInsets.all(20.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                const SizedBox(height: 50.0),
                const TextField(
                  controller: urlController,
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: 'Paste URL',
                  ),
                ),
            

const SizedBox(height: 20.0),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                TextButton(
                  onPressed: () {},
                  child: const Text(
                    'Download',
                    style: TextStyle(fontSize: 30.0),
                  ),
                  style: TextButton.styleFrom(
                    primary: Colors.white,
                    backgroundColor: const Color(0xff284635),
                  ),
                ),
                const SizedBox(width: 20.0),
                TextButton(
                  onPressed: () {
                    setState(() {
                      url = urlController.text;
                    });
                  },
                  child: const Text(
                    'Clear',
                    style: TextStyle(fontSize: 30.0),
                  ),
                  style: TextButton.styleFrom(
                    primary: Colors.white,
                    backgroundColor: const Color(0xff284635),
                  ),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}

只需删除TextField

前面的const值
          TextField(
                  controller: urlController,
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: 'Paste URL',
                  ),
            )