Reputation: 11
How to fix this error Too many positional arguments: 2 allowed, but 3 found. Try removing the extra positional arguments. const AndroidNotificationChannel channel = AndroidNotificationChannel(
Found this candidate, but the arguments don't match. Thank you for your help............................................
const AndroidNotificationChannel channel = AndroidNotificationChannel(
'high_importance_channel',
"High Importance Notifications",
"This channel is used for important notifications",
importance: Importance.high,
playSound: true);
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
print("A Message Just Showed Up : ${message.messageId} ");
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
try {
await Firebase.initializeApp();
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
await FirebaseMessaging.instance
.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
await setupLocator();
runApp(Phoenix(child: MyApp()));
} catch (error) {
print('Locator setup has failed! ' + error.toString());
}
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;
if (notification != null && android != null) {
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
channel.description,
color: Colors.green,
playSound: true,
icon: '@mipmap/ic_launcher',
),
),
);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print("A new message");
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;
if (notification != null && android != null) {
showDialog(
context: context,
builder: (_) {
return AlertDialog(
title: Text(notification.title!),
content: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [Text(notification.body!)],
)),
);
});
}
});
} ```
Upvotes: 1
Views: 1555
Reputation: 742
The constructor looks like this:
const AndroidNotificationChannel({
@required this.id,
@required this.name,
@required this.description,
this.importance = AndroidNotificationChannelImportance.HIGH,
this.vibratePattern = AndroidVibratePatterns.DEFAULT,
});
The parameters are named so you need to do something like this:
const AndroidNotificationChannel channel = AndroidNotificationChannel(
id:'high_importance_channel',
name: "High Importance Notifications",
description: "This channel is used for important notifications",
importance: Importance.high,
playSound: true);
Upvotes: 1