I'm trying to create a function where under buildKey I can input two elements, the background color and the soundNumber so that when buildKey is called I can enter say buildKey(red, 2) or buildKey(colName: red, soundNumber: 2) etc.
The soundNumber element works however no matter what I try I can't get a valid background color input to work.
Any help hugely appreciated.
class _MyHomePageState extends State<MyHomePage> {
void playSound(int noteNumber) {
AssetsAudioPlayer.newPlayer().open(
Audio("/assets/note$noteNumber.wav"),
);
}
Expanded buildKey({required MaterialColor color, required int soundNumber}) {
return Expanded(
child: TextButton(
style: TextButton.styleFrom(
backgroundColor: color,
),
onPressed: () {
playSound(soundNumber);
},
child: const Text(''),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildKey(color: MaterialStateProperty.all(Colors.red), soundNumber: 1),
],
),
),
);
}
}