gpt4 book ai didi

java - flutter : NoSuchMethodError: The getter 'nom' was called on null. 接收器; null 尝试调用:nom

转载 作者:行者123 更新时间:2023-12-01 17:35:01 26 4
gpt4 key购买 nike

我尝试为 PanierModel 的属性赋值,但在图片上收到此错误

NoSuchMethodError:在 null 上调用 getter 'nom'。接收者; null 尝试调用:nom

class _TestSQFLITEState extends State<TestSQFLITE> {

DatabaseHelper helper = DatabaseHelper();

PanierModel _panier;

@override
Widget build(BuildContext context) {


setState(() {
_panier.nom = _panier.nom == null ? "Arduino" : "";

});

void _ajouterPanier() async {
int result;
result = await helper.insertPanier(_panier);
if(result != 0)
print('STATUS Panier Save Successfully');
}

return Scaffold(
body: Container(
child: Center(
child: Column(
children: <Widget>[
Text(_panier.nom , style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold),),
Text("Abibou", style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold),),
],
),
),
),
floatingActionButton: FloatingActionButton(onPressed: _ajouterPanier,
child: Icon(Icons.add, color: Colors.white,),),
);
}
}

最佳答案

您的问题是您没有初始化 _panier,这就是您收到错误的原因,因为 _panier.nom 在 null 上调用,因为 _panier 为 null 并且 null 对象没有任何属性。您必须执行以下操作:

PanierModel _panier = PanierModel(); //now _panier is not null anymore

关于java - flutter : NoSuchMethodError: The getter 'nom' was called on null. 接收器; null 尝试调用:nom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61057474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com