Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Created June 23, 2019 09:33
Show Gist options
  • Save ryanlid/357bd928938cf70d9b14fc8bdb894b10 to your computer and use it in GitHub Desktop.
Save ryanlid/357bd928938cf70d9b14fc8bdb894b10 to your computer and use it in GitHub Desktop.
Xylophone - Flutter Functions
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),
],
),
),
),
);
}
}
@ryanlid
Copy link
Author

ryanlid commented Jun 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment