{"id":12943,"date":"2025-07-31T06:16:01","date_gmt":"2025-07-31T06:16:01","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=12943"},"modified":"2025-07-31T06:16:01","modified_gmt":"2025-07-31T06:16:01","slug":"signinwithgoogle-static-access","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/flutter\/signinwithgoogle-static-access","title":{"rendered":"Instance Member &#8216;signInWithGoogle&#8217; Can&#8217;t Be Accessed Using Static Access"},"content":{"rendered":"<p>You&#8217;re encountering this error because you&#8217;re trying to call an <strong>instance method using static access<\/strong>, which Dart doesn&#8217;t allow. The error message: Instance member &#8216;signInWithGoogle&#8217; can&#8217;t be accessed using static access means you&#8217;re calling signInWithGoogle() like this:<br \/>\n<code>final FBApi api = await FBApi.signInWithGoogle();<\/code><\/p>\n<p>But signInWithGoogle() is not marked as static, so it needs to be called on an instance of FBApi.<\/p>\n<h3>Solution 1: Make signInWithGoogle() a static method<\/h3>\n<p>If signInWithGoogle() doesn\u2019t rely on any instance-specific state (e.g., this.firebaseUser), the cleanest fix is to mark it as static.<\/p>\n<p>Once it&#8217;s static, you can call it using the class name (FBApi.signInWithGoogle()), which resolves the error.<\/p>\n<h3>After this change<\/h3>\n<ul>\n<li>Your sign-in method works as a one-time factory that returns an instance of FBApi after successful authentication.<\/li>\n<li>You can store that instance and call non-static methods (like signOut()) on it later if needed.<\/li>\n<\/ul>\n<h2>What you were doing :<\/h2>\n<p><code>await FBApi.signOut(); \/\/ Error: signOut is not static<br \/>\nawait FBApi.signInWithGoogle(); \/\/ Error: signInWithGoogle is not static<\/code><\/p>\n<h2>Summary:<\/h2>\n<p>Use static when you want to call a method <strong>without creating an object first.<\/strong><\/p>\n<p>Only make a method static if it <strong>doesn&#8217;t depend on instance variables.<\/strong><\/p>\n<p>For signing in\/out logic, making them static usually makes sense unless you&#8217;re maintaining internal session state.<br \/>\n<img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/31061250\/final-output-837x1024.png\" alt=\"final-output\" width=\"837\" height=\"1024\" class=\"alignright size-large wp-image-12945\" srcset=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/31061250\/final-output-837x1024.png 837w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/31061250\/final-output-245x300.png 245w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/31061250\/final-output-768x940.png 768w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/31061250\/final-output-1256x1536.png 1256w, https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/07\/31061250\/final-output.png 1674w\" sizes=\"(max-width: 837px) 100vw, 837px\" \/><\/p>\n<div class=\"qanda-read-box\"><div class=\"bg-light read-more-icon\"><img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/04\/24061434\/read-txt.png\" alt=\"Also Read\"><p><\/p><h3>Also Read:<\/h3><a href=\"https:\/\/www.bacancytechnology.com\/blog\/flutter-bloc-tutorial\" target=\"_blank\">Flutter BLoC Tutorial<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;re encountering this error because you&#8217;re trying to call an instance method using static access, which Dart doesn&#8217;t allow. The error message: Instance member &#8216;signInWithGoogle&#8217; can&#8217;t be accessed using static access means you&#8217;re calling signInWithGoogle() like this: final FBApi api = await FBApi.signInWithGoogle(); But signInWithGoogle() is not marked as static, so it needs to be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12944,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[15],"tags":[],"class_list":["post-12943","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-flutter"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12943"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=12943"}],"version-history":[{"count":2,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12943\/revisions"}],"predecessor-version":[{"id":12947,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/12943\/revisions\/12947"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/12944"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=12943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=12943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=12943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}