Categories: java, android, ios, flutter, dart

Flutter : NoSuchMethodError: The getter 'nom' was called on null. Receiver; null Tried calling: nom

1 answer

I try to assign value to the attributes of the PanierModel but I receive this error on picture

NoSuchMethodError: The getter 'nom' was called on null. Receiver; null Tried calling: 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,),), );   }  } 
Received answer to this question:
The best answer according to the author of the question:

Your problem is that you are not initialising your _panier and that's why you get the error because _panier.nom is called on null as _panier is null and null object doesn't have any attributes. You have to do the following:

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