import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
void main() => runApp(const CustomXylophoneApp());
class CustomXylophoneApp extends StatelessWidget {
const CustomXylophoneApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body:
SafeArea(
child: Column(
children: <Widget>[
TextButton(
onPressed: () {
AudioCache player = AudioCache();
player.play('assets_note1.wav');
TextButton.styleFrom(foregroundColor: Colors.red);
},
),
TextButton(
onPressed: () {
AudioCache player = AudioCache();
player.play('assets_note2.wav');
TextButton.styleFrom(foregroundColor: Colors.blue);
},
),
TextButton(
onPressed: () {
AudioCache player = AudioCache();
player.play('assets_note3.wav');
TextButton.styleFrom(foregroundColor: Colors.blueGrey);
},
),
TextButton(
onPressed: () {
AudioCache player = AudioCache();
player.play('assets_note4.wav');
TextButton.styleFrom(foregroundColor: Colors.green);
},
),
TextButton(
onPressed: () {
AudioCache player = AudioCache();
player.play('assets_note5.wav');
TextButton.styleFrom(foregroundColor: Colors.teal);
},
),
TextButton(
onPressed: () {
AudioCache player = AudioCache();
player.play('assets_note6.wav');
TextButton.styleFrom(foregroundColor: Colors.blueAccent);
},
),
TextButton(
onPressed: () {
AudioCache player = AudioCache();
player.play('assets_note7.wav');
TextButton.styleFrom(foregroundColor: Colors.pink);
},
),
],
),
),
),
);
}
}
Asked
Active
Viewed 23 times
1

Md. Yeasin Sheikh
- 54,221
- 7
- 29
- 56

Jishnu Vijayan
- 9
- 2
2 Answers
1
You need to call child
for each TextButton
like I am using Text widget on it
TextButton(
onPressed: () {
AudioCache player = AudioCache();
player.play('assets_note1.wav');
TextButton.styleFrom(foregroundColor: Colors.red);
},
child: Text("Button Name"), //this
),
More about TextButton

Md. Yeasin Sheikh
- 54,221
- 7
- 29
- 56
0
add child property in TextButton like this
TextButton(
child: Text("Play"),
onPressed: () {
AudioCache player = AudioCache();
player.play('assets_note2.wav');
TextButton.styleFrom(foregroundColor: Colors.blue);
},
),

Prem Danej
- 11
- 1
-
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – mohammad mobasher Oct 19 '22 at 08:02