Flutter 命名参数和 OneSignal 问题
Flutter named parameter and OneSignal issue
我正在开发一个基于 Flutter 2.2.3 构建的项目,但我更新了所有依赖项。此外,我还修复了许多错误,这些错误是将 flutter 从 2.2.3 升级到 2.5.2 的结果。现在我面临两个文件的问题。一个问题是 PersistentTabController,它对控制器、navBarHeight、onItemSelected、屏幕、项目等许多行表示 'The named parameter is not found'。好吧,我正在共享代码。左边完全是红色的。我该如何解决?
PersistentTabController(
controller: controller,
navBarHeight: MediaQuery.of(context).size.width > 768 ? 90 : 64,
onItemSelected: (item) {
int index = controller.index;
if (index == 0) {
setState(() {
appbarTitle = Languages.of(context).homeScreenTitle;
});
} else if (index == 1) {
setState(() {
appbarTitle = Languages.of(context).appointmentsScreenTitle;
});
} else if (index == 2) {
setState(() {
appbarTitle = Languages.of(context).favouriteScreenTitle;
});
} else if (index == 3) {
setState(() {
appbarTitle =
Languages.of(context).notificationsScreenTitle;
});
} else if (index == 4) {
setState(() {
appbarTitle = Languages.of(context).accountScreenTitle;
});
}
},
screens: _pages,
items: [
PersistentBottomNavBarItem(
icon: Icon(
Icons.home_outlined,
size: MediaQuery.of(context).size.width > 768 ? 40 : 24,
),
title: Languages.of(context).bottomNavHome,
activeColor: ColorConstants.primaryColor,
inactiveColor: ColorConstants.iconColor,
titleStyle: TextStyle(
fontSize:
MediaQuery.of(context).size.width > 768 ? 20 : 12)),
PersistentBottomNavBarItem(
icon: Icon(
Icons.calendar_today_outlined,
size: MediaQuery.of(context).size.width > 768 ? 40 : 24,
),
title: Languages.of(context).bottomNavAppointments,
activeColor: ColorConstants.primaryColor,
inactiveColor: ColorConstants.iconColor,
titleStyle: TextStyle(
fontSize:
MediaQuery.of(context).size.width > 768 ? 20 : 12)),
PersistentBottomNavBarItem(
icon: Icon(
Icons.favorite_border,
size: MediaQuery.of(context).size.width > 768 ? 40 : 24,
),
title: Languages.of(context).bottomNavFavourites,
activeColor: ColorConstants.primaryColor,
inactiveColor: ColorConstants.iconColor,
titleStyle: TextStyle(
fontSize:
MediaQuery.of(context).size.width > 768 ? 20 : 12)),
PersistentBottomNavBarItem(
icon: Icon(
Icons.notifications,
size: MediaQuery.of(context).size.width > 768 ? 40 : 24,
),
title: Languages.of(context).bottomNavNotifications,
activeColor: ColorConstants.primaryColor,
inactiveColor: ColorConstants.iconColor,
titleStyle: TextStyle(
fontSize:
MediaQuery.of(context).size.width > 768 ? 20 : 12)),
PersistentBottomNavBarItem(
icon: Icon(
Icons.person_outline,
size: MediaQuery.of(context).size.width > 768 ? 40 : 24,
),
title: Languages.of(context).bottomNavAccount,
activeColor: ColorConstants.primaryColor,
inactiveColor: ColorConstants.iconColor,
titleStyle: TextStyle(
fontSize:
MediaQuery.of(context).size.width > 768 ? 20 : 12)),
],
confineInSafeArea: true,
backgroundColor: Colors.white,
handleAndroidBackButtonPress: true,
resizeToAvoidBottomInset: true,
// This needs to be true if you want to move up the screen when keyboard appears.
stateManagement: false,
hideNavigationBarWhenKeyboardShows: true,
// Recommended to set 'resizeToAvoidBottomInset' as true while using this argument.
decoration: NavBarDecoration(
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(1.0),
colorBehindNavBar: Colors.black,
),
popAllScreensOnTapOfSelectedTab: true,
popActionScreens: PopActionScreensType.all,
itemAnimationProperties: ItemAnimationProperties(
// Navigation Bar's items animation properties.
duration: Duration(milliseconds: 200),
curve: Curves.ease,
),
screenTransitionAnimation: ScreenTransitionAnimation(
// Screen transition animation on change of selected tab.
animateTabTransition: true,
curve: Curves.ease,
duration: Duration(milliseconds: 200),
),
navBarStyle: NavBarStyle.style6,
),
同样在另一个文件中,我面临 OneSignal 问题,例如“未为类型 'OneSignal' 定义方法 setInFocusDisplayType 和”未为类型 'OneSignal' 定义方法“setNotificationReceivedHandler” .
这是代码
OneSignal.shared
.setInFocusDisplayType(OSNotificationDisplayType.notification);
OneSignal.shared
.setNotificationReceivedHandler((OSNotification notification) {
this.setState(() {
outPutString =
"Received notification: \n${notification.jsonRepresentation().replaceAll("\n", "\n")}";
});
我该如何解决这些问题?
我在这里分享我的 pubspec.yaml 文件。
name: test_app
description: A Test Application
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
cupertino_icons: ^1.0.0
shared_preferences: ^2.0.8
cached_network_image: ^3.1.0
flutter_rating_bar: ^4.0.0
url_launcher: ^6.0.12
country_code_picker: ^2.0.2
flutter_range_slider: "^1.5.0"
group_radio_button: ^1.0.1
carousel_slider: ^4.0.0
persistent_bottom_nav_bar: ^4.0.2
intl: ^0.17.0
provider: ^6.0.1
flutter_bloc: ^7.3.0
equatable: ^2.0.3
image_picker: ^0.8.4+2
dio: ^4.0.0
otp_text_field: ^1.0.2
path: ^1.7.0
mime: ^1.0.0
fluttertoast: ^8.0.8
date_format: ^2.0.4
html: ^0.15.0
flutter_calendar_carousel: ^2.0.3
onesignal_flutter: ^3.2.3
flutter_paytabs_bridge: ^2.1.1
http:
share: ^2.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
fonts:
- family: Quicksand
fonts:
- asset: assets/fonts/Quicksand/Quicksand-Bold.ttf
- asset: assets/fonts/Quicksand/Quicksand-Light.ttf
- asset: assets/fonts/Quicksand/Quicksand-Medium.ttf
- asset: assets/fonts/Quicksand/Quicksand-Regular.ttf
- asset: assets/fonts/Quicksand/Quicksand-SemiBold.ttf
- asset: assets/fonts/Quicksand/Quicksand-VariableFont_wght.ttf
assets:
- assets/images/
- assets/icons/
问题是您的插件已更新,但您使用的方法已过时。
第一个问题好像您使用的是 PersistentTabController
而不是 PersistentTabView
或 PersistentTabView.custom
。 Link documentation PersistentTab
而OneSignal插件有以下方法:
OneSignal.shared.setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event) {
// Will be called whenever a notification is received in foreground
// Display Notification, pass null param for not displaying the notification
event.complete(event.notification);
});
OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result) {
// Will be called whenever a notification is opened/button pressed.
});
我正在开发一个基于 Flutter 2.2.3 构建的项目,但我更新了所有依赖项。此外,我还修复了许多错误,这些错误是将 flutter 从 2.2.3 升级到 2.5.2 的结果。现在我面临两个文件的问题。一个问题是 PersistentTabController,它对控制器、navBarHeight、onItemSelected、屏幕、项目等许多行表示 'The named parameter is not found'。好吧,我正在共享代码。左边完全是红色的。我该如何解决?
PersistentTabController(
controller: controller,
navBarHeight: MediaQuery.of(context).size.width > 768 ? 90 : 64,
onItemSelected: (item) {
int index = controller.index;
if (index == 0) {
setState(() {
appbarTitle = Languages.of(context).homeScreenTitle;
});
} else if (index == 1) {
setState(() {
appbarTitle = Languages.of(context).appointmentsScreenTitle;
});
} else if (index == 2) {
setState(() {
appbarTitle = Languages.of(context).favouriteScreenTitle;
});
} else if (index == 3) {
setState(() {
appbarTitle =
Languages.of(context).notificationsScreenTitle;
});
} else if (index == 4) {
setState(() {
appbarTitle = Languages.of(context).accountScreenTitle;
});
}
},
screens: _pages,
items: [
PersistentBottomNavBarItem(
icon: Icon(
Icons.home_outlined,
size: MediaQuery.of(context).size.width > 768 ? 40 : 24,
),
title: Languages.of(context).bottomNavHome,
activeColor: ColorConstants.primaryColor,
inactiveColor: ColorConstants.iconColor,
titleStyle: TextStyle(
fontSize:
MediaQuery.of(context).size.width > 768 ? 20 : 12)),
PersistentBottomNavBarItem(
icon: Icon(
Icons.calendar_today_outlined,
size: MediaQuery.of(context).size.width > 768 ? 40 : 24,
),
title: Languages.of(context).bottomNavAppointments,
activeColor: ColorConstants.primaryColor,
inactiveColor: ColorConstants.iconColor,
titleStyle: TextStyle(
fontSize:
MediaQuery.of(context).size.width > 768 ? 20 : 12)),
PersistentBottomNavBarItem(
icon: Icon(
Icons.favorite_border,
size: MediaQuery.of(context).size.width > 768 ? 40 : 24,
),
title: Languages.of(context).bottomNavFavourites,
activeColor: ColorConstants.primaryColor,
inactiveColor: ColorConstants.iconColor,
titleStyle: TextStyle(
fontSize:
MediaQuery.of(context).size.width > 768 ? 20 : 12)),
PersistentBottomNavBarItem(
icon: Icon(
Icons.notifications,
size: MediaQuery.of(context).size.width > 768 ? 40 : 24,
),
title: Languages.of(context).bottomNavNotifications,
activeColor: ColorConstants.primaryColor,
inactiveColor: ColorConstants.iconColor,
titleStyle: TextStyle(
fontSize:
MediaQuery.of(context).size.width > 768 ? 20 : 12)),
PersistentBottomNavBarItem(
icon: Icon(
Icons.person_outline,
size: MediaQuery.of(context).size.width > 768 ? 40 : 24,
),
title: Languages.of(context).bottomNavAccount,
activeColor: ColorConstants.primaryColor,
inactiveColor: ColorConstants.iconColor,
titleStyle: TextStyle(
fontSize:
MediaQuery.of(context).size.width > 768 ? 20 : 12)),
],
confineInSafeArea: true,
backgroundColor: Colors.white,
handleAndroidBackButtonPress: true,
resizeToAvoidBottomInset: true,
// This needs to be true if you want to move up the screen when keyboard appears.
stateManagement: false,
hideNavigationBarWhenKeyboardShows: true,
// Recommended to set 'resizeToAvoidBottomInset' as true while using this argument.
decoration: NavBarDecoration(
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(1.0),
colorBehindNavBar: Colors.black,
),
popAllScreensOnTapOfSelectedTab: true,
popActionScreens: PopActionScreensType.all,
itemAnimationProperties: ItemAnimationProperties(
// Navigation Bar's items animation properties.
duration: Duration(milliseconds: 200),
curve: Curves.ease,
),
screenTransitionAnimation: ScreenTransitionAnimation(
// Screen transition animation on change of selected tab.
animateTabTransition: true,
curve: Curves.ease,
duration: Duration(milliseconds: 200),
),
navBarStyle: NavBarStyle.style6,
),
同样在另一个文件中,我面临 OneSignal 问题,例如“未为类型 'OneSignal' 定义方法 setInFocusDisplayType 和”未为类型 'OneSignal' 定义方法“setNotificationReceivedHandler” . 这是代码
OneSignal.shared
.setInFocusDisplayType(OSNotificationDisplayType.notification);
OneSignal.shared
.setNotificationReceivedHandler((OSNotification notification) {
this.setState(() {
outPutString =
"Received notification: \n${notification.jsonRepresentation().replaceAll("\n", "\n")}";
});
我该如何解决这些问题?
我在这里分享我的 pubspec.yaml 文件。
name: test_app
description: A Test Application
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
cupertino_icons: ^1.0.0
shared_preferences: ^2.0.8
cached_network_image: ^3.1.0
flutter_rating_bar: ^4.0.0
url_launcher: ^6.0.12
country_code_picker: ^2.0.2
flutter_range_slider: "^1.5.0"
group_radio_button: ^1.0.1
carousel_slider: ^4.0.0
persistent_bottom_nav_bar: ^4.0.2
intl: ^0.17.0
provider: ^6.0.1
flutter_bloc: ^7.3.0
equatable: ^2.0.3
image_picker: ^0.8.4+2
dio: ^4.0.0
otp_text_field: ^1.0.2
path: ^1.7.0
mime: ^1.0.0
fluttertoast: ^8.0.8
date_format: ^2.0.4
html: ^0.15.0
flutter_calendar_carousel: ^2.0.3
onesignal_flutter: ^3.2.3
flutter_paytabs_bridge: ^2.1.1
http:
share: ^2.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
fonts:
- family: Quicksand
fonts:
- asset: assets/fonts/Quicksand/Quicksand-Bold.ttf
- asset: assets/fonts/Quicksand/Quicksand-Light.ttf
- asset: assets/fonts/Quicksand/Quicksand-Medium.ttf
- asset: assets/fonts/Quicksand/Quicksand-Regular.ttf
- asset: assets/fonts/Quicksand/Quicksand-SemiBold.ttf
- asset: assets/fonts/Quicksand/Quicksand-VariableFont_wght.ttf
assets:
- assets/images/
- assets/icons/
问题是您的插件已更新,但您使用的方法已过时。
第一个问题好像您使用的是 PersistentTabController
而不是 PersistentTabView
或 PersistentTabView.custom
。 Link documentation PersistentTab
而OneSignal插件有以下方法:
OneSignal.shared.setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event) {
// Will be called whenever a notification is received in foreground
// Display Notification, pass null param for not displaying the notification
event.complete(event.notification);
});
OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult result) {
// Will be called whenever a notification is opened/button pressed.
});