Home > Software engineering >  Invalid constant value.dart(invalid_constant)
Invalid constant value.dart(invalid_constant)

Time:09-28

in the bellow code I got the error on " controller: urlController," this line

      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),
                  ),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}

CodePudding user response:

Just remove const value in front of TextField

          TextField(
                  controller: urlController,
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: 'Paste URL',
                  ),
            )
  • Related