Created
June 23, 2019 09:33
-
-
Save ryanlid/357bd928938cf70d9b14fc8bdb894b10 to your computer and use it in GitHub Desktop.
Xylophone
- Flutter Functions
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 { | |
static AudioCache player = AudioCache(); | |
void playAudio(int audioNumber) { | |
player.play('note$audioNumber.wav'); | |
} | |
Expanded audioExpanded({color: Color, audioNumber: int}) { | |
return Expanded( | |
child: FlatButton( | |
color: color, | |
onPressed: () { | |
playAudio(audioNumber); | |
}, | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
body: SafeArea( | |
child: Column( | |
mainAxisSize: MainAxisSize.max, | |
mainAxisAlignment: MainAxisAlignment.end, | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: <Widget>[ | |
audioExpanded(color: Colors.purpleAccent, audioNumber: 1), | |
audioExpanded(color: Colors.redAccent, audioNumber: 2), | |
audioExpanded(color: Colors.orange, audioNumber: 3), | |
audioExpanded(color: Colors.yellow, audioNumber: 4), | |
audioExpanded(color: Colors.lightGreen, audioNumber: 5), | |
audioExpanded(color: Colors.green, audioNumber: 6), | |
audioExpanded(color: Colors.teal, audioNumber: 7), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/londonappbrewery/xylophone-flutter