参数类型'动态函数(ApplovinAdlistener)'可以将分配给参数类型'动态函数(ApplovinAdlistener?)'
我正在尝试将Applovin间隙广告添加到Flutter应用程序中。但是它不断显示错误。我的SDK是SDK:'> = 2.12.0< 3.0.0'。
这是显示的错误
类型“布尔?”的值无法分配到类型“ bool”的变量。 尝试更改变量的类型,或将右手类型施放为“ bool”。
参数类型“动态函数(ApplovinAdlistener)'无法分配给参数类型'动态函数(ApplovinAdlistener?)'。
这是示例代码:
const CollectionCard();
@override
State<CollectionCard> createState() => _CollectionCardState();
}
class _CollectionCardState extends State<CollectionCard> {
AppLovinListener? get listener => null;
void initState() {
FlutterApplovinMax.initInterstitialAd('91b26a7777e1b455');
super.initState();
}
bool isInterstitialVideoAvailable = false;
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
/*24 is for notifications bar on Android */
final double itemHeight = (size.height - kToolbarHeight - 28) / 2;
final double itemWidth = size.width / 4;
return Container(
child: Padding(
padding: const EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 10.0),
child: Column(
children: <Widget>[
GridView.count(
primary: true,
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
crossAxisSpacing: 10, //Reduce Horizontal Spacing
mainAxisSpacing: 10, //Reduce Vertical Spacing
crossAxisCount: 3,
physics: ScrollPhysics(),
childAspectRatio: (6 / 8),
// (itemWidth / itemHeight),
shrinkWrap: true,
children: <Widget>[
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
elevation: 2,
color: Theme.of(context).scaffoldBackgroundColor,
child: InkWell(
onTap: () async {
isInterstitialVideoAvailable =
await FlutterApplovinMax.isInterstitialLoaded (listener);
if (isInterstitialVideoAvailable) {
FlutterApplovinMax.showInterstitialVideo(
(AppLovinAdListener event) => listener (event));
}
Navigator.push(
context,
MaterialPageRoute(
builder: (ctx) => LearnPage(),
),
);
},
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ImageIcon(
AssetImage('assets/icons/learn.png'),
color: kLightPrimary,
size: 60,
), // Icon(
// layout.icon,
// size: 40,
// ),
Text(
'Learn',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
),
下面是代码错误
I'm trying to add Applovin Interstitial ads to flutter app. But it keep showing errors. my sdk is sdk:'>=2.12.0 <3.0.0'.
This are the errors displayed
A value of type 'bool?' can't be assigned to a variable of type 'bool'.
Try changing the type of the variable, or casting the right-hand type to 'bool'.
The argument type 'dynamic Function(AppLovinAdListener)' can't be assigned to the parameter type 'dynamic Function(AppLovinAdListener?)'.
This is the sample code:
const CollectionCard();
@override
State<CollectionCard> createState() => _CollectionCardState();
}
class _CollectionCardState extends State<CollectionCard> {
AppLovinListener? get listener => null;
void initState() {
FlutterApplovinMax.initInterstitialAd('91b26a7777e1b455');
super.initState();
}
bool isInterstitialVideoAvailable = false;
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
/*24 is for notifications bar on Android */
final double itemHeight = (size.height - kToolbarHeight - 28) / 2;
final double itemWidth = size.width / 4;
return Container(
child: Padding(
padding: const EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 10.0),
child: Column(
children: <Widget>[
GridView.count(
primary: true,
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
crossAxisSpacing: 10, //Reduce Horizontal Spacing
mainAxisSpacing: 10, //Reduce Vertical Spacing
crossAxisCount: 3,
physics: ScrollPhysics(),
childAspectRatio: (6 / 8),
// (itemWidth / itemHeight),
shrinkWrap: true,
children: <Widget>[
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
elevation: 2,
color: Theme.of(context).scaffoldBackgroundColor,
child: InkWell(
onTap: () async {
isInterstitialVideoAvailable =
await FlutterApplovinMax.isInterstitialLoaded (listener);
if (isInterstitialVideoAvailable) {
FlutterApplovinMax.showInterstitialVideo(
(AppLovinAdListener event) => listener (event));
}
Navigator.push(
context,
MaterialPageRoute(
builder: (ctx) => LearnPage(),
),
);
},
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ImageIcon(
AssetImage('assets/icons/learn.png'),
color: kLightPrimary,
size: 60,
), // Icon(
// layout.icon,
// size: 40,
// ),
Text(
'Learn',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
),
Below is an image of the code error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
布尔是一个严格的布尔 - 可以是真实的,也可以是错误的,别无其他。
布尔?是宽松的布尔人或也称为无效的 - 可能是真实的,false的或空的。
该功能也是如此。
插件'applovin'我假设您正在使用或软件包,或您声明的功能,不支持Null-Safety ,这意味着它的功能可以返回null。
为了解决问题,您需要通过在类型声明后添加问号来制作类型 nullable (即
bool a;
将成为 - ,请确保您不要在null上调用的方法。编辑者将事先通知您(变量)可能是null ,并在其上调用一种方法将抛出Method> MethodnotFoundException
。确保通过添加null -Checks (感叹号 - '!')来确保这不会发生并满足编译器't null ,尽管它是 nullable。页面)您将获得以下异常 -null -Check在空值上使用。
bool is a strict boolean - it can be true or false, nothing else.
bool? is a loose boolean or also called nullable - it can be true, false or null.
Same goes for the function.
The Plugin 'AppLovin' I assume you are using or the package, or the function you declared, doesn't support null-safety, which means that it's functions can return null.
In order to solve the issue, you need to make the types nullable by adding a question mark after the type declaration (i.e.
bool a;
will become -bool? a;
and make sure you don't call a method on a null. Since your variables and methods can return null, the editor will inform you before hand that this (the variable) might be null and calling a method on it will throw aMethodNotFoundException
. Therefore, you should add your own logic to assure that this doesn't happen and satisfy the compiler by adding null-checks (exclamation marks - '!') to method calls which works as a form of asserting the compiler that this value isn't null, despite it being nullable. If it so happens that you do call a null on a value with a null check, at run time (after you press the run and load your page) you will get the following exception -Null-check used on a null value.