MissingPluginException(No implementation found for method listen on channel notifications)
When i use to listen notification it send me this exception
Device: Android My Code is
import 'dart:async';
import 'package:notifications/notifications.dart';
import 'package:flutter/material.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:teledart/teledart.dart';
import 'package:teledart/telegram.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
initializeService();
runApp(MyApp());
}
Future<void> initializeService() async {
final service = FlutterBackgroundService();
await service.configure(
androidConfiguration: AndroidConfiguration(
// this will executed when app is in foreground or background in separated isolate
onStart: onStart,
// auto start service
autoStart: true,
isForegroundMode: true,
),
iosConfiguration: IosConfiguration(
// auto start service
autoStart: true,
// this will executed when app is in foreground in separated isolate
onForeground: onStart,
// you have to enable background fetch capability on xcode project
onBackground: onIosBackground,
),
);
}
// to ensure this executed
// run app from xcode, then from xcode menu, select Simulate Background Fetch
void onIosBackground() {
WidgetsFlutterBinding.ensureInitialized();
print('FLUTTER BACKGROUND FETCH');
}
void onStart() {
WidgetsFlutterBinding.ensureInitialized();
print('object');
final service = FlutterBackgroundService();
service.onDataReceived.listen((event) {
if (event!["action"] == "setAsForeground") {
service.setForegroundMode(true);
return;
}
if (event["action"] == "setAsBackground") {
service.setForegroundMode(false);
}
if (event["action"] == "stopService") {
service.stopBackgroundService();
}
});
final token = 'token';
void startListen(id, message) async {
print("START LISTENING");
var telegram = Telegram(token);
var event = Event((await telegram.getMe()).username!);
telegram.sendMessage(id, message).then((value) => print('Message sent'));
}
List<String> _log = [];
void Notification() async {
Notifications().notificationStream?.forEach((element) {
if (element.message != null) {
if (!_log.contains(element.message.toString())) {
if (element.title == "any app") {
if (element.message != "") {
_log.add(element.message.toString());
startListen(ch_id, element.message);
}
}
if (element.title == "any app") {
if (element.message != "") {
_log.add(element.message.toString());
startListen(ch_id, element.message);
}
}
if (element.title == "any app") {
if (element.message != "") {
startListen(ch_id, element.message);
}
}
if (element.title == "any app") {
if (element.message != "") {
_log.add(element.message.toString());
startListen(ch_id, element.message);
}
}
if (element.title == "any app") {
if (element.message != "") {
startListen(ch_id, element.message);
}
}
if (element.title == "any app") {
if (element.message != "") {
startListen(ch_id, element.message);
}
}
if (element.title == "any app") {
if (element.message != "") {
startListen(ch_id, element.message);
}
}
}
}
});
print(_log);
}
// bring to foreground
service.setForegroundMode(true);
Timer.periodic(Duration(seconds: 1), (timer) async {
Notification();
print('time');
if (!(await service.isServiceRunning())) timer.cancel();
service.setNotificationInfo(
title: "My App Service",
content: "Updated at ${DateTime.now()}",
);
service.sendData(
{"current_date": DateTime.now().toIso8601String()},
);
});
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String text = "Stop Service";
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Service App'),
),
body: Column(
children: [
StreamBuilder<Map<String, dynamic>?>(
stream: FlutterBackgroundService().onDataReceived,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
final data = snapshot.data!;
DateTime? date = DateTime.tryParse(data["current_date"]);
return Text(date.toString());
},
),
ElevatedButton(
child: Text("Foreground Mode"),
onPressed: () {
FlutterBackgroundService()
.sendData({"action": "setAsForeground"});
},
),
ElevatedButton(
child: Text("Background Mode"),
onPressed: () {
FlutterBackgroundService()
.sendData({"action": "setAsBackground"});
},
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
FlutterBackgroundService().sendData({
"hello": "world",
});
},
child: Icon(Icons.play_arrow),
),
),
);
}
I am Facing a problem after some time it give me

My Flutter doc -v is here
D:\Android Studio Projects\maseka>flutter pub get Running "flutter pub get" in maseka... 887ms
D:\Android Studio Projects\maseka>flutter doctor -v [√] Flutter (Channel stable, 2.8.1, on Microsoft Windows [Version 10.0.22000.376], locale en-US) • Flutter version 2.8.1 at C:\Users\Ubaid Bodla\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 77d935af4d (3 weeks ago), 2021-12-16 08:37:33 -0800 • Engine revision 890a5fca2e • Dart version 2.15.1
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0) • Android SDK at C:\Users\Ubaid Bodla\AppData\Local\Android\sdk • Platform android-32, build-tools 32.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) • All Android licenses accepted.
[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 2020.3) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
[√] VS Code (version 1.63.2) • VS Code at C:\Users\Ubaid Bodla\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.32.0
[√] Connected device (3 available) • M2007J20CG (mobile) • 229ff5e4 • android-arm64 • Android 11 (API 30) • Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.110 • Edge (web) • edge • web-javascript • Microsoft Edge 96.0.1054.62
• No issues found!
i too have same issue