Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/allisto/allisto-app
Browse files Browse the repository at this point in the history
  • Loading branch information
rshrc committed Mar 9, 2019
2 parents cce3a04 + 8d1863f commit 6b9c17d
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 31 deletions.
6 changes: 3 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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"));
}
Expand Down
2 changes: 2 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
1 change: 1 addition & 0 deletions assets/animations/Voice.json
Original file line number Diff line number Diff line change
@@ -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}]}
2 changes: 2 additions & 0 deletions ios/Runner/GeneratedPluginRegistrant.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "GeneratedPluginRegistrant.h"
#import <audio_recorder2/AudioRecorder2Plugin.h>
#import <flutter_webview_plugin/FlutterWebviewPlugin.h>
#import <fluttie/FluttiePlugin.h>
#import <path_provider/PathProviderPlugin.h>
#import <simple_permissions/SimplePermissionsPlugin.h>

Expand All @@ -13,6 +14,7 @@ @implementation GeneratedPluginRegistrant
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)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"]];
}
Expand Down
8 changes: 4 additions & 4 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 35 additions & 1 deletion lib/pages/microphone_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

class Microphone extends StatefulWidget{

@override
State<StatefulWidget> createState() {
return MicrophonePage();
Expand All @@ -16,8 +17,13 @@ class Microphone extends StatefulWidget{
class MicrophonePage extends State<Microphone> {
bool isRecording;
String recordingMessage;

// int emojiComposition;
// FluttieAnimationController emojiAnimation;

@override
void initState() {
// animation();
recordingMessage = "Getting Ready";
record();
super.initState();
Expand Down Expand Up @@ -48,6 +54,9 @@ class MicrophonePage extends State<Microphone> {
),
),
),
// Padding(
// padding: EdgeInsets.all(8.0),
// child: FluttieAnimation(emojiAnimation),),
Padding(
padding: EdgeInsets.only(bottom: 60.0),
child: FloatingActionButton(
Expand All @@ -58,6 +67,8 @@ class MicrophonePage extends State<Microphone> {
setState(() {
recordingMessage = "Finishing up";
});
// if (emojiAnimation != null)
// emojiAnimation.stopAndReset(rewind: true);
AudioRecorder2.stop().then((recording) {
if (recording != null) {
setState(() {
Expand All @@ -66,7 +77,8 @@ class MicrophonePage extends State<Microphone> {
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 {
Expand All @@ -93,25 +105,47 @@ class MicrophonePage extends State<Microphone> {
}
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);
// }
}
32 changes: 22 additions & 10 deletions lib/utils/upload_audio_to_server.dart
Original file line number Diff line number Diff line change
@@ -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(
<String, dynamic>{
"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()));
}
24 changes: 12 additions & 12 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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"
Loading

0 comments on commit 6b9c17d

Please sign in to comment.