diff --git a/android/app/build.gradle b/android/app/build.gradle index dc72854..1cf5cc3 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -38,7 +38,7 @@ android { targetSdkVersion 28 versionCode flutterVersionCode.toInteger() versionName flutterVersionName - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -56,6 +56,6 @@ flutter { dependencies { testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test:runner:1.1.0-alpha4' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' } diff --git a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java index 698b003..929ae98 100644 --- a/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java +++ b/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java @@ -3,6 +3,7 @@ import io.flutter.plugin.common.PluginRegistry; import audiorecorder2.audiorecorder2.AudioRecorder2Plugin; import com.flutter_webview_plugin.FlutterWebviewPlugin; +import de.simolus3.fluttie.FluttiePlugin; import io.flutter.plugins.pathprovider.PathProviderPlugin; import com.ethras.simplepermissions.SimplePermissionsPlugin; @@ -16,6 +17,7 @@ public static void registerWith(PluginRegistry registry) { } AudioRecorder2Plugin.registerWith(registry.registrarFor("audiorecorder2.audiorecorder2.AudioRecorder2Plugin")); FlutterWebviewPlugin.registerWith(registry.registrarFor("com.flutter_webview_plugin.FlutterWebviewPlugin")); + FluttiePlugin.registerWith(registry.registrarFor("de.simolus3.fluttie.FluttiePlugin")); PathProviderPlugin.registerWith(registry.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin")); SimplePermissionsPlugin.registerWith(registry.registrarFor("com.ethras.simplepermissions.SimplePermissionsPlugin")); } diff --git a/android/gradle.properties b/android/gradle.properties index 8bd86f6..53ae0ae 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1 +1,3 @@ +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536M diff --git a/assets/animations/Voice.json b/assets/animations/Voice.json new file mode 100644 index 0000000..508cc00 --- /dev/null +++ b/assets/animations/Voice.json @@ -0,0 +1 @@ +{"v":"4.6.9","fr":29.9700012207031,"ip":0,"op":90.0000036657751,"w":800,"h":600,"nm":"Voice Icon","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Bar1","ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":30,"s":[25],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":34,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":70,"s":[100],"e":[25]},{"t":75.0000030548126}]},"r":{"a":0,"k":0},"p":{"a":0,"k":[540,329.375,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[8,16]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect"},{"ty":"fl","c":{"a":0,"k":[0.1058824,0.1058824,0.1058824,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill"},{"ty":"tr","p":{"a":0,"k":[-178,-29.375],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group"}],"ip":0,"op":300.00001221925,"st":0,"bm":0,"sr":1},{"ddd":0,"ind":2,"ty":4,"nm":"Bar2","ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":30,"s":[25],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":34,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":70,"s":[100],"e":[25]},{"t":75.0000030548126}]},"r":{"a":0,"k":0},"p":{"a":0,"k":[559,329.375,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":1,"k":[{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":30,"s":[8,16],"e":[8,40]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":35,"s":[8,40],"e":[8,20]},{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":39,"s":[8,20],"e":[8,40]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":42,"s":[8,40],"e":[8,20]},{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":52,"s":[8,20],"e":[8,40]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":55,"s":[8,40],"e":[8,20]},{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":57,"s":[8,20],"e":[8,40]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":60,"s":[8,40],"e":[8,16]},{"t":70.0000028511585}]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect"},{"ty":"fl","c":{"a":0,"k":[0.1058824,0.1058824,0.1058824,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill"},{"ty":"tr","p":{"a":0,"k":[-178,-29.375],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group"}],"ip":0,"op":300.00001221925,"st":0,"bm":0,"sr":1},{"ddd":0,"ind":3,"ty":4,"nm":"Bar3","ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":30,"s":[25],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":34,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":70,"s":[100],"e":[25]},{"t":75.0000030548126}]},"r":{"a":0,"k":0},"p":{"a":0,"k":[578,329.375,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":1,"k":[{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":30,"s":[8,16],"e":[8,75]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":35,"s":[8,75],"e":[8,32]},{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":39,"s":[8,32],"e":[8,75]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":42,"s":[8,75],"e":[8,32]},{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":52,"s":[8,32],"e":[8,75]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":55,"s":[8,75],"e":[8,32]},{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":57,"s":[8,32],"e":[8,75]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":60,"s":[8,75],"e":[8,16]},{"t":70.0000028511585}]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect"},{"ty":"fl","c":{"a":0,"k":[0.1058824,0.1058824,0.1058824,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill"},{"ty":"tr","p":{"a":0,"k":[-178,-29.375],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group"}],"ip":0,"op":300.00001221925,"st":0,"bm":0,"sr":1},{"ddd":0,"ind":4,"ty":4,"nm":"Bar4","ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":30,"s":[25],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":34,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":70,"s":[100],"e":[25]},{"t":75.0000030548126}]},"r":{"a":0,"k":0},"p":{"a":0,"k":[597,329.375,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":1,"k":[{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":30,"s":[8,16],"e":[8,40]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":35,"s":[8,40],"e":[8,20]},{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":39,"s":[8,20],"e":[8,40]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":42,"s":[8,40],"e":[8,20]},{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":52,"s":[8,20],"e":[8,40]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":55,"s":[8,40],"e":[8,20]},{"i":{"x":[0,0],"y":[0,1]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0_0_0p167_0p167","0_1_0p167_0p167"],"t":57,"s":[8,20],"e":[8,40]},{"i":{"x":[0.833,0.833],"y":[0.833,0.833]},"o":{"x":[0.167,0.167],"y":[0.167,0.167]},"n":["0p833_0p833_0p167_0p167","0p833_0p833_0p167_0p167"],"t":60,"s":[8,40],"e":[8,16]},{"t":70.0000028511585}]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect"},{"ty":"fl","c":{"a":0,"k":[0.1058824,0.1058824,0.1058824,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill"},{"ty":"tr","p":{"a":0,"k":[-178,-29.375],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group"}],"ip":0,"op":300.00001221925,"st":0,"bm":0,"sr":1},{"ddd":0,"ind":5,"ty":4,"nm":"Bar5","ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":30,"s":[25],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":34,"s":[100],"e":[100]},{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"n":["0p833_0p833_0p167_0p167"],"t":70,"s":[100],"e":[25]},{"t":75.0000030548126}]},"r":{"a":0,"k":0},"p":{"a":0,"k":[616,329.375,0]},"a":{"a":0,"k":[0,0,0]},"s":{"a":0,"k":[100,100,100]}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[8,16]},"p":{"a":0,"k":[0,0]},"r":{"a":0,"k":0},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect"},{"ty":"fl","c":{"a":0,"k":[0.1058824,0.1058824,0.1058824,1]},"o":{"a":0,"k":100},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill"},{"ty":"tr","p":{"a":0,"k":[-178,-29.375],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group"}],"ip":0,"op":300.00001221925,"st":0,"bm":0,"sr":1}]} \ No newline at end of file diff --git a/ios/Runner/GeneratedPluginRegistrant.m b/ios/Runner/GeneratedPluginRegistrant.m index 9cdbafb..ff10f9c 100644 --- a/ios/Runner/GeneratedPluginRegistrant.m +++ b/ios/Runner/GeneratedPluginRegistrant.m @@ -5,6 +5,7 @@ #import "GeneratedPluginRegistrant.h" #import #import +#import #import #import @@ -13,6 +14,7 @@ @implementation GeneratedPluginRegistrant + (void)registerWithRegistry:(NSObject*)registry { [AudioRecorder2Plugin registerWithRegistrar:[registry registrarForPlugin:@"AudioRecorder2Plugin"]]; [FlutterWebviewPlugin registerWithRegistrar:[registry registrarForPlugin:@"FlutterWebviewPlugin"]]; + [FluttiePlugin registerWithRegistrar:[registry registrarForPlugin:@"FluttiePlugin"]]; [FLTPathProviderPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTPathProviderPlugin"]]; [SimplePermissionsPlugin registerWithRegistrar:[registry registrarForPlugin:@"SimplePermissionsPlugin"]]; } diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index c30a335..2c228e5 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -46,10 +46,10 @@ class HomePage extends StatelessWidget { await SimplePermissions.requestPermission( Permission.WriteExternalStorage); } - } - hasPermissions = await AudioRecorder2.hasPermissions; - if(hasPermissions) { - Navigator.of(context).pushNamed("/mic"); + hasPermissions = await AudioRecorder2.hasPermissions; + if (hasPermissions) { + Navigator.of(context).pushNamed("/mic"); + } } }, backgroundColor: Colors.deepPurpleAccent, diff --git a/lib/pages/microphone_page.dart b/lib/pages/microphone_page.dart index 32e991c..ad0e5da 100644 --- a/lib/pages/microphone_page.dart +++ b/lib/pages/microphone_page.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; class Microphone extends StatefulWidget{ + @override State createState() { return MicrophonePage(); @@ -16,8 +17,13 @@ class Microphone extends StatefulWidget{ class MicrophonePage extends State { bool isRecording; String recordingMessage; + +// int emojiComposition; +// FluttieAnimationController emojiAnimation; + @override void initState() { +// animation(); recordingMessage = "Getting Ready"; record(); super.initState(); @@ -48,6 +54,9 @@ class MicrophonePage extends State { ), ), ), +// Padding( +// padding: EdgeInsets.all(8.0), +// child: FluttieAnimation(emojiAnimation),), Padding( padding: EdgeInsets.only(bottom: 60.0), child: FloatingActionButton( @@ -58,6 +67,8 @@ class MicrophonePage extends State { setState(() { recordingMessage = "Finishing up"; }); +// if (emojiAnimation != null) +// emojiAnimation.stopAndReset(rewind: true); AudioRecorder2.stop().then((recording) { if (recording != null) { setState(() { @@ -66,7 +77,8 @@ class MicrophonePage extends State { print("Path : ${recording.path}, Format : ${recording .audioOutputFormat}, Duration : ${recording .duration}, Extension : ${recording.extension},"); - readAudioFile(recording.path, "API URL HERE"); + readAudioFile(recording.path, + "https://projectallisto.pythonanywhere.com/api/v1"); Navigator.of(context).pop(); } else { @@ -93,25 +105,47 @@ class MicrophonePage extends State { } Future record() async { isRecording = await AudioRecorder2.isRecording; + if(!isRecording) { final path = (await getApplicationDocumentsDirectory()).path; + File file = new File("$path/Recording.m4a"); if (file != null && await file.exists()) await file.delete(); + AudioRecorder2.start( path: "$path/Recording", audioOutputFormat: AudioOutputFormat.AAC) .whenComplete(() { setState(() { recordingMessage = "Recording"; }); +// print("Recording starting"); +// if (emojiAnimation != null) +// emojiAnimation.start(); print("Recording started"); + }) + .catchError((Object error) { + print(error); + setState(() { + recordingMessage = "Something went wrong recording this."; + }); }); + } else { print("Already recording"); setState(() { +// emojiAnimation.stopAndReset(rewind: true); recordingMessage = "Something is wrong. Try restarting the app"; }); } } + +// Future animation() async { +// var instance = Fluttie(); +// emojiComposition = await instance.loadAnimationFromAsset( +// "assets/animations/voice.json",); +// //Replace this string with your actual file +// emojiAnimation = await instance.prepareAnimation(emojiComposition); +// } } diff --git a/lib/utils/upload_audio_to_server.dart b/lib/utils/upload_audio_to_server.dart index c4ba438..0746622 100644 --- a/lib/utils/upload_audio_to_server.dart +++ b/lib/utils/upload_audio_to_server.dart @@ -1,25 +1,37 @@ import 'dart:io'; + import 'package:dio/dio.dart'; -import 'package:http/http.dart' as http; import 'package:path/path.dart'; void readAudioFile(String filePath, String apiUrl) async { var config = File(filePath); var audioFile = await config.readAsBytes(); - File _audioFile = new File(filePath); // TODO + File _audioFile = new File(filePath); + print(audioFile.toString()); + print(_audioFile); Dio dio = Dio(); - FormData formData = FormData(); // just like JS - formData.add("audio", UploadFileInfo(_audioFile, basename(filePath))); - dio - .post( - apiUrl, + FormData formData = new FormData.from( + { + "audio_file": UploadFileInfo(_audioFile, basename(filePath)) + }); + print("Form data : " + formData.keys.toString()); + dio.options.baseUrl = apiUrl; + dio.post("/audio/", data: formData, options: Options( method: 'POST', + connectTimeout: 10000, + contentType: ContentType.parse("application/json"), + receiveDataWhenStatusError: true, + receiveTimeout: 10000, responseType: ResponseType.json // or ResponseType.JSON ), - ) - .then((response) => print(response)) - .catchError((error) => print(error)); + onSendProgress: (received, total) { + if (total != -1) { + print((received / total * 100).toStringAsFixed(0) + "%"); + } + },) + .then((response) => print("Response: " + response.toString())) + .catchError((error) => print("Error : " + error.toString())); } diff --git a/pubspec.lock b/pubspec.lock index 0d63c7f..ecadaae 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -56,7 +56,7 @@ packages: name: dio url: "https://pub.dartlang.org" source: hosted - version: "2.0.15" + version: "2.0.20" file: dependency: transitive description: @@ -81,6 +81,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.3.0+2" + fluttie: + dependency: "direct main" + description: + name: fluttie + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.1" http: dependency: "direct main" description: @@ -130,13 +137,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.1" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.0" quiver: dependency: transitive description: @@ -162,7 +162,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.4" + version: "1.4.1" stack_trace: dependency: transitive description: @@ -190,14 +190,14 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.0.1" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.2" + version: "0.2.1" typed_data: dependency: transitive description: @@ -220,5 +220,5 @@ packages: source: hosted version: "0.0.8" sdks: - dart: ">=2.1.0 <3.0.0" + dart: ">=2.0.0 <3.0.0" flutter: ">=0.1.4 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 4a19cfe..8df3286 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ description: A new Flutter project. # Both the version and the builder number may be overridden in flutter # build by specifying --build-name and --build-number, respectively. # Read more about versioning at semver.org. -version: 1.0.0+1 +version: 0.8.0+800 environment: @@ -30,6 +30,8 @@ dependencies: simple_permissions: ^0.1.9 + fluttie: ^0.3.0 + dev_dependencies: flutter_test: sdk: flutter