Flutter错误:位置参数太多:允许2个,但找到3个.lib/main.dart:13尝试删除多余的位置参数



如何修复此错误位置参数太多:允许2个,但找到3个。请尝试删除多余的位置参数。const AndroidNotificationChannel channel=安卓通知通道(

找到了此候选者,但参数不匹配。感谢您的帮助。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

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!)],
)),
);
});
}
});
} ```

构造函数如下所示:

const AndroidNotificationChannel({
@required this.id,
@required this.name,
@required this.description,
this.importance = AndroidNotificationChannelImportance.HIGH,
this.vibratePattern = AndroidVibratePatterns.DEFAULT,
});

参数是命名的,所以你需要这样做:

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);

最新更新