<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: coderqh</title>
    <description>The latest articles on DEV Community by coderqh (coderqh).</description>
    <link>https://dev.to/coderqh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F15780%2F9d2c2a94-e3ef-4ef2-990c-492c86792dce.png</url>
      <title>DEV Community: coderqh</title>
      <link>https://dev.to/coderqh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/coderqh"/>
    <language>en</language>
    <item>
      <title>Flutter app with a Laravel backend (2026 guide)</title>
      <dc:creator>Qihu Zhang</dc:creator>
      <pubDate>Fri, 06 Nov 2026 13:25:36 +0000</pubDate>
      <link>https://dev.to/coderqh/flutter-app-with-a-laravel-backend-2026-guide-5g2i</link>
      <guid>https://dev.to/coderqh/flutter-app-with-a-laravel-backend-2026-guide-5g2i</guid>
      <description>&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; install Laravel Sanctum, give the app a handful of JSON routes under &lt;code&gt;/api&lt;/code&gt;, and have Flutter send &lt;code&gt;Authorization: Bearer &amp;lt;token&amp;gt;&lt;/code&gt; on every call after sign-in. Keep the token in &lt;code&gt;flutter_secure_storage&lt;/code&gt;. Firebase stays only where Apple and Google make you use it: push delivery goes through FCM either way.&lt;/p&gt;

&lt;p&gt;Most Flutter tutorials assume Firebase for everything. That is quick to start, but your users, their data and your bill end up in someone else's console. A small Laravel app gives you the same building blocks on a server you control, plus an admin panel. This guide covers the six things a typical app needs from it, in the order you usually build them, and then how to set the project up so a coding agent can keep building it with you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Firebase or your own Laravel backend?
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Firebase&lt;/th&gt;
&lt;th&gt;Your own Laravel backend&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Accounts&lt;/td&gt;
&lt;td&gt;Firebase Auth&lt;/td&gt;
&lt;td&gt;Sanctum tokens, your own &lt;code&gt;users&lt;/code&gt; table&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data&lt;/td&gt;
&lt;td&gt;Firestore rules&lt;/td&gt;
&lt;td&gt;Routes and policies in PHP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Admin view of your users&lt;/td&gt;
&lt;td&gt;Firebase console&lt;/td&gt;
&lt;td&gt;An admin panel you build (Filament)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pricing&lt;/td&gt;
&lt;td&gt;Per read, write and sign-in&lt;/td&gt;
&lt;td&gt;One server, from a few dollars a month&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Push to phones&lt;/td&gt;
&lt;td&gt;FCM&lt;/td&gt;
&lt;td&gt;Still FCM, sent from your server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Leaving later&lt;/td&gt;
&lt;td&gt;Export and rewrite&lt;/td&gt;
&lt;td&gt;It is already yours&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Pick Firebase if you want zero servers. Pick Laravel if you already know PHP, want one place to see and edit your users, or need data to stay on infrastructure you choose.&lt;/p&gt;

&lt;h2&gt;
  
  
  The routes the app needs
&lt;/h2&gt;

&lt;p&gt;A complete first version is about a dozen routes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Route&lt;/th&gt;
&lt;th&gt;Auth&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;POST /api/auth/register&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;public&lt;/td&gt;
&lt;td&gt;Sends a 6-digit code, creates nothing yet&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;POST /api/auth/verify&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;public&lt;/td&gt;
&lt;td&gt;Code + password → account + token&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;POST /api/auth/login&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;public&lt;/td&gt;
&lt;td&gt;Email + password → token&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;POST /api/auth/social&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;public&lt;/td&gt;
&lt;td&gt;Google or Apple id token → token&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;POST /api/auth/password/forgot&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;public&lt;/td&gt;
&lt;td&gt;Sends a reset code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GET /api/auth/me&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;token&lt;/td&gt;
&lt;td&gt;The signed-in user&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;POST /api/auth/logout&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;token&lt;/td&gt;
&lt;td&gt;Revokes this token&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DELETE /api/auth/me&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;token&lt;/td&gt;
&lt;td&gt;Deletes the account and its data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PUT /api/backup&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;token&lt;/td&gt;
&lt;td&gt;Stores a snapshot of the app's data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GET /api/backup&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;token&lt;/td&gt;
&lt;td&gt;Latest snapshot, for restore&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;GET /api/version&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;public&lt;/td&gt;
&lt;td&gt;Latest and minimum app version&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Put the public auth routes behind a rate limiter (&lt;code&gt;throttle:&lt;/code&gt;) so nobody can use them to send thousands of emails.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Sanctum tokens
&lt;/h2&gt;

&lt;p&gt;In a new Laravel app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan &lt;span class="nb"&gt;install&lt;/span&gt;:api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That installs Sanctum and creates &lt;code&gt;routes/api.php&lt;/code&gt;. Add the &lt;code&gt;HasApiTokens&lt;/code&gt; trait to &lt;code&gt;User&lt;/code&gt;, then return a token from every route that signs someone in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$req&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'password'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'required|string'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nc"&gt;Hash&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'password'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nc"&gt;ValidationException&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;withMessages&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'Invalid credentials.'&lt;/span&gt;&lt;span class="p"&gt;]]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'token'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;createToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'mobile'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;plainTextToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'user'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'email'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything private goes in one group:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth:sanctum'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth/me'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;AuthController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'me'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth/logout'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;AuthController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'logout'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sanctum tokens do not expire unless you set &lt;code&gt;expiration&lt;/code&gt; in &lt;code&gt;config/sanctum.php&lt;/code&gt;. For a phone app that is usually what you want: sign-out deletes the token with &lt;code&gt;$req-&amp;gt;user()-&amp;gt;currentAccessToken()-&amp;gt;delete()&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: sign-up confirmed by an emailed code
&lt;/h2&gt;

&lt;p&gt;A code typed into the app works better on a phone than a link in an email, which opens the browser instead of the app. Split sign-up into two calls:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;register&lt;/code&gt; validates name, email and password, stores a hashed password next to a 6-digit code, emails the code and answers &lt;strong&gt;202&lt;/strong&gt;. No user row exists yet.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;verify&lt;/code&gt; takes the email, the code and the same password, creates the user with &lt;code&gt;email_verified_at&lt;/code&gt; set and answers with a token.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Two details matter. Answer &lt;code&gt;register&lt;/code&gt; the same way whether or not the address already has an account, and email the existing owner a note instead of a code, so the route cannot be used to find out who is signed up. And keep codes short-lived (10–15 minutes) with a limit on attempts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: calling the API from Flutter
&lt;/h2&gt;

&lt;p&gt;One small client handles the base URL, the headers and the token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Api&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;Api&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;baseUrl&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;baseUrl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;_storage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;FlutterSecureStorage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="n"&gt;Future&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_headers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;async&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_storage&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;key:&lt;/span&gt; &lt;span class="s"&gt;'api_token'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s"&gt;'Accept'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s"&gt;'Content-Type'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'application/json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s"&gt;'Authorization'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Bearer &lt;/span&gt;&lt;span class="si"&gt;$token&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;Future&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;async&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Uri&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="si"&gt;$baseUrl&lt;/span&gt;&lt;span class="s"&gt;/api/&lt;/span&gt;&lt;span class="si"&gt;$path&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nl"&gt;headers:&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_headers&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;jsonEncode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;seconds:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isEmpty&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;{}&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;jsonDecode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;dynamic&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_storage&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;key:&lt;/span&gt; &lt;span class="s"&gt;'api_token'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;statusCode&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;ApiException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s"&gt;'Error &lt;/span&gt;&lt;span class="si"&gt;${res.statusCode}&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="n"&gt;Future&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;signIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;async&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'auth/login'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'email'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'password'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_storage&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;key:&lt;/span&gt; &lt;span class="s"&gt;'api_token'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;value:&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'token'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pass the server address at build time instead of hard-coding it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;flutter run &lt;span class="nt"&gt;--dart-define&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;API_BASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://api.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and read it with &lt;code&gt;const String.fromEnvironment('API_BASE_URL')&lt;/code&gt;. When it is empty, the app can fall back to local-only mode, which keeps development and screenshots independent of a server.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Accept: application/json&lt;/code&gt; header is not optional: without it, Laravel answers a validation error with a redirect instead of JSON.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Google and Apple sign-in
&lt;/h2&gt;

&lt;p&gt;The phone does the provider part and gets an &lt;strong&gt;id token&lt;/strong&gt;. Send that token to &lt;code&gt;POST /api/auth/social&lt;/code&gt; with the provider name. The server checks the signature against Google's or Apple's public keys, checks &lt;code&gt;aud&lt;/code&gt; against your client ids, &lt;code&gt;iss&lt;/code&gt; and &lt;code&gt;exp&lt;/code&gt;, and then finds or creates the user.&lt;/p&gt;

&lt;p&gt;Match users in this order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;By provider and subject (&lt;code&gt;sub&lt;/code&gt;), stored on the user row. This never changes for a person.&lt;/li&gt;
&lt;li&gt;By email, but only if the provider says the email is verified &lt;strong&gt;and&lt;/strong&gt; your own row is verified too. Otherwise anyone could create a password account with someone else's address and be let into it when the real owner later signs in with Google.&lt;/li&gt;
&lt;li&gt;Otherwise create a new user.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer with the same &lt;code&gt;{ token, user }&lt;/code&gt; as a password login, so the rest of the app does not care how the person signed in. The phone side, including Apple's App Store rule and the Android SHA-1 keys, is in our guide to &lt;a href="https://coderqh.com/blog/flutter-google-apple-sign-in/" rel="noopener noreferrer"&gt;Google and Apple sign-in in Flutter&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: cloud backup on your server
&lt;/h2&gt;

&lt;p&gt;For most apps "sync" really means "restore my data on a new phone". That is much simpler than real-time sync: the app exports its local data as one JSON document and uploads it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'auth:sanctum'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'backup'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;BackupController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'store'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'backup'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;BackupController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'latest'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the model, cast the payload with &lt;code&gt;'payload' =&amp;gt; 'encrypted'&lt;/code&gt; so it is stored encrypted with your &lt;code&gt;APP_KEY&lt;/code&gt;. Three rules keep it safe:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Version every upload&lt;/strong&gt; and keep the last few, so a bad backup does not replace the only good one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limit the size&lt;/strong&gt; and answer 413 above it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep a copy of the app key.&lt;/strong&gt; A new &lt;code&gt;APP_KEY&lt;/code&gt; makes every stored backup unreadable. Answer that case with its own status (409) so the app can say "back up again" instead of "nothing found".&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 6: update prompts and push
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Update prompts.&lt;/strong&gt; A public &lt;code&gt;GET /api/version&lt;/code&gt; returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"latest"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"minimum"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"A few fixes and a faster start."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"android_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://play.google.com/store/apps/details?id=…"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"ios_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://apps.apple.com/app/id…"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On launch the app compares its own version (&lt;code&gt;package_info_plus&lt;/code&gt;) with both numbers. Below &lt;code&gt;minimum&lt;/code&gt;, block the app with a button to the store; below &lt;code&gt;latest&lt;/code&gt;, show a dismissible prompt. Keep the numbers in a table the admin panel can edit, so releasing a forced update does not need a deploy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Push.&lt;/strong&gt; Phones only receive push through FCM (and APNs behind it on iOS), so Firebase stays for this one job. Your server sends through the FCM HTTP v1 API with a service-account access token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nc"&gt;Http&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;withToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$accessToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"https://fcm.googleapis.com/v1/projects/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$projectId&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/messages:send"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'topic'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'all'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'notification'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'title'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'body'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$body&lt;/span&gt;&lt;span class="p"&gt;]]],&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Subscribe every install to a topic such as &lt;code&gt;all&lt;/code&gt; for announcements, and store device tokens on the user when you need to reach one person. Log every send, so the admin panel can show a history.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: make the project easy for a coding agent
&lt;/h2&gt;

&lt;p&gt;Most of the screens you add after this will probably be written with Claude Code, Cursor, Codex or Copilot. A Flutter app plus a Laravel app is two projects in two languages, and an agent that has to guess how they fit together guesses wrong. Two kinds of file fix most of that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project notes.&lt;/strong&gt; Put an &lt;code&gt;AGENTS.md&lt;/code&gt; at the root of the project. Agents read it before they change anything, so keep it short and factual: what the app is, where things live, how the two sides talk, and the commands that must pass.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; Flutter app in &lt;span class="sb"&gt;`app/`&lt;/span&gt;, Laravel API and Filament panel in &lt;span class="sb"&gt;`backend/`&lt;/span&gt;.
&lt;span class="p"&gt;-&lt;/span&gt; The app talks to the API only through &lt;span class="sb"&gt;`lib/data/api.dart`&lt;/span&gt;; every call
  sends &lt;span class="sb"&gt;`Accept: application/json`&lt;/span&gt; and the Sanctum token.
&lt;span class="p"&gt;-&lt;/span&gt; A new endpoint: route in &lt;span class="sb"&gt;`backend/routes/api.php`&lt;/span&gt;, a feature test in
  &lt;span class="sb"&gt;`backend/tests/Feature/`&lt;/span&gt;, then the call in &lt;span class="sb"&gt;`api.dart`&lt;/span&gt;.
&lt;span class="p"&gt;-&lt;/span&gt; Done means: &lt;span class="sb"&gt;`flutter analyze`&lt;/span&gt; clean, &lt;span class="sb"&gt;`flutter test`&lt;/span&gt; green,
  &lt;span class="sb"&gt;`cd backend &amp;amp;&amp;amp; composer test`&lt;/span&gt; green.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Claude Code reads &lt;code&gt;CLAUDE.md&lt;/code&gt; instead; a one-line &lt;code&gt;CLAUDE.md&lt;/code&gt; containing &lt;code&gt;@AGENTS.md&lt;/code&gt; imports the same file, so there is only one to keep up to date.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Skills&lt;/strong&gt; for the jobs you repeat. A skill is a folder with a &lt;code&gt;SKILL.md&lt;/code&gt;: a name, one sentence saying when to use it, then the exact steps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;add-api-endpoint&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Add a Laravel API route and the Flutter call that uses it. Use when a screen needs new data from the server.&lt;/span&gt;
&lt;span class="nn"&gt;---&lt;/span&gt;

&lt;span class="p"&gt;1.&lt;/span&gt; Add the route inside the &lt;span class="sb"&gt;`auth:sanctum`&lt;/span&gt; group in &lt;span class="sb"&gt;`backend/routes/api.php`&lt;/span&gt;.
&lt;span class="p"&gt;2.&lt;/span&gt; Write the controller method; validate input with &lt;span class="sb"&gt;`$req-&amp;gt;validate()`&lt;/span&gt;.
&lt;span class="p"&gt;3.&lt;/span&gt; Add a feature test that calls the route with and without a token.
&lt;span class="p"&gt;4.&lt;/span&gt; Add the method to &lt;span class="sb"&gt;`lib/data/api.dart`&lt;/span&gt; and use it from the controller.
&lt;span class="p"&gt;5.&lt;/span&gt; Run the three commands from AGENTS.md.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep skills in a &lt;code&gt;skills/&lt;/code&gt; folder and list them in &lt;code&gt;AGENTS.md&lt;/code&gt;, so every agent finds them; Claude Code also picks them up from &lt;code&gt;.claude/skills/&lt;/code&gt;. Good first skills: add an endpoint, add a screen, remove a feature you do not need, and ship a release (bump the version, then update &lt;code&gt;minimum&lt;/code&gt; and &lt;code&gt;latest&lt;/code&gt; from step 6).&lt;/p&gt;

&lt;p&gt;The tests are what make this work. With a test suite on both sides, "the commands pass" is a definition of done the agent can check by itself, instead of you reading every diff.&lt;/p&gt;

&lt;h2&gt;
  
  
  The admin panel
&lt;/h2&gt;

&lt;p&gt;Filament turns your models into an admin panel with very little code: a users list, the stored backups, a form that sends a push, and the version table from step 6. Restrict it to an &lt;code&gt;admin&lt;/code&gt; role, and keep it on the same Laravel app so it shares the models and the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist before release
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] HTTPS on the API domain, and &lt;code&gt;APP_DEBUG=false&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;APP_KEY&lt;/code&gt; stored somewhere outside the server&lt;/li&gt;
&lt;li&gt;[ ] Rate limits on every public auth route&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;Accept: application/json&lt;/code&gt; sent by the app&lt;/li&gt;
&lt;li&gt;[ ] Token deleted on sign-out and on 401&lt;/li&gt;
&lt;li&gt;[ ] Google and Apple id tokens verified on the server, never trusted from the phone&lt;/li&gt;
&lt;li&gt;[ ] A Delete account route that removes the user and their data (App Store guideline 5.1.1(v))&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;minimum&lt;/code&gt; version set before you ship a breaking API change&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;AGENTS.md&lt;/code&gt; names the commands that must pass on both sides&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Can Laravel replace Firebase for a Flutter app?&lt;/strong&gt;&lt;br&gt;
For accounts, data, backups, update checks and the admin side, yes. Push notifications still go through Firebase Cloud Messaging, because that is how Android and iOS deliver them, but your Laravel server can send them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Should I use Sanctum or Passport for a Flutter app?&lt;/strong&gt;&lt;br&gt;
Sanctum. It issues simple API tokens for first-party apps. Passport is a full OAuth2 server, which you only need if other companies' apps will sign in to your API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why does my Laravel API return HTML or a redirect to Flutter?&lt;/strong&gt;&lt;br&gt;
The request has no &lt;code&gt;Accept: application/json&lt;/code&gt; header, so Laravel treats it as a browser request. Send that header on every call, or add a middleware that forces JSON responses for &lt;code&gt;/api&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where should a Flutter app store the Laravel token?&lt;/strong&gt;&lt;br&gt;
In &lt;code&gt;flutter_secure_storage&lt;/code&gt;, which uses the Keychain on iOS and encrypted storage on Android. Not in &lt;code&gt;shared_preferences&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do I get Claude Code or Cursor to work well on a Flutter and Laravel project?&lt;/strong&gt;&lt;br&gt;
Add an &lt;code&gt;AGENTS.md&lt;/code&gt; that explains where the app and the API live, how they talk and which test commands must pass, and a skill for each job you repeat, such as adding an endpoint. Then ask for changes in terms of those skills.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does the app have to be online to work?&lt;/strong&gt;&lt;br&gt;
No. Keep the data on the phone and treat the server as a backup and an account. The app works offline and uploads a snapshot when it can.&lt;/p&gt;




&lt;p&gt;If you would rather start with all of this already wired up, &lt;a href="https://coderqh.com/boilerplate/skelora/" rel="noopener noreferrer"&gt;Skelora&lt;/a&gt; is a Flutter app with this Laravel API and a Filament admin panel in the same download: email-code accounts, Google and Apple sign-in, encrypted backups, update prompts and push. It ships with an &lt;code&gt;AGENTS.md&lt;/code&gt; and one skill per feature, so your coding agent can take out what you do not need.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://coderqh.com/blog/flutter-laravel-backend/" rel="noopener noreferrer"&gt;coderqh.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>laravel</category>
      <category>dart</category>
      <category>ai</category>
    </item>
    <item>
      <title>How to change the Flutter app icon on iOS and Android</title>
      <dc:creator>Qihu Zhang</dc:creator>
      <pubDate>Thu, 05 Nov 2026 13:17:34 +0000</pubDate>
      <link>https://dev.to/coderqh/how-to-change-the-flutter-app-icon-on-ios-and-android-3fm9</link>
      <guid>https://dev.to/coderqh/how-to-change-the-flutter-app-icon-on-ios-and-android-3fm9</guid>
      <description>&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; a Flutter app has two sets of icons, one per platform. iOS reads &lt;code&gt;ios/Runner/Assets.xcassets/AppIcon.appiconset/&lt;/code&gt; (PNG files plus a &lt;code&gt;Contents.json&lt;/code&gt; that lists them), and Android reads &lt;code&gt;ic_launcher.png&lt;/code&gt; in five &lt;code&gt;mipmap-*&lt;/code&gt; folders under &lt;code&gt;android/app/src/main/res/&lt;/code&gt;. Replace those files, then uninstall the app and run it again. Either use the &lt;a href="https://pub.dev/packages/flutter_launcher_icons" rel="noopener noreferrer"&gt;&lt;code&gt;flutter_launcher_icons&lt;/code&gt;&lt;/a&gt; package, or make the files in the browser with our free &lt;a href="https://coderqh.com/tools/app-icon-generator/" rel="noopener noreferrer"&gt;app icon generator&lt;/a&gt;. Whichever you use, make sure the iOS icons have no alpha channel, or App Store Connect refuses the build.&lt;/p&gt;

&lt;p&gt;Swapping the icon looks like a five-minute job, and the swap itself is. The time goes into three things that only show up later: an upload error about transparency, an Android 8+ phone that still shows the old icon, and a home screen that never seems to refresh. This guide covers the files first, then those three.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the icons live
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Platform&lt;/th&gt;
&lt;th&gt;Folder&lt;/th&gt;
&lt;th&gt;Files&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;iOS&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ios/Runner/Assets.xcassets/AppIcon.appiconset/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;21 PNG files and &lt;code&gt;Contents.json&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Android&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;android/app/src/main/res/mipmap-mdpi&lt;/code&gt; … &lt;code&gt;mipmap-xxxhdpi&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;ic_launcher.png&lt;/code&gt; in each&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Android 8+&lt;/td&gt;
&lt;td&gt;&lt;code&gt;android/app/src/main/res/mipmap-anydpi-v26/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;ic_launcher.xml&lt;/code&gt; (adaptive icon), if present&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Nothing in Dart code points at the icon. On Android, &lt;code&gt;AndroidManifest.xml&lt;/code&gt; says &lt;code&gt;android:icon="@mipmap/ic_launcher"&lt;/code&gt;, and Android picks the folder that matches the screen density. On iOS, Xcode compiles the asset catalog and reads &lt;code&gt;Contents.json&lt;/code&gt; to know which file is which.&lt;/p&gt;

&lt;h2&gt;
  
  
  The sizes
&lt;/h2&gt;

&lt;p&gt;Android wants one square icon per density:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Folder&lt;/th&gt;
&lt;th&gt;Pixels&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mipmap-mdpi&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;48&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mipmap-hdpi&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;72&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mipmap-xhdpi&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;96&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mipmap-xxhdpi&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;144&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mipmap-xxxhdpi&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;192&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Play Store listing takes one more: 512 × 512 px, a PNG of at most 1 MB, uploaded in Play Console rather than shipped in the app. Google Play rounds the corners itself, so keep the background solid all the way to the edges.&lt;/p&gt;

&lt;p&gt;iOS wants more files. The set that Flutter projects usually carry, and the one &lt;code&gt;flutter_launcher_icons&lt;/code&gt; writes, has 21 PNG files from 20 px to 1024 px:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Points&lt;/th&gt;
&lt;th&gt;Scales&lt;/th&gt;
&lt;th&gt;Pixels&lt;/th&gt;
&lt;th&gt;Used for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;1x, 2x, 3x&lt;/td&gt;
&lt;td&gt;20, 40, 60&lt;/td&gt;
&lt;td&gt;Notifications&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;1x, 2x, 3x&lt;/td&gt;
&lt;td&gt;29, 58, 87&lt;/td&gt;
&lt;td&gt;Settings&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;1x, 2x, 3x&lt;/td&gt;
&lt;td&gt;40, 80, 120&lt;/td&gt;
&lt;td&gt;Spotlight&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;60&lt;/td&gt;
&lt;td&gt;2x, 3x&lt;/td&gt;
&lt;td&gt;120, 180&lt;/td&gt;
&lt;td&gt;iPhone home screen&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;76&lt;/td&gt;
&lt;td&gt;1x, 2x&lt;/td&gt;
&lt;td&gt;76, 152&lt;/td&gt;
&lt;td&gt;iPad home screen&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;83.5&lt;/td&gt;
&lt;td&gt;2x&lt;/td&gt;
&lt;td&gt;167&lt;/td&gt;
&lt;td&gt;iPad Pro home screen&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1024&lt;/td&gt;
&lt;td&gt;1x&lt;/td&gt;
&lt;td&gt;1024&lt;/td&gt;
&lt;td&gt;App Store&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The set also includes 50, 57 and 72 pt files for iOS versions before 7. Xcode prints a notice for them and otherwise ignores them, so they are harmless. Recent versions of Xcode can also build every size from one 1024 px image (the "Single Size" option in the asset catalog), but most Flutter projects still have the full set, and replacing it file for file is the safest change.&lt;/p&gt;

&lt;p&gt;Start from one square image of at least 1024 × 1024 px. Smaller images have to be enlarged for the App Store icon and come out blurry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Option 1: flutter_launcher_icons
&lt;/h2&gt;

&lt;p&gt;Put your 1024 px image in the project, for example at &lt;code&gt;assets/icon/app_icon.png&lt;/code&gt;, and add this to &lt;code&gt;pubspec.yaml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;dev_dependencies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;flutter_launcher_icons&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;^0.14.3&lt;/span&gt;

&lt;span class="na"&gt;flutter_launcher_icons&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;android&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;ios&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;image_path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;assets/icon/app_icon.png"&lt;/span&gt;
  &lt;span class="na"&gt;remove_alpha_ios&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;background_color_ios&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;#FFFFFF"&lt;/span&gt;
  &lt;span class="na"&gt;adaptive_icon_background&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;#FFFFFF"&lt;/span&gt;
  &lt;span class="na"&gt;adaptive_icon_foreground&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;assets/icon/app_icon.png"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dart run flutter_launcher_icons
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It overwrites the iOS set and the Android &lt;code&gt;mipmap-*&lt;/code&gt; files, and with the last two lines it also writes an adaptive icon. &lt;code&gt;remove_alpha_ios: true&lt;/code&gt; is the line most people leave out, and the next section is why it matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Option 2: make the files in the browser
&lt;/h2&gt;

&lt;p&gt;If you would rather not add a dev dependency for a one-off job, our &lt;a href="https://coderqh.com/tools/app-icon-generator/" rel="noopener noreferrer"&gt;app icon generator&lt;/a&gt; makes the same files from one image. It runs in the browser tab, so the image is not uploaded, and it hands you a zip whose folders match a Flutter project. From the folder the zip is in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;unzip &lt;span class="nt"&gt;-o&lt;/span&gt; app-icons.zip &lt;span class="nt"&gt;-d&lt;/span&gt; path/to/your_app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not drag the folders into the project in the Finder. When a folder of the same name exists, the Finder replaces it instead of merging, and dragging &lt;code&gt;android&lt;/code&gt; in that way removes the rest of your &lt;code&gt;android/&lt;/code&gt; folder. &lt;code&gt;unzip -o&lt;/code&gt; only overwrites the files in the zip.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitfall 1: the App Store icon has an alpha channel
&lt;/h2&gt;

&lt;p&gt;You upload the build and App Store Connect answers with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ITMS-90717: Invalid App Store Icon. The App Store Icon in the asset catalog in 'Runner.app' can't be transparent nor contain an alpha channel.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The wording matters: &lt;strong&gt;nor contain an alpha channel&lt;/strong&gt;. An icon where every pixel is opaque still fails if the PNG is saved as RGBA. Many tools save RGBA by default. A browser canvas, for example, always exports RGBA, even after you paint a solid background over the whole image. This caught us while building the generator above: the icons looked perfect and would still have been refused.&lt;/p&gt;

&lt;p&gt;Check the file on a Mac:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sips &lt;span class="nt"&gt;-g&lt;/span&gt; hasAlpha ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;hasAlpha: no&lt;/code&gt; is what you want. To fix it, flatten the image onto a background color and save it as RGB: &lt;code&gt;remove_alpha_ios: true&lt;/code&gt; does that in &lt;code&gt;flutter_launcher_icons&lt;/code&gt;, and the generator does it for every iOS file. The Android launcher icons are fine with transparency, so leave those as they are.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitfall 2: Android 8+ still shows the old icon
&lt;/h2&gt;

&lt;p&gt;You replaced every &lt;code&gt;ic_launcher.png&lt;/code&gt;, and an Android 8 phone still shows the old icon. Look for &lt;code&gt;android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml&lt;/code&gt;. If it exists, the project has an &lt;strong&gt;adaptive icon&lt;/strong&gt;, and on Android 8 and later the system uses it instead of the PNG files.&lt;/p&gt;

&lt;p&gt;An adaptive icon has two layers: a background (often just a color) and a foreground image of 108 × 108 dp. The launcher cuts it to its own shape, circle, squircle or rounded square, and only the center is always visible: keep your artwork inside the middle 66 dp. &lt;code&gt;flutter_launcher_icons&lt;/code&gt; writes the foreground with a 16% inset for exactly that reason:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;adaptive-icon&lt;/span&gt; &lt;span class="na"&gt;xmlns:android=&lt;/span&gt;&lt;span class="s"&gt;"http://schemas.android.com/apk/res/android"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;background&lt;/span&gt; &lt;span class="na"&gt;android:drawable=&lt;/span&gt;&lt;span class="s"&gt;"@color/ic_launcher_background"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;foreground&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;inset&lt;/span&gt;
          &lt;span class="na"&gt;android:drawable=&lt;/span&gt;&lt;span class="s"&gt;"@drawable/ic_launcher_foreground"&lt;/span&gt;
          &lt;span class="na"&gt;android:inset=&lt;/span&gt;&lt;span class="s"&gt;"16%"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/foreground&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/adaptive-icon&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You have two fixes. Replace the adaptive icon too: the foreground PNG in each &lt;code&gt;drawable-*&lt;/code&gt; folder (108, 162, 216, 324 and 432 px) plus the background color in &lt;code&gt;values/colors.xml&lt;/code&gt;. Or delete &lt;code&gt;mipmap-anydpi-v26/ic_launcher.xml&lt;/code&gt;, and Android falls back to the PNG files. If &lt;code&gt;values/colors.xml&lt;/code&gt; already holds other colors, add the &lt;code&gt;ic_launcher_background&lt;/code&gt; line to it rather than replacing the file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pitfall 3: the home screen keeps the old icon
&lt;/h2&gt;

&lt;p&gt;The files are right and the home screen still shows the old icon. Both platforms cache icons per installed app, and &lt;code&gt;flutter run&lt;/code&gt; updates the code of an installed app without always refreshing its icon. Uninstall the app from the phone or simulator first, then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;flutter clean
flutter run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the iOS Simulator, deleting the app is usually enough. On Android, some launchers keep a cache even across reinstalls; restarting the launcher, or the phone, clears it. A release build installed fresh from TestFlight or an internal testing track never has this problem, so do not chase it further than that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist before you ship
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Source image is square and at least 1024 × 1024 px&lt;/li&gt;
&lt;li&gt;[ ] All 21 iOS files replaced, &lt;code&gt;Contents.json&lt;/code&gt; lists them&lt;/li&gt;
&lt;li&gt;[ ] &lt;code&gt;sips -g hasAlpha&lt;/code&gt; says &lt;code&gt;no&lt;/code&gt; for the 1024 px iOS icon&lt;/li&gt;
&lt;li&gt;[ ] Five &lt;code&gt;mipmap-*/ic_launcher.png&lt;/code&gt; files replaced&lt;/li&gt;
&lt;li&gt;[ ] Adaptive icon replaced, or &lt;code&gt;mipmap-anydpi-v26/ic_launcher.xml&lt;/code&gt; removed&lt;/li&gt;
&lt;li&gt;[ ] App uninstalled and installed again on a real device of each platform&lt;/li&gt;
&lt;li&gt;[ ] 512 px Play Store icon uploaded in Play Console&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Where is the app icon in a Flutter project?&lt;/strong&gt;&lt;br&gt;
iOS: &lt;code&gt;ios/Runner/Assets.xcassets/AppIcon.appiconset/&lt;/code&gt;. Android: &lt;code&gt;android/app/src/main/res/mipmap-*/ic_launcher.png&lt;/code&gt;, plus &lt;code&gt;mipmap-anydpi-v26/ic_launcher.xml&lt;/code&gt; if the project uses an adaptive icon.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What size should the Flutter app icon be?&lt;/strong&gt;&lt;br&gt;
Start from 1024 × 1024 px. iOS needs 21 files from 20 to 1024 px, Android needs 48, 72, 96, 144 and 192 px, and the Play Store listing needs 512 px.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why does App Store Connect say my icon has an alpha channel when it is not transparent?&lt;/strong&gt;&lt;br&gt;
The PNG is saved as RGBA. Apple refuses the channel itself, not only transparent pixels. Save the iOS icons as RGB, for example with &lt;code&gt;remove_alpha_ios: true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why did my Flutter app icon not change on Android?&lt;/strong&gt;&lt;br&gt;
Either an adaptive icon in &lt;code&gt;mipmap-anydpi-v26&lt;/code&gt; is overriding the PNG files on Android 8 and later, or the launcher cached the old icon. Replace or delete the adaptive icon, then uninstall and reinstall the app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I need flutter_launcher_icons to change the icon?&lt;/strong&gt;&lt;br&gt;
No. It only writes files into the folders above. You can make them with any tool, as long as the sizes, names and the iOS alpha channel are right.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I use an SVG for the Flutter app icon?&lt;/strong&gt;&lt;br&gt;
Not directly. Both platforms need PNG files for the launcher icon. Export the SVG at 1024 × 1024 px and make the sizes from that.&lt;/p&gt;




&lt;p&gt;The &lt;a href="https://coderqh.com/tools/app-icon-generator/" rel="noopener noreferrer"&gt;app icon generator&lt;/a&gt; is free and runs in your browser. Every app in our &lt;a href="https://coderqh.com/" rel="noopener noreferrer"&gt;Flutter app templates&lt;/a&gt; ships with this icon set in place, ready for yours.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://coderqh.com/blog/flutter-app-icon/" rel="noopener noreferrer"&gt;coderqh.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>ios</category>
      <category>android</category>
    </item>
    <item>
      <title>Structured AI output in Flutter: Gemini, OpenAI, Claude</title>
      <dc:creator>Qihu Zhang</dc:creator>
      <pubDate>Mon, 02 Nov 2026 10:44:33 +0000</pubDate>
      <link>https://dev.to/coderqh/structured-ai-output-in-flutter-gemini-openai-claude-10g2</link>
      <guid>https://dev.to/coderqh/structured-ai-output-in-flutter-gemini-openai-claude-10g2</guid>
      <description>&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; all three APIs can return JSON that matches a schema you send. Each wants the schema in its own dialect: Gemini takes upper-case type names, OpenAI's strict mode needs every property required and &lt;code&gt;additionalProperties: false&lt;/code&gt;, and Claude needs &lt;code&gt;additionalProperties: false&lt;/code&gt; on every object. Write the schema once and convert it per vendor, or use &lt;a href="https://pub.dev/packages/gemini_openai_claude" rel="noopener noreferrer"&gt;&lt;code&gt;gemini_openai_claude&lt;/code&gt;&lt;/a&gt;, which does the conversion and returns the decoded JSON.&lt;/p&gt;

&lt;p&gt;If your app reads a receipt, tags a note or fills a form from a photo, you want an object back, not prose you have to parse. This guide shows how to get that from all three vendors with one schema, and how to handle the failures that look like success.&lt;/p&gt;

&lt;h2&gt;
  
  
  One request, three dialects
&lt;/h2&gt;

&lt;p&gt;Here is the same small schema the way you would write it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"object"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"mood"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"string"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"enum"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"calm"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"busy"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"required"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And what each vendor actually needs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Gemini&lt;/th&gt;
&lt;th&gt;OpenAI (strict)&lt;/th&gt;
&lt;th&gt;Claude&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Where the schema goes&lt;/td&gt;
&lt;td&gt;&lt;code&gt;generationConfig.responseSchema&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;response_format.json_schema&lt;/code&gt; with &lt;code&gt;strict: true&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;output_config.format&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Type names&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;STRING&lt;/code&gt;, &lt;code&gt;OBJECT&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;string&lt;/code&gt;, &lt;code&gt;object&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;string&lt;/code&gt;, &lt;code&gt;object&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;additionalProperties: false&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;not needed&lt;/td&gt;
&lt;td&gt;on every object&lt;/td&gt;
&lt;td&gt;on every object&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Optional fields&lt;/td&gt;
&lt;td&gt;as written&lt;/td&gt;
&lt;td&gt;not allowed: list all in &lt;code&gt;required&lt;/code&gt;, make the optional ones nullable&lt;/td&gt;
&lt;td&gt;as written&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Optional &lt;code&gt;enum&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;as written&lt;/td&gt;
&lt;td&gt;must also list &lt;code&gt;null&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;as written&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Images&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;inline_data&lt;/code&gt; parts after the text&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;image_url&lt;/code&gt; with a &lt;code&gt;data:&lt;/code&gt; URL&lt;/td&gt;
&lt;td&gt;base64 &lt;code&gt;image&lt;/code&gt; blocks before the text&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Without OpenAI's &lt;code&gt;strict: true&lt;/code&gt;, the schema is only a hint and the reply may not match it. With it, an optional property makes the request fail with a 400. That is why &lt;code&gt;mood&lt;/code&gt; above becomes &lt;code&gt;"type": ["string", "null"]&lt;/code&gt; with &lt;code&gt;null&lt;/code&gt; added to its &lt;code&gt;enum&lt;/code&gt; before it goes to OpenAI.&lt;/p&gt;

&lt;p&gt;The important design choice is &lt;strong&gt;where these conversions live&lt;/strong&gt;. If you write the Claude conversion inside your Claude code path, the other two keep working, your tests against the default provider pass, and the feature is quietly broken for everyone who switched. Keep the conversions next to the schema so one change reaches all three.&lt;/p&gt;

&lt;h2&gt;
  
  
  The code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:gemini_openai_claude/gemini_openai_claude.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PromptSpec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nl"&gt;instruction:&lt;/span&gt; &lt;span class="s"&gt;'Suggest a short title and a mood for this note: "Ship the release before Friday."'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;schema:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s"&gt;'type'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'object'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;'properties'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="s"&gt;'title'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'type'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'string'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="s"&gt;'mood'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'type'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'string'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'enum'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'calm'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'busy'&lt;/span&gt;&lt;span class="p"&gt;]},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="s"&gt;'required'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'title'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;AiAdapter&lt;/span&gt; &lt;span class="n"&gt;ai&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s"&gt;'gemini'&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;GeminiProvider&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="s"&gt;'openai'&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;OpenAiProvider&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ClaudeProvider&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;ai&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;spec:&lt;/span&gt; &lt;span class="n"&gt;spec&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;apiKey:&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;model:&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// {"title": "Friday release", "mood": "busy"}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The package is plain Dart with one dependency (&lt;code&gt;http&lt;/code&gt;). It calls the REST APIs directly, so no vendor SDK update can break it. For a photo, add &lt;code&gt;images: [PromptImage(mime: 'image/jpeg', base64: base64Encode(bytes))]&lt;/code&gt; to the spec.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failures that arrive as HTTP 200
&lt;/h2&gt;

&lt;p&gt;Checking the status code is not enough. All three vendors can return 200 with no usable answer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Safety block or refusal.&lt;/strong&gt; Gemini returns no &lt;code&gt;content&lt;/code&gt;, with a &lt;code&gt;blockReason&lt;/code&gt; or a &lt;code&gt;finishReason&lt;/code&gt; such as &lt;code&gt;SAFETY&lt;/code&gt; or &lt;code&gt;RECITATION&lt;/code&gt;. OpenAI fills a &lt;code&gt;refusal&lt;/code&gt; field or ends with &lt;code&gt;content_filter&lt;/code&gt;. Claude returns &lt;code&gt;stop_reason: "refusal"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cut off at the token limit.&lt;/strong&gt; Gemini says &lt;code&gt;MAX_TOKENS&lt;/code&gt;, OpenAI &lt;code&gt;finish_reason: "length"&lt;/code&gt;, Claude &lt;code&gt;stop_reason: "max_tokens"&lt;/code&gt;. The JSON looks almost valid and then stops mid-token.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Empty answer.&lt;/strong&gt; A 200 with an empty candidate list.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you parse these as normal replies, your app reports "the API may have changed", which sends you to read code instead of retrying. The adapters turn each case into a &lt;code&gt;ProviderException&lt;/code&gt; with its own &lt;code&gt;kind&lt;/code&gt;: &lt;code&gt;declined&lt;/code&gt;, &lt;code&gt;truncated&lt;/code&gt; or &lt;code&gt;emptyResult&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The HTTP errors also deserve separate handling:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;th&gt;Usually means&lt;/th&gt;
&lt;th&gt;What to tell the user&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;401, or 400 mentioning the key&lt;/td&gt;
&lt;td&gt;Bad key&lt;/td&gt;
&lt;td&gt;Check the key&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;403 on Gemini&lt;/td&gt;
&lt;td&gt;API not enabled on the project, or region not supported&lt;/td&gt;
&lt;td&gt;Not a key problem&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;404&lt;/td&gt;
&lt;td&gt;Model name retired or misspelled&lt;/td&gt;
&lt;td&gt;Choose a current model&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;429&lt;/td&gt;
&lt;td&gt;Rate limit or billing&lt;/td&gt;
&lt;td&gt;Wait, or switch provider&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5xx, 529 on Claude&lt;/td&gt;
&lt;td&gt;Vendor overloaded&lt;/td&gt;
&lt;td&gt;Try again shortly&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Model names are a setting
&lt;/h2&gt;

&lt;p&gt;Vendors retire model names roughly once a year. If the name is a constant in your app, the feature stops working the day it is retired and stays broken until you ship an update. Make the model a setting or a remote config value, and treat a 404 as "choose a current model", not as a crash.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the API key lives
&lt;/h2&gt;

&lt;p&gt;Anything compiled into an app can be extracted, so &lt;strong&gt;do not ship your own API key in the binary&lt;/strong&gt;. Two patterns are safe:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Users bring their own key.&lt;/strong&gt; They paste it into settings, you store it in the Keychain or Keystore, and the app calls the vendor directly. Good for tools aimed at developers and power users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your server holds the key.&lt;/strong&gt; The app calls your backend, and the backend calls the vendor. This is the only option when you pay for the requests. Because the package is plain Dart, the same adapters can run on a Dart server.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Testing without a network
&lt;/h2&gt;

&lt;p&gt;Every adapter accepts an &lt;code&gt;http.Client&lt;/code&gt;, so tests use &lt;code&gt;MockClient&lt;/code&gt; and never call a vendor. &lt;code&gt;DemoProvider&lt;/code&gt; answers on the device from an offline answer you attach to the spec, which is useful for demo builds and screenshots:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PromptSpec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nl"&gt;instruction:&lt;/span&gt; &lt;span class="s"&gt;'...'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;schema:&lt;/span&gt; &lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;demo:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'title'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Friday release'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'mood'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'busy'&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nf"&gt;DemoProvider&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;spec:&lt;/span&gt; &lt;span class="n"&gt;spec&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;apiKey:&lt;/span&gt; &lt;span class="s"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;How do I get structured JSON output from Gemini, OpenAI and Claude with the same schema?&lt;/strong&gt;&lt;br&gt;
Write one JSON Schema and convert it per vendor: upper-case types for Gemini, strict mode with every property required for OpenAI, and &lt;code&gt;additionalProperties: false&lt;/code&gt; on every object for Claude. The &lt;code&gt;gemini_openai_claude&lt;/code&gt; package does this for you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why does OpenAI reject my schema with a 400?&lt;/strong&gt;&lt;br&gt;
In strict mode every property must be listed in &lt;code&gt;required&lt;/code&gt;, every object needs &lt;code&gt;additionalProperties: false&lt;/code&gt;, and an optional field must be nullable, including &lt;code&gt;null&lt;/code&gt; in its &lt;code&gt;enum&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why does Gemini return 403 with a valid API key?&lt;/strong&gt;&lt;br&gt;
The Generative Language API is not enabled on the key's project, or the region is not supported. It is a project setting, not the key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is it safe to put my OpenAI or Gemini API key in a Flutter app?&lt;/strong&gt;&lt;br&gt;
No. Let users bring their own key, or call the vendor from your own server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I need the vendor SDKs?&lt;/strong&gt;&lt;br&gt;
No. All three have REST APIs, and a thin HTTP client is easier to keep working across SDK releases.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://pub.dev/packages/gemini_openai_claude" rel="noopener noreferrer"&gt;&lt;code&gt;gemini_openai_claude&lt;/code&gt;&lt;/a&gt; is open source on &lt;a href="https://github.com/coderqh/gemini_openai_claude" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. It comes from the AI apps in our &lt;a href="https://coderqh.com/" rel="noopener noreferrer"&gt;Flutter app templates&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://coderqh.com/blog/flutter-ai-structured-output/" rel="noopener noreferrer"&gt;coderqh.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>ai</category>
      <category>openai</category>
    </item>
    <item>
      <title>Sign in with Google and Apple in Flutter (2026 guide)</title>
      <dc:creator>Qihu Zhang</dc:creator>
      <pubDate>Mon, 02 Nov 2026 10:39:04 +0000</pubDate>
      <link>https://dev.to/coderqh/sign-in-with-google-and-apple-in-flutter-2026-guide-1bd6</link>
      <guid>https://dev.to/coderqh/sign-in-with-google-and-apple-in-flutter-2026-guide-1bd6</guid>
      <description>&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; use &lt;code&gt;google_sign_in&lt;/code&gt; for Google and &lt;code&gt;sign_in_with_apple&lt;/code&gt; for Apple, or wrap both with &lt;a href="https://pub.dev/packages/google_apple_sign_in" rel="noopener noreferrer"&gt;&lt;code&gt;google_apple_sign_in&lt;/code&gt;&lt;/a&gt;. On Android, Google needs a Web OAuth client id plus one Android client per signing key's SHA-1. On iOS, Apple needs the Sign in with Apple capability. Then send the id token to Firebase or your backend.&lt;/p&gt;

&lt;p&gt;The code is the easy part. Most of the time goes into console setup, and most of the bugs only show up in release builds or in App Review. This guide walks through the four configurations in the order they usually break, then shows what to do with the token.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you are building
&lt;/h2&gt;

&lt;p&gt;A login screen with two buttons that work on both platforms:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Android&lt;/th&gt;
&lt;th&gt;iOS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Google&lt;/td&gt;
&lt;td&gt;Native sheet (Credential Manager)&lt;/td&gt;
&lt;td&gt;Native sheet&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Apple&lt;/td&gt;
&lt;td&gt;Web flow in a browser tab&lt;/td&gt;
&lt;td&gt;Native sheet&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both buttons return the same thing: an &lt;strong&gt;id token&lt;/strong&gt; (a signed JWT) that proves who the user is. Your app never handles a password.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 0: one interface for both providers
&lt;/h2&gt;

&lt;p&gt;If you call the two SDKs directly, you end up with two sets of exceptions, two result types and platform checks scattered across your UI. A thin interface keeps the login screen simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;signIn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PlatformSocialSignIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;SocialSignInConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nl"&gt;googleClientId:&lt;/span&gt; &lt;span class="s"&gt;'IOS_CLIENT_ID.apps.googleusercontent.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;googleServerClientId:&lt;/span&gt; &lt;span class="s"&gt;'WEB_CLIENT_ID.apps.googleusercontent.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;appleSignIn:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;// Which buttons to show on this platform&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;provider&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;signIn&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* build a button */&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;signIn&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;signIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;SocialProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;google&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// c.idToken, c.email, c.displayName (and c.rawNonce for Apple)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="kd"&gt;on&lt;/span&gt; &lt;span class="n"&gt;SocialSignInCancelled&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// the user closed the sheet: not an error&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="kd"&gt;on&lt;/span&gt; &lt;span class="n"&gt;SocialSignInFailure&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// misconfiguration, no network, platform error&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is the &lt;a href="https://pub.dev/packages/google_apple_sign_in" rel="noopener noreferrer"&gt;&lt;code&gt;google_apple_sign_in&lt;/code&gt;&lt;/a&gt; package (MIT). Install it with &lt;code&gt;flutter pub add google_apple_sign_in&lt;/code&gt;. Everything below applies whether you use it or call the SDKs yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Google on Android
&lt;/h2&gt;

&lt;p&gt;Google Cloud console → APIs &amp;amp; Services → Credentials. Configure the OAuth consent screen first if it asks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create a Web application client.&lt;/strong&gt; Its id goes into &lt;code&gt;serverClientId&lt;/code&gt; (&lt;code&gt;googleServerClientId&lt;/code&gt; in the package). This is the step people skip: without a Web client id, Android signs the user in but returns &lt;strong&gt;no id token&lt;/strong&gt;, so your backend has nothing to verify.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create an Android client for every key that signs your app.&lt;/strong&gt; Each one needs your package name and that key's SHA-1:

&lt;ul&gt;
&lt;li&gt;your debug key: &lt;code&gt;keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;your upload key: the same command on your upload keystore, or &lt;code&gt;cd android &amp;amp;&amp;amp; ./gradlew signingReport&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google Play's app signing key&lt;/strong&gt;: Play Console → your app → App integrity → App signing.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The third one causes the classic "works on my phone, fails for everyone on the Play Store" bug. Play re-signs your app with its own key, so the SHA-1 your users run is not the one on your machine.&lt;/p&gt;

&lt;p&gt;You do not need &lt;code&gt;google-services.json&lt;/code&gt; for Google sign-in itself. You need it only if you also use Firebase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Google on iOS
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create an &lt;strong&gt;iOS client&lt;/strong&gt; with your bundle id. Its id is &lt;code&gt;clientId&lt;/code&gt; (&lt;code&gt;googleClientId&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Add the &lt;em&gt;reversed&lt;/em&gt; client id as a URL scheme in &lt;code&gt;ios/Runner/Info.plist&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;key&amp;gt;&lt;/span&gt;CFBundleURLTypes&lt;span class="nt"&gt;&amp;lt;/key&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;array&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;dict&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;key&amp;gt;&lt;/span&gt;CFBundleURLSchemes&lt;span class="nt"&gt;&amp;lt;/key&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;array&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;string&amp;gt;&lt;/span&gt;com.googleusercontent.apps.YOUR_IOS_CLIENT_ID&lt;span class="nt"&gt;&amp;lt;/string&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/array&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/dict&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/array&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Set the Web client id from step 1 as &lt;code&gt;serverClientId&lt;/code&gt; here too. Then the token's audience is the same on both platforms, and your backend checks one value.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step 3: Apple on iOS, and App Store guideline 4.8
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Apple Developer → Certificates, Identifiers &amp;amp; Profiles → Identifiers → your App ID → enable &lt;strong&gt;Sign in with Apple&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Xcode → Runner target → Signing &amp;amp; Capabilities → &lt;strong&gt;+ Capability → Sign in with Apple&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Do both before you show the button. On an App ID without the capability, every tap fails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Guideline 4.8&lt;/strong&gt; is why Apple is hard to skip: an iOS app that offers a third-party login such as Google must also offer an equivalent login option that limits data to name and email, lets users hide their email, and does not track them. Sign in with Apple meets all three out of the box, so it is the usual answer, and a Google button alone on iOS is a common rejection. The package takes the safe default. &lt;code&gt;providers&lt;/code&gt; hides the Google button on iOS until &lt;code&gt;appleSignIn&lt;/code&gt; is true, and a debug build prints why in the console. Android shows whatever you configured.&lt;/p&gt;

&lt;p&gt;Two Apple behaviors to plan for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Apple sends the user's &lt;strong&gt;name and email only on the first sign-in&lt;/strong&gt; for that Apple ID. Save them then. Later sign-ins return no name.&lt;/li&gt;
&lt;li&gt;The email may be a &lt;strong&gt;private relay address&lt;/strong&gt; (an address at &lt;code&gt;privaterelay.appleid.com&lt;/code&gt;). Treat it as a real address that forwards; do not use it as the user's identity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 4: Apple on Android
&lt;/h2&gt;

&lt;p&gt;Android has no native Apple sign-in, so the flow runs in a browser tab and comes back through your server:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Apple Developer → Identifiers → &lt;strong&gt;Services IDs&lt;/strong&gt; → create one, for example &lt;code&gt;com.example.app.signin&lt;/code&gt;. That is &lt;code&gt;appleServiceId&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Turn on Sign in with Apple for it: choose your primary App ID, add your domain, and add a &lt;strong&gt;Return URL&lt;/strong&gt; on your server, for example &lt;code&gt;https://api.example.com/auth/apple/callback&lt;/code&gt;. That is &lt;code&gt;appleRedirectUri&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;That endpoint receives Apple's form POST and redirects into the app:
&lt;code&gt;intent://callback?&amp;lt;the posted fields&amp;gt;#Intent;package=YOUR.PACKAGE.NAME;scheme=signinwithapple;end&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Register the callback activity in &lt;code&gt;AndroidManifest.xml&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;activity&lt;/span&gt;
    &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"com.aboutyou.dart_packages.sign_in_with_apple.SignInWithAppleCallback"&lt;/span&gt;
    &lt;span class="na"&gt;android:exported=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;intent-filter&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;action&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.action.VIEW"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;category&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.category.DEFAULT"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;category&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.category.BROWSABLE"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;data&lt;/span&gt; &lt;span class="na"&gt;android:scheme=&lt;/span&gt;&lt;span class="s"&gt;"signinwithapple"&lt;/span&gt; &lt;span class="na"&gt;android:path=&lt;/span&gt;&lt;span class="s"&gt;"/callback"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/intent-filter&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/activity&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you do not have a server yet, skip Apple on Android. Google covers Android users, and guideline 4.8 only applies to iOS. The package offers the Apple button on Android only when &lt;code&gt;appleServiceId&lt;/code&gt; is set.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: use the token
&lt;/h2&gt;

&lt;h3&gt;
  
  
  With Firebase Auth
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;signIn&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;signIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;AuthCredential&lt;/span&gt; &lt;span class="n"&gt;cred&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;SocialProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;google&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;GoogleAuthProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;credential&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;idToken:&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;idToken&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="n"&gt;SocialProvider&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apple&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;OAuthProvider&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'apple.com'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;credential&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;idToken:&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;idToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;rawNonce:&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;rawNonce&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;accessToken:&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;authorizationCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;FirebaseAuth&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;signInWithCredential&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cred&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apple with Firebase needs a &lt;strong&gt;nonce&lt;/strong&gt;: you send Apple the SHA-256 of a random string and send Firebase the raw string, so Firebase can check that the token was issued for this request. The package generates the pair and returns the raw value as &lt;code&gt;rawNonce&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  With your own backend
&lt;/h3&gt;

&lt;p&gt;Post the id token (and &lt;code&gt;rawNonce&lt;/code&gt; for Apple) and verify it on the server. Never trust the email or name the app sends alongside it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check the signature against the provider's public keys: &lt;code&gt;https://www.googleapis.com/oauth2/v3/certs&lt;/code&gt; for Google, &lt;code&gt;https://appleid.apple.com/auth/keys&lt;/code&gt; for Apple.&lt;/li&gt;
&lt;li&gt;Check &lt;code&gt;iss&lt;/code&gt;: &lt;code&gt;https://accounts.google.com&lt;/code&gt; or &lt;code&gt;accounts.google.com&lt;/code&gt; for Google; &lt;code&gt;https://appleid.apple.com&lt;/code&gt; for Apple.&lt;/li&gt;
&lt;li&gt;Check &lt;code&gt;aud&lt;/code&gt;: your Web client id for Google; your bundle id (iOS) or Services ID (Android) for Apple.&lt;/li&gt;
&lt;li&gt;Check &lt;code&gt;exp&lt;/code&gt;, and for Apple check that the &lt;code&gt;nonce&lt;/code&gt; claim equals SHA-256 of &lt;code&gt;rawNonce&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Create or find the user by the token's &lt;code&gt;sub&lt;/code&gt;. Do not use email as the key: Apple's can be a relay, and either provider's can change.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Most server frameworks have a JWT library that does steps 1 to 4 when you give it the keys URL and expected values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing without real accounts
&lt;/h2&gt;

&lt;p&gt;Make your login screen depend on the &lt;code&gt;SocialSignIn&lt;/code&gt; interface and inject a fake in tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;fake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;FakeSocialSignIn&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;loginController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fake&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;tapGoogle&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fake&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;calls&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;fake&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the next tap behaves like the user closing the sheet&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you can check which buttons iOS would show without a device:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SocialSignInConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;googleServerClientId:&lt;/span&gt; &lt;span class="s"&gt;'x'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;offered&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;applePlatform:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;isEmpty&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// guideline 4.8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Checklist before release
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;[ ] Web client id set as &lt;code&gt;serverClientId&lt;/code&gt; on both platforms&lt;/li&gt;
&lt;li&gt;[ ] Android clients for debug, upload &lt;strong&gt;and&lt;/strong&gt; Play app signing SHA-1&lt;/li&gt;
&lt;li&gt;[ ] iOS reversed client id in &lt;code&gt;Info.plist&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;[ ] Sign in with Apple enabled on the App ID and in Xcode&lt;/li&gt;
&lt;li&gt;[ ] Google not offered alone on iOS (guideline 4.8)&lt;/li&gt;
&lt;li&gt;[ ] Name and email saved on the first Apple sign-in&lt;/li&gt;
&lt;li&gt;[ ] Backend verifies signature, &lt;code&gt;iss&lt;/code&gt;, &lt;code&gt;aud&lt;/code&gt;, &lt;code&gt;exp&lt;/code&gt; and keys users on &lt;code&gt;sub&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Do I need Firebase to add Google and Apple sign-in to Flutter?&lt;/strong&gt;&lt;br&gt;
No. Both SDKs return an id token you can verify on any backend. Firebase is one convenient place to send it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why does Google sign-in return a null id token on Android?&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;serverClientId&lt;/code&gt; is missing or set to the Android client id. It must be the Web application client id.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why does Google sign-in work in debug but fail from the Play Store?&lt;/strong&gt;&lt;br&gt;
The SHA-1 of Google Play's app signing key is not registered. Add another Android OAuth client with that SHA-1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I have to add Sign in with Apple if my app has Google sign-in?&lt;/strong&gt;&lt;br&gt;
On iOS, App Store guideline 4.8 requires an equivalent privacy-focused login next to any third-party login, and Sign in with Apple is the simplest way to meet it. On Android it is optional.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why does Apple not return the user's name the second time?&lt;/strong&gt;&lt;br&gt;
Apple only shares the name and email on the first authorization. To test the first-time flow again, remove the app under Settings → your name → Sign-In &amp;amp; Security → Sign in with Apple.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I use Sign in with Apple on Android?&lt;/strong&gt;&lt;br&gt;
Yes, through a web flow. It needs a Services ID and a server endpoint as the Return URL.&lt;/p&gt;




&lt;p&gt;The &lt;a href="https://pub.dev/packages/google_apple_sign_in" rel="noopener noreferrer"&gt;&lt;code&gt;google_apple_sign_in&lt;/code&gt;&lt;/a&gt; package is open source on &lt;a href="https://github.com/coderqh/google_apple_sign_in" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. It comes from the login screens in our &lt;a href="https://coderqh.com/" rel="noopener noreferrer"&gt;Flutter app templates&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://coderqh.com/blog/flutter-google-apple-sign-in/" rel="noopener noreferrer"&gt;coderqh.com&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>firebase</category>
      <category>authentication</category>
    </item>
  </channel>
</rss>
