I have this code below which plays a sound every time I hit a button.
AudioPlayer player = AudioPlayer();
Future<void> playSound({required String soundStr}) async {
player.setAsset(soundStr);
player.play();
}
But whenever I hit the button fast, sometimes it will show this error. How can I eliminate this error? I tried adding player.stop(); but it still the same.
E/flutter ( 4312): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(abort, Loading interrupted, null, null)
E/flutter ( 4312): #0 AudioPlayer._setPlatformActive.checkInterruption (package:just_audio/just_audio.dart:1236:7)
E/flutter ( 4312): #1 AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1347:11)
E/flutter ( 4312): <asynchronous suspension>
E/flutter ( 4312):
E/flutter ( 4312): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(abort, Loading interrupted, null, null)
E/flutter ( 4312):
Edit: I tried adding await.
Future<void> playSound({required String soundStr}) async {
await player.setAsset(soundStr);
await player.play();
}
If I hit the buttons fast, it will still have error. Though it is now different.
E/flutter (21654): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Connection aborted
E/flutter (21654): #0 AudioPlayer._load (package:just_audio/just_audio.dart:843:11)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654): #1 AudioPlayer.load (package:just_audio/just_audio.dart:770:14)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654): #2 AudioPlayer.setAudioSource (package:just_audio/just_audio.dart:745:18)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654): #3 playSound (package:super_pinoy_quiz/common/generic_methods.dart:396:3)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654):
I'm using this package: just_audio: ^0.9.29
Though I tried using different package but it also encounters the same error when hitting the button fast: audioplayers: ^1.1.1
Both setAsset and play are future method, you can await for setting assets
Future<void> playSound({required String soundStr}) async {
await player.setAsset(soundStr);
await player.play();
}
I have my flutter App integrated with firebase, everything was fine but after i integrate firebase i got error whenever I try to run my app.
My main method looks like this:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(child: MyApp());
}
Error:
E/flutter ( 7922): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception:
PlatformException(firebase_core, FirebaseApp name [DEFAULT] already exists!, null, null)
E/flutter ( 7922): #0 StandardMethodCodec.decodeEnvelope
(package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 7922): #1 MethodChannel._invokeMethod
(package:flutter/src/services/platform_channel.dart:177:18)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #2 MethodChannel.invokeMapMethod
(package:flutter/src/services/platform_channel.dart:377:43)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #3 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:100:40)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #4 Firebase.initializeApp
(package:firebase_core/src/firebase.dart:40:31)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #5 main (package:zunada/main.dart:11:3)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922):
I had similar issue when create firebase app by flavors using flutterfire CLI. I realized that flutterfire create apps with same name in different projects. Then I tried 2 ways and it works.
1st: manually change app name in each firebase project.
2nd: add param name when initialize such as in main_dev.dart
Example:
await Firebase.initializeApp(
name: "dev-project",
options: DefaultFirebaseOptions.currentPlatform);
I used the same name used in the firebase console as my project ID for consistency, keep in mind that you cannot add spaces to the name (only dashes -).
hoping someone is able to help me with this error i keep getting. I am using async - await method to call the function "drawPolylinefrompickuptodestination", but i keep getting this error..
[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0
E/flutter ( 7629): #0 List.[] (dart:core-patch/growable_array.dart:264:36)
E/flutter ( 7629): #1 AssistantMethods.pickupToDestinationDirections (package:parcel_you_driver_app/assistant/assistant_methods.dart:52:70)
E/flutter ( 7629): <asynchronous suspension>
E/flutter ( 7629): #2 _NewTripScreenState.drawPolylineFromPickupToDestination (package:parcel_you_driver_app/mainScreens/new_trip_screen.dart:395:33)
E/flutter ( 7629): <asynchronous suspension>
E/flutter ( 7629): #3 _NewTripScreenState.build.<anonymous closure> (package:parcel_you_driver_app/mainScreens/new_trip_screen.dart:252:29)
E/flutter ( 7629): <asynchronous suspension>
I have a query function for data from the database that comes with the id number from the database, then the id is saved in shared_preferences in case the new id that comes from the database is larger than the old id that was in the shared_preferences previously.But after running the code, the following problem comes:
E/flutter (30884): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: Class 'String' has no instance method '<'.
E/flutter (30884): Receiver: ""
E/flutter (30884): Tried calling: <(7)
E/flutter (30884): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (30884): #1 AddCommentsState.getLogin.<anonymous closure> (package:flutter_apptestqeuriy/AddComment.dart:84:46)
E/flutter (30884): #2 State.setState (package:flutter/src/widgets/framework.dart:1240:30)
E/flutter (30884): #3 AddCommentsState.getLogin (package:flutter_apptestqeuriy/AddComment.dart:78:5)
E/flutter (30884): <asynchronous suspension>
E/flutter (30884): #4 AddCommentsState.initState.<anonymous closure> (package:flutter_apptestqeuriy/AddComment.dart:57:9)
E/flutter (30884): #5 interval.function (package:flutter_apptestqeuriy/AddComment.dart:21:9)
E/flutter (30884): #6 _rootRun (dart:async/zone.dart:1182:47)
E/flutter (30884): #7 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (30884): #8 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (30884): #9 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter (30884): #10 _rootRun (dart:async/zone.dart:1190:13)
E/flutter (30884): #11 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (30884): #12 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
E/flutter (30884): #13 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (30884): #14 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter (30884): #15 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter (30884): #16 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (30884):
This is the code used to query from the database:
var user_id;
var my_pre_id;
Future<String> getLogin() async {
var response = await http.get(Uri.encodeFull("http://xxxxxxxxxxx/Application.php"),);
setState(() {
var convertDataToJson = json.decode(response.body);
data = convertDataToJson['result'];
if (data != null) {
user_id = int.parse(data[0]['id']);
my_pre_id = _myPreferences.id;
if (my_pre_id == null || my_pre_id < user_id ){
_myPreferences.id = user_id;
_myPreferences.commit();
// print("tappeeeeedddd $my_pre_id");
}
}
});
}
Does anyone know the cause of the problem?
I think the issue comes from my_pre_id < user_id where my_pre_id is actually a String. You might want to do an int.parse() on it as well or change its type in the class.
I'm parsing json from server and display it on screen. That is work when i parsing from localhost, but when i parsing from hosting there is an error like this
I/flutter (18089): [{"id":10,"reservation":"497538","order":"900000025301","equipment":"F6U-EA112","matcode":"6166357","description":"GASKET:2JKT;HE2;1302X1342X3MM;NASB\/CS","q_need":"1","q_available":"0","q_debt":"0","unit":"EA","location":"","required_date":null,"created_at":null,"updated_at":null},{"id":11,"reservation":"497538","order":"900000025301","equipment":"F6U-EA112","matcode":"6166345","description":"GASKET:2JKT;HE1;1302X1342X3MM;NASB\/CS","q_need":"1","q_available":"1","q_debt":"0","unit":"EA","location":"GD AUTOMOTIVE","required_date":null,"created_at":null,"updated_at":null},{"id":27,"reservation":"497566","order":"900000025329","equipment":"F6U-FA112","matcode":"6166298","description":"GASKET,SPW:IOR;24IN;150LB;GR;304\/304\/CS","q_need":"1","q_available":"0","q_debt":"0","unit":"EA","location":"GD AUTOMOTIVE","required_date":null,"created_at":null,"updated_at":null}]
E/flutter (18089): [ERROR:flutter/runtime/dart_isolate.cc(717)] Isolate (398792005) 'main.dart:_spawn()' exited with an error
E/flutter (18089): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (18089): type 'String' is not a subtype of type 'int'
E/flutter (18089): #0 new Matl.fromJson (package:tams/model/material.dart:49:26)
E/flutter (18089): #1 parseMatl.<anonymous closure> (package:tams/services/material.dart:22:42)
E/flutter (18089): #2 MappedListIterable.elementAt (dart:_internal/iterable.dart:414:29)
E/flutter (18089): #3 ListIterable.toList (dart:_internal/iterable.dart:219:19)
E/flutter (18089): #4 parseMatl (package:tams/services/material.dart:22:58)
E/flutter (18089): #5 _IsolateConfiguration.apply (package:flutter/src/foundation/isolates.dart:88:16)
E/flutter (18089): #6 _spawn.<anonymous closure> (package:flutter/src/foundation/isolates.dart:96:30)
E/flutter (18089): #7 Timeline.timeSync (dart:developer/timeline.dart:168:22)
E/flutter (18089): #8 _spawn (package:flutter/src/foundation/isolates.dart:93:12)
E/flutter (18089): #9 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:292:17)
E/flutter (18089): #10 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
thanks.
i found it.
it because there is different json response from localhost and shared host
localhost
[{"id":10,"reservation":497538,"order":900000025301,"equipment":"F6U-EA112","matcode":6166357,"description":"GASKET:2JKT;HE2;1302X1342X3MM;NASB\/CS","q_need":1,"q_available":0,"q_debt":0,"unit":"EA","location":"","required_date":null,"created_at":null,"updated_at":null},{"id":11,"reservation":497538,"order":900000025301,"equipment":"F6U-EA112","matcode":6166345,"description":"GASKET:2JKT;HE1;1302X1342X3MM;NASB\/CS","q_need":1,"q_available":1,"q_debt":0,"unit":"EA","location":"GD AUTOMOTIVE","required_date":null,"created_at":null,"updated_at":null},{"id":27,"reservation":497566,"order":900000025329,"equipment":"F6U-FA112","matcode":6166298,"description":"GASKET,SPW:IOR;24IN;150LB;GR;304\/304\/CS","q_need":1,"q_available":0,"q_debt":0,"unit":"EA","location":"GD AUTOMOTIVE","required_date":null,"created_at":null,"updated_at":null}]
shared host
[{"id":10,"reservation":"497538","order":"900000025301","equipment":"F6U-EA112","matcode":"6166357","description":"GASKET:2JKT;HE2;1302X1342X3MM;NASB\/CS","q_need":"1","q_available":"0","q_debt":"0","unit":"EA","location":"","required_date":null,"created_at":null,"updated_at":null},{"id":11,"reservation":"497538","order":"900000025301","equipment":"F6U-EA112","matcode":"6166345","description":"GASKET:2JKT;HE1;1302X1342X3MM;NASB\/CS","q_need":"1","q_available":"1","q_debt":"0","unit":"EA","location":"GD AUTOMOTIVE","required_date":null,"created_at":null,"updated_at":null},{"id":27,"reservation":"497566","order":"900000025329","equipment":"F6U-FA112","matcode":"6166298","description":"GASKET,SPW:IOR;24IN;150LB;GR;304\/304\/CS","q_need":"1","q_available":"0","q_debt":"0","unit":"EA","location":"GD AUTOMOTIVE","required_date":null,"created_at":null,"updated_at":null}]