Error: no named parameter with the name 'color' Flutter
958
You can style ElevatedButton by using the styleFrom
ElevatedButton(
child: const Text('Button'),
onPressed: () {},
style: ElevatedButton.styleFrom(
primary: Colors.purple,
),
or you can use ButtonStyle class
ElevatedButton(
child: const Text('Button'),
onPressed: () {},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.red),
),
Author by
BInaryBard2020
Updated on January 04, 2023Comments
-
BInaryBard2020 over 1 year
So I'm new to Dart & Flutter and have run across a problem. I'm trying to learn the layout and make subtle UI changes to text & button widgets. Here I'm trying to change the color of the
ElevatedButton
toblue
import 'package:flutter/material.dart'; class Answer extends StatelessWidget { @override Widget build(BuildContext context) { return Container( width: double.infinity, child: ElevatedButton( color: Colors.blue, child: Text('Answer 1'), onPressed: null, ), ); } }
When I run the code I get this error:
Error: no named parameter with the name 'color'
I thought with buttons there were color parameters that you could change. What would be the correct way of implementing this?