title: How to change background color of Elevated Button in Flutter from function?
body: <p>I am new to Flutter, I started Flutter last week, And now I want to make a simple Xylophone app. I created the UI successfully and made a function <code>playSound(int soundNumber)</code> but when I call this function for playing sound, it gives me this error.</p>
  <pre><code>**The following _TypeError was thrown building Body(dirty, state: _BodyState#051c2):
  type '_MaterialStatePropertyAll&lt;dynamic&gt;' is not a subtype of type 'MaterialStateProperty&lt;Color?&gt;?'**
  </code></pre>
  <p>Here's the code I wrote for <code>playSound(int soundNumber)</code> function.</p>
  <pre><code>void playSound(int soundNumber) {
  final player = AudioCache();
  player.play('note$soundNumber.wav');}
  
  Expanded buildPlayButton({MaterialStateProperty color, int soundNumber}){
  return Expanded(
    child: ElevatedButton(
      onPressed: () {
        playSound(soundNumber);
      },
      style: ButtonStyle(
        backgroundColor: color,
      ),
    ),
  );}
  </code></pre>
  <p>Here is the point where I am calling this function.</p>
  <pre><code>Widget build(BuildContext context) {
  return Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    children: &lt;Widget&gt;[
      buildPlayButton(color: MaterialStateProperty.all(Colors.red), soundNumber: 1),
      buildPlayButton(color: MaterialStateProperty.all(Colors.orangeAccent), soundNumber: 2),
      buildPlayButton(color: MaterialStateProperty.all(Colors.yellow), soundNumber: 3),
      buildPlayButton(color: MaterialStateProperty.all(Colors.indigo), soundNumber: 4),
      buildPlayButton(color: MaterialStateProperty.all(Colors.blue), soundNumber: 5),
      buildPlayButton(color: MaterialStateProperty.all(Colors.lightGreenAccent), soundNumber: 6),
      buildPlayButton(color: MaterialStateProperty.all(Colors.green), soundNumber: 7),
    ],
  );
  }
  </code></pre>
  <p>How to call this function because it gives me the above-mentioned error?</p>