【发布时间】:2021-05-31 21:46:07
【问题描述】:
我有 NoSuchMethodError 通过模拟我的应用程序。 NoSuchMethodError (NoSuchMethodError: 方法 '>=' 在 null 上被调用。 接收方:空 尝试调用:>=(55)) 当我模拟我的应用程序时,错误正在显示。
有人可以帮我吗?
我在这个文件中的完整代码:
class GameEN extends StatefulWidget {
//Game({Key key}) : super(key: key);
@override
_GameENState createState() => _GameENState();
}
class _GameENState extends State<GameEN> {
int _counterK;
int _pktK;
@override
void initState() {
_subscription =
super.initState();
_loadCounterK();
}
@override
void dispose() {
_subscription.cancel();
super.dispose();
}
//Loading counter value on start (load)
_loadCounterK() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
_counterK = (prefs.getInt('counterK') ?? 1);
_pktK = (prefs.getInt('pktK') ?? 0);
print(Text("Load number is: $_counterK"));
print(Text("Load pkt is: $_pktK"));
});
}
@override
Widget build(BuildContext context) {
return new WillPopScope(
onWillPop: () async => false,
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
centerTitle: true,
title: Text(
'ToolQuiz',
style: TextStyle(
fontStyle: FontStyle.italic,
color: Colors.black,
),
),
actions: <Widget>[
Padding(
padding: EdgeInsets.only(right: 15.0),
child: IconButton(
padding: EdgeInsets.all(0),
icon: Icon(
Icons.settings,
color: Colors.black,
),
onPressed: () {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) {
return Einstellungen();
},
),
);
}),
)
],
),
body: Center(
child: Container(
decoration: BoxDecoration(),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
//Küchenutensilien
GestureDetector(
onTap: () {
_interstitialAd.show();
_interstitialAd.dispose();
// _incrementCounterRightAnsK();
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) {
if (56 <= _counterK)
return KuechenutensilienEnd();
else
return KuechenutensilienStart();
},
transitionsBuilder:
(context, animation1, animation2, child) {
return FadeTransition(
opacity: animation1,
child: child,
);
},
transitionDuration: Duration(milliseconds: 500),
),
);
},
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.brown[600],
Colors.brown[700]
],
begin: Alignment.bottomLeft,
end: Alignment.topRight,
),
border:
Border.all(width: 2, color: Colors.black54),
borderRadius: const BorderRadius.all(
const Radius.circular(20))),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
child: Column(
children: <Widget>[
Container(
alignment: Alignment.center,
child: Text('Küchenutensilien',
style: Theme.of(context)
.textTheme
.headline5
.copyWith(color: Colors.black)),
),
Container(
alignment: Alignment.center,
child: Text(
_pktK.toString() + ' ' + 'Punkte',
),
),
Container(
alignment: Alignment.center,
child: Text(() {
if (_counterK >= 55) {
return 'Level ' + '55' + '/55';
}
return 'Level ' +
_counterK.toString() +
'/55';
}()),
),
],
),
),
],
))),
],
),
),
))));
}
}
所有人都在向我展示错误:如果....>= 我没有找到我的问题:(
感谢您的帮助
【问题讨论】:
-
无法重现错误。代码工作正常。您能否显示整个代码,也许您没有看到好的线路。 IDE 和一些错误消息可能会产生误导。
-
另外,请使用最新的稳定版 Dart/Flutter,只有使用过时的版本才会出现错误。
-
感谢 nvoigt 的帮助