ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • (플러터) 실로폰
    Coding/Flutter(수업) 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),
                ],
              ),
            ),
          ),
        );
      }
    }
    
    

    'Coding > Flutter(수업)' 카테고리의 다른 글

    다트 정리(기본)  (0) 2020.02.17

    댓글

Designed by Tistory.