정리

(플러터) 실로폰

디벨로프로 2020. 2. 20. 09:22
반응형
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),
            ],
          ),
        ),
      ),
    );
  }
}

'정리' 카테고리의 다른 글

데이터베이스 실행 순서  (0) 2020.02.24
(flutter) 테마지정  (0) 2020.02.20
(flutter) MagicBall 만들기  (0) 2020.02.19
다트 정리(기본)  (0) 2020.02.17
JPA 시작하기  (0) 2020.02.16