Created
March 13, 2020 22:00
-
-
Save emlanis/0477682b42b0db7ebb809c5fd02766ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:audioplayers/audio_cache.dart'; | |
| void main() => runApp(XylophoneApp()); | |
| class XylophoneApp extends StatelessWidget { | |
| void playSound(int soundNumber) { | |
| final player = AudioCache(); | |
| player.play('note$soundNumber.wav'); | |
| } | |
| Expanded buildKey({Color color, int soundNumber}) { | |
| return Expanded( | |
| child: FlatButton( | |
| color: color, | |
| onPressed: () { | |
| playSound(soundNumber); | |
| }, | |
| ), | |
| ); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| home: Scaffold( | |
| backgroundColor: Colors.black, | |
| appBar: AppBar( | |
| backgroundColor: Colors.black, | |
| title: Text('Xylophone'), | |
| ), | |
| body: SafeArea( | |
| child: Column( | |
| crossAxisAlignment: CrossAxisAlignment.stretch, | |
| children: <Widget>[ | |
| buildKey(color: Colors.indigo, soundNumber: 1), | |
| buildKey(color: Colors.blue, soundNumber: 2), | |
| buildKey(color: Colors.greenAccent, soundNumber: 3), | |
| buildKey(color: Colors.amber, soundNumber: 4), | |
| buildKey(color: Colors.brown, soundNumber: 5), | |
| buildKey(color: Colors.deepPurpleAccent, soundNumber: 6), | |
| buildKey(color: Colors.brown, soundNumber: 7), | |
| ], | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment