How to Resolve Getter ‘Value’ Was Called On Null In Flutter ?
When building a mobile application some times a user may forget to define a particular controller. And the compiler will go through an error that states about the getter value was called on null. So in today’s article, we will go through How to Resolve Getter ‘Value’ Was Called On Null In Flutter?
How to Resolve Getter Value Was Called On Null in Flutter?
To resolve this issue we need to take a look at the complete solution. But the probable solution could be from below.
In the initState(), you don’t always instantiate a controller. which means it can be null. Therefore inside the build method, you need to check null to not crash
(!this.controller?.value?.initialized ?? false) ? new Container() : cameraView ,
aspectRatio is a double value and it is assigned as false when it is null. Give it a double value.
aspectRatio: (this.controller?.value?.aspectRatio) ?? false
If you have created and assigned value to the variable and still it shows getter ‘value‘ was called on null, try to Run or Restart your app instead of Hot Reload. Because Hot Reload will not call initstate() where variables assign their values which will be only called by Restarting the app.
Thanks for being with us on a flutter journey!!!
In this article, we have been through how to how to resolve the getter value that was called on null in flutter?
Do let us know if you need any assistance with flutter development? We would love to assist you in your Flutter development journey.
Flutter Agency is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget Guide, Flutter Projects, Code libs and etc.
Flutter Agency is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.