我尝试将值分配给PanierModel的属性,但在图片上收到此错误
NoSuchMethodError:在null上调用了吸气剂“ 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,),),
);
}
}
答案 0 :(得分:0)
您的问题是您没有初始化_panier,这就是为什么会出现错误,因为_panier.nom在null上被调用,因为_panier为null且null对象没有任何属性。您必须执行以下操作:
PanierModel _panier = PanierModel(); //now _panier is not null anymore