From e0c1f80e152f474994ca96aef256815fab1f0acc Mon Sep 17 00:00:00 2001 From: Athanasios Papapzoglou Date: Wed, 22 Sep 2021 14:53:31 +0300 Subject: [PATCH 1/4] personal try --- .flutter-plugins-dependencies | 1 + ios/Flutter/flutter_export_environment.sh | 14 ++++ lib/main.dart | 99 ++++++++++++++++++++++- pubspec.yaml | 1 + 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 .flutter-plugins-dependencies create mode 100644 ios/Flutter/flutter_export_environment.sh diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies new file mode 100644 index 00000000..2e9c608b --- /dev/null +++ b/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"audioplayers","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\audioplayers-0.10.1\\\\","dependencies":["path_provider"]},{"name":"path_provider","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]}],"android":[{"name":"audioplayers","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\audioplayers-0.10.1\\\\","dependencies":["path_provider"]},{"name":"path_provider","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"audioplayers","dependencies":["path_provider"]},{"name":"path_provider","dependencies":[]}],"date_created":"2021-09-22 14:18:16.437580","version":"2.2.3"} \ No newline at end of file diff --git a/ios/Flutter/flutter_export_environment.sh b/ios/Flutter/flutter_export_environment.sh new file mode 100644 index 00000000..94441f37 --- /dev/null +++ b/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=C:\Users\grjur\Documents\development\sdks\flutter" +export "FLUTTER_APPLICATION_PATH=C:\Users\grjur\Documents\development\projects\xylophone-flutter" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" +export "FLUTTER_TARGET=lib\main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build\ios" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=false" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.packages" diff --git a/lib/main.dart b/lib/main.dart index 28fea9ce..e8524cf1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:audioplayers/audio_cache.dart'; void main() => runApp(XylophoneApp()); @@ -8,7 +9,103 @@ class XylophoneApp extends StatelessWidget { return MaterialApp( home: Scaffold( body: SafeArea( - child: Container(), + child: Center( + child: Column( + children: [ + Expanded( + child: Container( + width: double.infinity, + child: FlatButton( + color: Colors.red, + onPressed: () { + final player = AudioCache(); + player.play('note1.wav'); + }, + child: Text('C'), + ), + ), + ), + Expanded( + child: Container( + width: double.infinity, + child: FlatButton( + color: Colors.orange, + onPressed: () { + final player = AudioCache(); + player.play('note2.wav'); + }, + child: Text('D'), + ), + ), + ), + Expanded( + child: Container( + width: double.infinity, + child: FlatButton( + color: Colors.yellow, + onPressed: () { + final player = AudioCache(); + player.play('note3.wav'); + }, + child: Text('E'), + ), + ), + ), + Expanded( + child: Container( + width: double.infinity, + child: FlatButton( + color: Colors.green, + onPressed: () { + final player = AudioCache(); + player.play('note4.wav'); + }, + child: Text('F'), + ), + ), + ), + Expanded( + child: Container( + width: double.infinity, + child: FlatButton( + color: Colors.teal, + onPressed: () { + final player = AudioCache(); + player.play('note5.wav'); + }, + child: Text('G'), + ), + ), + ), + Expanded( + child: Container( + width: double.infinity, + child: FlatButton( + color: Colors.blue, + onPressed: () { + final player = AudioCache(); + player.play('note6.wav'); + }, + child: Text('A'), + ), + ), + ), + Expanded( + child: Container( + width: double.infinity, + child: FlatButton( + color: Colors.purple, + onPressed: () { + final player = AudioCache(); + player.play('note7.wav'); + }, + child: Text('B'), + ), + ), + ), + ], + ), + ), ), ), ); diff --git a/pubspec.yaml b/pubspec.yaml index 92b60bfb..331a88f6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: sdk: flutter cupertino_icons: ^0.1.2 + audioplayers: ^0.10.0 dev_dependencies: flutter_test: From 0b260acdf61af64a56f92352c611e866c52b2e9d Mon Sep 17 00:00:00 2001 From: Athanasios Papapzoglou Date: Wed, 22 Sep 2021 18:44:29 +0300 Subject: [PATCH 2/4] refactoring with functions --- .flutter-plugins-dependencies | 2 +- lib/main.dart | 72 +++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 2e9c608b..bc37e860 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"audioplayers","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\audioplayers-0.10.1\\\\","dependencies":["path_provider"]},{"name":"path_provider","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]}],"android":[{"name":"audioplayers","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\audioplayers-0.10.1\\\\","dependencies":["path_provider"]},{"name":"path_provider","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"audioplayers","dependencies":["path_provider"]},{"name":"path_provider","dependencies":[]}],"date_created":"2021-09-22 14:18:16.437580","version":"2.2.3"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"audioplayers","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\audioplayers-0.10.1\\\\","dependencies":["path_provider"]},{"name":"path_provider","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]}],"android":[{"name":"audioplayers","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\audioplayers-0.10.1\\\\","dependencies":["path_provider"]},{"name":"path_provider","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"audioplayers","dependencies":["path_provider"]},{"name":"path_provider","dependencies":[]}],"date_created":"2021-09-22 17:39:55.968548","version":"2.2.3"} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index e8524cf1..18f1013b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,9 +4,18 @@ import 'package:audioplayers/audio_cache.dart'; void main() => runApp(XylophoneApp()); class XylophoneApp extends StatelessWidget { + + void playSound(int noteCode) { + + final player = AudioCache(); + player.play('note$noteCode.wav'); + + } + @override Widget build(BuildContext context) { return MaterialApp( + debugShowCheckedModeBanner: false, home: Scaffold( body: SafeArea( child: Center( @@ -18,10 +27,13 @@ class XylophoneApp extends StatelessWidget { child: FlatButton( color: Colors.red, onPressed: () { - final player = AudioCache(); - player.play('note1.wav'); + playSound(1); }, - child: Text('C'), + child: Text('C', + style: TextStyle( + color: Colors.black, + fontSize: 30 + ),), ), ), ), @@ -31,10 +43,13 @@ class XylophoneApp extends StatelessWidget { child: FlatButton( color: Colors.orange, onPressed: () { - final player = AudioCache(); - player.play('note2.wav'); + playSound(2); }, - child: Text('D'), + child: Text('D', + style: TextStyle( + color: Colors.black, + fontSize: 30 + ),), ), ), ), @@ -44,10 +59,13 @@ class XylophoneApp extends StatelessWidget { child: FlatButton( color: Colors.yellow, onPressed: () { - final player = AudioCache(); - player.play('note3.wav'); + playSound(3); }, - child: Text('E'), + child: Text('E', + style: TextStyle( + color: Colors.black, + fontSize: 30 + ),), ), ), ), @@ -57,10 +75,13 @@ class XylophoneApp extends StatelessWidget { child: FlatButton( color: Colors.green, onPressed: () { - final player = AudioCache(); - player.play('note4.wav'); + playSound(4); }, - child: Text('F'), + child: Text('F', + style: TextStyle( + color: Colors.black, + fontSize: 30 + ),), ), ), ), @@ -70,10 +91,13 @@ class XylophoneApp extends StatelessWidget { child: FlatButton( color: Colors.teal, onPressed: () { - final player = AudioCache(); - player.play('note5.wav'); + playSound(5); }, - child: Text('G'), + child: Text('G', + style: TextStyle( + color: Colors.black, + fontSize: 30 + ),), ), ), ), @@ -83,10 +107,13 @@ class XylophoneApp extends StatelessWidget { child: FlatButton( color: Colors.blue, onPressed: () { - final player = AudioCache(); - player.play('note6.wav'); + playSound(6); }, - child: Text('A'), + child: Text('A', + style: TextStyle( + color: Colors.black, + fontSize: 30 + ),), ), ), ), @@ -96,10 +123,13 @@ class XylophoneApp extends StatelessWidget { child: FlatButton( color: Colors.purple, onPressed: () { - final player = AudioCache(); - player.play('note7.wav'); + playSound(7); }, - child: Text('B'), + child: Text('B', + style: TextStyle( + color: Colors.black, + fontSize: 30 + ),), ), ), ), From 9af262e23fd1e8cc6138d8e8dae92ceeefcbaa5d Mon Sep 17 00:00:00 2001 From: Athanasios Papapzoglou Date: Wed, 22 Sep 2021 19:06:21 +0300 Subject: [PATCH 3/4] dev init --- lib/main.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/main.dart b/lib/main.dart index 18f1013b..e881957b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,6 +12,7 @@ class XylophoneApp extends StatelessWidget { } + @override Widget build(BuildContext context) { return MaterialApp( From 95c88f87432caed3fe6ac7233c790087c98641c4 Mon Sep 17 00:00:00 2001 From: Athanasios Papapzoglou Date: Wed, 22 Sep 2021 19:40:31 +0300 Subject: [PATCH 4/4] full refactored --- .flutter-plugins-dependencies | 2 +- lib/main.dart | 139 +++++++--------------------------- 2 files changed, 28 insertions(+), 113 deletions(-) diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index bc37e860..1b0f101b 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"audioplayers","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\audioplayers-0.10.1\\\\","dependencies":["path_provider"]},{"name":"path_provider","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]}],"android":[{"name":"audioplayers","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\audioplayers-0.10.1\\\\","dependencies":["path_provider"]},{"name":"path_provider","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"audioplayers","dependencies":["path_provider"]},{"name":"path_provider","dependencies":[]}],"date_created":"2021-09-22 17:39:55.968548","version":"2.2.3"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"audioplayers","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\audioplayers-0.10.1\\\\","dependencies":["path_provider"]},{"name":"path_provider","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]}],"android":[{"name":"audioplayers","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\audioplayers-0.10.1\\\\","dependencies":["path_provider"]},{"name":"path_provider","path":"C:\\\\Users\\\\grjur\\\\Documents\\\\development\\\\sdks\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.5.0+1\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"audioplayers","dependencies":["path_provider"]},{"name":"path_provider","dependencies":[]}],"date_created":"2021-09-22 19:28:05.321601","version":"2.2.3"} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index e881957b..0250bab3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,6 +12,26 @@ class XylophoneApp extends StatelessWidget { } + Expanded produceKeyNote(Color noteColor, String letter, int noteNo) { + return Expanded( + child: Container( + width: double.infinity, + child: FlatButton( + color: noteColor, + onPressed: () { + playSound(noteNo); + }, + child: Text(letter, + style: TextStyle( + color: Colors.black, + fontSize: 30 + ), + ), + ), + ), + ); + } + @override Widget build(BuildContext context) { @@ -22,118 +42,13 @@ class XylophoneApp extends StatelessWidget { child: Center( child: Column( children: [ - Expanded( - child: Container( - width: double.infinity, - child: FlatButton( - color: Colors.red, - onPressed: () { - playSound(1); - }, - child: Text('C', - style: TextStyle( - color: Colors.black, - fontSize: 30 - ),), - ), - ), - ), - Expanded( - child: Container( - width: double.infinity, - child: FlatButton( - color: Colors.orange, - onPressed: () { - playSound(2); - }, - child: Text('D', - style: TextStyle( - color: Colors.black, - fontSize: 30 - ),), - ), - ), - ), - Expanded( - child: Container( - width: double.infinity, - child: FlatButton( - color: Colors.yellow, - onPressed: () { - playSound(3); - }, - child: Text('E', - style: TextStyle( - color: Colors.black, - fontSize: 30 - ),), - ), - ), - ), - Expanded( - child: Container( - width: double.infinity, - child: FlatButton( - color: Colors.green, - onPressed: () { - playSound(4); - }, - child: Text('F', - style: TextStyle( - color: Colors.black, - fontSize: 30 - ),), - ), - ), - ), - Expanded( - child: Container( - width: double.infinity, - child: FlatButton( - color: Colors.teal, - onPressed: () { - playSound(5); - }, - child: Text('G', - style: TextStyle( - color: Colors.black, - fontSize: 30 - ),), - ), - ), - ), - Expanded( - child: Container( - width: double.infinity, - child: FlatButton( - color: Colors.blue, - onPressed: () { - playSound(6); - }, - child: Text('A', - style: TextStyle( - color: Colors.black, - fontSize: 30 - ),), - ), - ), - ), - Expanded( - child: Container( - width: double.infinity, - child: FlatButton( - color: Colors.purple, - onPressed: () { - playSound(7); - }, - child: Text('B', - style: TextStyle( - color: Colors.black, - fontSize: 30 - ),), - ), - ), - ), + produceKeyNote(Colors.red,'C', 1), + produceKeyNote(Colors.orange,'D', 2), + produceKeyNote(Colors.yellow,'E', 3), + produceKeyNote(Colors.green,'F', 4), + produceKeyNote(Colors.teal,'G', 5), + produceKeyNote(Colors.blue,'A', 6), + produceKeyNote(Colors.purple,'B', 7), ], ), ),