{"id":6339,"date":"2021-05-22T06:33:36","date_gmt":"2021-05-22T06:33:36","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=6339"},"modified":"2021-05-22T06:37:38","modified_gmt":"2021-05-22T06:37:38","slug":"flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/","title":{"rendered":"[SOLVED] Flutter : NoSuchMethodError: The getter &#8216;isEmpty&#8217; was called on null."},"content":{"rendered":"\n<h2 class=\"has-text-align-center wp-block-heading\"><strong><span class=\"has-inline-color has-vivid-red-color\">Problem<\/span><\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;m Calling An API and getting response in Variable Data ($data). When data is coming then there is no Error but when I&#8217;m getting null as response then getting this error <strong>Unhandled Exception: NoSuchMethodError: The getter &#8216;isEmpty&#8217; was called on null.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> When I am using the below code then it is throwing me an error:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/SushantSinghRajput03\/794f41a5c997965d7d51719aab6811fa.js\"><\/script>\n\n\n\n<h2 class=\"has-text-align-center wp-block-heading\"><span class=\"has-inline-color has-vivid-red-color\">Solution<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">That is because <strong>$data<\/strong> returns&nbsp;<code>null<\/code>, So I&#8217;ve Used <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><span class=\"has-inline-color has-vivid-red-color\">if(data?.isEmpty ?? true)<\/span><\/code>\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>?<\/code>&nbsp;prevents an error if the previous part of the expression results in&nbsp;<code>null<\/code>&nbsp;and&nbsp;<code>?? true<\/code>&nbsp;results in&nbsp;<code>true<\/code>&nbsp;if the previous part of the expression is&nbsp;<code>null<\/code>&nbsp;and therefore treats&nbsp;<code>== null<\/code>&nbsp;and&nbsp;<code>isEmpty<\/code>&nbsp;the same for the&nbsp;<code>if(...)<\/code>&nbsp;check.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now My Code is working Fine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for reading.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keep Coding.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/professnow.com\/blog\/wp-content\/uploads\/2021\/01\/Keep_coding.gif\" alt=\"\" class=\"wp-image-26\" width=\"75\" height=\"75\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem I&#8217;m Calling An API and getting response in Variable Data ($data). When data is coming then there is no [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5319],"tags":[5321,5329,5330,5332,5328,5331,5333],"class_list":["post-6339","post","type-post","status-publish","format-standard","hentry","category-flutter","tag-flutter","tag-isempty","tag-isempty-was-called-on-null","tag-no-sound-null-flutter","tag-nosuchmethoderror","tag-null-safety","tag-null-safety-flutter"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[SOLVED] Flutter : NoSuchMethodError: The getter &#039;isEmpty&#039; was called on null. - scmGalaxy<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[SOLVED] Flutter : NoSuchMethodError: The getter &#039;isEmpty&#039; was called on null. - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"Problem I&#8217;m Calling An API and getting response in Variable Data ($data). When data is coming then there is no [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-22T06:33:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-22T06:37:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/professnow.com\/blog\/wp-content\/uploads\/2021\/01\/Keep_coding.gif\" \/>\n<meta name=\"author\" content=\"Sushant K\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sushant K\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/\"},\"author\":{\"name\":\"Sushant K\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/7cb2b03b970bcfe605e1be29d2b6791c\"},\"headline\":\"[SOLVED] Flutter : NoSuchMethodError: The getter &#8216;isEmpty&#8217; was called on null.\",\"datePublished\":\"2021-05-22T06:33:36+00:00\",\"dateModified\":\"2021-05-22T06:37:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/\"},\"wordCount\":137,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/professnow.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Keep_coding.gif\",\"keywords\":[\"flutter\",\"isEmpty\",\"isEmpty was called on null\",\"no sound null flutter\",\"NoSuchMethodError\",\"null safety\",\"null safety flutter\"],\"articleSection\":[\"Flutter\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/\",\"name\":\"[SOLVED] Flutter : NoSuchMethodError: The getter 'isEmpty' was called on null. - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/professnow.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Keep_coding.gif\",\"datePublished\":\"2021-05-22T06:33:36+00:00\",\"dateModified\":\"2021-05-22T06:37:38+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/7cb2b03b970bcfe605e1be29d2b6791c\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/#primaryimage\",\"url\":\"https:\\\/\\\/professnow.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Keep_coding.gif\",\"contentUrl\":\"https:\\\/\\\/professnow.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/01\\\/Keep_coding.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[SOLVED] Flutter : NoSuchMethodError: The getter &#8216;isEmpty&#8217; was called on null.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/7cb2b03b970bcfe605e1be29d2b6791c\",\"name\":\"Sushant K\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/092cd9bf0832fe9aa2450955f90b56545e8f7b54e08173f584c5130ad01df057?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/092cd9bf0832fe9aa2450955f90b56545e8f7b54e08173f584c5130ad01df057?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/092cd9bf0832fe9aa2450955f90b56545e8f7b54e08173f584c5130ad01df057?s=96&d=mm&r=g\",\"caption\":\"Sushant K\"},\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/sushant\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[SOLVED] Flutter : NoSuchMethodError: The getter 'isEmpty' was called on null. - scmGalaxy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/","og_locale":"en_US","og_type":"article","og_title":"[SOLVED] Flutter : NoSuchMethodError: The getter 'isEmpty' was called on null. - scmGalaxy","og_description":"Problem I&#8217;m Calling An API and getting response in Variable Data ($data). When data is coming then there is no [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/","og_site_name":"scmGalaxy","article_published_time":"2021-05-22T06:33:36+00:00","article_modified_time":"2021-05-22T06:37:38+00:00","og_image":[{"url":"https:\/\/professnow.com\/blog\/wp-content\/uploads\/2021\/01\/Keep_coding.gif","type":"","width":"","height":""}],"author":"Sushant K","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Sushant K","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/"},"author":{"name":"Sushant K","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/7cb2b03b970bcfe605e1be29d2b6791c"},"headline":"[SOLVED] Flutter : NoSuchMethodError: The getter &#8216;isEmpty&#8217; was called on null.","datePublished":"2021-05-22T06:33:36+00:00","dateModified":"2021-05-22T06:37:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/"},"wordCount":137,"commentCount":0,"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/#primaryimage"},"thumbnailUrl":"https:\/\/professnow.com\/blog\/wp-content\/uploads\/2021\/01\/Keep_coding.gif","keywords":["flutter","isEmpty","isEmpty was called on null","no sound null flutter","NoSuchMethodError","null safety","null safety flutter"],"articleSection":["Flutter"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/","name":"[SOLVED] Flutter : NoSuchMethodError: The getter 'isEmpty' was called on null. - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/#primaryimage"},"image":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/#primaryimage"},"thumbnailUrl":"https:\/\/professnow.com\/blog\/wp-content\/uploads\/2021\/01\/Keep_coding.gif","datePublished":"2021-05-22T06:33:36+00:00","dateModified":"2021-05-22T06:37:38+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/7cb2b03b970bcfe605e1be29d2b6791c"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/#primaryimage","url":"https:\/\/professnow.com\/blog\/wp-content\/uploads\/2021\/01\/Keep_coding.gif","contentUrl":"https:\/\/professnow.com\/blog\/wp-content\/uploads\/2021\/01\/Keep_coding.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"[SOLVED] Flutter : NoSuchMethodError: The getter &#8216;isEmpty&#8217; was called on null."}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/7cb2b03b970bcfe605e1be29d2b6791c","name":"Sushant K","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/092cd9bf0832fe9aa2450955f90b56545e8f7b54e08173f584c5130ad01df057?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/092cd9bf0832fe9aa2450955f90b56545e8f7b54e08173f584c5130ad01df057?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/092cd9bf0832fe9aa2450955f90b56545e8f7b54e08173f584c5130ad01df057?s=96&d=mm&r=g","caption":"Sushant K"},"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/sushant\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/6339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=6339"}],"version-history":[{"count":7,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/6339\/revisions"}],"predecessor-version":[{"id":6346,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/6339\/revisions\/6346"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=6339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=6339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=6339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}