import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';
// Xylophone 실로폰
void main() => runApp(Xylophone());
class Xylophone extends StatelessWidget {
final AudioCache audioPlayer = AudioCache();
final List<String> text = [' ', '도', '레', '미', '파', '솔', '라', '시'];
void playSound(int number) {
audioPlayer.play('note$number.wav');
}
Expanded buildKey({int num, Color color}) {
return Expanded(
// tap 키를 누르면 hold 된 것이 해제된다.
child: FlatButton(
child: Text(
text[num],
style: TextStyle(fontSize: 30.0),
),
onPressed: () {
playSound(num);
},
color: color),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
// ctrl+w 코드블럭, alt+shift+클릭
buildKey(num: 1, color: Colors.red),
buildKey(num: 2, color: Colors.orange),
buildKey(num: 3, color: Colors.yellow),
buildKey(num: 4, color: Colors.green),
buildKey(num: 5, color: Colors.teal),
buildKey(num: 6, color: Colors.blue),
buildKey(num: 7, color: Colors.purple),
],
),
),
),
);
}
}