Google Mobile Ads Throwing MissingPluginException - flutter

RewardedAd doesn't work on google_mobile_ads: 2.0.1
I've already searched everywhere and the fixes don't work.
This is the Error on The Logs.
E/DartMessenger( 5002): Uncaught exception in binary message listener
E/DartMessenger( 5002): java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
E/DartMessenger( 5002): at io.flutter.plugins.googlemobileads.AdMessageCodec.readValueOfType(AdMessageCodec.java:231)
E/DartMessenger( 5002): at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:340)
E/DartMessenger( 5002): at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:434)
E/DartMessenger( 5002): at io.flutter.plugins.googlemobileads.AdMessageCodec.readValueOfType(AdMessageCodec.java:319)
E/DartMessenger( 5002): at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:340)
E/DartMessenger( 5002): at io.flutter.plugin.common.StandardMethodCodec.decodeMethodCall(StandardMethodCodec.java:51)
E/DartMessenger( 5002): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:260)
E/DartMessenger( 5002): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/DartMessenger( 5002): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319)
E/DartMessenger( 5002): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/DartMessenger( 5002): at android.os.Handler.handleCallback(Handler.java:883)
E/DartMessenger( 5002): at android.os.Handler.dispatchMessage(Handler.java:100)
E/DartMessenger( 5002): at android.os.Looper.loop(Looper.java:237)
E/DartMessenger( 5002): at android.app.ActivityThread.main(ActivityThread.java:7830)
E/DartMessenger( 5002): at java.lang.reflect.Method.invoke(Native Method)
E/DartMessenger( 5002): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/DartMessenger( 5002): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1040)
E/flutter ( 5002): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method loadRewardedAd on channel plugins.flutter.io/google_mobile_ads)
E/flutter ( 5002): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7)
E/flutter ( 5002): <asynchronous suspension>
E/flutter ( 5002): #1 RewardedAd.load (package:google_mobile_ads/src/ad_containers.dart:1154:5)
E/flutter ( 5002): <asynchronous suspension>
E/flutter ( 5002):
I already Ad this code on MainActivity
override fun configureFlutterEngine(#NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
I made sure also to put this on build.gradle
implementation 'com.google.android.gms:play-services-ads:21.1.0'
I also add this to manifest file
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
This is my implementation
I added this on my main
final initFuture = MobileAds.instance.initialize();
final adState = AdState(initFuture);
And Created another File for AdState
static String get rewardedAdUnitId {
if (Platform.isAndroid) {
return "ca-app-pub-3940256099942544/5224354917";
} else if (Platform.isIOS) {
return "ca-app-pub-3940256099942544/1712485313";
} else {
throw new UnsupportedError("Unsupported platform");
}
}
Future initialization;
AdState(this.initialization);
On my Implementation
void loadRewardedAd(BuildContext context) {
RewardedAd.load(
adUnitId: AdState.rewardedAdUnitId,
request: const AdRequest(),
rewardedAdLoadCallback:
RewardedAdLoadCallback(onAdLoaded: (ad) {
ad.show(
onUserEarnedReward: (ad,rewardPoints){
CommonTools.showMessage(context, 'Energy Received : ');
}
);
ad.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (ad){
},
onAdFailedToShowFullScreenContent: (ad,error){
CommonTools.showMessage(context, 'Ads Not Available For Now');
ad.dispose();
},
onAdDismissedFullScreenContent: (ad){
CommonTools.showMessage(context, 'Ads Not Available For Now');
ad.dispose();
}
);
}, onAdFailedToLoad: (er) {
CommonTools.showMessage(context, 'Ads Not Available For Now');
}));
}

After making this issue traumatize me I managed to make it work. What I did is wrap everything in MaterialApp and put routes on my main Widget.
runApp(
MaterialApp(
routes: <String, WidgetBuilder>{
'/': (BuildContext context) => MyApp()
},
),
);
As for how this works, I don't know how it fix everything but it might help you if you encounter this issue.

The above Main Activity code is for kotlin. Make sure your Main Activity is also in Kotlin.

Related

simple push notification but its not working and its throwing an error

im trying to display a push notification by clicking a text button but then it throws this error i tried to search but couldnt fix it, i tried reinstalling the app and also restarted the app multiple times
E/flutter ( 8853): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter ( 8853): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 8853): at android.os.Looper.loop(Looper.java:223)
E/flutter ( 8853): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/flutter ( 8853): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 8853): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter ( 8853): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter ( 8853): )
E/flutter ( 8853): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:653
E/flutter ( 8853): #1 MethodChannel.\_invokeMethod
package:flutter/…/services/platform_channel.dart:296
E/flutter ( 8853): \<asynchronous suspension\>
E/flutter ( 8853): #2 FlutterLocalNotificationsPlugin.show
package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:234
E/flutter ( 8853): \<asynchronous suspension\>
E/flutter ( 8853):
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class NotificationApi {
static final _notification = FlutterLocalNotificationsPlugin();
static Future _notificationDetails() async {
return const NotificationDetails(
android: AndroidNotificationDetails(
'channel id'
'channel name',
'channel description',
importance: Importance.high,
),
iOS: DarwinNotificationDetails(),
);
}
static Future showNotification({
int id = 0,
String? title,
String? body,
String? payload,
}) async =>
_notification.show(id, title, body, await _notificationDetails(),
payload: payload);
}
flutter_local_notifications: ^12.0.3+1

java.lang.NoClassDefFoundError: de.mintware.barcode_scan.Protos$Configuration

i'm trying to develop an app and adding a barcode scanner to track the the food eaten, but every time i run i've got the errors from barcode:scan:
E/flutter ( 5352): Caused by: java.lang.NoClassDefFoundError: de.mintware.barcode_scan.Protos$Configuration
E/flutter ( 5352):de.mintware.barcode_scan.ChannelHandler.onMethodCall(ChannelHandler.kt:111)
E/flutter ( 5352): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter ( 5352): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/flutter ( 5352): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:320)
E/flutter ( 5352): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter ( 5352): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter ( 5352): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 5352): at android.os.Looper.loopOnce(Looper.java:201)
E/flutter ( 5352): at android.os.Looper.loop(Looper.java:288)
E/flutter ( 5352): at android.app.ActivityThread.main(ActivityThread.java:7842)
E/flutter ( 5352): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 5352): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/flutter ( 5352): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/flutter ( 5352): Caused by: java.lang.NoClassDefFoundError: de.mintware.barcode_scan.Protos$Configuration
E/flutter ( 5352): at de.mintware.barcode_scan.Protos$Configuration.newBuilder(Protos.java:1357)
E/flutter ( 5352): at de.mintware.barcode_scan.ChannelHandler.scan(ChannelHandler.kt:27)
my android/build.gradle is:
buildscript {
ext.kotlin_version = '1.6.20'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.android.tools.build:gradle:7.3.0-alpha04'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.13"
classpath 'com.android.tools.build:gradle:4.3.8'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Let me know how can i fix it

Flutter app fail when download PDF from webhosting

We have education app created with Flutter, this app very same to Udemy app features.
in this app the course may contain videos lectures of PDF files
all things working well except PDF downloading
The situation is:
when user click on PDF file name in lectures list, will open download page, it's contain only one button
when user click download button, download process start and download notification appear in notifications area
after few seconds notification show file link and failed message
I'm not sure what the problem here
Note that: the app was published on play & app store, and the PDF file download is fail in test mode and published versions.
the run log file for download process:
E/flutter (27102): #5 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
E/flutter (27102): #6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
E/flutter (27102): #7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (27102): #8 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
E/flutter (27102): #9 _StreamController._add (dart:async/stream_controller.dart:607:7)
E/flutter (27102): #10 _StreamController.add (dart:async/stream_controller.dart:554:5)
E/flutter (27102): #11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
E/flutter (27102):
D/DownloadWorker(27102): Content-Type = application/pdf
D/DownloadWorker(27102): Content-Length = 1165606
D/DownloadWorker(27102): Charset = null
D/DownloadWorker(27102): Content-Disposition = null
D/DownloadWorker(27102): fileName = 7339d9826c027c3facdf76b943e452eb.pdf
W/System.err(27102): java.io.IOException: Permission denied
W/System.err(27102): at java.io.UnixFileSystem.createFileExclusively0(Native Method)
W/System.err(27102): at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
W/System.err(27102): at java.io.File.createNewFile(File.java:1008)
W/System.err(27102): at vn.hunghd.flutterdownloader.DownloadWorker.createDownloadFileWithDirectFilePath(DownloadWorker.java:490)
W/System.err(27102): at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.java:393)
W/System.err(27102): at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.java:232)
W/System.err(27102): at androidx.work.Worker$1.run(Worker.java:86)
W/System.err(27102): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err(27102): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err(27102): at java.lang.Thread.run(Thread.java:919)
E/DownloadWorker(27102): Create a file using java.io API failed
D/DownloadWorker(27102): Update too frequently!!!!, but it is the final update, we should sleep a second to ensure the update call can be processed
E/flutter (27102): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: setState() called after dispose(): _MyCourseDownloadScreenState#6a6b6(lifecycle state: defunct, not mounted)
E/flutter (27102): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
E/flutter (27102): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
E/flutter (27102): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
E/flutter (27102): #0 State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1052:9)
E/flutter (27102): #1 State.setState (package:flutter/src/widgets/framework.dart:1087:6)
E/flutter (27102): #2 _MyCourseDownloadScreenState.initState.<anonymous closure> (package:connect/screens/my_course_download_screen.dart:43:7)
E/flutter (27102): #3 _rootRunUnary (dart:async/zone.dart:1444:13)
E/flutter (27102): #4 _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter (27102): #5 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
E/flutter (27102): #6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
E/flutter (27102): #7 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (27102): #8 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:733:19)
E/flutter (27102): #9 _StreamController._add (dart:async/stream_controller.dart:607:7)
E/flutter (27102): #10 _StreamController.add (dart:async/stream_controller.dart:554:5)
E/flutter (27102): #11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
E/flutter (27102):
D/Surface (27102): Surface::disconnect(this=0x701217d000,api=1)
D/View (27102): [Warning] assignParent to null: this = android.widget.FrameLayout{f9df83 V.E...... ......ID 0,0-376,125}
I/InputTransport(27102): Destroy ARC handle: 0x708af9a7c0
D/DownloadWorker(27102): Update notification: {notificationId: 3, title: https://connect-elearning.com/newVersion/uploads/lesson_files/7339d9826c027c3facdf76b943e452eb.pdf, status: 4, progress: -1}
W/System.err(27102): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getPath()' on a null object reference
W/System.err(27102): at vn.hunghd.flutterdownloader.DownloadWorker.downloadFile(DownloadWorker.java:394)
W/System.err(27102): at vn.hunghd.flutterdownloader.DownloadWorker.doWork(DownloadWorker.java:232)
W/System.err(27102): at androidx.work.Worker$1.run(Worker.java:86)
W/System.err(27102): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/System.err(27102): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err(27102): at java.lang.Thread.run(Thread.java:919)
I/WM-WorkerWrapper(27102): Worker result FAILURE for Work [ id=99a29ba5-9003-4ef4-9f19-9fda892a3c5b, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ]
download page code:
import 'dart:io';
import 'dart:isolate';
import 'dart:ui';
import 'package:connect/models/common_functions.dart';
import 'package:connect/widgets/app_bar_two.dart';
import 'package:file_utils/file_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import '../constants.dart';
class MyCourseDownloadScreen extends StatefulWidget {
static const routeName = '/my-download-screen';
#override
_MyCourseDownloadScreenState createState() => _MyCourseDownloadScreenState();
}
class _MyCourseDownloadScreenState extends State<MyCourseDownloadScreen> {
int progress = 0;
ReceivePort _receivePort = ReceivePort();
static downloadingCallback(id, status, progress) {
///Looking up for a send port
SendPort sendPort = IsolateNameServer.lookupPortByName("downloading");
///ssending the data
sendPort.send([id, status, progress]);
}
#override
void initState() {
super.initState();
IsolateNameServer.registerPortWithName(_receivePort.sendPort, "downloading");
///Listening for the data is coming other isolates
_receivePort.listen((message) {
progress = message[2];
setState(() {
progress = message[2];
});
print(progress);
});
FlutterDownloader.registerCallback(downloadingCallback);
}
#override
Widget build(BuildContext context) {
final selectedUrl = ModalRoute.of(context).settings.arguments as String;
return Scaffold(
appBar: CustomAppBarTwo(),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Download File", style: TextStyle(fontSize: 18),),
),
color: Colors.redAccent,
textColor: Colors.white,
onPressed: () async {
final status = await Permission.storage.request();
String externalDir = "";
if (status.isGranted) {
if (Platform.isAndroid) {
externalDir = "/sdcard/download/";
} else {
externalDir = (await getApplicationDocumentsDirectory()).path;
}
try {
FileUtils.mkdir([externalDir]);
final id = await FlutterDownloader.enqueue(
url: selectedUrl,
savedDir: externalDir,
// fileName: "download1234.pdf",
showNotification: true,
openFileFromNotification: true,
);
CommonFunctions.showSuccessToast("Downloading");
} catch(e){
print(e.getMessage());
CommonFunctions.showSuccessToast("Download Error");
}
} else {
print("Permission denied");
}
},
)
],
),
),
);
}
}

Why flutter local notifications give exceptions

I'm trying to send a notification with flutter on android using this dependency:
"flutter_local_notifications: ^9.0.1"
But it gives me this error when I click the button "test".
Anyone has an idea how can I solve it?
////////////////////////////////////////////////////////////////////////
In main.dart:
ElevatedButton(
onPressed: () => NotificationApi.showNotification(
title: 'Samira', body: 'Heyy theree !!!', payload: 'samira'),
child: Text("test"),
In notification.dart:
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class NotificationApi {
static final _notifications = FlutterLocalNotificationsPlugin();
static Future _notificationDetails() async {
return const NotificationDetails(
android: AndroidNotificationDetails(
'channel id',
'channel name',
channelDescription: 'channel description',
importance: Importance.max,
),
//iOS: IOSNotificationDetails(),
);
}
static Future showNotification({
int id = 0,
String? title,
String? body,
String? payload,
}) async =>
_notifications.show(
id,
title,
body,
await _notificationDetails(),
payload: payload,
);
}
The error in my console:
Performing hot reload...
Syncing files to device Android SDK built for x86...
Reloaded 1 of 1023 libraries in 426ms.
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): Failed to handle method call
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:238)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:180)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:793)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1056)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:949)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:872)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at android.os.MessageQueue.next(MessageQueue.java:323)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at android.os.Looper.loop(Looper.java:136)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at android.app.ActivityThread.main(ActivityThread.java:6077)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
E/MethodChannel#dexterous.com/flutter/local_notifications(15565): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
E/flutter (15565): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/flutter (15565): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:238)
E/flutter (15565): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:180)
E/flutter (15565): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:793)
E/flutter (15565): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1056)
E/flutter (15565): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:949)
E/flutter (15565): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter (15565): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
E/flutter (15565): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:872)
E/flutter (15565): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (15565): at android.os.MessageQueue.next(MessageQueue.java:323)
E/flutter (15565): at android.os.Looper.loop(Looper.java:136)
E/flutter (15565): at android.app.ActivityThread.main(ActivityThread.java:6077)
E/flutter (15565): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (15565): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
E/flutter (15565): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
E/flutter (15565): )
E/flutter (15565): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (15565): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter (15565): <asynchronous suspension>
E/flutter (15565): #2 FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:194:7)
E/flutter (15565): <asynchronous suspension>
E/flutter (15565):
You should add the notification icon properly. It solved my issue.
static Future _notificationDetails() async {
return const NotificationDetails(
android: AndroidNotificationDetails(
'channel id',
'channel name',
channelDescription: 'channel description',
importance: Importance.max,
icon: "ic_notification", //<-- Add this parameter
),
//iOS: IOSNotificationDetails(),
);
}

Can't play sound in Flutter Android using just_audio

So, I'm trying to have this sound from Flutter assets when I click the button. And I've tried many different packages by this moment and none of them seems to work for me.
I'm constantly getting this:
D/ViewRootImpl( 8796): enqueueInputEventMotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=582.0, y[0]=1570.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=48512196, downTime=48512196, deviceId=-1, source=0x1002, displayId=0 }
D/ViewRootImpl[MainActivity]( 8796): processMotionEvent MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=582.0, y[0]=1570.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=48512196, downTime=48512196, deviceId=-1, source=0x1002, displayId=0 }
D/ViewRootImpl[MainActivity]( 8796): dispatchPointerEvent handled=true, event=MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=582.0, y[0]=1570.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=48512196, downTime=48512196, deviceId=-1, source=0x1002, displayId=0 }
W/Choreographer( 8796): Frame time is 0.144734 ms in the future! Check that graphics HAL is generating vsync timestamps using the correct timebase.
D/ViewRootImpl[MainActivity]( 8796): processMotionEvent MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=582.0, y[0]=1570.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=48512312, downTime=48512196, deviceId=-1, source=0x1002, displayId=0 }
D/ViewRootImpl[MainActivity]( 8796): dispatchPointerEvent handled=true, event=MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=582.0, y[0]=1570.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=48512312, downTime=48512196, deviceId=-1, source=0x1002, displayId=0 }
I/ExoPlayerImpl( 8796): Init e31da6b [ExoPlayerLib/2.13.1] [RMX2025CN, RMX2025, realme, 30]
D/AudioManager( 8796): getStreamVolume packageName=com.example.dicee_v2_red, index=14, streamType=3
E/ExoPlayerImplInternal( 8796): Playback error
E/ExoPlayerImplInternal( 8796): com.google.android.exoplayer2.ExoPlaybackException: Source error
E/ExoPlayerImplInternal( 8796): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:579)
E/ExoPlayerImplInternal( 8796): at android.os.Handler.dispatchMessage(Handler.java:102)
E/ExoPlayerImplInternal( 8796): at android.os.Looper.loop(Looper.java:260)
E/ExoPlayerImplInternal( 8796): at android.os.HandlerThread.run(HandlerThread.java:67)
E/ExoPlayerImplInternal( 8796): Caused by: com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (Mp3Extractor, FlvExtractor, FlacExtractor, WavExtractor, FragmentedMp4Extractor, Mp4Extractor, AmrExtractor, PsExtractor, OggExtractor, TsExtractor, MatroskaExtractor, AdtsExtractor, Ac3Extractor, Ac4Extractor, JpegExtractor) could read the stream.
E/ExoPlayerImplInternal( 8796): at com.google.android.exoplayer2.source.BundledExtractorsAdapter.init(BundledExtractorsAdapter.java:92)
E/ExoPlayerImplInternal( 8796): at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1026)
E/ExoPlayerImplInternal( 8796): at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:415)
E/ExoPlayerImplInternal( 8796): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ExoPlayerImplInternal( 8796): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ExoPlayerImplInternal( 8796): at java.lang.Thread.run(Thread.java:923)
E/AudioPlayer( 8796): TYPE_SOURCE: None of the available extractors (Mp3Extractor, FlvExtractor, FlacExtractor, WavExtractor, FragmentedMp4Extractor, Mp4Extractor, AmrExtractor, PsExtractor, OggExtractor, TsExtractor, MatroskaExtractor, AdtsExtractor, Ac3Extractor, Ac4Extractor, JpegExtractor) could read the stream.
E/flutter ( 8796): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: (0) Source error
E/flutter ( 8796): #0 AudioPlayer._load (package:just_audio/just_audio.dart:716:9)
E/flutter ( 8796): <asynchronous suspension>
E/flutter ( 8796): #1 AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1096:28)
E/flutter ( 8796): <asynchronous suspension>
E/flutter ( 8796):
I/ExoPlayerImpl( 8796): Release e31da6b [ExoPlayerLib/2.13.1] [RMX2025CN, RMX2025, realme, 30] [goog.exo.core]
But when I load my app in Web, it works perfectly fine. Why?
My code:
import 'package:flutter/material.dart';
import 'dart:math';
import 'package:flutter/services.dart';
import 'package:just_audio/just_audio.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((_) {
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.red,
appBar: AppBar(
title: Text('Dicee'),
backgroundColor: Colors.blue.shade300,
),
body: NewDice(),
),
),
);
});
}
class NewDice extends StatefulWidget {
#override
_NewDiceState createState() => _NewDiceState();
}
class _NewDiceState extends State<NewDice> {
late AudioPlayer player;
#override
void initState() {
super.initState();
player = AudioPlayer();
}
#override
void dispose() {
player.dispose();
super.dispose();
}
int leftDiceNumber = 1;
int rightDiceNumber = 1;
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset('assets/dice$leftDiceNumber.png'),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.asset('assets/dice$rightDiceNumber.png'),
),
),
],
),
ElevatedButton(
onPressed: () async {
await player.setAsset('audio/roll.mp3');
player.play();
setState(() {
rightDiceNumber = Random().nextInt(6) + 1;
leftDiceNumber = Random().nextInt(6) + 1;
});
},
style: ElevatedButton.styleFrom(
primary: Colors.blue.shade300,
),
child: Text('Roll the dice!',
style: TextStyle(
fontSize: 18,
)),
),
],
);
}
}
Please help :)
I have also tried flutter_audio_player 0.1.2 and many other packages... none seems to work...
tried audiofileplayer 2.0.1, another bug now...
I/AudiofileplayerPlugin(11305): onMethodCall: method = load
I/AudiofileplayerPlugin(11305): onMethodCall: method = play
E/MethodChannel#audiofileplayer(11305): Failed to handle method call
E/MethodChannel#audiofileplayer(11305): java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.flutter.plugins.audiofileplayer.ManagedMediaPlayer.play(boolean, int)' on a null object reference
E/MethodChannel#audiofileplayer(11305): at com.google.flutter.plugins.audiofileplayer.AudiofileplayerPlugin.onMethodCall(AudiofileplayerPlugin.java:256)
E/MethodChannel#audiofileplayer(11305): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#audiofileplayer(11305): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#audiofileplayer(11305): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/MethodChannel#audiofileplayer(11305): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#audiofileplayer(11305): at android.os.MessageQueue.next(MessageQueue.java:335)
E/MethodChannel#audiofileplayer(11305): at android.os.Looper.loop(Looper.java:183)
E/MethodChannel#audiofileplayer(11305): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/MethodChannel#audiofileplayer(11305): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#audiofileplayer(11305): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/MethodChannel#audiofileplayer(11305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/DartMessenger(11305): Uncaught exception in binary message listener
E/DartMessenger(11305): java.lang.IllegalStateException: Reply already submitted
E/DartMessenger(11305): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:155)
E/DartMessenger(11305): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:253)
E/DartMessenger(11305): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/DartMessenger(11305): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/DartMessenger(11305): at android.os.MessageQueue.nativePollOnce(Native Method)
E/DartMessenger(11305): at android.os.MessageQueue.next(MessageQueue.java:335)
E/DartMessenger(11305): at android.os.Looper.loop(Looper.java:183)
E/DartMessenger(11305): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/DartMessenger(11305): at java.lang.reflect.Method.invoke(Native Method)
E/DartMessenger(11305): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/DartMessenger(11305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter (11305): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(AudioPluginError, Could not create ManagedMediaPlayer:flutter_assets/assets/audio/roll2.wav, null, null)
E/flutter (11305): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7)
E/flutter (11305): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
E/flutter (11305): <asynchronous suspension>
E/flutter (11305): #2 Audio._sendMethodCall (package:audiofileplayer/audiofileplayer.dart:751:7)
E/flutter (11305): <asynchronous suspension>
E/flutter (11305): #3 Audio._load (package:audiofileplayer/audiofileplayer.dart:433:7)
E/flutter (11305): <asynchronous suspension>
E/flutter (11305):
E/flutter (11305): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(AudioPluginError, Called play on an unloaded player: 8dbbdf54-e262-4c2a-af1c-e6cbff1ac399, null, null)
E/flutter (11305): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7)
E/flutter (11305): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
E/flutter (11305): <asynchronous suspension>
E/flutter (11305): #2 Audio._sendMethodCall (package:audiofileplayer/audiofileplayer.dart:751:7)
E/flutter (11305): <asynchronous suspension>
E/flutter (11305): #3 Audio._playNative (package:audiofileplayer/audiofileplayer.dart:661:7)
E/flutter (11305): <asynchronous suspension>
E/flutter (11305): #4 Audio._playHelper (package:audiofileplayer/audiofileplayer.dart:556:5)
E/flutter (11305): <asynchronous suspension>
E/flutter (11305): #5 Audio.play (package:audiofileplayer/audiofileplayer.dart:517:5)
E/flutter (11305): <asynchronous suspension>
E/flutter (11305):
I had this issue and it was due to a bad MP3 file (that apparently Chrome knows how to play but ExoPlayer does not). I verified this by swapping in a known good MP3: flutter.github.io/samples/game_template/assets/sfx/dsht1.mp3 .
Try replacing your file with that and see if it works.
just_audio package has some issues with some emulators. You can create another emulator and probably it will work.