<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Neemii: Flutter and mobile app development</title>
    <link>https://neemii.dev/blog/</link>
    <atom:link href="https://neemii.dev/rss.xml" rel="self" type="application/rss+xml" />
    <description>Practical guides on Flutter, app costs and App Store and Google Play releases, by Muhammad Naeem.</description>
    <language>en</language>
    <lastBuildDate>Sun, 22 Nov 2026 00:00:00 GMT</lastBuildDate>
    <item>
      <title>App Store Rejection Reasons in 2026 and How to Fix Each One</title>
      <link>https://neemii.dev/blog/app-store-rejection-reasons-fixes/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/app-store-rejection-reasons-fixes/</guid>
      <pubDate>Sun, 22 Nov 2026 00:00:00 GMT</pubDate>
      <description>The most common App Store rejections (guidelines 2.1, 2.3, 4.2, 4.8, 5.1.1 and more), what each message means, how to fix it, and how to reply or appeal.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> most App Store rejections come from a few guidelines. Apple says <a href="https://developer.apple.com/distribute/app-review/">over 40% of unresolved issues relate to guideline 2.1, App Completeness</a>: crashes, placeholder content, broken links and missing demo accounts. The other common ones are vague permission text and privacy issues (5.1.1), screenshots that don’t show the app (2.3), too little functionality (4.2), social login without an equivalent private option (4.8), and digital purchases outside In-App Purchase (3.1.1). Read which guideline the rejection names, fix that exact thing, reply in App Store Connect explaining what changed, and resubmit.</p>
<p>A rejection isn’t a ban. It’s a message saying one specific thing doesn’t meet a specific guideline. Below is each common rejection, what it looks like, and how I fix it in the Flutter apps I ship.</p>
<h2 id="how-to-read-a-rejection">How to read a rejection</h2>
<p>In App Store Connect, open your app and go to <strong>App Review</strong>. The rejected submission shows a message from the reviewer. It always names one or more guidelines, for example “Guideline 2.1 - Performance - App Completeness”, followed by what they saw, often with screenshots and the device they tested on.</p>
<p>Three things to check before you change any code:</p>
<ol>
<li><strong>The guideline number.</strong> It tells you which rule, and you can read the exact text in Apple’s <a href="https://developer.apple.com/app-store/review/guidelines/">App Review Guidelines</a>.</li>
<li><strong>The device and OS.</strong> If they tested on an iPad and you only tested on iPhones, that’s often the whole story.</li>
<li><strong>Whether it’s a rejection or a question.</strong> “Guideline 2.1 - Information Needed” isn’t a rejection of the app. They need an answer, and you can usually reply without a new build.</li>
</ol>
<h2 id="the-most-common-rejections-and-their-fixes">The most common rejections and their fixes</h2>
<h3 id="guideline-21-app-completeness-crashes-bugs-placeholders">Guideline 2.1: App Completeness (crashes, bugs, placeholders)</h3>
<p><strong>What it looks like:</strong> “We discovered one or more bugs in your app”, “Your app crashed on launch”, or “We found placeholder content”.</p>
<p>Apple says submissions should be final builds with complete metadata and working URLs, tested on a device, with no placeholder text and with the back end live during review.</p>
<p><strong>How to fix it:</strong></p>
<ul>
<li>Test the <strong>release</strong> build, not debug, on a real device. In Flutter, <code>flutter build ipa</code> produces a build with tree shaking and (if you use it) obfuscation, which can fail where debug works.</li>
<li>Test on an iPad too. iPhone apps run on iPad by default, and reviewers often use one.</li>
<li>Remove “coming soon” screens, empty tabs, test data and lorem ipsum.</li>
<li>Check every link: the support URL and privacy policy URL in App Store Connect, and every link inside the app.</li>
<li>If the crash happened on launch, look at the crash log attached to the rejection and at Xcode’s Organizer. A common Flutter cause is a missing <code>Info.plist</code> key for a permission a package asks for.</li>
</ul>
<h3 id="guideline-21-information-needed-demo-account">Guideline 2.1: Information Needed (demo account)</h3>
<p><strong>What it looks like:</strong> “We were unable to sign in” or “Please provide a demo account”.</p>
<p><strong>How to fix it:</strong> in App Store Connect, under <strong>App Review Information</strong>, add a username and password for a working account with realistic sample data. If the app needs special hardware, a QR code or an invite code, explain how to get past it in the notes, or attach a short screen recording. Make sure the server that account uses stays online during review. A staging server switched off over the weekend is a classic cause.</p>
<h3 id="guideline-511-data-collection-permission-strings-and-privacy">Guideline 5.1.1: Data collection, permission strings and privacy</h3>
<p><strong>What it looks like:</strong> “Your app’s purpose string does not sufficiently explain the use of protected resources”, or questions about why the app asks for certain data.</p>
<p>Permission text (“purpose strings” in <code>Info.plist</code>) must explain what the feature does with the data. “This app needs access to your camera” doesn’t. “Acme uses your camera to scan QR codes at checkout” does.</p>
<p><strong>How to fix it:</strong></p>
<ul>
<li>Rewrite each purpose string to name the feature and the benefit. My free <a href="https://neemii.dev/tools/ios-permission-text-generator/">iOS permission text generator</a> writes the <code>Info.plist</code> lines for Flutter apps and flags vague wording.</li>
<li>Ask for a permission at the moment the user needs it, not on the first launch.</li>
<li>Don’t ask for data the app doesn’t need. If a package asks for a permission you don’t use, remove the package or the feature.</li>
<li>Make sure the privacy policy says what you collect, why, who you share it with, and how users delete it. See <a href="https://neemii.dev/blog/app-privacy-policy-requirements/">what Apple and Google require in an app privacy policy</a>, or create one with the <a href="https://neemii.dev/tools/app-privacy-policy-generator/">app privacy policy generator</a>.</li>
</ul>
<h3 id="guideline-511v-account-deletion">Guideline 5.1.1(v): Account deletion</h3>
<p><strong>What it looks like:</strong> “Your app supports account creation but does not include an option to initiate account deletion.”</p>
<p><strong>How to fix it:</strong> if users can create an account, they must be able to start deleting it <strong>inside the app</strong>, usually from the settings or profile screen. A link to an email address isn’t enough. If you use Firebase Auth, delete the user and their data on your server or with a Cloud Function, not only on the device, and sign them out afterwards.</p>
<h3 id="guideline-23-accurate-metadata-and-screenshots">Guideline 2.3: Accurate metadata and screenshots</h3>
<p><strong>What it looks like:</strong> “Your screenshots do not sufficiently reflect your app in use” or “Your app description mentions features that aren’t in the app”.</p>
<p>Screenshots must show the app being used, not only a splash screen, a login page or marketing art. The name, description and screenshots must match what the current version actually does.</p>
<p><strong>How to fix it:</strong> take screenshots of real screens with real-looking data. Marketing text on top is fine, but the app itself must be visible. Remove features from the description that aren’t in this build, and don’t mention other platforms such as Android in the iOS listing.</p>
<h3 id="guideline-42-minimum-functionality">Guideline 4.2: Minimum functionality</h3>
<p><strong>What it looks like:</strong> “Your app provides a limited user experience as it is not sufficiently different from a mobile browsing experience.”</p>
<p>This usually means a WebView wrapped around a website, or an app with one screen and nothing an app can do better than a web page.</p>
<p><strong>How to fix it:</strong> add features that use the phone: offline access, push notifications, the camera, native navigation, saved data. If the app really is a website, publish it as a website. For Flutter apps built around an existing web product, build at least the main flows natively instead of loading web pages.</p>
<h3 id="guideline-43-spam">Guideline 4.3: Spam</h3>
<p><strong>What it looks like:</strong> “Your app duplicates the content and functionality of other apps.”</p>
<p>It happens when one developer submits many near-identical apps (for example one per city or one per client from the same template), or when an app is very similar to many others on the store.</p>
<p><strong>How to fix it:</strong> combine variants into one app with in-app choices, or make each app clearly different. For white-label client apps, each client should publish under their own developer account, not all under yours.</p>
<h3 id="guideline-48-login-services-sign-in-with-apple">Guideline 4.8: Login services (Sign in with Apple)</h3>
<p><strong>What it looks like:</strong> “Your app uses a third-party login service but does not offer an equivalent login option.”</p>
<p>If your app’s main account uses Google, Facebook or another third-party login, Apple asks for an option that limits data to name and email and lets users hide their email address. Sign in with Apple meets this.</p>
<p><strong>How to fix it:</strong> add Sign in with Apple next to the other buttons. In Flutter, the <code>sign_in_with_apple</code> package (or Firebase Auth’s Apple provider) handles it, and you need to enable the capability in Xcode and in your Apple developer account.</p>
<h3 id="guideline-311-in-app-purchase">Guideline 3.1.1: In-App Purchase</h3>
<p><strong>What it looks like:</strong> “Your app unlocks paid digital content or features without using In-App Purchase.”</p>
<p>Digital things used inside the app, such as premium features, subscriptions, coins or courses, generally have to be sold with Apple’s In-App Purchase, not your own payment page, license keys or QR codes. Physical goods and services used outside the app (food delivery, rides, hotel bookings) are different and use normal payment providers. The rules for linking to outside payments have changed in some regions, so read the current version of guideline 3.1 for the storefronts you sell in.</p>
<p><strong>How to fix it:</strong> use In-App Purchase for digital goods (in Flutter, <code>in_app_purchase</code> or RevenueCat), include a “Restore purchases” button, and make sure the purchase items are submitted for review with the build.</p>
<h3 id="upload-errors-that-look-like-rejections">Upload errors that look like rejections</h3>
<p>Some problems stop the build before a human sees it. You get an email from App Store Connect instead of a review message:</p>
<ul>
<li><strong>ITMS-90683: Missing purpose string in Info.plist.</strong> A package in your app references a permission (camera, photos, location) and there’s no text for it. Add the key with an honest sentence.</li>
<li><strong>ITMS-91053: Missing API declaration.</strong> Your app or an SDK uses a “required reason” API without a privacy manifest declaring why. Update the packages (most popular Flutter plugins now ship a manifest) and add a <code>PrivacyInfo.xcprivacy</code> file for your own code if needed. The <a href="https://neemii.dev/tools/apple-privacy-manifest-generator/">Apple privacy manifest generator</a> builds that file and lists the reason codes.</li>
</ul>
<h2 id="how-to-reply-to-app-review">How to reply to App Review</h2>
<p>Reply in the <strong>App Review</strong> section of App Store Connect, on the rejected submission. A good reply is short and specific:</p>
<blockquote>
<p>Thank you for the review. We’ve added account deletion under Settings → Account → Delete account (screenshot attached). It removes the account and all user data from our servers. The new build is 1.4.1 (23).</p>
</blockquote>
<p>If you think the reviewer misunderstood the app, say so politely and explain what it does. On one of my own apps, a personal budgeting app, App Review treated it as if it handled real money. It only tracks budgets and spending that the user types in, and no money moves through it. A clear reply explaining exactly that solved it without any code change.</p>
<p>A few rules I follow:</p>
<ul>
<li>Answer every point in the message, in the same order.</li>
<li>Attach screenshots or a short screen recording showing the fix.</li>
<li>Don’t argue about other apps that do the same thing. Reviewers judge your app against the guidelines.</li>
<li>If you only changed metadata (screenshots, description, demo account), you often don’t need a new build. Update it and reply.</li>
</ul>
<h2 id="when-to-appeal">When to appeal</h2>
<p>If you’ve replied and still believe the app follows the guidelines, you can <a href="https://developer.apple.com/distribute/app-review/">appeal to the App Review Board</a>. Give specific reasons with guideline references. Apple accepts one appeal per rejected submission and asks you to answer any open questions from App Review first.</p>
<p>You can also book a 30-minute call with App Review through Apple’s developer site to ask how to fix a rejection, and request an <strong>expedited review</strong> for a critical bug fix or a time-sensitive event.</p>
<h2 id="how-long-review-takes-after-a-fix">How long review takes after a fix</h2>
<p>Apple says it typically reviews at least 50% of submissions in under 24 hours and 90% in under 48 hours. A resubmission usually goes through in a similar time. Replies without a new build are often answered faster.</p>
<h2 id="a-checklist-before-you-submit">A checklist before you submit</h2>
<ul>
<li>Release build tested on a real iPhone and an iPad</li>
<li>Demo account with sample data in App Review Information, and the server online</li>
<li>No placeholder content, every link working</li>
<li>Clear purpose string for every permission</li>
<li>Privacy policy link in App Store Connect and inside the app</li>
<li>Account deletion inside the app if users can sign up</li>
<li>Sign in with Apple if you offer Google or Facebook login</li>
<li>Screenshots of the real app, matching this version</li>
<li>In-App Purchase for digital goods, with Restore purchases</li>
<li>Privacy manifest and up-to-date packages</li>
</ul>
<p>The full release process, including Google Play, is in <a href="https://neemii.dev/blog/publish-flutter-app-app-store-google-play/">how to publish a Flutter app on the App Store and Google Play</a>.</p>
<h2 id="frequently-asked-questions">Frequently asked questions</h2>
<div class="faq-list">
<details class="faq" name="faq">
<summary>What is the most common reason for App Store rejection?</summary>
<p>Guideline 2.1, App Completeness. Apple says it accounts for over 40% of unresolved issues: crashes, bugs, placeholder content, broken links and missing demo account details.</p>
</details>
<details class="faq" name="faq">
<summary>Do I need to upload a new build after a rejection?</summary>
<p>Only if the fix needs code changes. If the problem was metadata, such as screenshots, the description or the demo account, update it in App Store Connect and reply to App Review without a new build.</p>
</details>
<details class="faq" name="faq">
<summary>How long does Apple take to review a resubmitted app?</summary>
<p>Apple typically reviews at least 50% of submissions in under 24 hours and 90% in under 48 hours. Resubmissions usually take about the same time.</p>
</details>
<details class="faq" name="faq">
<summary>Can I appeal an App Store rejection?</summary>
<p>Yes. If you believe the app follows the guidelines, appeal to the App Review Board from Apple’s App Review page, with specific reasons. You can submit one appeal per rejected submission.</p>
</details>
<details class="faq" name="faq">
<summary>Why was my app rejected for its permission text?</summary>
<p>Guideline 5.1.1 asks apps to explain clearly why they need protected data. Text like “This app needs camera access” doesn’t say why. Name the feature and the benefit, for example “Acme uses your camera to scan QR codes at checkout”.</p>
</details>
<details class="faq" name="faq">
<summary>Does a rejection hurt my developer account?</summary>
<p>A normal rejection doesn’t. It’s part of the process, and many apps are rejected once or twice. Repeated attempts to hide features from review, spam or fraud are different and can lead to account termination.</p>
</details>
</div>
<p>Has App Review rejected your Flutter app? <a href="https://neemii.dev/#contact">Send me the rejection message</a>. I’m Muhammad Naeem, a Flutter developer with 10+ apps live on the App Store and Google Play, and I can usually tell you what needs to change in one reply. For ongoing releases, see <a href="https://neemii.dev/services/app-maintenance/">app maintenance and support</a>.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-app-store-rejection-reasons-fixes.png" type="image/png" length="0" />
    </item>
    <item>
      <title>Google Play Target API Level 2026: Android 16 (API 36) for Flutter</title>
      <link>https://neemii.dev/blog/google-play-target-api-level-flutter/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/google-play-target-api-level-flutter/</guid>
      <pubDate>Fri, 20 Nov 2026 00:00:00 GMT</pubDate>
      <description>Google Play now requires new apps and updates to target Android 16 (API 36). What the rule means, deadlines, and how to update a Flutter app step by step.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> since August 31, 2026, every new app and every app update on Google Play must target <strong>Android 16 (API level 36)</strong> or higher. Existing apps that target lower than <strong>Android 15 (API 35)</strong> stop showing to new users on newer Android versions. In a Flutter app, you usually fix this by upgrading Flutter (3.35 already targets API 36 by default), checking <code>targetSdk</code> and <code>compileSdk</code> in <code>android/app/build.gradle</code>, updating the Android Gradle Plugin, and testing the Android 16 behaviour changes before you upload.</p>
<p>Google raises this requirement every year, and it’s one of the most common reasons a Flutter app suddenly can’t be updated. Here’s what the rule says, and the exact steps I follow to move a Flutter app to the new target.</p>
<h2 id="what-google-play-requires-right-now">What Google Play requires right now</h2>
<p>From Google’s <a href="https://support.google.com/googleplay/android-developer/answer/11926878">target API level requirements</a> page:</p>
<table>
<thead>
<tr>
<th>Who</th>
<th>Requirement</th>
<th>Since</th>
</tr>
</thead>
<tbody>
<tr>
<td>New apps and app updates (phones and tablets)</td>
<td>Target <strong>Android 16 (API 36)</strong> or higher</td>
<td>31 Aug 2026</td>
</tr>
<tr>
<td>Existing apps, to stay visible to new users on newer devices</td>
<td>Target <strong>Android 15 (API 35)</strong> or higher</td>
<td>31 Aug 2026</td>
</tr>
<tr>
<td>Wear OS and Android Automotive OS (new apps and updates)</td>
<td>Android 15 (API 35) or higher</td>
<td>31 Aug 2026</td>
</tr>
<tr>
<td>Android TV and Android XR</td>
<td>Android 14 (API 34) or higher</td>
<td>See Google’s table</td>
</tr>
</tbody>
</table>
<p>Google offered an extension to <strong>1 November 2026</strong> for apps that needed more time, through a form linked from the policy warning in Play Console. That date has passed, so if your app is still behind, the update is no longer optional.</p>
<p>The only exception Google lists is <strong>permanently private apps</strong>, meaning apps restricted to users in one organisation for internal use.</p>
<h2 id="what-happens-if-you-dont-update">What happens if you don’t update</h2>
<ul>
<li><strong>You can’t upload a new version.</strong> Play Console rejects any app bundle that targets a lower API level. Even an urgent bug fix is blocked until you update the target.</li>
<li><strong>New users on newer phones can’t find the app.</strong> If your app targets below API 35, it stops being available to new users whose devices run a newer Android version than your target.</li>
<li><strong>Current users keep the app.</strong> Google says people who already installed the app aren’t affected. But you can’t ship them fixes, and your audience slowly shrinks.</li>
</ul>
<p>Play Console shows a warning on the <strong>Policy status</strong> page and in your inbox before this happens. If you see one, plan the update for that week, not for the deadline.</p>
<h2 id="how-to-update-a-flutter-app-to-target-api-36">How to update a Flutter app to target API 36</h2>
<h3 id="1-check-where-you-are">1. Check where you are</h3>
<p>Open <code>android/app/build.gradle</code> (or <code>build.gradle.kts</code>) and look at the <code>defaultConfig</code> block:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="kotlin"><code><span class="line"><span style="color:#B392F0">android</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    compileSdk </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> flutter.compileSdkVersion</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    defaultConfig</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">        minSdk </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> flutter.minSdkVersion</span></span>
<span class="line"><span style="color:#E1E4E8">        targetSdk </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> flutter.targetSdkVersion</span></span>
<span class="line"><span style="color:#6A737D">        // ...</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>If it says <code>flutter.targetSdkVersion</code>, the target comes from your Flutter version. If it says a number like <code>34</code> or <code>35</code>, someone hard-coded it, and you need to change it yourself.</p>
<h3 id="2-upgrade-flutter">2. Upgrade Flutter</h3>
<p>In Flutter 3.35, <code>flutter.compileSdkVersion</code> and <code>flutter.targetSdkVersion</code> are both <strong>36</strong>, and <code>flutter.minSdkVersion</code> is <strong>24</strong>. Older Flutter versions use older defaults. Upgrade on a separate branch:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> upgrade</span></span>
<span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> pub</span><span style="color:#9ECBFF"> upgrade</span><span style="color:#79B8FF"> --major-versions</span></span>
<span class="line"><span style="color:#B392F0">dart</span><span style="color:#9ECBFF"> fix</span><span style="color:#79B8FF"> --apply</span></span></code></pre>
<p>Then read the breaking changes for every major package update. The free <a href="https://neemii.dev/tools/flutter-package-checker/">Flutter package checker</a> shows which packages are discontinued or several major versions behind before you start.</p>
<h3 id="3-set-the-sdk-levels">3. Set the SDK levels</h3>
<p>Either keep the Flutter defaults, or set them explicitly:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="kotlin"><code><span class="line"><span style="color:#B392F0">android</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    compileSdk </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> 36</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    defaultConfig</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">        targetSdk </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> 36</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>Plugins sometimes need <code>compileSdk</code> at least as high as the target, so keep both at 36.</p>
<h3 id="4-update-the-android-build-tools">4. Update the Android build tools</h3>
<p>A new <code>compileSdk</code> usually needs a newer <strong>Android Gradle Plugin</strong> (in <code>android/settings.gradle</code>) and <strong>Gradle wrapper</strong> (in <code>android/gradle/wrapper/gradle-wrapper.properties</code>), and sometimes a newer Kotlin version. If the build fails with a message about an unsupported compile SDK or AGP version, that’s what it means. Android Studio’s AGP Upgrade Assistant can make these changes for you, and my free <a href="https://neemii.dev/tools/flutter-target-api-checker/">Flutter target API and Gradle checker</a> shows which versions your project needs: paste the Gradle files and it writes the fix.</p>
<h3 id="5-test-the-android-16-behaviour-changes">5. Test the Android 16 behaviour changes</h3>
<p>Targeting a new API level turns on that version’s behaviour changes. Android’s <a href="https://developer.android.com/about/versions/16/behavior-changes-16">Android 16 behaviour changes</a> page lists them. The ones I check first in Flutter apps:</p>
<ul>
<li><strong>Edge-to-edge.</strong> Apps targeting Android 16 can no longer opt out of edge-to-edge display. Check that app bars, bottom navigation and buttons aren’t hidden under the status bar or gesture bar. Wrapping screens in <code>SafeArea</code>, or using <code>MediaQuery.paddingOf(context)</code>, fixes most issues.</li>
<li><strong>Large screens.</strong> On tablets and foldables, Android 16 ignores many orientation and resizability restrictions for apps targeting API 36. If your app is locked to portrait, test it on a tablet emulator in landscape.</li>
<li><strong>Back navigation.</strong> Test the system back gesture on every screen, especially screens with <code>PopScope</code> or custom back handling.</li>
<li><strong>Permissions and background work.</strong> Re-test location, notifications, camera and anything running in the background on an Android 16 emulator.</li>
</ul>
<h3 id="6-build-test-and-upload">6. Build, test and upload</h3>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> build</span><span style="color:#9ECBFF"> appbundle</span><span style="color:#79B8FF"> --release</span></span></code></pre>
<p>Install the release build on a real device or an Android 16 emulator, go through the main flows, then upload the <code>.aab</code> to an internal or closed testing track before production. The full release checklist is in <a href="https://neemii.dev/blog/publish-flutter-app-app-store-google-play/">how to publish a Flutter app to the App Store and Google Play</a>.</p>
<p>If the build breaks during the upgrade, the two most common errors are <a href="https://neemii.dev/answers/flutter-unsupported-class-file-major-version/">“Unsupported class file major version 65”</a> and <a href="https://neemii.dev/answers/flutter-kotlin-gradle-plugin-newer-version/">“requires a newer version of the Kotlin Gradle plugin”</a>.</p>
<blockquote>
<p><strong>From my own work:</strong> I’ve had to ship a hotfix while a target SDK update was blocking uploads. That’s exactly the situation to avoid. Now I move every app I maintain to the new target soon after Google announces it, on a branch, with a test build the same week. The yearly routine is in the <a href="https://neemii.dev/blog/flutter-app-maintenance-checklist/">Flutter app maintenance checklist</a>.</p>
</blockquote>
<h2 id="how-long-does-it-take">How long does it take?</h2>
<p>For a well-maintained Flutter app on a recent Flutter version, often a few hours: bump the version, run the build, test the behaviour changes. For an app that’s two or three Flutter versions behind, with discontinued packages and old Gradle files, it can take several days, because the target SDK update pulls every other overdue upgrade with it. That’s why updating a little every quarter is cheaper than updating everything once a year.</p>
<h2 id="frequently-asked-questions">Frequently asked questions</h2>
<div class="faq-list">
<details class="faq" name="faq">
<summary>What target API level does Google Play require in 2026?</summary>
<p>New apps and app updates must target Android 16 (API level 36) or higher since August 31, 2026. Existing apps must target at least Android 15 (API level 35) to stay available to new users on newer devices. Wear OS and Android Automotive OS apps need API 35, and Android TV and Android XR apps need API 34.</p>
</details>
<details class="faq" name="faq">
<summary>How do I change the target SDK in a Flutter app?</summary>
<p>Open android/app/build.gradle (or build.gradle.kts) and set targetSdk in defaultConfig, along with compileSdk. If it uses flutter.targetSdkVersion, upgrading Flutter updates it for you: Flutter 3.35 targets API 36 by default. Then update the Android Gradle Plugin if the build asks for it.</p>
</details>
<details class="faq" name="faq">
<summary>Will my existing users lose the app if I don't update?</summary>
<p>No. Users who already installed the app keep it. But you can’t upload updates, including bug fixes, and if your target is below API 35 the app stops being available to new users on newer Android versions.</p>
</details>
<details class="faq" name="faq">
<summary>Can I still get an extension?</summary>
<p>Google offered an extension to November 1, 2026 through a form linked from the policy warning in Play Console. That date has passed, so plan to update now. Check the Policy status page in Play Console for the current state of your app.</p>
</details>
<details class="faq" name="faq">
<summary>Does raising the target SDK break anything in Flutter?</summary>
<p>It can. Each Android version brings behaviour changes that only apply once you target it. For Android 16 the main ones are enforced edge-to-edge display, fewer orientation and resizability restrictions on large screens, and back navigation changes. Test these on an Android 16 emulator before you upload.</p>
</details>
</div>
<p>Is a target API warning blocking your app? <a href="https://neemii.dev/#contact">Send me the details</a>. I’m Muhammad Naeem, a Flutter developer who maintains live apps on both stores, and I can usually move an app to the new target within a few days. See also <a href="https://neemii.dev/services/app-maintenance/">app maintenance and support</a>.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-google-play-target-api-level-flutter.png" type="image/png" length="0" />
    </item>
    <item>
      <title>Flutter vs Native App Development in 2026: Which to Choose</title>
      <link>https://neemii.dev/blog/flutter-vs-native-app-development/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/flutter-vs-native-app-development/</guid>
      <pubDate>Thu, 19 Nov 2026 00:00:00 GMT</pubDate>
      <description>Flutter or native Swift and Kotlin for your app in 2026? An honest comparison of cost, speed, performance and when native is still the right call.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> for most startups and business apps in 2026, Flutter is the better choice. You build one app instead of two, ship to iOS and Android at the same time, and spend your budget on features instead of keeping two codebases in sync. Native development (Swift for iOS, Kotlin for Android) is still the right call when the app’s main value depends on deep platform features, or when you can afford two specialist teams for the long run.</p>
<p>I’ve worked on 10+ Flutter apps that are live on the App Store and Google Play, and I also write native Kotlin when a feature needs it. Here is how I help clients decide.</p>
<h2 id="the-quick-comparison">The quick comparison</h2>
<table>
<thead>
<tr>
<th></th>
<th>Flutter</th>
<th>Native (Swift + Kotlin)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Codebases</td>
<td>One, in Dart</td>
<td>Two: Swift/SwiftUI for iOS, Kotlin/Jetpack Compose for Android</td>
</tr>
<tr>
<td>Team</td>
<td>One Flutter team</td>
<td>An iOS developer and an Android developer (at least)</td>
</tr>
<tr>
<td>Build cost</td>
<td>Close to one app, plus some platform-specific work</td>
<td>Close to two apps</td>
</tr>
<tr>
<td>Time to launch on both stores</td>
<td>Same day on both</td>
<td>Often one platform first, the other later</td>
</tr>
<tr>
<td>UI consistency</td>
<td>Identical design on both platforms by default</td>
<td>Each platform looks and behaves natively by default</td>
</tr>
<tr>
<td>Performance</td>
<td>Smooth for almost all business apps</td>
<td>Best possible, with direct platform access</td>
</tr>
<tr>
<td>New OS features</td>
<td>Usually available through plugins, sometimes after a delay</td>
<td>Available on day one</td>
</tr>
<tr>
<td>Long-term maintenance</td>
<td>One codebase to update</td>
<td>Two codebases to update and keep in sync</td>
</tr>
</tbody>
</table>
<h2 id="where-flutter-wins">Where Flutter wins</h2>
<p><strong>Cost and speed.</strong> The biggest difference is simple: one codebase. Screens, business logic, API calls, state management and tests are written once. For a typical MVP with sign-in, a few core screens, a backend and push notifications, that usually means a much smaller budget and an earlier launch than building twice. You can get a first estimate from the <a href="https://neemii.dev/tools/app-cost-calculator/">app cost calculator</a>, and the <a href="https://neemii.dev/blog/flutter-app-development-cost/">Flutter app development cost guide</a> breaks down where the hours go.</p>
<p><strong>Both stores at once.</strong> With native, many teams launch on one platform and leave the other for later, which splits your users and your feedback. With Flutter, iOS and Android users get the same features on the same day.</p>
<p><strong>One design, everywhere.</strong> Flutter draws its own UI, so your design looks the same on every phone. For brand-heavy apps that’s a feature, not a limitation. If you want platform-specific touches, such as iOS-style switches, you can still add them.</p>
<p><strong>Easier maintenance.</strong> Apps are never finished. Store requirements change every year, SDKs get updated and features get added. With one codebase, every fix and every update happens once. The <a href="https://neemii.dev/blog/flutter-app-maintenance-checklist/">app maintenance checklist</a> covers what that looks like each year.</p>
<p><strong>Performance is not the problem it used to be.</strong> Flutter compiles to native machine code, and its Impeller renderer is now the default on iOS and modern Android. For business apps, marketplaces, social apps, booking apps, ride-hailing, AI tools and dashboards, users can’t tell the difference.</p>
<h2 id="where-native-still-wins">Where native still wins</h2>
<p><strong>Deep platform features are the product.</strong> If your app is mainly a home-screen widget, an Apple Watch or Wear OS app, CarPlay or Android Auto, heavy AR, or advanced camera and audio processing, native is the safer choice. Flutter can call native code through platform channels, but if most of the app lives there, you lose the benefit of sharing code.</p>
<p><strong>You need new OS features on day one.</strong> Apple and Google announce new APIs every year. Native apps can use them immediately. In Flutter you wait for a plugin, or write the native part yourself.</p>
<p><strong>Every megabyte matters.</strong> A Flutter app includes its engine, so the smallest possible app is larger than the smallest native one. For most apps this doesn’t matter. For apps targeting very low-end devices or markets with expensive data, it can.</p>
<p><strong>You already have two strong native teams.</strong> If an iOS team and an Android team are already in place and productive, switching to Flutter costs time. The case for Flutter is strongest when you’re starting fresh or rebuilding.</p>
<h2 id="what-about-react-native-and-kotlin-multiplatform">What about React Native and Kotlin Multiplatform?</h2>
<p><strong>React Native</strong> is the other main cross-platform option. It’s a good fit if your team already knows React and JavaScript, especially if you share code with a React web app. Flutter tends to give more consistent UI and performance out of the box, and its tooling feels more complete for mobile.</p>
<p><strong>Kotlin Multiplatform</strong> shares business logic between iOS and Android while each UI stays native (or uses Compose Multiplatform). It suits teams with strong Android and Kotlin skills who want native UI with shared logic. It’s a middle path: more sharing than fully native, less than Flutter.</p>
<h2 id="how-i-decide-with-clients">How I decide with clients</h2>
<p>I ask four questions:</p>
<ol>
<li><strong>Does the app’s core value depend on one platform’s special features?</strong> Widgets, watch apps, CarPlay, heavy AR. If yes, native or a hybrid.</li>
<li><strong>Do you need both iOS and Android from launch?</strong> If yes, Flutter saves the most.</li>
<li><strong>What’s the budget for the first year, including maintenance?</strong> If one team is all you can fund, Flutter.</li>
<li><strong>Who will maintain it later?</strong> One Flutter developer can keep both apps running. Native needs both skill sets.</li>
</ol>
<p>For most founders I talk to, from ride-hailing and marketplaces to AI apps and internal business tools, the answers point to Flutter. When a single feature needs native code, such as a background location service or a custom camera pipeline, I write that part in Kotlin or Swift and keep the rest in Flutter. You get one codebase with native power where it counts.</p>
<h2 id="frequently-asked-questions">Frequently asked questions</h2>
<div class="faq-list">
<details class="faq" name="faq">
<summary>Is Flutter good enough for production apps in 2026?</summary>
<p>Yes. Flutter is used for large production apps across banking, e-commerce, ride-hailing and AI products. It compiles to native code, renders smoothly with its Impeller engine, and ships to both stores from one codebase. The apps I’ve worked on, including a ride-hailing app with 10,000+ downloads and AI apps on both stores, are built in Flutter.</p>
</details>
<details class="faq" name="faq">
<summary>Is Flutter cheaper than native development?</summary>
<p>Usually, yes. You build and maintain one codebase instead of two, with one team instead of two. Platform-specific work still adds some hours, but the total is normally much closer to one app than two. The saving grows over the years, because every update and store requirement is handled once.</p>
</details>
<details class="faq" name="faq">
<summary>Can a Flutter app use native features like GPS, camera and payments?</summary>
<p>Yes. Common features such as location, camera, maps, push notifications, in-app purchases, biometrics and file access have mature plugins. For anything without a plugin, Flutter calls native Swift or Kotlin code through platform channels, so nothing is off-limits.</p>
</details>
<details class="faq" name="faq">
<summary>Will users notice my app is built with Flutter?</summary>
<p>Not if it’s built well. Flutter apps run at a smooth frame rate and can follow each platform’s conventions where it matters, such as back navigation and system dialogs. Users judge the design and speed, not the framework.</p>
</details>
<details class="faq" name="faq">
<summary>When should I definitely choose native?</summary>
<p>When the app’s main job depends on platform-only features, such as widgets, smartwatch apps, CarPlay or Android Auto, or heavy AR. Also when you need every new OS feature on release day, or when you already have productive iOS and Android teams.</p>
</details>
</div>
<p>Not sure which fits your app? <a href="https://neemii.dev/#contact">Tell me what you’re building</a>. I’m Muhammad Naeem, a Flutter developer in Lahore working with startups in the UAE, Pakistan and worldwide. I’ll reply within 24 hours with an honest recommendation, even if it’s native. See also <a href="https://neemii.dev/services/flutter-app-development/">Flutter app development</a> and <a href="https://neemii.dev/services/ai-app-development/">AI app development</a>.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-flutter-vs-native-app-development.png" type="image/png" length="0" />
    </item>
    <item>
      <title>Flutter Live Location Tracking on Google Maps (Uber-Style)</title>
      <link>https://neemii.dev/blog/flutter-live-location-tracking-google-maps/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/flutter-live-location-tracking-google-maps/</guid>
      <pubDate>Wed, 18 Nov 2026 00:00:00 GMT</pubDate>
      <description>Uber-style live, real-time location tracking in Flutter: background GPS with geolocator, filtering bad fixes, WebSocket updates and a smooth map marker.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> Stream GPS with geolocator, drop readings with poor accuracy or impossible jumps, and send only the newest good position to your server every 3–5 seconds over a WebSocket. On Android, run a foreground service so updates continue with the screen off. On the rider’s map, animate the marker between positions instead of jumping, so the car moves smoothly.</p>
<p>Live tracking looks simple in a demo. A driver’s position comes in and a marker moves on the map. On real roads it breaks in ways a demo never shows. GPS jumps a block away, the stream stops when the phone locks, the socket drops in a tunnel, and the car on the rider’s screen teleports instead of driving.</p>
<p>This guide builds the version that holds up on real rides. A driver app sends its location, a server relays it, and a rider app shows a marker that moves smoothly. It is based on what I worked on in <a href="https://neemii.dev/work/shedrives/">SheDrives</a>, a women-only ride-hailing app in Lahore with 10,000+ downloads, where live tracking was the hardest part of the app.</p>
<p>All the Dart code below is in one file and passes <code>flutter analyze</code>. The GPS filter has a unit test. Tested with Flutter 3.35, geolocator 14.0, google_maps_flutter 2.14 and web_socket_channel 3.0.</p>
<h2 id="how-the-pieces-fit">How the pieces fit</h2>
<p>There are three parts:</p>
<ol>
<li><strong>Driver app.</strong> It reads GPS with <code>geolocator</code>, drops bad readings, and sends the latest good position every 4 seconds over a WebSocket.</li>
<li><strong>Server.</strong> It keeps one “room” per trip, checks that the sender really is that trip’s driver, and passes each position to the rider in the same room.</li>
<li><strong>Rider app.</strong> It receives positions and animates the car marker from the old point to the new one, so the movement looks continuous.</li>
</ol>
<p>Why a WebSocket and not a database write for every update? You can use Firestore or Supabase Realtime, and for small apps they’re fine. But at one update every 4 seconds, each active driver makes 900 writes an hour. A WebSocket server only passes messages along, so the cost stays flat as you grow. And you need the socket anyway if you have live features like driver bids.</p>
<blockquote>
<p><strong>From SheDrives:</strong> live tracking and driver bids first worked through polling, and both lagged. Moving them onto a WebSocket connection, and splitting connection handling, ride state and UI into separate layers, is what made them reliable. More on that in the <a href="https://neemii.dev/work/shedrives/">SheDrives case study</a>.</p>
</blockquote>
<h2 id="step-1-packages-and-platform-setup">Step 1: Packages and platform setup</h2>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="yaml"><code><span class="line"><span style="color:#85E89D">dependencies</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#85E89D">  geolocator</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">^14.0.2</span></span>
<span class="line"><span style="color:#85E89D">  google_maps_flutter</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">^2.14.2</span></span>
<span class="line"><span style="color:#85E89D">  web_socket_channel</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">^3.0.3</span></span></code></pre>
<p><strong>Android</strong> (<code>android/app/src/main/AndroidManifest.xml</code>): add these above <code>&lt;application&gt;</code>:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="xml"><code><span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">uses-permission</span><span style="color:#B392F0"> android:name</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"android.permission.ACCESS_FINE_LOCATION"</span><span style="color:#E1E4E8"> /&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">uses-permission</span><span style="color:#B392F0"> android:name</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"android.permission.ACCESS_COARSE_LOCATION"</span><span style="color:#E1E4E8"> /&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">uses-permission</span><span style="color:#B392F0"> android:name</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"android.permission.FOREGROUND_SERVICE"</span><span style="color:#E1E4E8"> /&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">uses-permission</span><span style="color:#B392F0"> android:name</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"android.permission.FOREGROUND_SERVICE_LOCATION"</span><span style="color:#E1E4E8"> /&gt;</span></span></code></pre>
<p>Then add the Maps key inside <code>&lt;application&gt;</code>:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="xml"><code><span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">meta-data</span><span style="color:#B392F0"> android:name</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"com.google.android.geo.API_KEY"</span></span>
<span class="line"><span style="color:#B392F0">           android:value</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"YOUR_ANDROID_MAPS_KEY"</span><span style="color:#E1E4E8"> /&gt;</span></span></code></pre>
<p><strong>iOS:</strong></p>
<ul>
<li><code>Info.plist</code> needs <code>NSLocationWhenInUseUsageDescription</code> and <code>NSLocationAlwaysAndWhenInUseUsageDescription</code>. Write a real sentence in each, such as “Your location is shared with your rider during a trip”, because App Review reads them.</li>
<li>For updates while the app is in the background, add <code>location</code> to <code>UIBackgroundModes</code>.</li>
<li>Give the Maps SDK its key in <code>AppDelegate.swift</code> with <code>GMSServices.provideAPIKey("YOUR_IOS_MAPS_KEY")</code>.</li>
</ul>
<p>Restrict both Maps keys in Google Cloud Console: the Android key to your package name and signing certificate, the iOS key to your bundle ID. A Maps key inside an app can be pulled out of the install file, so the restriction is what protects it. The same idea applies to any key, see <a href="https://neemii.dev/blog/flutter-ai-chat-without-exposing-api-key/">keeping API keys out of your app</a>.</p>
<h2 id="step-2-ask-for-permission-properly">Step 2: Ask for permission properly</h2>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#79B8FF">Future</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">bool</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">ensureLocationPermission</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">async</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  if</span><span style="color:#E1E4E8"> (</span><span style="color:#F97583">!await</span><span style="color:#79B8FF"> Geolocator</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">isLocationServiceEnabled</span><span style="color:#E1E4E8">()) {</span></span>
<span class="line"><span style="color:#F97583">    await</span><span style="color:#79B8FF"> Geolocator</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">openLocationSettings</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">    return</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#F97583">  var</span><span style="color:#E1E4E8"> permission </span><span style="color:#F97583">=</span><span style="color:#F97583"> await</span><span style="color:#79B8FF"> Geolocator</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">checkPermission</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">  if</span><span style="color:#E1E4E8"> (permission </span><span style="color:#F97583">==</span><span style="color:#79B8FF"> LocationPermission</span><span style="color:#E1E4E8">.denied) {</span></span>
<span class="line"><span style="color:#E1E4E8">    permission </span><span style="color:#F97583">=</span><span style="color:#F97583"> await</span><span style="color:#79B8FF"> Geolocator</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">requestPermission</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#F97583">  if</span><span style="color:#E1E4E8"> (permission </span><span style="color:#F97583">==</span><span style="color:#79B8FF"> LocationPermission</span><span style="color:#E1E4E8">.deniedForever) {</span></span>
<span class="line"><span style="color:#F97583">    await</span><span style="color:#79B8FF"> Geolocator</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">openAppSettings</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">    return</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#E1E4E8"> permission </span><span style="color:#F97583">==</span><span style="color:#79B8FF"> LocationPermission</span><span style="color:#E1E4E8">.always </span><span style="color:#F97583">||</span></span>
<span class="line"><span style="color:#E1E4E8">      permission </span><span style="color:#F97583">==</span><span style="color:#79B8FF"> LocationPermission</span><span style="color:#E1E4E8">.whileInUse;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>Ask at the moment it makes sense. For a driver, that is when they tap “Go online”, not on the first launch. A request that comes with a reason the user can see gets accepted far more often.</p>
<h2 id="step-3-keep-updates-coming-when-the-screen-is-off">Step 3: Keep updates coming when the screen is off</h2>
<p>A driver’s phone sits in a mount with the screen locked or another app open. By default, location updates stop when your app leaves the screen. Set this up per platform:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#79B8FF">LocationSettings</span><span style="color:#B392F0"> driverLocationSettings</span><span style="color:#E1E4E8">() {</span></span>
<span class="line"><span style="color:#F97583">  if</span><span style="color:#E1E4E8"> (defaultTargetPlatform </span><span style="color:#F97583">==</span><span style="color:#79B8FF"> TargetPlatform</span><span style="color:#E1E4E8">.android) {</span></span>
<span class="line"><span style="color:#F97583">    return</span><span style="color:#79B8FF"> AndroidSettings</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">      accuracy</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> LocationAccuracy</span><span style="color:#E1E4E8">.bestForNavigation,</span></span>
<span class="line"><span style="color:#E1E4E8">      distanceFilter</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 5</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      intervalDuration</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> Duration</span><span style="color:#E1E4E8">(seconds</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 2</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">      foregroundNotificationConfig</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> ForegroundNotificationConfig</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">        notificationTitle</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'You are online'</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">        notificationText</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'Sharing your location with your rider'</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">        enableWakeLock</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      ),</span></span>
<span class="line"><span style="color:#E1E4E8">    );</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#F97583">  if</span><span style="color:#E1E4E8"> (defaultTargetPlatform </span><span style="color:#F97583">==</span><span style="color:#79B8FF"> TargetPlatform</span><span style="color:#E1E4E8">.iOS) {</span></span>
<span class="line"><span style="color:#F97583">    return</span><span style="color:#79B8FF"> AppleSettings</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">      accuracy</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> LocationAccuracy</span><span style="color:#E1E4E8">.bestForNavigation,</span></span>
<span class="line"><span style="color:#E1E4E8">      activityType</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> ActivityType</span><span style="color:#E1E4E8">.automotiveNavigation,</span></span>
<span class="line"><span style="color:#E1E4E8">      distanceFilter</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 5</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      pauseLocationUpdatesAutomatically</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      allowBackgroundLocationUpdates</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      showBackgroundLocationIndicator</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">    );</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> LocationSettings</span><span style="color:#E1E4E8">(accuracy</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> LocationAccuracy</span><span style="color:#E1E4E8">.high, distanceFilter</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 5</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p><strong>On Android</strong>, <code>foregroundNotificationConfig</code> starts a foreground service with a visible notification, so the system keeps your app alive.</p>
<ul>
<li>Start it while the app is on screen, when the driver taps “Go online”. Android then treats this as foreground location access.</li>
<li>That way you usually don’t need <code>ACCESS_BACKGROUND_LOCATION</code> at all. That permission triggers an extra review in Google Play: a declaration form, a video and a prominent in-app disclosure.</li>
<li>Ask for it only if you must track with no notification showing, which a ride app rarely needs.</li>
<li>Google Play also asks you to declare the foreground service type (location) in the Play Console when you target Android 14 or later.</li>
</ul>
<p><strong>On iOS</strong>, the blue location indicator in the status bar is the price of background updates. <code>pauseLocationUpdatesAutomatically: false</code> stops iOS from pausing updates when the car waits at a long red light.</p>
<h2 id="step-4-throw-away-bad-gps-readings">Step 4: Throw away bad GPS readings</h2>
<p>This is the part most tutorials skip, and it’s where real apps break. Phones report positions with an accuracy radius, and in cities, near tall buildings or in basements, a reading can be 100 m off, or jump across a block and back.</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">class</span><span style="color:#79B8FF"> FixFilter</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  FixFilter</span><span style="color:#E1E4E8">({</span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">.maxAccuracyMeters </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> 30</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">.maxSpeedMps </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> 50</span><span style="color:#E1E4E8">});</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> double</span><span style="color:#E1E4E8"> maxAccuracyMeters;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> double</span><span style="color:#E1E4E8"> maxSpeedMps; </span><span style="color:#6A737D">// 50 m/s = 180 km/h</span></span>
<span class="line"><span style="color:#79B8FF">  Position</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> _last;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  bool</span><span style="color:#B392F0"> accept</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Position</span><span style="color:#E1E4E8"> p) {</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (p.accuracy </span><span style="color:#F97583">&gt;</span><span style="color:#E1E4E8"> maxAccuracyMeters) </span><span style="color:#F97583">return</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> last </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> _last;</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (last </span><span style="color:#F97583">!=</span><span style="color:#79B8FF"> null</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">      final</span><span style="color:#E1E4E8"> meters </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Geolocator</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">distanceBetween</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">          last.latitude, last.longitude, p.latitude, p.longitude);</span></span>
<span class="line"><span style="color:#F97583">      final</span><span style="color:#E1E4E8"> seconds </span><span style="color:#F97583">=</span></span>
<span class="line"><span style="color:#E1E4E8">          p.timestamp.</span><span style="color:#B392F0">difference</span><span style="color:#E1E4E8">(last.timestamp).inMilliseconds </span><span style="color:#F97583">/</span><span style="color:#79B8FF"> 1000</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">      if</span><span style="color:#E1E4E8"> (seconds </span><span style="color:#F97583">&lt;=</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">return</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">      if</span><span style="color:#E1E4E8"> (meters </span><span style="color:#F97583">/</span><span style="color:#E1E4E8"> seconds </span><span style="color:#F97583">&gt;</span><span style="color:#E1E4E8"> maxSpeedMps) </span><span style="color:#F97583">return</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">    _last </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> p;</span></span>
<span class="line"><span style="color:#F97583">    return</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>Two rules do most of the work:</p>
<ul>
<li>Drop readings with a large accuracy radius.</li>
<li>Drop readings that would mean the car moved faster than any car can.</li>
</ul>
<p>The unit test for this feeds in normal city driving (accepted), an 80 m accuracy reading (rejected), a 1 km jump in 4 seconds (rejected) and a normal reading after it (accepted again).</p>
<blockquote>
<p><strong>From SheDrives:</strong> the most common real-device problem was inaccurate GPS. Positions on the map didn’t match where the driver really was. We moved to Google Maps Platform for more accurate location and tested repeatedly on real rides, not only in the emulator. Those test rides are where problems like this show up.</p>
</blockquote>
<h2 id="step-5-send-the-latest-position-every-4-seconds">Step 5: Send the latest position every 4 seconds</h2>
<p>Don’t send every reading. The GPS stream can fire every second, and most of those messages would be stale before the rider’s phone finishes drawing the last one. Keep the newest good position and send it on a timer:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">class</span><span style="color:#79B8FF"> DriverLocationSender</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  DriverLocationSender</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">.socketUrl, </span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">.tripId,</span></span>
<span class="line"><span style="color:#E1E4E8">      {</span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">.every </span><span style="color:#F97583">=</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> Duration</span><span style="color:#E1E4E8">(seconds</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 4</span><span style="color:#E1E4E8">)});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> Uri</span><span style="color:#E1E4E8"> socketUrl;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> String</span><span style="color:#E1E4E8"> tripId;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> Duration</span><span style="color:#E1E4E8"> every;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> _filter </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> FixFilter</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#79B8FF">  WebSocketChannel</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> _channel;</span></span>
<span class="line"><span style="color:#79B8FF">  StreamSubscription</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">Position</span><span style="color:#E1E4E8">&gt;</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> _gps;</span></span>
<span class="line"><span style="color:#79B8FF">  Timer</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> _tick;</span></span>
<span class="line"><span style="color:#79B8FF">  Timer</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> _retry;</span></span>
<span class="line"><span style="color:#79B8FF">  Position</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> _latest;</span></span>
<span class="line"><span style="color:#79B8FF">  int</span><span style="color:#E1E4E8"> _attempt </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  bool</span><span style="color:#E1E4E8"> _running </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  Future</span><span style="color:#E1E4E8">&lt;</span><span style="color:#F97583">void</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">start</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">async</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (</span><span style="color:#F97583">!await</span><span style="color:#B392F0"> ensureLocationPermission</span><span style="color:#E1E4E8">()) </span><span style="color:#F97583">return</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    _running </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">    await</span><span style="color:#B392F0"> _connect</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">    _gps </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Geolocator</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">getPositionStream</span><span style="color:#E1E4E8">(locationSettings</span><span style="color:#F97583">:</span><span style="color:#B392F0"> driverLocationSettings</span><span style="color:#E1E4E8">())</span></span>
<span class="line"><span style="color:#E1E4E8">        .</span><span style="color:#B392F0">where</span><span style="color:#E1E4E8">(_filter.accept)</span></span>
<span class="line"><span style="color:#E1E4E8">        .</span><span style="color:#B392F0">listen</span><span style="color:#E1E4E8">((p) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> _latest </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> p);</span></span>
<span class="line"><span style="color:#E1E4E8">    _tick </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Timer</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">periodic</span><span style="color:#E1E4E8">(every, (_) </span><span style="color:#F97583">=&gt;</span><span style="color:#B392F0"> _send</span><span style="color:#E1E4E8">());</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  Future</span><span style="color:#E1E4E8">&lt;</span><span style="color:#F97583">void</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">_connect</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">async</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">    try</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">      final</span><span style="color:#E1E4E8"> channel </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> WebSocketChannel</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">connect</span><span style="color:#E1E4E8">(socketUrl);</span></span>
<span class="line"><span style="color:#F97583">      await</span><span style="color:#E1E4E8"> channel.ready;</span></span>
<span class="line"><span style="color:#E1E4E8">      _channel </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> channel;</span></span>
<span class="line"><span style="color:#E1E4E8">      _attempt </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      channel.stream.</span><span style="color:#B392F0">listen</span><span style="color:#E1E4E8">((_) {}, onDone</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> _reconnect, onError</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> (_) </span><span style="color:#F97583">=&gt;</span><span style="color:#B392F0"> _reconnect</span><span style="color:#E1E4E8">());</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#F97583">catch</span><span style="color:#E1E4E8"> (_) {</span></span>
<span class="line"><span style="color:#B392F0">      _reconnect</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  void</span><span style="color:#B392F0"> _reconnect</span><span style="color:#E1E4E8">() {</span></span>
<span class="line"><span style="color:#E1E4E8">    _channel </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> null</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (</span><span style="color:#F97583">!</span><span style="color:#E1E4E8">_running </span><span style="color:#F97583">||</span><span style="color:#E1E4E8"> (_retry</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">.isActive </span><span style="color:#F97583">??</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">)) </span><span style="color:#F97583">return</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> seconds </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> math.</span><span style="color:#B392F0">min</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">30</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1</span><span style="color:#F97583"> &lt;&lt;</span><span style="color:#E1E4E8"> _attempt</span><span style="color:#F97583">++</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">// 1, 2, 4 ... 30 s</span></span>
<span class="line"><span style="color:#E1E4E8">    _retry </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Timer</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Duration</span><span style="color:#E1E4E8">(seconds</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> seconds), _connect);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  void</span><span style="color:#B392F0"> _send</span><span style="color:#E1E4E8">() {</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> p </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> _latest;</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> channel </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> _channel;</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (p </span><span style="color:#F97583">==</span><span style="color:#79B8FF"> null</span><span style="color:#F97583"> ||</span><span style="color:#E1E4E8"> channel </span><span style="color:#F97583">==</span><span style="color:#79B8FF"> null</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">return</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    channel.sink.</span><span style="color:#B392F0">add</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">jsonEncode</span><span style="color:#E1E4E8">({</span></span>
<span class="line"><span style="color:#9ECBFF">      'type'</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'driver_location'</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#9ECBFF">      'trip'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> tripId,</span></span>
<span class="line"><span style="color:#9ECBFF">      'lat'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> p.latitude,</span></span>
<span class="line"><span style="color:#9ECBFF">      'lng'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> p.longitude,</span></span>
<span class="line"><span style="color:#9ECBFF">      'heading'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> p.heading,</span></span>
<span class="line"><span style="color:#9ECBFF">      'speed'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> p.speed,</span></span>
<span class="line"><span style="color:#9ECBFF">      'accuracy'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> p.accuracy,</span></span>
<span class="line"><span style="color:#9ECBFF">      'ts'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> p.timestamp.</span><span style="color:#B392F0">toUtc</span><span style="color:#E1E4E8">().</span><span style="color:#B392F0">toIso8601String</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">    }));</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  Future</span><span style="color:#E1E4E8">&lt;</span><span style="color:#F97583">void</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">stop</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">async</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    _running </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    _tick</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">cancel</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">    _retry</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">cancel</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">    await</span><span style="color:#E1E4E8"> _gps</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">cancel</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">    await</span><span style="color:#E1E4E8"> _channel</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">.sink.</span><span style="color:#B392F0">close</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>How this holds up on the road:</p>
<ul>
<li><strong>Why 4 seconds:</strong> in SheDrives we sent the driver’s location every 3 to 5 seconds. That kept the map smooth without flooding the connection. Each message is about 200 bytes, so that’s around 180 KB an hour per driver, which is nothing on mobile data.</li>
<li><strong>Reconnect with backoff:</strong> mobile connections drop all the time, in tunnels, lifts and network handovers. The sender waits 1, 2, 4, up to 30 seconds between attempts, so a dead server isn’t hit by every driver at once. When the socket comes back, the next tick sends the newest position, not a queue of old ones.</li>
<li><strong>The timestamp travels with the position</strong>, so the server and the rider can ignore anything that arrives out of order or too late to be useful.</li>
</ul>
<p>The imports for this file are <code>dart:async</code>, <code>dart:convert</code>, <code>dart:math</code> (as <code>math</code>), <code>package:flutter/foundation.dart</code>, <code>package:flutter/material.dart</code> and the three packages.</p>
<h2 id="step-6-move-the-marker-smoothly-on-the-riders-map">Step 6: Move the marker smoothly on the rider’s map</h2>
<p>If you set the marker to each new position, the car jumps every 4 seconds. Instead, animate it from where it is now to the new point over the same 4 seconds. The next update arrives just as the animation ends, so the car seems to drive continuously:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">class</span><span style="color:#79B8FF"> DriverMap</span><span style="color:#F97583"> extends</span><span style="color:#79B8FF"> StatefulWidget</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#79B8FF"> DriverMap</span><span style="color:#E1E4E8">({</span><span style="color:#79B8FF">super</span><span style="color:#E1E4E8">.key, </span><span style="color:#F97583">required</span><span style="color:#79B8FF"> this</span><span style="color:#E1E4E8">.updates, </span><span style="color:#F97583">required</span><span style="color:#79B8FF"> this</span><span style="color:#E1E4E8">.start});</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> Stream</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;&gt; updates; </span><span style="color:#6A737D">// decoded socket messages</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> LatLng</span><span style="color:#E1E4E8"> start;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  @override</span></span>
<span class="line"><span style="color:#79B8FF">  State</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">DriverMap</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">createState</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> _DriverMapState</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">class</span><span style="color:#79B8FF"> _DriverMapState</span><span style="color:#F97583"> extends</span><span style="color:#79B8FF"> State</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">DriverMap</span><span style="color:#E1E4E8">&gt; </span><span style="color:#F97583">with</span><span style="color:#79B8FF"> SingleTickerProviderStateMixin</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  late</span><span style="color:#F97583"> final</span><span style="color:#79B8FF"> AnimationController</span><span style="color:#E1E4E8"> _anim </span><span style="color:#F97583">=</span></span>
<span class="line"><span style="color:#79B8FF">      AnimationController</span><span style="color:#E1E4E8">(vsync</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> this</span><span style="color:#E1E4E8">, duration</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> Duration</span><span style="color:#E1E4E8">(seconds</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 4</span><span style="color:#E1E4E8">));</span></span>
<span class="line"><span style="color:#F97583">  late</span><span style="color:#79B8FF"> LatLng</span><span style="color:#E1E4E8"> _from </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> widget.start;</span></span>
<span class="line"><span style="color:#F97583">  late</span><span style="color:#79B8FF"> LatLng</span><span style="color:#E1E4E8"> _to </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> widget.start;</span></span>
<span class="line"><span style="color:#79B8FF">  double</span><span style="color:#E1E4E8"> _heading </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  GoogleMapController</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> _map;</span></span>
<span class="line"><span style="color:#79B8FF">  StreamSubscription</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;&gt;</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> _sub;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  @override</span></span>
<span class="line"><span style="color:#F97583">  void</span><span style="color:#B392F0"> initState</span><span style="color:#E1E4E8">() {</span></span>
<span class="line"><span style="color:#79B8FF">    super</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">initState</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">    _anim.</span><span style="color:#B392F0">addListener</span><span style="color:#E1E4E8">(() </span><span style="color:#F97583">=&gt;</span><span style="color:#B392F0"> setState</span><span style="color:#E1E4E8">(() {}));</span></span>
<span class="line"><span style="color:#E1E4E8">    _sub </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> widget.updates.</span><span style="color:#B392F0">listen</span><span style="color:#E1E4E8">(_onUpdate);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  void</span><span style="color:#B392F0"> _onUpdate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt; m) {</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (m[</span><span style="color:#9ECBFF">'type'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">!=</span><span style="color:#9ECBFF"> 'driver_location'</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">return</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> next </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> LatLng</span><span style="color:#E1E4E8">((m[</span><span style="color:#9ECBFF">'lat'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> num</span><span style="color:#E1E4E8">).</span><span style="color:#B392F0">toDouble</span><span style="color:#E1E4E8">(), (m[</span><span style="color:#9ECBFF">'lng'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> num</span><span style="color:#E1E4E8">).</span><span style="color:#B392F0">toDouble</span><span style="color:#E1E4E8">());</span></span>
<span class="line"><span style="color:#E1E4E8">    _from </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> _current; </span><span style="color:#6A737D">// start from wherever the marker is now</span></span>
<span class="line"><span style="color:#E1E4E8">    _to </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> next;</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> heading </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> (m[</span><span style="color:#9ECBFF">'heading'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> num</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">)</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">toDouble</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">??</span><span style="color:#F97583"> -</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> speed </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> (m[</span><span style="color:#9ECBFF">'speed'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> num</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">)</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">toDouble</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">??</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#6A737D">    // Stopped cars report a heading of 0 or -1: keep the last good one.</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (heading </span><span style="color:#F97583">&gt;=</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583"> &amp;&amp;</span><span style="color:#E1E4E8"> speed </span><span style="color:#F97583">&gt;</span><span style="color:#79B8FF"> 1</span><span style="color:#E1E4E8">) _heading </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> heading;</span></span>
<span class="line"><span style="color:#E1E4E8">    _anim.</span><span style="color:#B392F0">forward</span><span style="color:#E1E4E8">(from</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    _map</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">animateCamera</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">CameraUpdate</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">newLatLng</span><span style="color:#E1E4E8">(next));</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  LatLng</span><span style="color:#F97583"> get</span><span style="color:#E1E4E8"> _current {</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> t </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Curves</span><span style="color:#E1E4E8">.linear.</span><span style="color:#B392F0">transform</span><span style="color:#E1E4E8">(_anim.value);</span></span>
<span class="line"><span style="color:#F97583">    return</span><span style="color:#79B8FF"> LatLng</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">      _from.latitude </span><span style="color:#F97583">+</span><span style="color:#E1E4E8"> (_to.latitude </span><span style="color:#F97583">-</span><span style="color:#E1E4E8"> _from.latitude) </span><span style="color:#F97583">*</span><span style="color:#E1E4E8"> t,</span></span>
<span class="line"><span style="color:#E1E4E8">      _from.longitude </span><span style="color:#F97583">+</span><span style="color:#E1E4E8"> (_to.longitude </span><span style="color:#F97583">-</span><span style="color:#E1E4E8"> _from.longitude) </span><span style="color:#F97583">*</span><span style="color:#E1E4E8"> t,</span></span>
<span class="line"><span style="color:#E1E4E8">    );</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  @override</span></span>
<span class="line"><span style="color:#79B8FF">  Widget</span><span style="color:#B392F0"> build</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">BuildContext</span><span style="color:#E1E4E8"> context) {</span></span>
<span class="line"><span style="color:#F97583">    return</span><span style="color:#79B8FF"> GoogleMap</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">      initialCameraPosition</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> CameraPosition</span><span style="color:#E1E4E8">(target</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> widget.start, zoom</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 16</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">      onMapCreated</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> (c) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> _map </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> c,</span></span>
<span class="line"><span style="color:#E1E4E8">      markers</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        Marker</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">          markerId</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> MarkerId</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'driver'</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">          position</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> _current,</span></span>
<span class="line"><span style="color:#E1E4E8">          rotation</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> _heading,</span></span>
<span class="line"><span style="color:#E1E4E8">          anchor</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> Offset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">          flat</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">        ),</span></span>
<span class="line"><span style="color:#E1E4E8">      },</span></span>
<span class="line"><span style="color:#E1E4E8">    );</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  @override</span></span>
<span class="line"><span style="color:#F97583">  void</span><span style="color:#B392F0"> dispose</span><span style="color:#E1E4E8">() {</span></span>
<span class="line"><span style="color:#E1E4E8">    _sub</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">cancel</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">    _anim.</span><span style="color:#B392F0">dispose</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#79B8FF">    super</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">dispose</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// Turning raw socket messages into the stream DriverMap expects.</span></span>
<span class="line"><span style="color:#79B8FF">Stream</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;&gt; </span><span style="color:#B392F0">decodeUpdates</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">WebSocketChannel</span><span style="color:#E1E4E8"> channel) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> channel.stream</span></span>
<span class="line"><span style="color:#E1E4E8">    .</span><span style="color:#B392F0">map</span><span style="color:#E1E4E8">((raw) </span><span style="color:#F97583">=&gt;</span><span style="color:#B392F0"> jsonDecode</span><span style="color:#E1E4E8">(raw </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> String</span><span style="color:#E1E4E8">))</span></span>
<span class="line"><span style="color:#E1E4E8">    .</span><span style="color:#B392F0">where</span><span style="color:#E1E4E8">((m) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> m </span><span style="color:#F97583">is</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;)</span></span>
<span class="line"><span style="color:#E1E4E8">    .</span><span style="color:#B392F0">cast</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;&gt;();</span></span></code></pre>
<p>Some details here matter:</p>
<ul>
<li><strong>Each animation starts from the current position, not the last target.</strong> If an update arrives early, the car doesn’t snap back first.</li>
<li><strong>Straight-line movement between two points is fine.</strong> Over 4 seconds of driving the error is a few metres. Snapping to roads is something the Roads API can do on the server if you need it.</li>
<li><strong><code>flat: true</code> and <code>rotation</code></strong> turn the car icon to the direction of travel and keep it flat on the map when the user tilts the camera. Use a top-down car image with <code>BitmapDescriptor.asset</code> for the real app.</li>
<li><strong>Heading is kept from the last moving reading.</strong> A stopped car often reports 0, which would spin the icon to face north at every red light.</li>
</ul>
<h2 id="the-server-a-relay-with-checks">The server: a relay with checks</h2>
<p>The server can be small. Node.js, Go or Dart all work. What matters is what it checks:</p>
<ul>
<li><strong>Only the trip’s driver can send positions to that trip.</strong> Authenticate the socket with the same token as your API, and check the trip ID against your database. Otherwise anyone who guesses a trip ID could move the car on a rider’s screen.</li>
<li><strong>Only the trip’s rider (and your support team) can receive them.</strong> Stop relaying when the trip ends.</li>
<li><strong>Store a thinned copy, not every message</strong>, for example one point every 30 seconds for receipts and disputes. Say so in your privacy policy, because location history is sensitive data, and both stores ask about it. The <a href="https://neemii.dev/tools/app-privacy-policy-generator/">privacy policy generator</a> and the <a href="https://neemii.dev/tools/flutter-data-safety/">Data safety helper</a> cover location.</li>
</ul>
<h2 id="testing-it-before-real-rides">Testing it before real rides</h2>
<ul>
<li><strong>Android emulator:</strong> Extended controls → Location → Routes lets you play a route at different speeds.</li>
<li><strong>iOS Simulator:</strong> Features → Location → <em>City Run</em> or <em>Freeway Drive</em> gives a moving position.</li>
<li><strong>Real rides are the test that counts.</strong> Lock the screen, open another app, drive through an underpass, switch off mobile data for 20 seconds and turn it back on. Watch the rider’s map the whole time. The simulators never show you GPS drift near tall buildings.</li>
</ul>
<h2 id="before-you-submit-to-the-stores">Before you submit to the stores</h2>
<ul>
<li>The permission text in <code>Info.plist</code> must explain why, in words a user understands. Vague text is a common reason for App Review questions.</li>
<li>If you do use <code>ACCESS_BACKGROUND_LOCATION</code>, Google Play needs the location permissions declaration, a short video of the feature, and a prominent disclosure screen in the app before the permission prompt.</li>
<li>Fill in the location sections of the App Store privacy details and the Google Play Data safety form to match what you actually collect. The full checklist is in <a href="https://neemii.dev/blog/publish-flutter-app-app-store-google-play/">how to publish a Flutter app to the App Store and Google Play</a>.</li>
</ul>
<h2 id="frequently-asked-questions">Frequently asked questions</h2>
<div class="faq-list">
<details class="faq" name="faq">
<summary>How often should a driver app send its location?</summary>
<p>Every 3 to 5 seconds is a good range for ride-hailing. Faster than that adds server load and battery drain, and the rider can’t see the difference because the marker is animated between updates anyway. Slower than about 10 seconds and the car visibly lags behind the real one when it turns.</p>
</details>
<details class="faq" name="faq">
<summary>Does Flutter location tracking work in the background?</summary>
<p>Yes. On Android, use geolocator’s foreground notification setting, which runs a foreground service while the driver is online. On iOS, enable the location background mode and set <code>allowBackgroundLocationUpdates</code>. What you can’t do is keep tracking after the user force-closes the app, on either platform.</p>
</details>
<details class="faq" name="faq">
<summary>Should I use Firestore or a WebSocket for live tracking?</summary>
<p>For a small number of drivers, Firestore or Supabase Realtime is quicker to set up. As you grow, every position becomes a billed write, around 900 an hour per active driver at a 4-second interval. A WebSocket relay costs the same however many messages pass through it, and you can use the same connection for bids and trip status.</p>
</details>
<details class="faq" name="faq">
<summary>Why does my marker jump or point the wrong way?</summary>
<p>Jumping comes from setting the marker straight to each new position. Animate it between positions as in Step 6. A wrong direction comes from using the heading while the car is stopped, when phones report 0 or -1. Keep the last heading from a moving reading.</p>
</details>
<details class="faq" name="faq">
<summary>How much does a ride-hailing app with live tracking cost to build?</summary>
<p>It depends mostly on the rider app, the driver app, the admin panel and the real-time backend. See <a href="https://neemii.dev/blog/women-only-ride-sharing-app-development/">how to build a women-only ride-sharing app</a> for the full feature list, or get a quick estimate from the <a href="https://neemii.dev/tools/app-cost-calculator/">app cost calculator</a>.</p>
</details>
</div>
<p>Building a ride-hailing, delivery or field-service app with live tracking? <a href="https://neemii.dev/#contact">Tell me about it</a>. I’m Muhammad Naeem, a Flutter developer in Lahore, and I have shipped live tracking in production. I’ll reply within 24 hours with questions and a rough plan.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-flutter-live-location-tracking-google-maps.png" type="image/png" length="0" />
    </item>
    <item>
      <title>AI Photo Editor App Cost in 2026: A Real Build Breakdown</title>
      <link>https://neemii.dev/blog/ai-photo-editor-app-cost/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/ai-photo-editor-app-cost/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>What an AI photo editor app costs to build and run in 2026: build hours, AI cost per image, store fees and servers, from the real Evoke AI build.</description>
      <content:encoded><![CDATA[<p>Most articles about the cost of an AI photo editor app come from agencies, and their numbers run from $20,000 to over $500,000. That range is too wide to plan with, and it leaves out the part that decides whether the app survives: <strong>every AI edit costs money, every time a user taps the button.</strong></p>
<p>This guide splits the cost into the two parts that matter: what it costs to <strong>build</strong> the app, and what it costs to <strong>run</strong> it per image. It is based on <a href="https://neemii.dev/work/evoke-ai/">Evoke AI</a>, an AI photo app I co-built with one other developer. It is live on the App Store and Google Play, with 4,000+ active members. Prices are from the providers’ official pages in November 2026; they change often, so check the linked pages before you budget.</p>
<blockquote>
<p><strong>Quick answer:</strong> a focused AI photo editor MVP (sign-in, 2–3 AI features, credits and a paywall) usually takes about <strong>600–1,000 hours</strong> to build with Flutter, roughly <strong>$15,000–$40,000</strong> with an experienced South Asian developer and much more with a US agency. Running it costs about <strong>$0.03–$0.13 per generated image</strong> with Google’s current image models, plus store fees of <strong>15%</strong> on most small apps’ sales and a server from about <strong>€5 a month</strong>.</p>
</blockquote>
<h2 id="what-we-actually-built">What we actually built</h2>
<p>Evoke AI is an app and a website. The app has an AI chatbot, prompt-to-image generation, AI photo editing by prompt, a moments feed and a set of file converters. The website has more than 60 AI tools and converters. Two of us built it in about <strong>six months</strong>.</p>
<p>The parts that took real engineering were not the AI calls themselves:</p>
<ul>
<li><strong>In-app purchases for credits</strong>, end to end.</li>
<li><strong>Ads, including ads that unlock a prompt.</strong></li>
<li><strong>A server-side quota</strong>: every new account gets 5 free prompts, then buys credits or watches an ad per prompt.</li>
<li><strong>Our own backend</strong> on a Contabo server, so the app never holds an AI API key.</li>
</ul>
<p>That last point is not optional. If the key is inside the app, anyone can extract it and run up your bill. How to set this up: <a href="https://neemii.dev/blog/flutter-ai-chat-without-exposing-api-key/">calling an AI API from Flutter without exposing your key</a>.</p>
<h2 id="build-cost-feature-by-feature">Build cost, feature by feature</h2>
<p>These are <strong>planning estimates</strong> for a Flutter app on iOS and Android with one experienced developer, in the same ranges as my <a href="https://neemii.dev/blog/flutter-app-development-cost/">Flutter app development cost</a> guide. They are not Evoke’s invoice.</p>
<table>
<thead>
<tr>
<th>Part</th>
<th>Hours (estimate)</th>
<th>Why it takes that long</th>
</tr>
</thead>
<tbody>
<tr>
<td>App shell: sign-in, profile, settings, gallery</td>
<td>120–200</td>
<td>Standard screens, plus account deletion both stores require</td>
</tr>
<tr>
<td>2–3 AI features (generate, edit by prompt, remove background)</td>
<td>120–220</td>
<td>Upload, progress, errors, retries, saving and sharing results</td>
</tr>
<tr>
<td>Credits and paywall (in-app purchases)</td>
<td>60–120</td>
<td>Store products, receipts, restoring purchases, edge cases</td>
</tr>
<tr>
<td>Rewarded ads</td>
<td>30–60</td>
<td>Ad SDK, consent, granting the reward on the server</td>
</tr>
<tr>
<td>Backend: AI proxy, quota, credits ledger</td>
<td>120–220</td>
<td>The part that protects your API bill</td>
</tr>
<tr>
<td>Admin basics and analytics</td>
<td>40–80</td>
<td>Seeing usage and cost per user</td>
</tr>
<tr>
<td>QA, store review and release</td>
<td>110–180</td>
<td>Testing AI results, content rules, store listing and review</td>
</tr>
<tr>
<td><strong>Total</strong></td>
<td><strong>600–1,080</strong></td>
<td></td>
</tr>
</tbody>
</table>
<p>At the hourly bands from the cost guide, that is roughly <strong>$15,000–$43,000</strong> at South Asia rates ($25–$40/h), <strong>$21,000–$81,000</strong> in Eastern Europe ($35–$75/h) and <strong>$60,000–$162,000</strong> with a US agency ($100–$150/h, assumption). A website with dozens of extra tools, like Evoke’s, is a separate project on top.</p>
<p>To estimate your own scope, use the free <a href="https://neemii.dev/tools/app-cost-calculator/">app cost calculator</a> and tick the AI and payments features.</p>
<h2 id="running-cost-what-each-ai-edit-costs">Running cost: what each AI edit costs</h2>
<p>This is the cost most founders miss. You pay the AI provider for every image, whether or not that user ever pays you.</p>
<table>
<thead>
<tr>
<th>Model (provider)</th>
<th>Price per image</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td>Gemini 3.1 Flash Lite Image (Google)</td>
<td>about <strong>$0.034</strong> at 1K</td>
<td>Cheapest current Google option</td>
</tr>
<tr>
<td>Gemini 3.1 Flash Image (Google)</td>
<td>about <strong>$0.067</strong> at 1K</td>
<td></td>
</tr>
<tr>
<td>Gemini 3 Pro Image (Google)</td>
<td><strong>$0.134</strong> at 1K–2K, <strong>$0.24</strong> at 4K</td>
<td>Highest quality, highest cost</td>
</tr>
<tr>
<td>OpenAI image models</td>
<td>billed by tokens, from <strong>$8</strong> (gpt-image-1-mini) to <strong>$32</strong> per 1M image output tokens</td>
<td>Per-image cost depends on size and quality; use OpenAI’s calculator</td>
</tr>
<tr>
<td>remove.bg (background removal)</td>
<td>about <strong>$0.07–$0.23</strong></td>
<td>Falls with volume on its subscription plans</td>
</tr>
</tbody>
</table>
<p>Sources: <a href="https://ai.google.dev/gemini-api/docs/pricing">Gemini API pricing</a>, <a href="https://developers.openai.com/api/docs/pricing">OpenAI API pricing</a>, <a href="https://www.remove.bg/pricing">remove.bg pricing</a>. Both Google and OpenAI also offer a <strong>Batch</strong> option at half price, which only suits jobs that don’t need an instant result.</p>
<h3 id="a-worked-example">A worked example</h3>
<p>Say 1,000 people install your app in a month and each uses the 5 free prompts:</p>
<ul>
<li>5,000 images × $0.034 = <strong>$170</strong> with the cheapest Gemini model.</li>
<li>5,000 images × $0.134 = <strong>$670</strong> with Gemini 3 Pro Image.</li>
</ul>
<p>That is before a single sale. If the free tier is unlimited instead of 5 prompts, the bill has no ceiling. This is why the free quota has to be <strong>enforced on your server</strong>, not in the app, where a modified copy of the app could skip it.</p>
<h2 id="store-fees-and-servers">Store fees and servers</h2>
<p><strong>Store commission.</strong> Apple’s <a href="https://developer.apple.com/app-store/small-business-program/">Small Business Program</a> takes <strong>15%</strong> on paid apps and in-app purchases for developers with up to $1 million in proceeds the year before. Google Play’s <a href="https://support.google.com/googleplay/android-developer/answer/112622">service fees</a> are <strong>15% on the first $1 million</strong> a year in most markets. In the US, EEA, UK, Japan and Australia, Google is moving to a new structure: 10% plus a 5% billing fee for subscriptions, and 20% plus 5% for other purchases on new installs. Budget for the commission when you price credits.</p>
<p><strong>Servers.</strong> The backend that holds your keys and counts credits is light. A VPS like Contabo’s <a href="https://contabo.com/en/vps/">Cloud VPS</a> starts from about <strong>€4.40–€5.50 a month</strong> (4 vCPU, 8 GB RAM), which is enough to start. Add a database and file storage for user images; Firebase or Supabase free tiers often cover an MVP.</p>
<h2 id="make-the-ai-pay-for-itself">Make the AI pay for itself</h2>
<p>The model that worked for us in Evoke AI:</p>
<ol>
<li><strong>A small free quota</strong> (5 prompts) so people can try the app.</li>
<li><strong>Then credits or an ad.</strong> Users buy credits, or watch a rewarded ad for one more prompt. Every prompt is either paid for or covered by ad revenue.</li>
<li><strong>Everything checked on the server</strong>: quota, credits and ad rewards.</li>
</ol>
<p>Price credits from your real cost: AI cost per image, plus the store’s commission, plus a margin. If a credit pack sells for $4.99 and the store keeps 15%, you receive about $4.24. At $0.034 per image, even 50 credits cost you only $1.70 in AI. At $0.134 per image, the same 50 credits cost $6.70, more than you receive. <strong>Choose the model before you set the price</strong>, not after.</p>
<h2 id="mistakes-that-make-ai-apps-expensive">Mistakes that make AI apps expensive</h2>
<ul>
<li><strong>An API key inside the app.</strong> It will be extracted. Keep keys on your server.</li>
<li><strong>No per-user limits.</strong> One script or one heavy user can burn a month’s budget in a day.</li>
<li><strong>The most expensive model for everything.</strong> Use the cheap model for previews and drafts, the premium one only for final exports users pay for.</li>
<li><strong>No cost tracking.</strong> Log the AI cost of every request per user from day one, so you can see if a feature loses money.</li>
<li><strong>Ignoring content rules.</strong> If users can share generated images with each other, Apple’s <a href="https://developer.apple.com/app-store/review/guidelines/#user-generated-content">guideline 1.2</a> on user-generated content applies: filtering, reporting and blocking. Plan for it before review, not after a rejection.</li>
</ul>
<h2 id="questions">Questions</h2>
<div class="faq-list">
<details class="faq" name="faq">
<summary>How much does it cost to build an app like Remini or Lensa?</summary>
<p>A focused version with 2–3 AI features, credits and a paywall is usually 600–1,000 hours of work with Flutter, about $15,000–$40,000 with an experienced South Asian developer. Matching every feature of a large app costs far more. The bigger ongoing cost is the AI itself, at roughly $0.03–$0.13 per image with current Google models.</p>
</details>
<details class="faq" name="faq">
<summary>Is it cheaper to train my own AI model?</summary>
<p>Almost never for a first version. Training and hosting your own image model means GPU servers and machine learning work that cost far more than API fees at MVP scale. Start with a provider’s API, measure your real usage, and only consider your own model when the API bill is large and predictable.</p>
</details>
<details class="faq" name="faq">
<summary>Can I build an AI photo editor with Flutter?</summary>
<p>Yes. Flutter handles the app on iOS and Android from one codebase, and the AI runs on a backend you control. Evoke AI is built this way. On-device features such as face detection or simple filters can run in the app itself without any API cost.</p>
</details>
<details class="faq" name="faq">
<summary>How do AI photo apps make money?</summary>
<p>Usually with a small free quota, then credit packs or a subscription, and often rewarded ads for users who don’t pay. The key is that every AI request is either paid for or covered by ad revenue, and that the limits are enforced on the server.</p>
</details>
</div>
<h2 id="planning-an-ai-photo-app">Planning an AI photo app?</h2>
<p>I’m Muhammad Naeem, a Flutter developer in Lahore with 10+ apps live, including Evoke AI. If you are planning an AI photo or creative app, <a href="https://neemii.dev/#contact">tell me about your idea</a> and I’ll reply with a scope, the AI cost per user and a price range. See also <a href="https://neemii.dev/services/ai-app-development/">AI app development</a>.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-ai-photo-editor-app-cost.png" type="image/png" length="0" />
    </item>
    <item>
      <title>App Privacy Policy Requirements in 2026: Apple and Google Play</title>
      <link>https://neemii.dev/blog/app-privacy-policy-requirements/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/app-privacy-policy-requirements/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>What Apple and Google Play require for app privacy: privacy policy, Data safety form, privacy labels and manifests, account deletion, ATT, SDKs, kids, GDPR and CCPA.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> Every app on the App Store and Google Play needs a public privacy policy URL, even if it collects nothing. On top of that, Google Play needs an accurate Data safety form and Apple needs App Privacy labels and, for many SDKs, a privacy manifest. If users can create an account, both stores require a way to delete it, and Google also wants a web link for deletion. Your policy, the forms and every SDK in the app must describe the same data.</p>
<p>Privacy is one of the most common reasons an app update gets blocked or rejected. Both stores ask for the same basics: a real privacy policy, an honest description of what the app and its SDKs collect, and a working way to delete an account. Apple also wants a privacy manifest in the app bundle. Each requirement below links to its official source.</p>
<p><strong>This is not legal advice.</strong> It explains store rules and the basics of privacy law; for your specific app, especially one for children, talk to a lawyer.</p>
<h2 id="1-the-privacy-policy-url">1. The privacy policy URL</h2>
<p>Both stores require a privacy policy, even if your app collects nothing.</p>
<h3 id="apple">Apple</h3>
<p><a href="https://developer.apple.com/app-store/review/guidelines/#data-collection-and-storage">App Review Guideline 5.1.1(i)</a> says all apps must link their privacy policy in two places: the App Store Connect metadata field, and <strong>inside the app</strong> “in an easily accessible manner.” The policy must clearly:</p>
<ul>
<li>Say what data the app collects, how it collects it, and every use of that data.</li>
<li>Confirm that any third party you share data with (analytics tools, ad networks, third-party SDKs, parent or related companies) gives the same or equal protection.</li>
<li>Explain your data retention and deletion policy, and how a user can revoke consent or request deletion.</li>
</ul>
<p>In App Store Connect, the <a href="https://developer.apple.com/app-store/app-privacy-details/">privacy details page</a> lists the Privacy Policy URL as required and a “Privacy Choices” URL as optional.</p>
<h3 id="google-play">Google Play</h3>
<p>The <a href="https://support.google.com/googleplay/android-developer/answer/10144311">User Data policy</a> requires a privacy policy link in the designated field in Play Console, plus a privacy policy link or text inside the app. The policy must:</p>
<ul>
<li>Name the developer and give a privacy point of contact.</li>
<li>List the types of personal and sensitive data the app accesses, collects, uses and shares, and who it is shared with.</li>
<li>Describe secure handling procedures, and your data retention and deletion policy.</li>
<li>Be clearly labelled as a privacy policy.</li>
<li>Live on an active, publicly accessible, non-geofenced URL. <strong>No PDFs.</strong></li>
</ul>
<p>If you do not have a policy yet, the free <a href="https://neemii.dev/tools/app-privacy-policy-generator/">app privacy policy generator</a> gives you a starting draft with these headings. Edit it to match what your app actually does; a generic policy that doesn’t match the app is what reviewers flag.</p>
<h2 id="2-google-play-data-safety-form">2. Google Play Data safety form</h2>
<p>The <a href="https://support.google.com/googleplay/android-developer/answer/10787469">Data safety section</a> is the form in Play Console that produces the “Data safety” panel on your store listing. Key points:</p>
<ul>
<li><strong>Everyone fills it in.</strong> Every app published on Google Play must complete it, “even developers with apps that do not collect any user data.” Apps that only exist on the internal testing track are exempt.</li>
<li><strong>“Collect” means data leaves the device.</strong> Processing that stays on the device does not count as collection.</li>
<li><strong>“Sharing” means sending data to a third party.</strong> Transfers to a service provider that processes data on your behalf, legal requests, and some user-initiated transfers are exceptions.</li>
<li><strong>SDKs count as your app.</strong> Data collected by third-party libraries in your app must be declared. You are responsible for it, not the SDK vendor.</li>
<li><strong>Security practices.</strong> You state whether data is encrypted in transit and whether users can request deletion.</li>
<li><strong>Ephemeral processing.</strong> Data kept only in memory for a real-time request can be marked ephemeral, but data used to build advertising or user profiles cannot.</li>
</ul>
<p>Google has required an accurate form for all apps since July 20, 2022. Google says you alone are responsible for your declarations. If they find a mismatch, you must fix it, and apps that stay non-compliant can have updates blocked or be removed.</p>
<blockquote>
<p><strong>My own mistake:</strong> when I first published my app Chatified on Google Play, it had no privacy policy page and no account deletion option. Play Console sent me a series of policy warnings and emails about both. I added a hosted privacy policy, an in-app account deletion flow and a web deletion link, and updated the store forms to match. After that the app moved to early access and then went live. Now I add both before the first submission, not after the warnings. (The rest of the release process is in <a href="https://neemii.dev/blog/publish-flutter-app-app-store-google-play/">publishing a Flutter app on the App Store and Google Play</a>.)</p>
</blockquote>
<h2 id="3-apple-app-privacy-labels">3. Apple App Privacy labels</h2>
<p>The App Store “nutrition label” is built from your answers in App Store Connect. Apple’s <a href="https://developer.apple.com/app-store/app-privacy-details/">App privacy details</a> page sets the rules:</p>
<ul>
<li>You must answer for your own code <strong>and</strong> for “third-party partners,” meaning analytics tools, ad networks, SDKs or other vendors whose code is in your app.</li>
<li>“Collect” means sending data off the device in a way that lets you or a partner access it for longer than needed to serve the request in real time.</li>
<li>Some data is optional to disclose, but only if it meets <strong>all</strong> of Apple’s criteria (not used for tracking or advertising, collected only rarely, optional for the user, and clearly provided by them each time). Most apps should just disclose.</li>
<li>For each data type you also say whether it is <strong>linked to the user</strong> and whether it is <strong>used for tracking</strong>.</li>
<li>You can update answers any time without a new build, and must when your practices change.</li>
</ul>
<h2 id="4-apple-privacy-manifests-privacyinfoxcprivacy">4. Apple privacy manifests (PrivacyInfo.xcprivacy)</h2>
<p>A <a href="https://developer.apple.com/documentation/bundleresources/privacy-manifest-files">privacy manifest</a> is a property list file named <code>PrivacyInfo.xcprivacy</code> that ships inside your app or SDK. It has four top-level keys:</p>
<ul>
<li><code>NSPrivacyTracking</code>: whether the app or SDK uses data for tracking as defined by ATT.</li>
<li><code>NSPrivacyTrackingDomains</code>: domains used for tracking. If the user has not allowed tracking, network requests to these domains fail.</li>
<li><code>NSPrivacyCollectedDataTypes</code>: the data types collected.</li>
<li><code>NSPrivacyAccessedAPITypes</code>: the “required reason” APIs used, with an approved reason code for each.</li>
</ul>
<h3 id="required-reason-apis">Required reason APIs</h3>
<p>Some system APIs can be misused for fingerprinting, so Apple asks you to <a href="https://developer.apple.com/documentation/bundleresources/describing-use-of-required-reason-api">declare why you use them</a>. Categories include user defaults, file timestamps, system boot time, disk space and active keyboards. You pick one or more approved reason codes per category, and you may only use the API for those reasons. Fingerprinting is not allowed even if the user grants tracking permission.</p>
<p>Each executable or framework that calls these APIs needs its own manifest. An SDK cannot rely on the app’s manifest to cover it.</p>
<h3 id="dates-that-matter">Dates that matter</h3>
<ul>
<li>Apple <a href="https://developer.apple.com/news/?id=r1henawx">announced the SDK and required reason rules</a> on December 7, 2023.</li>
<li>Since <strong>May 1, 2024</strong>, Apple’s documentation states that apps that don’t describe their use of required reason APIs in their privacy manifest “aren’t accepted by App Store Connect.” A <a href="https://developer.apple.com/news?id=pvszzano">reminder from April 26, 2024</a> adds that a newly added SDK from Apple’s list of <a href="https://developer.apple.com/support/third-party-SDK-requirements/">commonly used third-party SDKs</a> needs its privacy manifest, and a valid signature if it is a binary dependency.</li>
</ul>
<p>That list includes <code>Flutter</code> itself, many Firebase modules (such as FirebaseCore, FirebaseAuth, FirebaseCrashlytics, FirebaseMessaging), <code>GoogleSignIn</code>, and several popular Flutter plugins.</p>
<h2 id="5-account-deletion-on-both-stores">5. Account deletion on both stores</h2>
<h3 id="apple-1">Apple</h3>
<p><a href="https://developer.apple.com/app-store/review/guidelines/#data-collection-and-storage">Guideline 5.1.1(v)</a>: if your app supports account creation, you must offer account deletion within the app. This has been enforced <a href="https://developer.apple.com/news?id=12m75xbj">since June 30, 2022</a>. Apple’s <a href="https://developer.apple.com/support/offering-account-deletion-in-your-app/">account deletion guidance</a> adds:</p>
<ul>
<li>Make the option easy to find, usually in account settings.</li>
<li>Delete the entire account record and associated personal data. Only offering to deactivate or disable the account is not enough.</li>
<li>If the user has to finish on a website, link directly to that page.</li>
<li>Apps outside highly regulated industries should not make people call, email or go through support to delete.</li>
<li>If you use Sign in with Apple, revoke the user’s tokens with the Sign in with Apple REST API.</li>
</ul>
<h3 id="google-play-1">Google Play</h3>
<p>Google’s <a href="https://support.google.com/googleplay/android-developer/answer/13327111">account deletion requirement</a> applies to apps that let users create an account. You must:</p>
<ul>
<li>Provide an in-app path to delete the account and its data.</li>
<li>Provide a <strong>web link</strong> where users can request deletion without reinstalling the app, and enter it in the Data safety form.</li>
<li>Delete the user data tied to that account. Deactivating or freezing the account does not count, per the <a href="https://support.google.com/googleplay/android-developer/answer/10144311">User Data policy</a>.</li>
<li>If you keep some data for security, fraud prevention or legal reasons, say so in your privacy policy.</li>
</ul>
<p>The deadline to complete these questions was December 7, 2023, with extensions available to May 31, 2024.</p>
<h2 id="6-app-tracking-transparency-att">6. App Tracking Transparency (ATT)</h2>
<p>Apple defines <a href="https://developer.apple.com/app-store/user-privacy-and-data-use/">tracking</a> as linking user or device data from your app with data from other companies’ apps, websites or offline properties for targeted ads or ad measurement, or sharing it with data brokers.</p>
<ul>
<li>On iOS 14.5 and later, you need permission through the ATT framework to track a user or to read the advertising identifier (IDFA). Without it, the IDFA is all zeros.</li>
<li>The prompt needs a purpose string (<code>NSUserTrackingUsageDescription</code> in Info.plist) that explains what the data is used for.</li>
<li>An SDK that combines your users’ data with other developers’ data for ads counts as tracking, <strong>even if you don’t use it for that</strong>.</li>
<li><a href="https://developer.apple.com/app-store/review/guidelines/#data-use-and-sharing">Guideline 5.1.2(i)</a> says you cannot require users to allow tracking to use the app or reward them for allowing it.</li>
</ul>
<p>If your app shows personalised ads (for example with AdMob), you will usually need the ATT prompt, <code>NSPrivacyTracking</code> set to true in the manifest, and “used for tracking” answers in your privacy label. Make sure all three agree.</p>
<h2 id="7-third-party-sdk-disclosures">7. Third-party SDK disclosures</h2>
<p>Both stores make you responsible for what your SDKs do. Apple’s guidelines say this directly in the introduction, and Google says the same in the Data safety rules. In practice:</p>
<ul>
<li><strong>Firebase:</strong> Google’s <a href="https://firebase.google.com/docs/android/play-data-disclosure">Data safety guide for Firebase</a> lists what each product collects. Crashlytics, for example, collects crash stack traces, device metadata and an installation UUID. Firebase also says you are “solely responsible” for your form answers. Custom logs and user IDs you attach yourself also need to be declared.</li>
<li><strong>AdMob:</strong> Google publishes a <a href="https://developers.google.com/admob/android/play-data-disclosure">Play data disclosure guide</a> for the Google Mobile Ads SDK, which collects data such as IP address, user interactions, diagnostics and device identifiers.</li>
<li><strong>Everything else:</strong> Find each vendor’s disclosure page and carry its data types into your form, label and policy.</li>
</ul>
<p><strong>Firebase apps in detail.</strong> Firebase’s <a href="https://firebase.google.com/support/privacy">privacy and security page</a> lists what each product processes and for how long. A few examples:</p>
<ul>
<li><strong>Authentication</strong> processes email addresses, phone numbers, passwords, IP addresses and user agents. It keeps IP logs for a few weeks and the rest until you delete the user.</li>
<li><strong>Crashlytics</strong> keeps crash traces and their identifiers for 90 days.</li>
<li><strong>Cloud Messaging</strong> and <strong>Remote Config</strong> use Firebase installation IDs, which are kept until you delete them.</li>
<li><strong>Google Analytics for Firebase</strong> is a separate service with its own terms, so list it on its own.</li>
</ul>
<p>Google generally acts as a data processor for Firebase, while your app is the controller, so handling users’ privacy requests is your job. The <a href="https://neemii.dev/tools/app-privacy-policy-generator/">privacy policy generator</a> has each Firebase product as a checkbox and writes these lines for you, and the <a href="https://neemii.dev/tools/flutter-data-safety/">Data safety helper</a> turns your pubspec.yaml into the matching form answers.</p>
<h2 id="8-apps-for-children">8. Apps for children</h2>
<p>This is the area with the highest legal risk, so keep this section as a map, not a rulebook, and get a legal review.</p>
<ul>
<li><strong>Apple:</strong> <a href="https://developer.apple.com/app-store/review/guidelines/#kids-category">Guidelines 1.3 and 5.1.4</a> say Kids Category apps should not include third-party analytics or advertising, except in limited cases, and may not send personal or device information to third parties. Links out and purchases must sit behind a parental gate.</li>
<li><strong>Google Play:</strong> The <a href="https://support.google.com/googleplay/android-developer/answer/9893335">Families policy</a> requires you to declare your target audience. Apps that only target children must not transmit the Android advertising ID or use SDKs that are not approved for child-directed services. Ads shown to children must come from Families Self-Certified Ads SDKs and must not be interest-based.</li>
<li><strong>COPPA (US):</strong> The <a href="https://www.ftc.gov/business-guidance/resources/complying-coppa-frequently-asked-questions">FTC’s COPPA FAQ</a> explains that the rule covers apps directed to children under 13, or apps that know they collect data from them, and generally requires verifiable parental consent. Persistent identifiers such as device IDs count as personal information. The rule was amended on April 22, 2025.</li>
</ul>
<h2 id="9-gdpr-and-ccpa-basics-for-apps">9. GDPR and CCPA basics for apps</h2>
<p>These are laws, not store rules, and they can apply even if you are not based in the EU or California.</p>
<ul>
<li><strong>GDPR (EU):</strong> Per <a href="https://gdpr.eu/what-is-gdpr/">gdpr.eu</a>, it applies to organisations anywhere that target or collect data related to people in the EU. You need a lawful basis for each kind of processing (such as consent, contract or legitimate interests) and must support rights like access, rectification, erasure and portability. Top-tier fines reach €20 million or 4% of worldwide annual turnover, whichever is higher.</li>
<li><strong>CCPA (California):</strong> The California Privacy Protection Agency’s <a href="https://cppa.ca.gov/faq.html">FAQ</a> says it covers businesses in California that meet one threshold: $26.625 million or more in annual gross revenue (from January 1, 2025), buying, selling or sharing personal information of 100,000 or more California residents or households, or earning 50% or more of revenue from selling or sharing it. Users can know, delete, correct, opt out of sale or sharing, and limit use of sensitive data.</li>
</ul>
<p>Many small apps fall below the CCPA thresholds, but the store rules apply to every app.</p>
<h2 id="10-flutter-how-plugins-ship-privacy-manifests">10. Flutter: how plugins ship privacy manifests</h2>
<p>Flutter apps are not exempt from Apple’s manifest rules, but most of the work is done by the framework and plugins:</p>
<ul>
<li><strong>The Flutter engine</strong> has included its own <code>PrivacyInfo.xcprivacy</code> in <code>Flutter.framework</code> <a href="https://dart.googlesource.com/monorepo//+/5750bcc3cdcf92f3adad785ba286a39a6e4b1952">since a December 2023 change</a>, declaring its file timestamp and system boot time API use.</li>
<li><strong>Plugins</strong> carry their own manifests. The <a href="https://docs.flutter.dev/packages-and-plugins/developing-packages">Flutter plugin guide</a> tells plugin authors to describe their privacy impact in <code>PrivacyInfo.xcprivacy</code> and include it as a resource in <code>Package.swift</code> (Swift Package Manager) or through <code>resource_bundles</code> in the podspec (CocoaPods).</li>
<li><strong>Your own native code</strong> in <code>ios/Runner</code> is your responsibility. If it calls a required reason API, add a manifest to the Runner target in Xcode (File &gt; New File &gt; App Privacy).</li>
</ul>
<p>What to check before you submit:</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" disabled> Run <code>flutter pub outdated</code> and update plugins. Older plugin versions may predate their manifests.</li>
<li class="task-list-item"><input type="checkbox" disabled> For each plugin with iOS code, check its repository or pub.dev source for a <code>PrivacyInfo.xcprivacy</code> file and the matching podspec or <code>Package.swift</code> entry.</li>
<li class="task-list-item"><input type="checkbox" disabled> Read any App Store Connect emails after upload. Apple emails you when a required reason is missing.</li>
<li class="task-list-item"><input type="checkbox" disabled> Don’t copy a big “catch-all” manifest from a blog post. Declare only APIs and reasons your code actually uses.</li>
<li class="task-list-item"><input type="checkbox" disabled> Make sure the data types in the manifests, your App Store privacy label and your privacy policy all agree.</li>
</ul>
<h2 id="pre-submission-checklist">Pre-submission checklist</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" disabled> Privacy policy on a public HTML page (not a PDF), linked in App Store Connect, Play Console <strong>and</strong> inside the app.</li>
<li class="task-list-item"><input type="checkbox" disabled> Policy names you, gives a contact, lists data types, third parties, retention and deletion.</li>
<li class="task-list-item"><input type="checkbox" disabled> Data safety form complete and matches the policy, including every SDK.</li>
<li class="task-list-item"><input type="checkbox" disabled> App Store privacy label complete, with “linked” and “tracking” answers checked.</li>
<li class="task-list-item"><input type="checkbox" disabled> Privacy manifests present for the app and all SDKs; no missing-reason emails.</li>
<li class="task-list-item"><input type="checkbox" disabled> In-app account deletion, plus a web deletion link for Google Play.</li>
<li class="task-list-item"><input type="checkbox" disabled> ATT prompt and purpose string, if you track.</li>
<li class="task-list-item"><input type="checkbox" disabled> Target audience declared on Google Play; legal review if children may use the app.</li>
<li class="task-list-item"><input type="checkbox" disabled> GDPR and CCPA rights covered in the policy if you have EU or California users.</li>
</ul>
<blockquote>
<p><strong>My pre-submission check for client apps:</strong></p>
<ol>
<li>Read the app’s full documentation, then confirm QA is done and every module works as described.</li>
<li>Make sure the privacy policy and terms of service are clear from the user’s point of view and match store policies.</li>
<li>Check that every permission the app requests and every piece of data it collects is listed in the policy, with the reason.</li>
<li>Test account and data deletion end to end, and confirm no user data is left behind.</li>
<li>Make sure users can open the privacy policy and terms, and delete their account and data, at any time from inside the app.</li>
</ol>
</blockquote>
<h2 id="need-help-getting-through-review">Need help getting through review?</h2>
<p>I build Flutter apps for iOS and Android and handle store submission, including privacy forms, labels and manifests. If your app is stuck in review or you want it set up right the first time, <a href="https://neemii.dev/#contact">get in touch</a>.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-app-privacy-policy-requirements.png" type="image/png" length="0" />
    </item>
    <item>
      <title>How to Change the App Icon in Flutter (Android, iOS and Web)</title>
      <link>https://neemii.dev/blog/change-flutter-app-icon-android-ios/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/change-flutter-app-icon-android-ios/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>Replace Flutter's default launcher icon on Android, iOS and web: file locations, sizes, adaptive and themed icons, flutter_launcher_icons config and store icons.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> Start from one 1024 × 1024 px square image, then either run the flutter_launcher_icons package or generate the files and copy them into android/app/src/main/res and ios/Runner/Assets.xcassets/AppIcon.appiconset. On Android 8+ add an adaptive icon (foreground and background layers), and on iOS use a full-bleed image with no transparency. If the old icon still shows, uninstall the app and rebuild.</p>
<p>Every new Flutter project ships with the blue Flutter logo as its launcher icon. Replacing it looks like a five-minute job, and the basic version is. But Android wants adaptive icons with a safe zone, iOS rejects icons with transparency, the web has its own maskable icons, and the stores want separate listing images on top of all that.</p>
<p>This post covers where the icons live, the sizes and rules for each platform, how to do it with <code>flutter_launcher_icons</code>, and why your new icon sometimes doesn’t show up after you build.</p>
<h2 id="start-with-one-good-source-image">Start with one good source image</h2>
<p>Whatever method you use, start from a single square PNG at 1024 × 1024 px:</p>
<ul>
<li><strong>Square, no rounded corners.</strong> Android and iOS apply their own masks. If you round the corners yourself, you get a rounded square inside a rounded square.</li>
<li><strong>No transparency for iOS.</strong> You can keep a transparent version for the Android adaptive foreground, but the iOS icon has to be fully opaque.</li>
<li><strong>Keep the logo away from the edges.</strong> Android adaptive icons and web maskable icons crop the outer area. A logo that touches the edges will be cut off.</li>
<li><strong>Simple shapes.</strong> The icon is shown at 48 px on some screens. Thin lines and small text disappear.</li>
</ul>
<h2 id="where-flutter-keeps-the-default-icons">Where Flutter keeps the default icons</h2>
<p>A new project created with <code>flutter create</code> has its icons in these places:</p>
<table>
<thead>
<tr>
<th>Platform</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<td>Android</td>
<td><code>android/app/src/main/res/mipmap-mdpi</code> … <code>mipmap-xxxhdpi/ic_launcher.png</code></td>
</tr>
<tr>
<td>iOS</td>
<td><code>ios/Runner/Assets.xcassets/AppIcon.appiconset/</code> (PNGs plus <code>Contents.json</code>)</td>
</tr>
<tr>
<td>Web</td>
<td><code>web/favicon.png</code> and <code>web/icons/</code> (<code>Icon-192.png</code>, <code>Icon-512.png</code>, <code>Icon-maskable-192.png</code>, <code>Icon-maskable-512.png</code>)</td>
</tr>
</tbody>
</table>
<p>Android points to the icon from <code>android/app/src/main/AndroidManifest.xml</code>:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="xml"><code><span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">application</span></span>
<span class="line"><span style="color:#B392F0">    android:label</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"my_app"</span></span>
<span class="line"><span style="color:#B392F0">    android:icon</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"@mipmap/ic_launcher"</span><span style="color:#E1E4E8">&gt;</span></span></code></pre>
<p>As long as you keep the file name <code>ic_launcher</code>, you can replace the PNGs and the manifest doesn’t need to change.</p>
<h2 id="android-legacy-icons-and-densities">Android: legacy icons and densities</h2>
<p>Android picks an icon based on the screen density. The legacy (non-adaptive) launcher icon is 48 dp, which works out to these pixel sizes:</p>
<table>
<thead>
<tr>
<th>Folder</th>
<th>Density</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>mipmap-mdpi</code></td>
<td>1x</td>
<td>48 × 48</td>
</tr>
<tr>
<td><code>mipmap-hdpi</code></td>
<td>1.5x</td>
<td>72 × 72</td>
</tr>
<tr>
<td><code>mipmap-xhdpi</code></td>
<td>2x</td>
<td>96 × 96</td>
</tr>
<tr>
<td><code>mipmap-xxhdpi</code></td>
<td>3x</td>
<td>144 × 144</td>
</tr>
<tr>
<td><code>mipmap-xxxhdpi</code></td>
<td>4x</td>
<td>192 × 192</td>
</tr>
</tbody>
</table>
<p>The manual way: export your icon at these five sizes, name each one <code>ic_launcher.png</code>, and overwrite the files in the matching folders. That’s enough for older devices, but on Android 8.0 and above a plain PNG icon can end up shrunk inside a white circle or squircle on some launchers. That’s what adaptive icons fix.</p>
<h2 id="android-adaptive-icons-api-26">Android: adaptive icons (API 26+)</h2>
<p>Since Android 8.0 (API 26), a launcher icon can be built from two layers: a <strong>background</strong> and a <strong>foreground</strong>. The launcher masks them into whatever shape the device uses (circle, squircle, rounded square) and can animate the layers separately.</p>
<p>The numbers from the <a href="https://developer.android.com/develop/ui/views/launch/icon_design_adaptive">Android adaptive icon guide</a>:</p>
<ul>
<li>Each layer is <strong>108 × 108 dp</strong>.</li>
<li>The mask shows roughly the inner <strong>72 × 72 dp</strong>. The outer 18 dp on each side is used for parallax and masking effects.</li>
<li>Your logo should sit inside the central <strong>66 × 66 dp</strong> safe zone, so no mask shape cuts it.</li>
</ul>
<p>In pixels, the foreground layer is 108 px at mdpi, up to 432 px at xxxhdpi (108 × 4). The most common mistake is putting the 48 dp legacy icon artwork straight into the foreground layer. It fills the whole 108 dp canvas, and the mask crops the logo. Scale the logo down so it fits the safe zone, with transparent padding around it.</p>
<blockquote>
<p><strong>From client work:</strong> I’ve had a client’s logo lose its corners to a phone maker’s mask. The permanent fix is to keep every important part of the logo inside the central 66 dp safe zone of the 108 dp canvas, by adding transparent padding to the image before export (in Figma or Canva) or scaling it down in the generator. Never let the logo run to the edge of the canvas.</p>
</blockquote>
<p>To add an adaptive icon by hand:</p>
<ol>
<li>Put the foreground PNGs (transparent background) in each <code>mipmap-*</code> folder as <code>ic_launcher_foreground.png</code>.</li>
<li>Add a background colour in <code>android/app/src/main/res/values/colors.xml</code>:</li>
</ol>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="xml"><code><span class="line"><span style="color:#E1E4E8">&lt;?</span><span style="color:#85E89D">xml</span><span style="color:#B392F0"> version</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"1.0"</span><span style="color:#B392F0"> encoding</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"utf-8"</span><span style="color:#E1E4E8">?&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">resources</span><span style="color:#E1E4E8">&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">    &lt;</span><span style="color:#85E89D">color</span><span style="color:#B392F0"> name</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"ic_launcher_background"</span><span style="color:#E1E4E8">&gt;#FFFFFF&lt;/</span><span style="color:#85E89D">color</span><span style="color:#E1E4E8">&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">&lt;/</span><span style="color:#85E89D">resources</span><span style="color:#E1E4E8">&gt;</span></span></code></pre>
<ol start="3">
<li>Create <code>android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml</code>:</li>
</ol>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="xml"><code><span class="line"><span style="color:#E1E4E8">&lt;?</span><span style="color:#85E89D">xml</span><span style="color:#B392F0"> version</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"1.0"</span><span style="color:#B392F0"> encoding</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"utf-8"</span><span style="color:#E1E4E8">?&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">adaptive-icon</span><span style="color:#B392F0"> xmlns:android</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"http://schemas.android.com/apk/res/android"</span><span style="color:#E1E4E8">&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">    &lt;</span><span style="color:#85E89D">background</span><span style="color:#B392F0"> android:drawable</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"@color/ic_launcher_background"</span><span style="color:#E1E4E8"> /&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">    &lt;</span><span style="color:#85E89D">foreground</span><span style="color:#B392F0"> android:drawable</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"@mipmap/ic_launcher_foreground"</span><span style="color:#E1E4E8"> /&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">&lt;/</span><span style="color:#85E89D">adaptive-icon</span><span style="color:#E1E4E8">&gt;</span></span></code></pre>
<p>The <code>-v26</code> qualifier means devices on API 26 and above use this XML, while older devices fall back to the <code>ic_launcher.png</code> files. Keep both. The background can also be an image instead of a colour; reference a drawable or mipmap instead of <code>@color/...</code>.</p>
<h3 id="themed-monochrome-icons-on-android-13">Themed (monochrome) icons on Android 13</h3>
<p>Android 13 (API 33) added themed icons: when the user turns on themed icons, the launcher tints app icons to match the wallpaper colours. Your app only takes part if the adaptive icon includes a <code>monochrome</code> layer:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="xml"><code><span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">adaptive-icon</span><span style="color:#B392F0"> xmlns:android</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"http://schemas.android.com/apk/res/android"</span><span style="color:#E1E4E8">&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">    &lt;</span><span style="color:#85E89D">background</span><span style="color:#B392F0"> android:drawable</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"@color/ic_launcher_background"</span><span style="color:#E1E4E8"> /&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">    &lt;</span><span style="color:#85E89D">foreground</span><span style="color:#B392F0"> android:drawable</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"@mipmap/ic_launcher_foreground"</span><span style="color:#E1E4E8"> /&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">    &lt;</span><span style="color:#85E89D">monochrome</span><span style="color:#B392F0"> android:drawable</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"@mipmap/ic_launcher_monochrome"</span><span style="color:#E1E4E8"> /&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">&lt;/</span><span style="color:#85E89D">adaptive-icon</span><span style="color:#E1E4E8">&gt;</span></span></code></pre>
<p>The monochrome image is a single-colour silhouette of your logo on a transparent background, same 108 dp canvas and safe zone as the foreground. Only the alpha channel matters; the system supplies the colour. Without this layer, your icon shows in its normal colours while the rest of the home screen is tinted, which makes it stand out in a bad way.</p>
<h2 id="ios-the-asset-catalog-and-its-rules">iOS: the asset catalog and its rules</h2>
<p>On iOS, icons live in an asset catalog: <code>ios/Runner/Assets.xcassets/AppIcon.appiconset/</code>. The folder contains the PNGs and a <code>Contents.json</code> that tells Xcode which file is which size, idiom and scale. A shortened example:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="json"><code><span class="line"><span style="color:#E1E4E8">{</span></span>
<span class="line"><span style="color:#79B8FF">  "images"</span><span style="color:#E1E4E8"> : [</span></span>
<span class="line"><span style="color:#E1E4E8">    {</span></span>
<span class="line"><span style="color:#79B8FF">      "size"</span><span style="color:#E1E4E8"> : </span><span style="color:#9ECBFF">"60x60"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">      "idiom"</span><span style="color:#E1E4E8"> : </span><span style="color:#9ECBFF">"iphone"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">      "filename"</span><span style="color:#E1E4E8"> : </span><span style="color:#9ECBFF">"Icon-App-60x60@2x.png"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">      "scale"</span><span style="color:#E1E4E8"> : </span><span style="color:#9ECBFF">"2x"</span></span>
<span class="line"><span style="color:#E1E4E8">    },</span></span>
<span class="line"><span style="color:#E1E4E8">    {</span></span>
<span class="line"><span style="color:#79B8FF">      "size"</span><span style="color:#E1E4E8"> : </span><span style="color:#9ECBFF">"1024x1024"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">      "idiom"</span><span style="color:#E1E4E8"> : </span><span style="color:#9ECBFF">"ios-marketing"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">      "filename"</span><span style="color:#E1E4E8"> : </span><span style="color:#9ECBFF">"Icon-App-1024x1024@1x.png"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">      "scale"</span><span style="color:#E1E4E8"> : </span><span style="color:#9ECBFF">"1x"</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  ],</span></span>
<span class="line"><span style="color:#79B8FF">  "info"</span><span style="color:#E1E4E8"> : {</span></span>
<span class="line"><span style="color:#79B8FF">    "version"</span><span style="color:#E1E4E8"> : </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    "author"</span><span style="color:#E1E4E8"> : </span><span style="color:#9ECBFF">"xcode"</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>If you replace the PNGs by hand, keep the exact file names and pixel sizes that <code>Contents.json</code> lists, or Xcode will warn about unassigned or wrong-sized images. The easier manual route is to open <code>ios/Runner.xcworkspace</code> in Xcode, select <code>Assets</code> → <code>AppIcon</code>, and drag your images into the slots.</p>
<p>The rules that matter:</p>
<ul>
<li><strong>The 1024 × 1024 marketing icon is required.</strong> It’s the <code>ios-marketing</code> entry, and App Store Connect uses it for your store listing. You don’t upload the App Store icon separately; it comes from the asset catalog in your build.</li>
<li><strong>No transparency, no alpha channel.</strong> An icon with an alpha channel fails validation when you upload the build. “No transparent pixels” isn’t enough; a PNG exported with an alpha channel can still be flagged. Export without alpha, or flatten it onto a solid background.</li>
<li><strong>No pre-rounded corners.</strong> iOS applies its own rounded mask. Give it a full square.</li>
</ul>
<p>Apple’s <a href="https://developer.apple.com/design/human-interface-guidelines/app-icons">app icon guidelines</a> cover the design side.</p>
<h2 id="web-favicon-pwa-and-maskable-icons">Web: favicon, PWA and maskable icons</h2>
<p>Flutter web uses <code>web/favicon.png</code> for the browser tab, and the icons in <code>web/icons/</code> for the PWA install (home screen, app launcher). They’re listed in <code>web/manifest.json</code>:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="json"><code><span class="line"><span style="color:#9ECBFF">"icons"</span><span style="color:#E1E4E8">: [</span></span>
<span class="line"><span style="color:#E1E4E8">  { </span><span style="color:#79B8FF">"src"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"icons/Icon-192.png"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"sizes"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"192x192"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"type"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"image/png"</span><span style="color:#E1E4E8"> },</span></span>
<span class="line"><span style="color:#E1E4E8">  { </span><span style="color:#79B8FF">"src"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"icons/Icon-512.png"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"sizes"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"512x512"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"type"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"image/png"</span><span style="color:#E1E4E8"> },</span></span>
<span class="line"><span style="color:#E1E4E8">  { </span><span style="color:#79B8FF">"src"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"icons/Icon-maskable-192.png"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"sizes"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"192x192"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"type"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"image/png"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"purpose"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"maskable"</span><span style="color:#E1E4E8"> },</span></span>
<span class="line"><span style="color:#E1E4E8">  { </span><span style="color:#79B8FF">"src"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"icons/Icon-maskable-512.png"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"sizes"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"512x512"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"type"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"image/png"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"purpose"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"maskable"</span><span style="color:#E1E4E8"> }</span></span>
<span class="line"><span style="color:#E1E4E8">]</span></span></code></pre>
<p>Maskable icons work like Android adaptive icons: the platform crops them to its own shape, so the logo needs to sit in the central safe area with a solid background behind it. A regular icon used as maskable gets its edges cut off. The <a href="https://web.dev/articles/maskable-icon">web.dev guide to maskable icons</a> explains the safe zone. Also update <code>theme_color</code> and <code>background_color</code> in the same <code>manifest.json</code> so the install splash matches your brand.</p>
<h2 id="the-easy-way-flutter_launcher_icons">The easy way: flutter_launcher_icons</h2>
<p>Doing all of the above by hand for every app, and again every time the logo changes, gets old fast. The <a href="https://pub.dev/packages/flutter_launcher_icons">flutter_launcher_icons</a> package generates the Android, iOS and web icons from one source image and writes them into the right folders.</p>
<p>Add it as a dev dependency:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> pub</span><span style="color:#9ECBFF"> add</span><span style="color:#9ECBFF"> dev:flutter_launcher_icons</span></span></code></pre>
<p>Then add the config, either under a <code>flutter_launcher_icons</code> key in <code>pubspec.yaml</code> or in a separate <code>flutter_launcher_icons.yaml</code> next to it:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="yaml"><code><span class="line"><span style="color:#85E89D">flutter_launcher_icons</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#85E89D">  image_path</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"assets/icon/icon.png"</span></span>
<span class="line"><span style="color:#85E89D">  android</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">true</span></span>
<span class="line"><span style="color:#85E89D">  ios</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">true</span></span>
<span class="line"><span style="color:#85E89D">  min_sdk_android</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">21</span></span>
<span class="line"><span style="color:#85E89D">  remove_alpha_ios</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">true</span></span>
<span class="line"><span style="color:#85E89D">  background_color_ios</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"#FFFFFF"</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">  adaptive_icon_background</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"#FFFFFF"</span></span>
<span class="line"><span style="color:#85E89D">  adaptive_icon_foreground</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"assets/icon/icon_foreground.png"</span></span>
<span class="line"><span style="color:#85E89D">  adaptive_icon_monochrome</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"assets/icon/icon_monochrome.png"</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">  web</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#85E89D">    generate</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">true</span></span>
<span class="line"><span style="color:#85E89D">    image_path</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"assets/icon/icon.png"</span></span>
<span class="line"><span style="color:#85E89D">    background_color</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"#FFFFFF"</span></span>
<span class="line"><span style="color:#85E89D">    theme_color</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"#0175C2"</span></span></code></pre>
<p>What the main options do:</p>
<ul>
<li><code>image_path</code>: the source image for all platforms. You can override it per platform with <code>image_path_android</code> and <code>image_path_ios</code>.</li>
<li><code>android</code> / <code>ios</code>: <code>true</code> replaces the default icon. A string such as <code>"launcher_icon"</code> generates a new icon with that name instead and leaves the default files alone. <code>false</code> skips the platform.</li>
<li><code>adaptive_icon_background</code>: a hex colour or an image path.</li>
<li><code>adaptive_icon_foreground</code>: the transparent foreground image. Make this a version of your logo with padding, not the full-bleed icon, or it gets cropped. There’s also <code>adaptive_icon_foreground_inset</code> if you need to adjust the padding.</li>
<li><code>adaptive_icon_monochrome</code>: the Android 13 themed icon layer.</li>
<li><code>remove_alpha_ios</code>: strips the alpha channel from the iOS icons, so the App Store upload doesn’t fail. <code>background_color_ios</code> sets the colour used to fill transparent areas.</li>
<li><code>min_sdk_android</code>: your app’s minimum Android SDK (default 21).</li>
<li><code>web</code>: generates the favicon and the PWA icons, and sets the manifest colours.</li>
</ul>
<p>The package also supports <code>windows</code> and <code>macos</code> blocks if you ship desktop builds.</p>
<p>Run it:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> pub</span><span style="color:#9ECBFF"> get</span></span>
<span class="line"><span style="color:#B392F0">dart</span><span style="color:#9ECBFF"> run</span><span style="color:#9ECBFF"> flutter_launcher_icons</span></span></code></pre>
<p>If you use a config file with a different name, pass it with <code>-f</code>. For flavors, the package picks up files named <code>flutter_launcher_icons-&lt;flavor&gt;.yaml</code>. The <a href="https://pub.dev/packages/flutter_launcher_icons">README</a> has the full option list; check it against the version you install, since options get added between releases.</p>
<p>Run <code>git diff</code> afterwards and look at what changed. You should see new PNGs in the <code>mipmap-*</code> folders, an <code>ic_launcher.xml</code> in <code>mipmap-anydpi-v26</code> if you set the adaptive options, the iOS asset catalog, and the web icons.</p>
<h2 id="without-a-package-generate-the-files-in-the-browser">Without a package: generate the files in the browser</h2>
<p>If you don’t want another dev dependency, or you just want to see the icons on every mask shape before committing them, I built a free <a href="https://neemii.dev/tools/app-icon-generator/">app icon generator</a>. You upload one image and download a zip that uses Flutter’s folder layout: Android <code>mipmap-*</code> folders with the adaptive icon XML, the iOS <code>AppIcon.appiconset</code> with <code>Contents.json</code> and no alpha, the web icons including maskable ones, and the Play Store and App Store images. It runs in your browser, so the image isn’t uploaded anywhere. Unzip it over your project and you’re done.</p>
<p>Which to use? If you want the icon setup to live in the repo, so anyone on the team can change the logo and regenerate with one command, use <code>flutter_launcher_icons</code>. That’s the better long-term choice for a team project. The generator is faster for a one-off, for checking the result visually before you commit, or for producing the store listing images, which the package doesn’t make.</p>
<blockquote>
<p><strong>What I use:</strong> in client apps I use flutter_launcher_icons. The configuration lives in the repository, so anyone on the team can regenerate every icon with one command when the logo changes. The online generator is handy for a quick preview or a project without the package.</p>
</blockquote>
<h2 id="change-the-app-name-while-youre-at-it">Change the app name while you’re at it</h2>
<p>The name under the icon is separate from the icon itself:</p>
<ul>
<li><strong>Android:</strong> <code>android:label</code> on the <code>&lt;application&gt;</code> tag in <code>android/app/src/main/AndroidManifest.xml</code>.</li>
<li><strong>iOS:</strong> <code>CFBundleDisplayName</code> in <code>ios/Runner/Info.plist</code>.</li>
</ul>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="xml"><code><span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">key</span><span style="color:#E1E4E8">&gt;CFBundleDisplayName&lt;/</span><span style="color:#85E89D">key</span><span style="color:#E1E4E8">&gt;</span></span>
<span class="line"><span style="color:#E1E4E8">&lt;</span><span style="color:#85E89D">string</span><span style="color:#E1E4E8">&gt;My App&lt;/</span><span style="color:#85E89D">string</span><span style="color:#E1E4E8">&gt;</span></span></code></pre>
<p>This only changes the name on the home screen. The name on the store listing is set in Play Console and App Store Connect.</p>
<h2 id="why-the-icon-doesnt-change">Why the icon doesn’t change</h2>
<p>You replaced the icons, rebuilt, and the old Flutter logo is still there. The usual causes:</p>
<ol>
<li><strong>Hot reload and hot restart don’t touch native resources.</strong> Icons are part of the Android and iOS projects, not your Dart code. Stop the app and run a full build.</li>
<li><strong>The launcher caches icons.</strong> Android launchers and the iOS home screen keep the old icon in a cache. Uninstall the app from the device or emulator, then install it again.</li>
<li><strong>Stale build output.</strong> Run <code>flutter clean</code>, then <code>flutter pub get</code>, then build again.</li>
<li><strong>The adaptive XML wins.</strong> On API 26+, if <code>mipmap-anydpi-v26/ic_launcher.xml</code> exists, Android uses it and ignores your new <code>ic_launcher.png</code> files. If you only replaced the PNGs, you’ll still see the old adaptive icon. Update or remove the foreground layer too.</li>
<li><strong>The manifest points somewhere else.</strong> If you used a custom name like <code>launcher_icon</code>, check that <code>android:icon</code> in <code>AndroidManifest.xml</code> points to <code>@mipmap/launcher_icon</code>.</li>
</ol>
<h2 id="store-listing-icons">Store listing icons</h2>
<p>The stores have their own requirements, separate from the icon inside the app:</p>
<ul>
<li><strong>Google Play:</strong> a 512 × 512 px, 32-bit PNG (alpha allowed), up to 1 MB, uploaded in Play Console under the store listing. Upload a full square; Google Play applies the rounded corners and shadow itself. See Google’s <a href="https://developer.android.com/distribute/google-play/resources/icon-design-specifications">icon design specifications</a>.</li>
<li><strong>App Store:</strong> the 1024 × 1024 icon from your asset catalog. There’s no separate upload; App Store Connect takes it from the build. Same rules as before: no alpha, no rounded corners.</li>
</ul>
<p>If you’re getting ready to release, my post on <a href="https://neemii.dev/blog/publish-flutter-app-app-store-google-play/">publishing a Flutter app to the App Store and Google Play</a> covers the rest of the store checklist.</p>
<h2 id="summary">Summary</h2>
<ul>
<li>Start from one square 1024 × 1024 PNG with no rounded corners, and keep the logo away from the edges.</li>
<li>Android needs legacy icons at five densities plus an adaptive icon (108 dp layers, 66 dp safe zone), and a monochrome layer for Android 13 themed icons.</li>
<li>iOS needs a full asset catalog with a 1024 marketing icon and no alpha channel.</li>
<li>Web needs a favicon, 192 and 512 icons, and maskable versions.</li>
<li>Use <code>flutter_launcher_icons</code> to keep it all in config, or the <a href="https://neemii.dev/tools/app-icon-generator/">app icon generator</a> for a quick zip in Flutter’s layout.</li>
<li>If the icon doesn’t update, uninstall the app, run <code>flutter clean</code> and do a full build.</li>
</ul>
<p>An icon is a small part of an app, but it’s the first thing users see in the store and on their phone. If you’re building a Flutter app and want someone who has shipped more than ten of them to handle it end to end, icons and store release included, <a href="https://neemii.dev/#contact">tell me about your project</a>.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-change-flutter-app-icon-android-ios.png" type="image/png" length="0" />
    </item>
    <item>
      <title>Flutter AI Chat Without Exposing Your OpenAI API Key</title>
      <link>https://neemii.dev/blog/flutter-ai-chat-without-exposing-api-key/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/flutter-ai-chat-without-exposing-api-key/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>Add a ChatGPT-style chat to a Flutter app without shipping your API key: a small Dart backend proxy, per-user rate limits, streaming replies and cost controls.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> Never put an OpenAI, Gemini or Claude API key inside a Flutter app, because anyone can pull it out of the install file. Put a small backend in between: the app calls your server, your server holds the key, checks the user and their limits, calls the AI provider and streams the answer back. If you don’t want to run a server, Firebase AI Logic is a managed alternative.</p>
<p>Adding an AI chat screen to a Flutter app looks like a one-afternoon job. You grab an API key from OpenAI or Google, call the chat endpoint with <code>package:http</code>, and print the reply. It works on your phone, so you ship it.</p>
<p>Then someone pulls the key out of your app and runs their own traffic on your account. You find out from the bill.</p>
<p>This post shows the setup I’d use instead: the key lives on a small server you control, the app talks to that server with the signed-in user’s token, and the server handles rate limits, the model choice and the cost caps. The reply still streams into the chat UI word by word. All the Dart code below (the proxy and the client) was run locally against a fake upstream server, so it does what it says.</p>
<h2 id="why-an-api-key-inside-your-app-is-not-secret">Why an API key inside your app is not secret</h2>
<p>Anything you put in an app binary goes to every person who installs it. An APK or IPA is an archive. People unzip it, run <code>strings</code> over the compiled Dart code, or put a proxy like mitmproxy between the phone and the internet and read the <code>Authorization</code> header as it goes past. A long string that starts with <code>sk-</code> is not hard to spot.</p>
<p>The usual “fixes” don’t change this:</p>
<ul>
<li><strong><code>.env</code> files with <code>flutter_dotenv</code></strong>. The <code>.env</code> file is bundled as an asset. It’s sitting in the app package as plain text.</li>
<li><strong><code>--dart-define</code> or <code>--dart-define-from-file</code></strong>. These keep the key out of your Git repo, which is good, but the value is compiled into the app. It’s still in the binary.</li>
<li><strong>Obfuscation</strong>. Flutter’s own docs say obfuscation “only renames symbols” and does not protect against reverse engineering, and that storing secrets in an app is “a poor security practice” (<a href="https://docs.flutter.dev/deployment/obfuscate">Flutter docs</a>).</li>
<li><strong>Splitting or encrypting the key</strong>. The app has to rebuild the real key to use it, so the code to rebuild it ships too. And once the key is in memory, it shows up in the network request anyway.</li>
</ul>
<p>So the rule is simple: if a request carries your provider key, that request must come from a server, not from the phone.</p>
<h2 id="the-backend-proxy-pattern">The backend proxy pattern</h2>
<p>The app never talks to OpenAI or Gemini directly. It talks to your endpoint:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="plaintext"><code><span class="line"><span>Flutter app  --(user's auth token)--&gt;  your /chat endpoint  --(API key)--&gt;  LLM provider</span></span>
<span class="line"><span>             &lt;--(streamed text)-------                      &lt;--(SSE)-------</span></span></code></pre>
<p>Your endpoint can be a tiny Dart server on Cloud Run or a VPS, a Firebase Cloud Function, a Supabase Edge Function, or anything else that can hold an environment variable and make an HTTPS request. It does five jobs:</p>
<ol>
<li><strong>Holds the key</strong> in an environment variable or secret manager. It never leaves the server.</li>
<li><strong>Checks who is calling.</strong> The app sends the user’s auth token (a Firebase ID token, a Supabase JWT, your own session token). No valid user, no AI call.</li>
<li><strong>Limits each user.</strong> A per-user rate limit and, ideally, a daily or monthly quota.</li>
<li><strong>Decides the request.</strong> Model, system prompt and maximum reply length are set on the server. The app only sends the conversation.</li>
<li><strong>Streams the reply back</strong> so the UI can show text as it arrives.</li>
</ol>
<p>Point 4 is easy to undervalue. If the model name is hard-coded in your app, changing it means a store release and waiting for users to update. If it’s an environment variable on the server, you can switch from one OpenAI model to a cheaper one, or to Gemini, in a minute. Google even offers an OpenAI-compatible endpoint for Gemini at <code>https://generativelanguage.googleapis.com/v1beta/openai/</code> (<a href="https://aistudio.google.com/docs/openai">Gemini docs</a>), so the same proxy code can talk to either provider by changing the base URL, key and model name.</p>
<blockquote>
<p><strong>How I do it in my own apps:</strong> none of my AI apps ship an API key. Evoke AI and Hashtag AI Expert call my own backend on a Contabo server, and Inlinker, a client company’s app, runs its backend on DigitalOcean. The apps only talk to that backend, and the backend holds the keys and calls the AI providers. Keys never go into the app code or a GitHub repository. Around that I use Firebase and Supabase for app data and auth, Firebase Cloud Messaging for notifications, and Crashlytics to catch crashes in the live apps.</p>
</blockquote>
<h2 id="a-minimal-dart-proxy">A minimal Dart proxy</h2>
<p>Here is a complete proxy using only <code>dart:io</code> and <code>package:http</code>. It speaks the OpenAI Chat Completions format: <code>POST {base}/chat/completions</code> with <code>model</code>, <code>messages</code> and <code>"stream": true</code>, and a server-sent events (SSE) stream back where each <code>data:</code> line holds a chunk with the new text in <code>choices[0].delta.content</code>, ending with <code>data: [DONE]</code> (<a href="https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create">OpenAI API reference</a>).</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'dart:async'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'dart:convert'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'dart:io'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'package:http/http.dart'</span><span style="color:#F97583"> as</span><span style="color:#E1E4E8"> http;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// Everything provider-specific lives here, on the server.</span></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> apiKey </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Platform</span><span style="color:#E1E4E8">.environment[</span><span style="color:#9ECBFF">'LLM_API_KEY'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> ''</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> baseUrl </span><span style="color:#F97583">=</span></span>
<span class="line"><span style="color:#79B8FF">    Platform</span><span style="color:#E1E4E8">.environment[</span><span style="color:#9ECBFF">'LLM_BASE_URL'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> 'https://api.openai.com/v1'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> model </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Platform</span><span style="color:#E1E4E8">.environment[</span><span style="color:#9ECBFF">'LLM_MODEL'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> ''</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#E1E4E8"> systemPrompt </span><span style="color:#F97583">=</span></span>
<span class="line"><span style="color:#9ECBFF">    'You are a helpful assistant inside a mobile app. '</span></span>
<span class="line"><span style="color:#9ECBFF">    'Keep answers short.'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// Simple per-user limit: 20 requests per 10 minutes.</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#E1E4E8"> maxRequests </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> 20</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#E1E4E8"> window </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Duration</span><span style="color:#E1E4E8">(minutes</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 10</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> _hits </span><span style="color:#F97583">=</span><span style="color:#F97583"> &lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">List</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">DateTime</span><span style="color:#E1E4E8">&gt;</span><span style="color:#F97583">&gt;</span><span style="color:#E1E4E8">{};</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> _upstream </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> http.</span><span style="color:#79B8FF">Client</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">Future</span><span style="color:#E1E4E8">&lt;</span><span style="color:#F97583">void</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">main</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">async</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  if</span><span style="color:#E1E4E8"> (apiKey.isEmpty </span><span style="color:#F97583">||</span><span style="color:#E1E4E8"> model.isEmpty) {</span></span>
<span class="line"><span style="color:#E1E4E8">    stderr.</span><span style="color:#B392F0">writeln</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Set LLM_API_KEY and LLM_MODEL.'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#B392F0">    exit</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> port </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> int</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">parse</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Platform</span><span style="color:#E1E4E8">.environment[</span><span style="color:#9ECBFF">'PORT'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> '8080'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> server </span><span style="color:#F97583">=</span><span style="color:#F97583"> await</span><span style="color:#79B8FF"> HttpServer</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">bind</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">InternetAddress</span><span style="color:#E1E4E8">.anyIPv4, port);</span></span>
<span class="line"><span style="color:#B392F0">  print</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Proxy listening on port </span><span style="color:#9ECBFF">${</span><span style="color:#79B8FF">server</span><span style="color:#9ECBFF">.</span><span style="color:#79B8FF">port</span><span style="color:#9ECBFF">}</span><span style="color:#9ECBFF">'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">  await</span><span style="color:#F97583"> for</span><span style="color:#E1E4E8"> (</span><span style="color:#F97583">final</span><span style="color:#E1E4E8"> request </span><span style="color:#F97583">in</span><span style="color:#E1E4E8"> server) {</span></span>
<span class="line"><span style="color:#B392F0">    unawaited</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">_handle</span><span style="color:#E1E4E8">(request));</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">Future</span><span style="color:#E1E4E8">&lt;</span><span style="color:#F97583">void</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">_handle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">HttpRequest</span><span style="color:#E1E4E8"> req) </span><span style="color:#F97583">async</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> res </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> req.response;</span></span>
<span class="line"><span style="color:#F97583">  try</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (req.method </span><span style="color:#F97583">!=</span><span style="color:#9ECBFF"> 'POST'</span><span style="color:#F97583"> ||</span><span style="color:#E1E4E8"> req.uri.path </span><span style="color:#F97583">!=</span><span style="color:#9ECBFF"> '/chat'</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">      return</span><span style="color:#B392F0"> _fail</span><span style="color:#E1E4E8">(res, </span><span style="color:#79B8FF">HttpStatus</span><span style="color:#E1E4E8">.notFound, </span><span style="color:#9ECBFF">'not found'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    // 1. Who is calling? Never trust a user id sent in the body.</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> auth </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> req.headers.</span><span style="color:#B392F0">value</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">HttpHeaders</span><span style="color:#E1E4E8">.authorizationHeader) </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> ''</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> userId </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> auth.</span><span style="color:#B392F0">startsWith</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Bearer '</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#F97583">        ?</span><span style="color:#F97583"> await</span><span style="color:#B392F0"> verifyToken</span><span style="color:#E1E4E8">(auth.</span><span style="color:#B392F0">substring</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">7</span><span style="color:#E1E4E8">))</span></span>
<span class="line"><span style="color:#F97583">        :</span><span style="color:#79B8FF"> null</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (userId </span><span style="color:#F97583">==</span><span style="color:#79B8FF"> null</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">      return</span><span style="color:#B392F0"> _fail</span><span style="color:#E1E4E8">(res, </span><span style="color:#79B8FF">HttpStatus</span><span style="color:#E1E4E8">.unauthorized, </span><span style="color:#9ECBFF">'sign in first'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    // 2. Per-user rate limit.</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (</span><span style="color:#F97583">!</span><span style="color:#B392F0">_allow</span><span style="color:#E1E4E8">(userId)) {</span></span>
<span class="line"><span style="color:#E1E4E8">      res.headers.</span><span style="color:#B392F0">set</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Retry-After'</span><span style="color:#E1E4E8">, </span><span style="color:#9ECBFF">'60'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">      return</span><span style="color:#B392F0"> _fail</span><span style="color:#E1E4E8">(res, </span><span style="color:#79B8FF">HttpStatus</span><span style="color:#E1E4E8">.tooManyRequests, </span><span style="color:#9ECBFF">'slow down'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    // 3. Validate input: only user/assistant turns, capped size.</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> body </span><span style="color:#F97583">=</span><span style="color:#B392F0"> jsonDecode</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">await</span><span style="color:#E1E4E8"> utf8.</span><span style="color:#B392F0">decodeStream</span><span style="color:#E1E4E8">(req)) </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> history </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> (body[</span><span style="color:#9ECBFF">'messages'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> List</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#E1E4E8">        .</span><span style="color:#B392F0">cast</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&gt;()</span></span>
<span class="line"><span style="color:#E1E4E8">        .</span><span style="color:#B392F0">where</span><span style="color:#E1E4E8">((m) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> m[</span><span style="color:#9ECBFF">'role'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">==</span><span style="color:#9ECBFF"> 'user'</span><span style="color:#F97583"> ||</span><span style="color:#E1E4E8"> m[</span><span style="color:#9ECBFF">'role'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">==</span><span style="color:#9ECBFF"> 'assistant'</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#E1E4E8">        .</span><span style="color:#B392F0">map</span><span style="color:#E1E4E8">((m) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> {</span><span style="color:#9ECBFF">'role'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> m[</span><span style="color:#9ECBFF">'role'</span><span style="color:#E1E4E8">], </span><span style="color:#9ECBFF">'content'</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> '</span><span style="color:#9ECBFF">${</span><span style="color:#79B8FF">m</span><span style="color:#9ECBFF">[</span><span style="color:#9ECBFF">'content'</span><span style="color:#9ECBFF">]}</span><span style="color:#9ECBFF">'</span><span style="color:#E1E4E8">})</span></span>
<span class="line"><span style="color:#E1E4E8">        .</span><span style="color:#B392F0">toList</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> recent </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> history.length </span><span style="color:#F97583">&gt;</span><span style="color:#79B8FF"> 20</span></span>
<span class="line"><span style="color:#F97583">        ?</span><span style="color:#E1E4E8"> history.</span><span style="color:#B392F0">sublist</span><span style="color:#E1E4E8">(history.length </span><span style="color:#F97583">-</span><span style="color:#79B8FF"> 20</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#F97583">        :</span><span style="color:#E1E4E8"> history;</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (recent.isEmpty </span><span style="color:#F97583">||</span><span style="color:#E1E4E8"> recent.</span><span style="color:#B392F0">any</span><span style="color:#E1E4E8">((m) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> m[</span><span style="color:#9ECBFF">'content'</span><span style="color:#E1E4E8">]</span><span style="color:#F97583">!</span><span style="color:#E1E4E8">.length </span><span style="color:#F97583">&gt;</span><span style="color:#79B8FF"> 4000</span><span style="color:#E1E4E8">)) {</span></span>
<span class="line"><span style="color:#F97583">      return</span><span style="color:#B392F0"> _fail</span><span style="color:#E1E4E8">(res, </span><span style="color:#79B8FF">HttpStatus</span><span style="color:#E1E4E8">.badRequest, </span><span style="color:#9ECBFF">'bad messages'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    // 4. Forward to the provider. Model, system prompt and token cap</span></span>
<span class="line"><span style="color:#6A737D">    //    are chosen here, not in the app.</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> upstreamReq </span><span style="color:#F97583">=</span></span>
<span class="line"><span style="color:#E1E4E8">        http.</span><span style="color:#79B8FF">Request</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'POST'</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">Uri</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">parse</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'</span><span style="color:#9ECBFF">$</span><span style="color:#79B8FF">baseUrl</span><span style="color:#9ECBFF">/chat/completions'</span><span style="color:#E1E4E8">))</span></span>
<span class="line"><span style="color:#E1E4E8">          ..headers[</span><span style="color:#9ECBFF">'Authorization'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">=</span><span style="color:#9ECBFF"> 'Bearer </span><span style="color:#9ECBFF">$</span><span style="color:#79B8FF">apiKey</span><span style="color:#9ECBFF">'</span></span>
<span class="line"><span style="color:#E1E4E8">          ..headers[</span><span style="color:#9ECBFF">'Content-Type'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">=</span><span style="color:#9ECBFF"> 'application/json'</span></span>
<span class="line"><span style="color:#E1E4E8">          ..body </span><span style="color:#F97583">=</span><span style="color:#B392F0"> jsonEncode</span><span style="color:#E1E4E8">({</span></span>
<span class="line"><span style="color:#9ECBFF">            'model'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> model,</span></span>
<span class="line"><span style="color:#9ECBFF">            'stream'</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#9ECBFF">            'max_completion_tokens'</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 500</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#9ECBFF">            'safety_identifier'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> userId, </span><span style="color:#6A737D">// OpenAI field; check your provider</span></span>
<span class="line"><span style="color:#9ECBFF">            'messages'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> [</span></span>
<span class="line"><span style="color:#E1E4E8">              {</span><span style="color:#9ECBFF">'role'</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'system'</span><span style="color:#E1E4E8">, </span><span style="color:#9ECBFF">'content'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> systemPrompt},</span></span>
<span class="line"><span style="color:#E1E4E8">              ...recent,</span></span>
<span class="line"><span style="color:#E1E4E8">            ],</span></span>
<span class="line"><span style="color:#E1E4E8">          });</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> upstream </span><span style="color:#F97583">=</span><span style="color:#F97583"> await</span><span style="color:#E1E4E8"> _upstream.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(upstreamReq);</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (upstream.statusCode </span><span style="color:#F97583">!=</span><span style="color:#79B8FF"> 200</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#E1E4E8">      stderr.</span><span style="color:#B392F0">writeln</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#9ECBFF">        'upstream </span><span style="color:#9ECBFF">${</span><span style="color:#79B8FF">upstream</span><span style="color:#9ECBFF">.</span><span style="color:#79B8FF">statusCode</span><span style="color:#9ECBFF">}</span><span style="color:#9ECBFF">: '</span></span>
<span class="line"><span style="color:#9ECBFF">        '</span><span style="color:#9ECBFF">${</span><span style="color:#79B8FF">await</span><span style="color:#79B8FF"> upstream</span><span style="color:#9ECBFF">.</span><span style="color:#79B8FF">stream</span><span style="color:#9ECBFF">.</span><span style="color:#B392F0">bytesToString</span><span style="color:#9ECBFF">()}</span><span style="color:#9ECBFF">'</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      );</span></span>
<span class="line"><span style="color:#F97583">      return</span><span style="color:#B392F0"> _fail</span><span style="color:#E1E4E8">(res, </span><span style="color:#79B8FF">HttpStatus</span><span style="color:#E1E4E8">.badGateway, </span><span style="color:#9ECBFF">'AI service unavailable'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    // 5. Read the provider's SSE stream and send plain text deltas on.</span></span>
<span class="line"><span style="color:#E1E4E8">    res.headers.contentType </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> ContentType</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'text'</span><span style="color:#E1E4E8">, </span><span style="color:#9ECBFF">'plain'</span><span style="color:#E1E4E8">, charset</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'utf-8'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    res.bufferOutput </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> lines </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> upstream.stream</span></span>
<span class="line"><span style="color:#E1E4E8">        .</span><span style="color:#B392F0">transform</span><span style="color:#E1E4E8">(utf8.decoder)</span></span>
<span class="line"><span style="color:#E1E4E8">        .</span><span style="color:#B392F0">transform</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">const</span><span style="color:#79B8FF"> LineSplitter</span><span style="color:#E1E4E8">());</span></span>
<span class="line"><span style="color:#F97583">    await</span><span style="color:#F97583"> for</span><span style="color:#E1E4E8"> (</span><span style="color:#F97583">final</span><span style="color:#E1E4E8"> line </span><span style="color:#F97583">in</span><span style="color:#E1E4E8"> lines) {</span></span>
<span class="line"><span style="color:#F97583">      if</span><span style="color:#E1E4E8"> (</span><span style="color:#F97583">!</span><span style="color:#E1E4E8">line.</span><span style="color:#B392F0">startsWith</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'data: '</span><span style="color:#E1E4E8">)) </span><span style="color:#F97583">continue</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">      final</span><span style="color:#E1E4E8"> data </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> line.</span><span style="color:#B392F0">substring</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">6</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">      if</span><span style="color:#E1E4E8"> (data </span><span style="color:#F97583">==</span><span style="color:#9ECBFF"> '[DONE]'</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">break</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">      final</span><span style="color:#E1E4E8"> chunk </span><span style="color:#F97583">=</span><span style="color:#B392F0"> jsonDecode</span><span style="color:#E1E4E8">(data) </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;;</span></span>
<span class="line"><span style="color:#F97583">      final</span><span style="color:#E1E4E8"> choices </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> chunk[</span><span style="color:#9ECBFF">'choices'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> List</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">      if</span><span style="color:#E1E4E8"> (choices.isEmpty) </span><span style="color:#F97583">continue</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">      final</span><span style="color:#E1E4E8"> text </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> choices[</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">][</span><span style="color:#9ECBFF">'delta'</span><span style="color:#E1E4E8">]</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">[</span><span style="color:#9ECBFF">'content'</span><span style="color:#E1E4E8">];</span></span>
<span class="line"><span style="color:#F97583">      if</span><span style="color:#E1E4E8"> (text </span><span style="color:#F97583">is</span><span style="color:#79B8FF"> String</span><span style="color:#F97583"> &amp;&amp;</span><span style="color:#E1E4E8"> text.isNotEmpty) {</span></span>
<span class="line"><span style="color:#E1E4E8">        res.</span><span style="color:#B392F0">write</span><span style="color:#E1E4E8">(text);</span></span>
<span class="line"><span style="color:#F97583">        await</span><span style="color:#E1E4E8"> res.</span><span style="color:#B392F0">flush</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#F97583">    await</span><span style="color:#E1E4E8"> res.</span><span style="color:#B392F0">close</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#F97583">catch</span><span style="color:#E1E4E8"> (e) {</span></span>
<span class="line"><span style="color:#E1E4E8">    stderr.</span><span style="color:#B392F0">writeln</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'error: </span><span style="color:#9ECBFF">$</span><span style="color:#79B8FF">e</span><span style="color:#9ECBFF">'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">    try</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">      await</span><span style="color:#B392F0"> _fail</span><span style="color:#E1E4E8">(res, </span><span style="color:#79B8FF">HttpStatus</span><span style="color:#E1E4E8">.internalServerError, </span><span style="color:#9ECBFF">'server error'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#F97583">catch</span><span style="color:#E1E4E8"> (_) {</span></span>
<span class="line"><span style="color:#6A737D">      // Headers already sent; the client sees a cut-off stream.</span></span>
<span class="line"><span style="color:#F97583">      await</span><span style="color:#E1E4E8"> res.</span><span style="color:#B392F0">close</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/// Placeholder. In a real app, verify a Firebase ID token, Supabase JWT</span></span>
<span class="line"><span style="color:#6A737D">/// or your own session token here and return the user's id.</span></span>
<span class="line"><span style="color:#79B8FF">Future</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">?&gt; </span><span style="color:#B392F0">verifyToken</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8"> token) </span><span style="color:#F97583">async</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#E1E4E8"> demoUsers </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> {</span><span style="color:#9ECBFF">'demo-token-alice'</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'alice'</span><span style="color:#E1E4E8">, </span><span style="color:#9ECBFF">'demo-token-bob'</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'bob'</span><span style="color:#E1E4E8">};</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#E1E4E8"> demoUsers[token];</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">bool</span><span style="color:#B392F0"> _allow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8"> userId) {</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> now </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> DateTime</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">now</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> hits </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> _hits.</span><span style="color:#B392F0">putIfAbsent</span><span style="color:#E1E4E8">(userId, () </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> [])</span></span>
<span class="line"><span style="color:#E1E4E8">    ..</span><span style="color:#B392F0">removeWhere</span><span style="color:#E1E4E8">((t) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> now.</span><span style="color:#B392F0">difference</span><span style="color:#E1E4E8">(t) </span><span style="color:#F97583">&gt;</span><span style="color:#E1E4E8"> window);</span></span>
<span class="line"><span style="color:#F97583">  if</span><span style="color:#E1E4E8"> (hits.length </span><span style="color:#F97583">&gt;=</span><span style="color:#E1E4E8"> maxRequests) </span><span style="color:#F97583">return</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  hits.</span><span style="color:#B392F0">add</span><span style="color:#E1E4E8">(now);</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">Future</span><span style="color:#E1E4E8">&lt;</span><span style="color:#F97583">void</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">_fail</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">HttpResponse</span><span style="color:#E1E4E8"> res, </span><span style="color:#79B8FF">int</span><span style="color:#E1E4E8"> status, </span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8"> message) </span><span style="color:#F97583">async</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.statusCode </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> status;</span></span>
<span class="line"><span style="color:#E1E4E8">  res.headers.contentType </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> ContentType</span><span style="color:#E1E4E8">.json;</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">write</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">jsonEncode</span><span style="color:#E1E4E8">({</span><span style="color:#9ECBFF">'error'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> message}));</span></span>
<span class="line"><span style="color:#F97583">  await</span><span style="color:#E1E4E8"> res.</span><span style="color:#B392F0">close</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>Run it with the key in the environment, never in a file you commit:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#E1E4E8">LLM_API_KEY</span><span style="color:#F97583">=</span><span style="color:#9ECBFF">...</span><span style="color:#E1E4E8"> LLM_MODEL</span><span style="color:#F97583">=</span><span style="color:#9ECBFF">your-model-name</span><span style="color:#B392F0"> dart</span><span style="color:#9ECBFF"> run</span><span style="color:#9ECBFF"> bin/proxy.dart</span></span></code></pre>
<p>A few choices in there are deliberate:</p>
<ul>
<li><strong>The app can’t send a system message.</strong> The server drops any role other than <code>user</code> and <code>assistant</code> and adds its own system prompt. Otherwise anyone can turn your “recipe helper” into a free general-purpose chatbot.</li>
<li><strong>History and message size are capped.</strong> Chat APIs bill for input tokens too, and the whole conversation is sent on every turn. Sending only the last 20 turns and refusing huge messages keeps each request’s cost bounded.</li>
<li><strong>The reply length is capped</strong> with <code>max_completion_tokens</code>. OpenAI now uses this name; the older <code>max_tokens</code> is deprecated. Parameter names differ between providers and their OpenAI-compatible layers, so check the docs for the one you use.</li>
<li><strong>The proxy turns SSE into plain text.</strong> The app receives raw text chunks, not the provider’s event format. If you later switch to a provider with a different streaming format, only the server changes.</li>
<li><strong>Provider errors stay on the server.</strong> The app gets a generic 502, and the real error goes to your logs.</li>
</ul>
<p>The in-memory rate limiter is fine for a single server instance and for learning. With more than one instance, or serverless functions that start fresh, the counter has to live somewhere shared: Redis, Firestore, or a database row per user per day. For <code>verifyToken</code>, use the official verification for your auth system, for example the Firebase Admin SDK’s ID token check, or verifying a Supabase JWT with your project’s key.</p>
<h2 id="the-client-consuming-the-stream-in-dart">The client: consuming the stream in Dart</h2>
<p>This function is plain Dart with <code>package:http</code>, so it runs unchanged in a Flutter app:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'dart:convert'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'package:http/http.dart'</span><span style="color:#F97583"> as</span><span style="color:#E1E4E8"> http;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">class</span><span style="color:#79B8FF"> ChatException</span><span style="color:#F97583"> implements</span><span style="color:#79B8FF"> Exception</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  ChatException</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">.statusCode, </span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">.message);</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> int</span><span style="color:#E1E4E8"> statusCode;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> String</span><span style="color:#E1E4E8"> message;</span></span>
<span class="line"><span style="color:#F97583">  @override</span></span>
<span class="line"><span style="color:#79B8FF">  String</span><span style="color:#B392F0"> toString</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">=&gt;</span><span style="color:#9ECBFF"> 'ChatException(</span><span style="color:#9ECBFF">$</span><span style="color:#79B8FF">statusCode</span><span style="color:#9ECBFF">): </span><span style="color:#9ECBFF">$</span><span style="color:#79B8FF">message</span><span style="color:#9ECBFF">'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/// Sends the conversation to your backend and yields the reply as it</span></span>
<span class="line"><span style="color:#6A737D">/// streams in. The app never sees a provider API key.</span></span>
<span class="line"><span style="color:#79B8FF">Stream</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">streamChat</span><span style="color:#E1E4E8">({</span></span>
<span class="line"><span style="color:#F97583">  required</span><span style="color:#E1E4E8"> http.</span><span style="color:#79B8FF">Client</span><span style="color:#E1E4E8"> client,</span></span>
<span class="line"><span style="color:#F97583">  required</span><span style="color:#79B8FF"> Uri</span><span style="color:#E1E4E8"> endpoint,</span></span>
<span class="line"><span style="color:#F97583">  required</span><span style="color:#79B8FF"> String</span><span style="color:#E1E4E8"> userToken,</span></span>
<span class="line"><span style="color:#F97583">  required</span><span style="color:#79B8FF"> List</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">&gt;&gt; messages,</span></span>
<span class="line"><span style="color:#E1E4E8">}) </span><span style="color:#F97583">async*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> request </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> http.</span><span style="color:#79B8FF">Request</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'POST'</span><span style="color:#E1E4E8">, endpoint)</span></span>
<span class="line"><span style="color:#E1E4E8">    ..headers[</span><span style="color:#9ECBFF">'Authorization'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">=</span><span style="color:#9ECBFF"> 'Bearer </span><span style="color:#9ECBFF">$</span><span style="color:#79B8FF">userToken</span><span style="color:#9ECBFF">'</span></span>
<span class="line"><span style="color:#E1E4E8">    ..headers[</span><span style="color:#9ECBFF">'Content-Type'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">=</span><span style="color:#9ECBFF"> 'application/json'</span></span>
<span class="line"><span style="color:#E1E4E8">    ..body </span><span style="color:#F97583">=</span><span style="color:#B392F0"> jsonEncode</span><span style="color:#E1E4E8">({</span><span style="color:#9ECBFF">'messages'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> messages});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> response </span><span style="color:#F97583">=</span><span style="color:#F97583"> await</span><span style="color:#E1E4E8"> client.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(request);</span></span>
<span class="line"><span style="color:#F97583">  if</span><span style="color:#E1E4E8"> (response.statusCode </span><span style="color:#F97583">!=</span><span style="color:#79B8FF"> 200</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">    final</span><span style="color:#E1E4E8"> body </span><span style="color:#F97583">=</span><span style="color:#F97583"> await</span><span style="color:#E1E4E8"> response.stream.</span><span style="color:#B392F0">bytesToString</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">    throw</span><span style="color:#79B8FF"> ChatException</span><span style="color:#E1E4E8">(response.statusCode, body);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#F97583">  yield*</span><span style="color:#E1E4E8"> response.stream.</span><span style="color:#B392F0">transform</span><span style="color:#E1E4E8">(utf8.decoder);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>The important part is <code>client.send</code> instead of <code>http.post</code>. <code>http.post</code> waits for the whole body. <code>send</code> gives you a <code>StreamedResponse</code>, and you get the bytes as they arrive. <code>utf8.decoder</code> as a stream transformer also handles a multi-byte character (an emoji, an Urdu letter, an accented “é”) that is split across two network chunks.</p>
<h3 id="how-i-tested-it">How I tested it</h3>
<p>I ran both pieces against a fake upstream server that checks the API key header, records the request, and sends back an OpenAI-style SSE stream in 7-byte pieces, so that both SSE lines and UTF-8 characters get split mid-way. The proxy ran as a separate process with a dummy key in its environment. The checks that passed:</p>
<ul>
<li>The full reply arrived, correctly decoded, in more than one chunk.</li>
<li>The upstream request had the server’s model, <code>"stream": true</code>, and only <code>system,user</code> roles (the client’s injected system message was dropped).</li>
<li>The user id sent upstream came from the token, not the request body.</li>
<li>A made-up token got <code>401</code>.</li>
<li>One user got 20 replies, then <code>429</code>. A second user was not affected.</li>
</ul>
<p><code>dart analyze</code> reported no issues. No real API key was used and nothing was sent to OpenAI.</p>
<h2 id="the-chat-ui-state-in-flutter">The chat UI state in Flutter</h2>
<p>The UI needs a list of messages, a flag for “a reply is streaming”, and a way to grow the last assistant message as chunks arrive. A <code>ChangeNotifier</code> is enough. This code is illustrative: I haven’t compiled it here, but it uses only standard Flutter APIs and the <code>streamChat</code> function above.</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">class</span><span style="color:#79B8FF"> ChatController</span><span style="color:#F97583"> extends</span><span style="color:#79B8FF"> ChangeNotifier</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  ChatController</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">._client, </span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">._endpoint, </span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">._token);</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> http.</span><span style="color:#79B8FF">Client</span><span style="color:#E1E4E8"> _client;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> Uri</span><span style="color:#E1E4E8"> _endpoint;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> Future</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">&gt; </span><span style="color:#79B8FF">Function</span><span style="color:#E1E4E8">() _token; </span><span style="color:#6A737D">// e.g. user.getIdToken()</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> messages </span><span style="color:#F97583">=</span><span style="color:#F97583"> &lt;</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">&gt;</span><span style="color:#F97583">&gt;</span><span style="color:#E1E4E8">[];</span></span>
<span class="line"><span style="color:#79B8FF">  bool</span><span style="color:#E1E4E8"> streaming </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  String</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> error;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  Future</span><span style="color:#E1E4E8">&lt;</span><span style="color:#F97583">void</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8"> text) </span><span style="color:#F97583">async</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (streaming </span><span style="color:#F97583">||</span><span style="color:#E1E4E8"> text.</span><span style="color:#B392F0">trim</span><span style="color:#E1E4E8">().isEmpty) </span><span style="color:#F97583">return</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    messages.</span><span style="color:#B392F0">add</span><span style="color:#E1E4E8">({</span><span style="color:#9ECBFF">'role'</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'user'</span><span style="color:#E1E4E8">, </span><span style="color:#9ECBFF">'content'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> text.</span><span style="color:#B392F0">trim</span><span style="color:#E1E4E8">()});</span></span>
<span class="line"><span style="color:#E1E4E8">    messages.</span><span style="color:#B392F0">add</span><span style="color:#E1E4E8">({</span><span style="color:#9ECBFF">'role'</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'assistant'</span><span style="color:#E1E4E8">, </span><span style="color:#9ECBFF">'content'</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> ''</span><span style="color:#E1E4E8">});</span></span>
<span class="line"><span style="color:#E1E4E8">    streaming </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    error </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> null</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">    notifyListeners</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">    try</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">      final</span><span style="color:#E1E4E8"> history </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> messages.</span><span style="color:#B392F0">sublist</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, messages.length </span><span style="color:#F97583">-</span><span style="color:#79B8FF"> 1</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">      await</span><span style="color:#F97583"> for</span><span style="color:#E1E4E8"> (</span><span style="color:#F97583">final</span><span style="color:#E1E4E8"> piece </span><span style="color:#F97583">in</span><span style="color:#B392F0"> streamChat</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">        client</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> _client,</span></span>
<span class="line"><span style="color:#E1E4E8">        endpoint</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> _endpoint,</span></span>
<span class="line"><span style="color:#E1E4E8">        userToken</span><span style="color:#F97583">:</span><span style="color:#F97583"> await</span><span style="color:#B392F0"> _token</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">        messages</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> history,</span></span>
<span class="line"><span style="color:#E1E4E8">      )) {</span></span>
<span class="line"><span style="color:#E1E4E8">        messages.last[</span><span style="color:#9ECBFF">'content'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> messages.last[</span><span style="color:#9ECBFF">'content'</span><span style="color:#E1E4E8">]</span><span style="color:#F97583">!</span><span style="color:#F97583"> +</span><span style="color:#E1E4E8"> piece;</span></span>
<span class="line"><span style="color:#B392F0">        notifyListeners</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#F97583">on</span><span style="color:#79B8FF"> ChatException</span><span style="color:#F97583"> catch</span><span style="color:#E1E4E8"> (e) {</span></span>
<span class="line"><span style="color:#E1E4E8">      messages.</span><span style="color:#B392F0">removeLast</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">      error </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> e.statusCode </span><span style="color:#F97583">==</span><span style="color:#79B8FF"> 429</span></span>
<span class="line"><span style="color:#F97583">          ?</span><span style="color:#9ECBFF"> 'You are sending messages too fast. Try again in a minute.'</span></span>
<span class="line"><span style="color:#F97583">          :</span><span style="color:#9ECBFF"> 'Could not get a reply. Please try again.'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#F97583">finally</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">      streaming </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">      notifyListeners</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>In the widget, wrap a <code>ListView.builder</code> in a <code>ListenableBuilder(listenable: controller, ...)</code>, disable the send button while <code>controller.streaming</code> is true, and show <code>controller.error</code> in a <code>SnackBar</code> or under the input field. If you already use Riverpod or Bloc, the same state fits in a notifier or cubit. Two small things that matter in practice: scroll to the bottom as text grows, and handle a 429 with a clear message instead of a generic error, because a user who hits the limit should know why.</p>
<h2 id="costs-and-abuse-limits-worth-setting">Costs and abuse: limits worth setting</h2>
<p>Your proxy is now a public endpoint that spends money. Treat it that way:</p>
<ul>
<li><strong>Require sign-in for AI features.</strong> Anonymous access makes per-user limits meaningless, because a new “user” costs nothing.</li>
<li><strong>Rate limit per user</strong> (requests per minute) to stop scripts, and <strong>quota per user</strong> (messages or tokens per day or month) to cap what one account can cost you. Tie the quota to the plan: free users get a small daily number, paying users more.</li>
<li><strong>Cap tokens on every request</strong>: input (history length, message size) and output (<code>max_completion_tokens</code>).</li>
<li><strong>Set a budget alert and a hard spending limit</strong> in your provider’s billing settings. This is your last line of defence if everything else fails.</li>
<li><strong>Log usage per user.</strong> The streaming response can include token usage at the end if you ask for it (<code>stream_options: {"include_usage": true}</code> in OpenAI’s API). Store it so you can see who costs what.</li>
<li><strong>Pick the model on purpose.</strong> A smaller model is often good enough for chat inside an app, and costs a fraction of the largest one. Because the model is a server setting, you can test this without a release.</li>
<li><strong>Add App Check or Play Integrity / App Attest</strong> if you want to block requests that don’t come from your real app. It raises the bar for scripts that copy a user’s token.</li>
</ul>
<blockquote>
<p><strong>What I did in <a href="https://neemii.dev/work/evoke-ai/">Evoke AI</a>:</strong> every new account gets a small free quota of 5 AI prompts. After that, users either buy credits or watch an ad for each prompt. The backend enforces the quota, not the app, so a modified app can’t skip it. Because every prompt is either paid for or covered by an ad, AI costs grow with revenue instead of with free usage.</p>
</blockquote>
<h2 id="the-managed-alternative-firebase-ai-logic">The managed alternative: Firebase AI Logic</h2>
<p>If you’d rather not run a server, Firebase AI Logic (the <code>firebase_ai</code> Flutter package, formerly Vertex AI in Firebase) lets the app call Gemini models through Firebase, without a Gemini API key in the app. Firebase acts as the gateway, and Firebase App Check verifies that requests come from your genuine app before they’re forwarded (<a href="https://firebase.google.com/docs/ai-logic/app-check">App Check for Firebase AI Logic</a>). Firebase’s docs say App Check enforcement is required starting November 2, 2026, and support limited-use tokens with replay protection for tighter security. There is also a per-user rate limit, 100 requests per minute per user by default (<a href="https://firebase.google.com/docs/ai-logic/quotas">Firebase AI Logic quotas</a>).</p>
<p>The trade-offs, honestly:</p>
<ul>
<li><strong>Good</strong>: no server to deploy, real attestation of the app, official Flutter SDK with streaming.</li>
<li><strong>Less good</strong>: you’re tied to Google’s models through this route, the system prompt and model name usually live in app code (Firebase Remote Config helps here), and the built-in per-user limit is one value for all users. Per-plan quotas, like “free users get 10 messages a day”, still need your own logic.</li>
</ul>
<p>For a prototype or an app that only needs Gemini, Firebase AI Logic is a sensible choice. For multiple providers, paid plans with quotas, or a system prompt you want to keep off the device, a small proxy gives you more control.</p>
<h2 id="summary">Summary</h2>
<ul>
<li>An API key in a Flutter app is public. <code>.env</code>, <code>--dart-define</code> and obfuscation don’t change that.</li>
<li>Put the key on a server. The app sends the user’s auth token and the conversation, nothing else.</li>
<li>Choose the model, system prompt and token limits on the server, so you can change them without a release.</li>
<li>Stream the reply with <code>client.send</code> and <code>utf8.decoder</code>, and grow the last message in your chat state.</li>
<li>Rate limit per user, set daily quotas, cap tokens, and set a billing alert.</li>
</ul>
<p>If you’re planning an AI feature for your app and want it built this way from the start, see my <a href="https://neemii.dev/services/ai-app-development/">AI app development service</a>. I’m Muhammad Naeem, a Flutter developer in Lahore, and I’ve shipped AI apps that use OpenAI, Gemini and Claude. <a href="https://neemii.dev/#contact">Tell me about your app</a> and I’ll reply with how I’d set it up and what it would cost.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-flutter-ai-chat-without-exposing-api-key.png" type="image/png" length="0" />
    </item>
    <item>
      <title>Flutter App Development Cost in 2026: An Honest Breakdown</title>
      <link>https://neemii.dev/blog/flutter-app-development-cost/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/flutter-app-development-cost/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>What a Flutter app really costs in 2026: hourly rates by region, hour estimates for simple, medium and complex apps, and the running costs founders forget.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> a Flutter app for iOS and Android costs roughly <strong>$6,000–$40,000</strong> with a South Asian developer and <strong>$25,000–$150,000</strong> with a US agency for a simple to medium app, and $35,000–$375,000 for a complex one. It takes about 250–450 hours for a simple app, 600–1,000 for a medium app and 1,400–2,500+ for a complex one. One Flutter codebase usually costs less than two native apps. Try the free <a href="https://neemii.dev/tools/app-cost-calculator/">app development cost calculator</a> for your own range.</p>
<p>“How much will my app cost?” is the first question almost every founder asks, and the honest answer is “it depends.” That answer is useless on its own, so this post breaks it down. You will get the main things that drive cost, real hourly rates by region with sources, three example scopes priced out, and the running costs that show up after launch.</p>
<p>Every number below either links to its source or is labelled as an <strong>assumption</strong>. Where sources disagree, I give the range and say so.</p>
<h2 id="the-short-answer">The short answer</h2>
<p>Cost is <strong>hours × hourly rate</strong>, plus running costs after launch. Hours depend on what the app does. The rate depends mostly on where your team is and whether it is a freelancer, a small studio or an agency.</p>
<p>For context, Clutch, which collects verified client reviews of development firms, reports that most mobile projects reviewed on its platform fall between <a href="https://clutch.co/app-developers/resources/cost-build-mobile-app">$10,000 and $49,999, with an average project cost of about $90,780 and an average timeline of around 11 months</a>. That average includes large projects. A <a href="https://www.prnewswire.com/news-releases/develop-a-simple-mobile-app-in-3-weeks-costing-just-12k-says-goodfirms-2022-survey-301542663.html">GoodFirms survey from 2022</a> put a simple app at around $12,000. Your number can sit far above or below either figure, depending on scope.</p>
<h2 id="what-actually-drives-the-cost">What actually drives the cost</h2>
<h3 id="1-number-of-screens-and-features">1. Number of screens and features</h3>
<p>This is the biggest factor. A login screen, a profile and a list of items is a small app. Add search, filters, bookmarks, notifications, user roles and settings, and the hours multiply quickly. Each feature also needs its own design, error states, empty states and testing, not only the “happy path.”</p>
<h3 id="2-platforms">2. Platforms</h3>
<p>Do you need iOS, Android or both? With Flutter, one codebase covers both. With native development you build two apps, Swift for iOS and Kotlin for Android, which is close to two client-side projects. More on this below.</p>
<h3 id="3-backend-and-admin-panel">3. Backend and admin panel</h3>
<p>Most apps need a server: user accounts, a database, file storage and business logic. You can use a managed backend such as <a href="https://firebase.google.com/pricing">Firebase</a> or Supabase for simpler apps, or build a custom API for more control. Almost every business also needs an <strong>admin panel</strong> to manage users, content and orders. Founders often forget the admin panel when they budget, and it can be a project of its own.</p>
<h3 id="4-integrations">4. Integrations</h3>
<p>Each third-party service adds setup, edge cases and testing:</p>
<ul>
<li><strong>Payments</strong> (Stripe, local gateways, in-app purchases): refunds, failed payments, receipts, and store rules.</li>
<li><strong>Maps and location</strong>: live tracking, geofencing, background location permissions.</li>
<li><strong>Chat and real-time features</strong>: message delivery, read receipts, typing indicators, media.</li>
<li><strong>Social login, push notifications, analytics, AI APIs.</strong></li>
</ul>
<p>Real-time chat and live location are among the most expensive features to build well. I have worked on them in apps like <a href="https://neemii.dev/work/shedrives/">SheDrives</a>, a ride-hailing app with live driver tracking and real-time bids, and DapUp, a location-based social app with live maps and messaging, and they always take more hours than the screen count suggests.</p>
<h3 id="5-design">5. Design</h3>
<p>Using a well-built component system with light customisation is cheaper than fully custom UI with complex animations. Custom design pays off for consumer apps where look and feel matter. For internal tools it usually does not.</p>
<h3 id="6-testing-and-launch">6. Testing and launch</h3>
<p>Testing on real devices, fixing bugs, preparing store listings, screenshots, privacy policy answers and handling App Store review take real time. Budget for it from the start instead of treating it as “the last few days.” (What that work involves: <a href="https://neemii.dev/blog/publish-flutter-app-app-store-google-play/">publishing a Flutter app on the App Store and Google Play</a>.)</p>
<h3 id="where-the-hours-usually-go">Where the hours usually go</h3>
<p>This split is an <strong>assumption</strong> based on typical projects, not a measured industry figure. It varies a lot by app.</p>
<table>
<thead>
<tr>
<th>Area</th>
<th>Share of total hours (assumption)</th>
</tr>
</thead>
<tbody>
<tr>
<td>UI/UX design</td>
<td>10–15%</td>
</tr>
<tr>
<td>Flutter app (both platforms)</td>
<td>40–50%</td>
</tr>
<tr>
<td>Backend and admin panel</td>
<td>20–30%</td>
</tr>
<tr>
<td>Testing and bug fixing</td>
<td>10–15%</td>
</tr>
<tr>
<td>Project management and launch</td>
<td>5–10%</td>
</tr>
</tbody>
</table>
<h2 id="hourly-rates-by-region">Hourly rates by region</h2>
<p>Rates vary widely, and published data does not agree. Here is what the sources say, in USD.</p>
<table>
<thead>
<tr>
<th>Region</th>
<th>Typical rate</th>
<th>Source</th>
</tr>
</thead>
<tbody>
<tr>
<td>South and Southeast Asia (incl. Pakistan, India)</td>
<td>$24–$31 junior, $31–$41 senior</td>
<td><a href="https://www.accelerance.com/blog/2026-outsourcing-rate-trends-asia-europe-latam">Accelerance, Nov 2025</a></td>
</tr>
<tr>
<td>India (firms)</td>
<td>under $25</td>
<td><a href="https://clutch.co/directory/mobile-application-developers/pricing">Clutch, 2026</a></td>
</tr>
<tr>
<td>Europe (incl. Central and Eastern Europe)</td>
<td>$31–$39 junior, $64–$76 senior</td>
<td><a href="https://www.accelerance.com/blog/2026-outsourcing-rate-trends-asia-europe-latam">Accelerance, Nov 2025</a></td>
</tr>
<tr>
<td>Poland / Ukraine (firms)</td>
<td>$50–$99 / $25–$49</td>
<td><a href="https://clutch.co/directory/mobile-application-developers/pricing">Clutch, 2026</a></td>
</tr>
<tr>
<td>UAE (local agencies)</td>
<td>AED 200–350 ($55–$95)</td>
<td><a href="https://www.ptolemay.com/post/how-much-does-it-cost-to-develop-an-app-in-the-uae">Ptolemay, Aug 2025</a></td>
</tr>
<tr>
<td>Australia (firms)</td>
<td>$100–$149</td>
<td><a href="https://clutch.co/directory/mobile-application-developers/pricing">Clutch, 2026</a></td>
</tr>
<tr>
<td>United States (salary, not agency rate)</td>
<td>$64.44 median hourly wage</td>
<td><a href="https://www.bls.gov/ooh/computer-and-information-technology/software-developers.htm">US BLS, May 2025</a></td>
</tr>
</tbody>
</table>
<p>A few notes on this data:</p>
<ul>
<li><strong>There is no reliable Pakistan-only survey.</strong> I could not find a current, published survey of Pakistani mobile developer rates, so the South Asia figures are the best available proxy.</li>
<li><strong>The UAE figure is from a vendor</strong>, not a survey. Treat it as a rough guide.</li>
<li><strong>US figures disagree.</strong> Clutch’s location table lists US firms at $25–$49 per hour, which is lower than most other guides. The BLS figure is what an employed developer earns, before the employer’s overhead and margin, so an agency rate will be higher. Agency guides commonly quote <a href="https://www.fullestop.com/blog/?p=10427">$100–$149 for US firms</a>, but that is a secondary source citing Clutch data. I use <strong>$100–$150</strong> below as an <strong>assumption</strong> for US agencies.</li>
</ul>
<p>Cheaper per hour is not automatically cheaper per project. A senior developer at $40 who ships in 500 hours costs less than a junior at $20 who needs 1,200 hours and leaves you with code that is hard to maintain.</p>
<h2 id="three-example-scopes-priced-out">Three example scopes, priced out</h2>
<p>The hour ranges below are <strong>assumptions</strong> for a Flutter app on iOS and Android. They include design, a backend, an admin panel where noted, testing and store launch. They assume a clear scope agreed before development starts.</p>
<h3 id="simple-app-250450-hours-assumption">Simple app: 250–450 hours (assumption)</h3>
<ul>
<li>5–10 screens</li>
<li>Email or social login, profile, content lists and detail pages</li>
<li>Managed backend (for example Firebase), basic admin via the backend console</li>
<li>Push notifications, no payments</li>
<li>Examples: a booking request app, a company content app, a simple utility</li>
</ul>
<h3 id="medium-app-6001000-hours-assumption">Medium app: 600–1,000 hours (assumption)</h3>
<ul>
<li>15–30 screens, two user roles</li>
<li>Custom or managed backend plus a web admin panel</li>
<li>Payments or subscriptions, push notifications</li>
<li>One heavier feature: maps, chat or a third-party API</li>
<li>Examples: a service marketplace MVP, a delivery app for one business, a membership app</li>
</ul>
<p>With a fully custom backend and real-time chat, a medium app can reach about 1,200 hours.</p>
<h3 id="complex-app-14002500-hours-assumption">Complex app: 1,400–2,500+ hours (assumption)</h3>
<ul>
<li>30+ screens, several user roles</li>
<li>Real-time chat, live location, or both</li>
<li>Custom backend, full admin panel with reporting</li>
<li>Multiple integrations: payments, maps, AI services, external systems</li>
<li>Examples: ride-hailing, social apps with real-time features, multi-vendor marketplaces</li>
</ul>
<h3 id="cost-table">Cost table</h3>
<p>Hours × rate. The rate bands are taken from the regional table above, with the US band labelled as an assumption.</p>
<table>
<thead>
<tr>
<th>Scope</th>
<th>Hours</th>
<th>South Asia ($25–$40/h)</th>
<th>Eastern Europe ($35–$75/h)</th>
<th>UAE agency ($55–$95/h)</th>
<th>US agency ($100–$150/h, assumption)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Simple</td>
<td>250–450</td>
<td>$6,250–$18,000</td>
<td>$8,750–$33,750</td>
<td>$13,750–$42,750</td>
<td>$25,000–$67,500</td>
</tr>
<tr>
<td>Medium</td>
<td>600–1,000</td>
<td>$15,000–$40,000</td>
<td>$21,000–$75,000</td>
<td>$33,000–$95,000</td>
<td>$60,000–$150,000</td>
</tr>
<tr>
<td>Complex</td>
<td>1,400–2,500</td>
<td>$35,000–$100,000</td>
<td>$49,000–$187,500</td>
<td>$77,000–$237,500</td>
<td>$140,000–$375,000</td>
</tr>
</tbody>
</table>
<p>These are ranges, not quotes. The real number depends on your exact feature list, the team’s experience and how stable the scope is during the project.</p>
<blockquote>
<p><strong>My own pricing:</strong> a typical Flutter MVP with me costs about $5,000–$8,000. That sits at the low end of the South Asia band in the table, because I work as a solo developer and keep an MVP to the features it needs to launch. Larger scopes are quoted after we go through the feature list together.</p>
</blockquote>
<h2 id="why-flutter-usually-costs-less-than-two-native-apps">Why Flutter usually costs less than two native apps</h2>
<p>With native development, the iOS and Android apps are written separately. Every screen, every bug fix and every new feature is done twice and tested twice. Flutter uses one Dart codebase for both platforms, so most of that work is done once.</p>
<p>The savings are real, but not 50% of the whole project, because some work is shared either way: design, backend, admin panel, project management and store setup. My <strong>assumption</strong> for planning is that two native apps need roughly 1.6–1.9× the client-side hours of one Flutter app, while backend and design hours stay the same.</p>
<p>Published case studies point in the same direction, though they come from different contexts:</p>
<ul>
<li>Dow Jones’ MarketWatch game was built in Flutter by Very Good Ventures, who <a href="https://verygood.ventures/success-stories/marketwatch-stock-market-game">report a 50% cost reduction</a> compared with building natively. This is the agency’s own case study and does not show how the figure was calculated.</li>
<li>Supercell <a href="https://flutter.dev/showcase/supercell">reduced the core code of Supercell ID by 45%</a> with Flutter, even after adding desktop support.</li>
<li>Zoho Tables <a href="https://flutter.dev/showcase/zoho-tables">reached feature parity with its web app in 14% less time</a>.</li>
</ul>
<p>Less code also means lower maintenance: one codebase to update, test and keep secure.</p>
<h3 id="when-flutter-does-not-save-money">When Flutter does not save money</h3>
<ul>
<li><strong>You only need one platform.</strong> If your users are all on iOS, one native app may cost about the same.</li>
<li><strong>The app depends heavily on platform-specific features</strong>, such as home screen widgets, Apple Watch or Wear OS apps, CarPlay, advanced AR or unusual hardware SDKs. Flutter can do these through native code, but that part is written per platform anyway.</li>
<li><strong>You already have a strong native team</strong> and an existing native codebase. Rewriting a working app just to switch frameworks rarely pays off.</li>
</ul>
<h2 id="costs-people-forget">Costs people forget</h2>
<h3 id="store-fees">Store fees</h3>
<ul>
<li><strong>Apple Developer Program:</strong> <a href="https://developer.apple.com/programs/whats-included/">99 USD per year</a>, or local currency equivalent. Some nonprofits, schools and government bodies can get a fee waiver.</li>
<li><strong>Google Play developer account:</strong> <a href="https://support.google.com/googleplay/android-developer/answer/6112435">25 USD, one-time</a>.</li>
<li><strong>Store commission on digital sales:</strong> If you sell digital content or subscriptions inside the app, Apple’s <a href="https://developer.apple.com/app-store/small-business-program/">Small Business Program</a> charges 15% for developers under 1 million USD in yearly proceeds. Google Play charges <a href="https://support.google.com/googleplay/android-developer/answer/112622">15% on the first 1 million USD each year</a>, and 15% on auto-renewing subscriptions. Physical goods and services, like food delivery or rides, generally go through your own payment gateway instead.</li>
</ul>
<h3 id="servers-and-third-party-services">Servers and third-party services</h3>
<p>Hosting, database, file storage, email, SMS, maps and AI APIs are billed monthly, usually by usage. Many services, including <a href="https://firebase.google.com/pricing">Firebase</a> and <a href="https://mapsplatform.google.com/pricing/">Google Maps Platform</a>, have free tiers that cover an early MVP. Costs then grow with your user count. Ask your developer for a monthly running-cost estimate at 1,000, 10,000 and 100,000 users before you commit to an architecture.</p>
<h3 id="maintenance">Maintenance</h3>
<p>The most common rule of thumb is that yearly maintenance costs <strong>15–20% of the original build cost</strong>. <a href="https://cleveroad.com/blog/app-maintenance-cost">Cleveroad attributes this figure to CISQ</a>, though I could not find the primary CISQ study, and other vendor guides quote higher numbers. Treat it as a planning heuristic, not a measured fact. On a $40,000 app, that means budgeting roughly $6,000–$8,000 a year.</p>
<h3 id="updates-for-new-os-versions">Updates for new OS versions</h3>
<p>This is not optional. Both stores force regular updates:</p>
<ul>
<li>Since April 28, 2026, apps uploaded to App Store Connect <a href="https://developer.apple.com/news/upcoming-requirements/">must be built with Xcode 26 and the iOS 26 SDK</a>.</li>
<li>From August 31, 2026, new apps and updates on Google Play <a href="https://developer.android.com/google/play/requirements/target-sdk">must target Android 16 (API level 36)</a>, and existing apps targeting old API levels stop being available to new users on newer Android devices.</li>
</ul>
<p>Every year, someone has to update the app, its packages and its build tools, then test it again. With Flutter, that is one codebase instead of two.</p>
<h2 id="how-to-cut-cost-without-hurting-quality">How to cut cost without hurting quality</h2>
<h3 id="start-with-a-real-mvp">Start with a real MVP</h3>
<p>An MVP is the smallest version of the app that proves people will use it or pay for it. Write down the one main job your app does. Every feature that does not support that job goes to a “later” list. Most first versions do not need an in-app chat, a referral system or five login options.</p>
<h3 id="launch-in-phases">Launch in phases</h3>
<p>Phase 1 is the core flow and a basic admin panel. Phase 2 adds what real users ask for. This spreads the cost, and the second phase is based on data instead of guesses.</p>
<h3 id="use-managed-services">Use managed services</h3>
<p>Firebase, Supabase, Stripe and similar services remove weeks of backend work in the early stages. You can move to a custom backend later if scale or cost requires it.</p>
<h3 id="keep-design-simple-not-cheap">Keep design simple, not cheap</h3>
<p>A clean, consistent design built from a small component set looks professional and is faster to build than a unique layout on every screen. Spend the custom design budget on the screens users see most.</p>
<h3 id="fix-the-scope-before-development">Fix the scope before development</h3>
<p>Changing direction halfway through is the most expensive thing you can do. A short paid discovery phase, with clickable wireframes and a feature list, usually saves more than it costs.</p>
<h3 id="do-not-choose-on-hourly-rate-alone">Do not choose on hourly rate alone</h3>
<p>Ask for past apps that are live in the App Store and Google Play, and download them. Ask who will maintain the app after launch. A slightly higher rate from someone who has shipped similar apps is often the cheaper option overall.</p>
<blockquote>
<p><strong>A real example:</strong> one of my projects was a crime reporting system for a police service. It had two apps. The police app received complaints, issued warnings, listed wanted persons, and managed complaints and officers. A separate public app let citizens file complaints. Both apps, the backend and a website came in at roughly $5,000–$8,000. That was possible because the scope was clear before development started, and both apps shared one backend and one design system.</p>
</blockquote>
<h2 id="frequently-asked-questions">Frequently asked questions</h2>
<div class="faq-list">
<details class="faq" name="faq">
<summary>How much does it cost to develop a Flutter app?</summary>
<p>Roughly $6,000–$40,000 for a simple or medium app built by a developer in South Asia, $21,000–$75,000 in Eastern Europe, and $25,000–$150,000 with a US agency. Complex apps with real-time features, payments and an admin panel cost more. The number is hours × hourly rate, plus running costs after launch.</p>
</details>
<details class="faq" name="faq">
<summary>Is Flutter cheaper than native app development?</summary>
<p>Usually, yes. One Dart codebase runs on iOS and Android, so screens, fixes and features are built once. Two native apps need roughly 1.6–1.9× the client-side hours of one Flutter app, while backend and design costs stay about the same.</p>
</details>
<details class="faq" name="faq">
<summary>How long does it take to build a Flutter app?</summary>
<p>A simple app takes about 250–450 hours, a medium app 600–1,000 hours and a complex app 1,400–2,500 hours or more. For one developer that’s roughly 2–3 months for a simple app and 4–6 months for a medium one.</p>
</details>
<details class="faq" name="faq">
<summary>What does a Flutter MVP cost?</summary>
<p>A focused MVP with only the features needed to launch typically costs $5,000–$8,000 with me as a solo Flutter developer. Agencies in higher-cost regions usually charge several times more for the same scope.</p>
</details>
<details class="faq" name="faq">
<summary>What running costs come after launch?</summary>
<p>Store fees ($99 a year for Apple, a one-time $25 for Google Play), servers and third-party services such as Firebase or maps, and maintenance: Flutter and package updates, new OS and store requirements, and bug fixes.</p>
</details>
</div>
<h2 id="get-your-own-estimate">Get your own estimate</h2>
<p>If you want a rough number for your idea, try the free <a href="https://neemii.dev/tools/app-cost-calculator/">app cost calculator</a>. Pick your features, platforms and region, and it gives you an hour and cost range based on the same assumptions as this post.</p>
<p>For a real estimate, <a href="https://neemii.dev/#contact">send me your idea</a>. I am Muhammad Naeem, a Flutter developer in Lahore building iOS and Android apps for startups in the UAE, Pakistan and worldwide. Tell me what the app should do, and I will reply with a scope, a timeline and a price range, free and with no obligation.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-flutter-app-development-cost.png" type="image/png" length="0" />
    </item>
    <item>
      <title>Flutter App Maintenance: What It Costs and What to Do Each Year</title>
      <link>https://neemii.dev/blog/flutter-app-maintenance-checklist/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/flutter-app-maintenance-checklist/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>Why live Flutter apps break without code changes, a monthly, quarterly and yearly maintenance checklist, how to upgrade Flutter safely, and what it costs.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> A Flutter app needs maintenance even when its code doesn’t change, because store rules, OS versions, SDKs and packages keep moving. Check crashes and policy emails monthly, upgrade Flutter and packages quarterly, and bump the Android target SDK, Xcode, certificates and store listings every year. As a starting point, budget about 15–20% of the build cost per year.</p>
<p>A shipped app is not a finished app. You can leave the code untouched for a year and still find that you can’t publish an update, that a login flow stopped working on the newest iPhone, or that Google Play has quietly stopped showing your app to people with new phones.</p>
<p>This post is for founders who want to know what they are paying for after launch, and for developers who want a checklist they can actually follow. It covers why apps break on their own, what to check monthly, quarterly and yearly, how to upgrade Flutter without wrecking a release, and how to budget for all of it.</p>
<h2 id="why-apps-break-without-code-changes">Why apps break without code changes</h2>
<p>Your code stays the same. Everything around it moves.</p>
<h3 id="google-play-raises-the-target-api-level-every-year">Google Play raises the target API level every year</h3>
<p>Google Play requires apps to target a recent Android API level, and the bar goes up once a year. According to Google’s <a href="https://support.google.com/googleplay/android-developer/answer/11926878">target API level requirements page</a>, from August 31, 2026:</p>
<ul>
<li>New apps and app updates must target <strong>Android 16 (API level 36)</strong> or higher to be submitted.</li>
<li>Existing apps must target <strong>Android 15 (API level 35)</strong> or higher. Apps below that risk losing visibility to new users on devices running a newer Android version than the app targets.</li>
</ul>
<p>Developers could request an extension to November 1, 2026. That date has passed, so if your app still targets an older level, you can’t ship an update until you fix it.</p>
<p>Bumping <code>targetSdkVersion</code> is rarely a one-line change. Each Android version changes behaviour for apps that target it: permissions, background work, notifications, edge-to-edge display. The bump also usually pulls in a newer Android Gradle Plugin, Gradle and Kotlin, which pulls in newer plugin versions. Plan it as a small project, not a five-minute fix. For the current requirement and the exact Flutter steps, see <a href="https://neemii.dev/blog/google-play-target-api-level-flutter/">Google Play target API level 2026 for Flutter</a>, and check your project with the <a href="https://neemii.dev/tools/flutter-target-api-checker/">target API and Gradle checker</a>.</p>
<h3 id="apple-requires-a-recent-xcode-and-sdk">Apple requires a recent Xcode and SDK</h3>
<p>Apple sets a minimum Xcode and SDK version for uploads, usually each spring. Apple’s <a href="https://developer.apple.com/news/upcoming-requirements/">upcoming requirements page</a> says that since April 28, 2026, apps uploaded to App Store Connect must be built with <strong>Xcode 26 or later</strong> using the iOS 26 SDK (or the matching iPadOS, tvOS, visionOS or watchOS 26 SDK).</p>
<p>In practice this means your Mac, your Xcode, your CocoaPods setup and your Flutter version all have to be recent enough to build with that SDK. If your project has been sitting on an old Flutter version for two years, this is often where it breaks.</p>
<p>Apple also requires a privacy manifest declaring “required reason” APIs your app and its SDKs use. Since May 1, 2024, you need <a href="https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api">approved reasons for the listed APIs</a> to upload a new or updated app. Old versions of plugins that don’t ship a privacy manifest are a common cause of rejected uploads.</p>
<h3 id="packages-get-deprecated-or-abandoned">Packages get deprecated or abandoned</h3>
<p>A typical Flutter app depends on 20 to 60 packages from pub.dev, directly and indirectly. Over time some of them:</p>
<ul>
<li>get marked as discontinued, often with a suggested replacement</li>
<li>stop supporting the newest Flutter or Dart version</li>
<li>stop being updated for new Android or iOS requirements, such as a newer Gradle setup or a privacy manifest</li>
</ul>
<p>The longer you wait, the more of these pile up, and the harder each upgrade becomes because several packages need major-version jumps at once.</p>
<h3 id="firebase-sdks-change">Firebase SDKs change</h3>
<p>Firebase ships new SDK versions regularly, and the FlutterFire plugins follow. Major releases can remove deprecated APIs, raise the minimum iOS deployment target or Android <code>minSdkVersion</code>, or require a newer Gradle or Xcode. Some Firebase products are also deprecated or replaced over time, with migration deadlines announced in the Firebase docs and release notes. If you use Firebase, read the <a href="https://firebase.flutter.dev/">FlutterFire changelog</a> and the Firebase release notes before major upgrades.</p>
<h3 id="the-operating-systems-change">The operating systems change</h3>
<p>Every new Android and iOS release changes something: permission prompts, background limits, photo picker behaviour, notification permissions, keyboard and safe-area handling. Usually Flutter and the plugins absorb most of it, but only if you are on versions released after the OS change. An app built two years ago runs on the new OS with two-year-old assumptions.</p>
<blockquote>
<p><strong>A real example:</strong> a client app hadn’t been touched for over a year. When it needed a quick hotfix, Google Play blocked the release because the app targeted an outdated API level. Raising the target SDK then broke background work and permissions, especially WorkManager jobs and location and notification permissions. To ship what was a one-line text change, we had to upgrade Gradle, replace three abandoned packages and declare explicit foreground service types in <code>AndroidManifest.xml</code>.</p>
</blockquote>
<h2 id="the-maintenance-checklist">The maintenance checklist</h2>
<p>Here’s the routine I’d recommend for a typical live Flutter app. Adjust the frequency to how much the app earns and how fast it changes.</p>
<h3 id="monthly">Monthly</h3>
<ul>
<li><strong>Review crashes.</strong> Open Firebase <a href="https://firebase.google.com/docs/crashlytics">Crashlytics</a> (or whatever you use) and look at new issues, regressions and the crash-free users rate. Fix the top few, not all of them.</li>
<li><strong>Read store feedback.</strong> Check Play Console and App Store Connect reviews, plus Android vitals in Play Console (ANR rate and crash rate). Bad vitals can affect how Play shows your app.</li>
<li><strong>Check policy emails.</strong> Google Play and Apple send policy and requirement notices to the account owner’s email. Someone needs to actually read them. Many “sudden” rejections were announced months before.</li>
<li><strong>Watch backend and third-party usage.</strong> API keys, quotas and billing alerts on Firebase, Google Maps, payment providers and so on.</li>
</ul>
<h3 id="quarterly">Quarterly</h3>
<ul>
<li><strong>Upgrade Flutter to the latest stable release</strong> and check your packages (commands below).</li>
<li><strong>Run <code>flutter pub outdated</code></strong> and upgrade what can be upgraded safely. Note anything marked discontinued.</li>
<li><strong>Check dependency security.</strong> Dart doesn’t have a built-in audit command, so look at the package pages on pub.dev, the GitHub security advisories for your key packages, and your native dependencies (Gradle and CocoaPods). Prioritise anything that touches auth, payments, networking or storage.</li>
<li><strong>Update native tooling:</strong> Android Gradle Plugin, Gradle wrapper, Kotlin, Xcode and CocoaPods.</li>
<li><strong>Test on real devices</strong>, including at least one older, low-end Android phone and the newest iOS version.</li>
<li><strong>Re-check privacy declarations whenever SDKs change.</strong> If you added or upgraded an analytics, ads or crash-reporting SDK, your Google Play <a href="https://support.google.com/googleplay/android-developer/answer/10787469">Data safety form</a> and App Store <a href="https://developer.apple.com/app-store/app-privacy-details/">App Privacy details</a> may no longer be accurate. Also make sure the iOS build still includes the privacy manifests that the SDKs ship.</li>
</ul>
<h3 id="yearly">Yearly</h3>
<ul>
<li><strong>Bump the Android target SDK</strong> to meet the Google Play requirement before the deadline, not after. Google usually announces the next level well in advance on the requirements page.</li>
<li><strong>Build with the Xcode version Apple requires</strong> for uploads, and raise the iOS deployment target if your plugins need it.</li>
<li><strong>Check certificates, keys and profiles.</strong> Apple distribution certificates and provisioning profiles expire, so put the expiry dates in a calendar. If you send push notifications on iOS with an older APNs certificate (<code>.p12</code>), it also expires; an APNs auth key (<code>.p8</code>) avoids that yearly renewal. Check your Android upload key setup in Play App Signing too, and make sure more than one person knows where the keystore and passwords live.</li>
<li><strong>Renew the Apple Developer Program membership.</strong> If it lapses, your apps are removed from the App Store.</li>
<li><strong>Refresh the store listing.</strong> Update screenshots if the UI changed, check the description still matches the app, and review the age rating and content questionnaires if the stores ask again.</li>
<li><strong>Review the privacy policy</strong> against what the app actually collects today.</li>
<li><strong>Do one major-version pass</strong> on packages that you skipped in quarterly upgrades because they had breaking changes.</li>
</ul>
<blockquote>
<p><strong>My rule for client apps:</strong> I never move a production app to a <code>.0</code> Flutter release. I wait for the first or second patch (<code>.1</code> or <code>.2</code>), so early plugin and ecosystem regressions are fixed first. Dependencies get a scheduled quarterly check, unless a critical security patch or a Google Play or App Store deadline comes first. The Flutter version is pinned with <a href="https://fvm.app/">FVM</a>, so the whole team builds with exactly the same SDK.</p>
</blockquote>
<h2 id="how-to-upgrade-flutter-safely">How to upgrade Flutter safely</h2>
<p>Upgrades go wrong when they are done on <code>main</code>, on the day of a release, with no tests. Here is the process I’d follow.</p>
<h3 id="1-work-on-a-branch">1. Work on a branch</h3>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> checkout</span><span style="color:#79B8FF"> -b</span><span style="color:#9ECBFF"> chore/flutter-upgrade</span></span>
<span class="line"><span style="color:#B392F0">flutter</span><span style="color:#79B8FF"> --version</span></span></code></pre>
<p>Write down the current Flutter and Dart versions. If something goes badly wrong, you know exactly where to go back to.</p>
<h3 id="2-read-the-breaking-changes-first">2. Read the breaking changes first</h3>
<p>Flutter publishes a <a href="https://docs.flutter.dev/release/breaking-changes">breaking changes and migration guide</a> for each release. Skim every release between your current version and the target version, not just the newest one. If you are jumping several releases, this list is the difference between a one-hour upgrade and a lost week.</p>
<h3 id="3-upgrade-flutter-and-packages">3. Upgrade Flutter and packages</h3>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> upgrade</span></span>
<span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> pub</span><span style="color:#9ECBFF"> outdated</span></span>
<span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> pub</span><span style="color:#9ECBFF"> upgrade</span></span></code></pre>
<p><code>flutter pub upgrade</code> only moves packages within the version ranges in your <code>pubspec.yaml</code>. To see and apply major-version upgrades:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> pub</span><span style="color:#9ECBFF"> upgrade</span><span style="color:#79B8FF"> --major-versions</span></span></code></pre>
<p>This rewrites the constraints in <code>pubspec.yaml</code>. Do it in small batches if you have many packages, and read each major package’s changelog. A major version bump is the package author telling you something broke.</p>
<p>The official <a href="https://docs.flutter.dev/release/upgrade">upgrade guide</a> covers channels and switching versions. If you maintain several apps on different Flutter versions, a version manager such as FVM saves a lot of switching.</p>
<h3 id="4-apply-automated-fixes">4. Apply automated fixes</h3>
<p>Many Flutter and Dart deprecations come with automated migrations. Preview them, then apply:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">dart</span><span style="color:#9ECBFF"> fix</span><span style="color:#79B8FF"> --dry-run</span></span>
<span class="line"><span style="color:#B392F0">dart</span><span style="color:#9ECBFF"> fix</span><span style="color:#79B8FF"> --apply</span></span>
<span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> analyze</span></span></code></pre>
<p><a href="https://dart.dev/tools/dart-fix"><code>dart fix</code></a> won’t catch everything, but it handles a lot of renamed parameters and deprecated APIs. Fix the remaining <code>flutter analyze</code> warnings before moving on, especially deprecation warnings, because those are next year’s errors.</p>
<h3 id="5-update-the-native-side">5. Update the native side</h3>
<p>For Android, check the versions of the Android Gradle Plugin and Kotlin in <code>android/settings.gradle</code> (or <code>settings.gradle.kts</code>), and the Gradle wrapper in <code>android/gradle/wrapper/gradle-wrapper.properties</code>. Newer Flutter templates and plugins expect newer versions here, and the build error will usually tell you the minimum. Then set your <code>targetSdk</code> and <code>compileSdk</code> in <code>android/app/build.gradle</code> (or <code>.kts</code>).</p>
<p>For iOS:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#79B8FF">cd</span><span style="color:#9ECBFF"> ios</span></span>
<span class="line"><span style="color:#B392F0">pod</span><span style="color:#9ECBFF"> repo</span><span style="color:#9ECBFF"> update</span></span>
<span class="line"><span style="color:#B392F0">pod</span><span style="color:#9ECBFF"> install</span></span>
<span class="line"><span style="color:#79B8FF">cd</span><span style="color:#9ECBFF"> ..</span></span></code></pre>
<p>If <code>pod install</code> fails after an upgrade, deleting <code>ios/Podfile.lock</code> and the <code>ios/Pods</code> folder and running it again often clears version conflicts. Raise the platform version at the top of the <code>Podfile</code> if a plugin requires it.</p>
<p>Then do a clean build on both platforms:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> clean</span></span>
<span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> pub</span><span style="color:#9ECBFF"> get</span></span>
<span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> build</span><span style="color:#9ECBFF"> appbundle</span><span style="color:#79B8FF"> --release</span></span>
<span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> build</span><span style="color:#9ECBFF"> ipa</span><span style="color:#79B8FF"> --release</span></span></code></pre>
<h3 id="6-test-on-real-devices">6. Test on real devices</h3>
<p>Run your tests:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> test</span></span></code></pre>
<p>Then install release builds on real devices. Emulators won’t show you everything: camera, push notifications, in-app purchases, deep links, biometrics and background behaviour all need a real phone. Walk through the core flows: sign up, log in, the main feature, payment if there is one, and push notifications.</p>
<h3 id="7-release-in-stages">7. Release in stages</h3>
<p>On Google Play, use a staged rollout and watch Crashlytics and Android vitals for a day or two before going to 100%. On iOS, phased release does a similar job for automatic updates. If crashes spike, you can halt the rollout instead of shipping the problem to everyone.</p>
<h2 id="what-maintenance-costs">What maintenance costs</h2>
<p>The common rule of thumb is that yearly maintenance costs <strong>15–20% of the original build cost</strong>. I use the same figure in my <a href="https://neemii.dev/blog/flutter-app-development-cost/">Flutter app development cost guide</a>. It is a planning heuristic, not a measured fact. Your real number depends on:</p>
<ul>
<li><strong>How many third-party SDKs you use.</strong> Every SDK is something that can break or need an upgrade. Payments, maps, ads and analytics add the most work.</li>
<li><strong>How far behind the app already is.</strong> Skipping a year of upgrades doesn’t save that work; it stacks it up. Upgrading across many Flutter releases and several major package versions at once usually takes longer than doing it in steps.</li>
<li><strong>Test coverage.</strong> With good automated tests, an upgrade is mostly running commands and checking results. Without them, every upgrade means a full manual test pass.</li>
<li><strong>Backend changes.</strong> If the API changes, the app has to change with it.</li>
<li><strong>New features.</strong> Maintenance usually means keeping what exists working. New features are extra and should be budgeted separately.</li>
</ul>
<p>On a $40,000 app, 15–20% is roughly $6,000–$8,000 a year. Some years cost less, some years cost more (a big target SDK bump plus a Firebase major version in the same year, for example). If you don’t know your build cost yet, the <a href="https://neemii.dev/tools/app-cost-calculator/">app cost calculator</a> gives you a range to start from.</p>
<h3 id="doing-it-in-house-vs-paying-for-it">Doing it in-house vs. paying for it</h3>
<p>If you have a developer on the team, maintenance can be a few days each quarter on their calendar. The risk is that it always loses to feature work until a store deadline forces it.</p>
<p>If you don’t, a <a href="https://neemii.dev/services/app-maintenance/">maintenance plan</a> with a fixed scope is usually cheaper than paying for emergency fixes when an update is rejected. Whoever does it, make sure you own the accounts: Play Console, App Store Connect, Firebase, the signing keys and the source code repository should be in your company’s name, not a freelancer’s personal account.</p>
<h2 id="the-short-version">The short version</h2>
<ul>
<li>Apps break without code changes because store rules, OS versions, SDKs and packages keep moving.</li>
<li>Google Play raises the target API level every year. Apple raises the minimum Xcode and SDK version for uploads.</li>
<li>Check crashes and policy emails monthly, upgrade Flutter and packages quarterly, and bump target SDK, Xcode, certificates and store listings yearly.</li>
<li>Upgrade on a branch, read the breaking changes, run <code>dart fix --apply</code>, update the native side, and test release builds on real devices.</li>
<li>Budget roughly 15–20% of the build cost per year as a starting point.</li>
</ul>
<h2 id="need-someone-to-keep-your-app-updated">Need someone to keep your app updated?</h2>
<p>I’ve built and shipped 10+ Flutter apps, and I maintain apps for clients after launch: Flutter and package upgrades, target SDK and Xcode requirements, crash fixes and store submissions. If your app is falling behind or an update just got rejected, see my <a href="https://neemii.dev/services/app-maintenance/">app maintenance service</a> or <a href="https://neemii.dev/#contact">get in touch</a> and tell me what’s going on.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-flutter-app-maintenance-checklist.png" type="image/png" length="0" />
    </item>
    <item>
      <title>Flutter JSON Parsing: fromJson, Null Safety and Code Generation</title>
      <link>https://neemii.dev/blog/flutter-json-parsing/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/flutter-json-parsing/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>How to parse JSON in Flutter: jsonDecode, fromJson/toJson models, null safety, nested lists, json_serializable vs freezed, and the runtime errors you will hit.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> Decode the response with jsonDecode, then map it into a typed Dart model with a fromJson factory and a toJson method. Make fields nullable when the API can omit them, read numbers through num so 450 and 450.5 both work, and give nested objects and lists their own classes. For more than a few models, generate the code with json_serializable or freezed instead of writing it by hand.</p>
<p>Almost every Flutter app talks to an API, and almost every API speaks JSON. Dart has no reflection in Flutter, so you can’t hand a JSON string to a library and get a typed object back by magic. You either write the mapping yourself or generate it.</p>
<p>This post covers both, in the order you’ll meet them: <code>jsonDecode</code>, a hand-written model, the null safety traps, nested objects and lists, <code>json_serializable</code>, <code>freezed</code>, and the error messages that show up when something doesn’t match.</p>
<h2 id="step-1-jsondecode-gives-you-dynamic-data">Step 1: jsonDecode gives you dynamic data</h2>
<p><code>jsonDecode</code> from <code>dart:convert</code> turns a JSON string into plain Dart values: <code>Map&lt;String, dynamic&gt;</code> for objects, <code>List&lt;dynamic&gt;</code> for arrays, and <code>String</code>, <code>int</code>, <code>double</code>, <code>bool</code> or <code>null</code> for the rest.</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'dart:convert'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">void</span><span style="color:#B392F0"> main</span><span style="color:#E1E4E8">() {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#E1E4E8"> body </span><span style="color:#F97583">=</span><span style="color:#9ECBFF"> '{"id": 7, "name": "Ayesha", "email": null}'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#E1E4E8"> data </span><span style="color:#F97583">=</span><span style="color:#B392F0"> jsonDecode</span><span style="color:#E1E4E8">(body) </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;;</span></span>
<span class="line"><span style="color:#B392F0">  print</span><span style="color:#E1E4E8">(data[</span><span style="color:#9ECBFF">'name'</span><span style="color:#E1E4E8">]); </span><span style="color:#6A737D">// Ayesha</span></span>
<span class="line"><span style="color:#B392F0">  print</span><span style="color:#E1E4E8">(data[</span><span style="color:#9ECBFF">'id'</span><span style="color:#E1E4E8">].runtimeType); </span><span style="color:#6A737D">// int</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>You could pass <code>data</code> around your app and read <code>data['name']</code> everywhere. Don’t. Every read is untyped, a typo in a key returns <code>null</code> instead of a compile error, and when the API changes you find out from a crash report. Convert it to a class once, at the edge of your app.</p>
<h2 id="step-2-a-model-class-with-fromjson-and-tojson">Step 2: a model class with fromJson and toJson</h2>
<p>The standard pattern is a <code>fromJson</code> factory constructor and a <code>toJson</code> method:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">class</span><span style="color:#79B8FF"> User</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#79B8FF"> User</span><span style="color:#E1E4E8">({</span><span style="color:#F97583">required</span><span style="color:#79B8FF"> this</span><span style="color:#E1E4E8">.id, </span><span style="color:#F97583">required</span><span style="color:#79B8FF"> this</span><span style="color:#E1E4E8">.name, </span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">.email});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> int</span><span style="color:#E1E4E8"> id;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> String</span><span style="color:#E1E4E8"> name;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> String</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> email;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  factory</span><span style="color:#79B8FF"> User</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt; json) </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> User</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">        id</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'id'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> int</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">        name</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'name'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> String</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">        email</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'email'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> String</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      );</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">toJson</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#9ECBFF">        'id'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> id,</span></span>
<span class="line"><span style="color:#9ECBFF">        'name'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> name,</span></span>
<span class="line"><span style="color:#9ECBFF">        'email'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> email,</span></span>
<span class="line"><span style="color:#E1E4E8">      };</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>Usage:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> user </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> User</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(data);</span></span>
<span class="line"><span style="color:#B392F0">print</span><span style="color:#E1E4E8">(user.email); </span><span style="color:#6A737D">// null</span></span>
<span class="line"><span style="color:#B392F0">print</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">jsonEncode</span><span style="color:#E1E4E8">(user.</span><span style="color:#B392F0">toJson</span><span style="color:#E1E4E8">())); </span><span style="color:#6A737D">// {"id":7,"name":"Ayesha","email":null}</span></span></code></pre>
<p>The <code>as</code> casts are the important part. They are where the type check happens, and they are where your app will throw if the API sends something you didn’t expect. That is a good thing: it fails at the parsing line, with a clear message, instead of three screens later.</p>
<p>If you don’t want to type these classes by hand, paste a real response into my <a href="https://neemii.dev/tools/json-to-dart/">JSON to Dart converter</a>. It produces this same style of model (plain Dart, <code>json_serializable</code> or <code>freezed</code>), runs in your browser, and doesn’t send your JSON anywhere.</p>
<h2 id="null-safety-where-most-parsing-bugs-come-from">Null safety: where most parsing bugs come from</h2>
<p>Dart’s null safety only protects you after the data is inside a typed field. The cast from <code>dynamic</code> is where you decide what’s allowed to be null, and getting that decision wrong is the most common source of crashes.</p>
<h3 id="int-vs-double">int vs double</h3>
<p>JSON has one number type. Dart has two. <code>jsonDecode('450')</code> gives you an <code>int</code>, and <code>jsonDecode('450.0')</code> gives you a <code>double</code>. Many APIs send prices as <code>450</code> one day and <code>450.5</code> the next, so this will eventually crash on a phone:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#E1E4E8">price</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'price'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> double</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">// throws when the API sends 450</span></span></code></pre>
<p>Read every <code>double</code> through <code>num</code> instead:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#E1E4E8">price</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> (json[</span><span style="color:#9ECBFF">'price'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> num</span><span style="color:#E1E4E8">).</span><span style="color:#B392F0">toDouble</span><span style="color:#E1E4E8">(),</span></span></code></pre>
<p>One detail that makes this bug sneaky: on Flutter web compiled to JavaScript (the default build), <code>int</code> and <code>double</code> are both JavaScript numbers, so <code>450 as double</code> succeeds. The same line compiled with <code>dart compile js</code> printed <code>450</code>, while the Dart VM threw. If you test mainly on web, you can ship this bug to Android and iOS without seeing it once.</p>
<h3 id="missing-keys-and-null-values">Missing keys and null values</h3>
<p>Reading a key that isn’t in the map returns <code>null</code>, the same as a key whose value is <code>null</code>. So <code>json['email'] as String?</code> handles both cases. A field that’s required in your class but missing from the response throws:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="text"><code><span class="line"><span>type 'Null' is not a subtype of type 'String' in type cast</span></span></code></pre>
<p>For each field, decide which of three things it is:</p>
<ol>
<li><strong>Always present</strong>: non-nullable type, plain cast (<code>as String</code>).</li>
<li><strong>Sometimes missing, and null means something</strong>: nullable type (<code>String?</code>, <code>as String?</code>).</li>
<li><strong>Sometimes missing, but there’s a sensible default</strong>: nullable cast plus <code>??</code>.</li>
</ol>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#E1E4E8">status</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'status'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> String</span><span style="color:#F97583">?</span><span style="color:#F97583"> ??</span><span style="color:#9ECBFF"> 'pending'</span><span style="color:#E1E4E8">,</span></span></code></pre>
<p>Don’t make everything nullable just to stop crashes. You’ll trade one crash at parse time for <code>!</code> operators and null checks spread through your UI code. Be strict where the API contract is strict, and loose only where it really is optional.</p>
<blockquote>
<p><strong>From my own work:</strong> on a government survey app I’m working on (I can’t share details), records were getting stuck on some enumerators’ devices and never reached the server. I went through the Postman responses, the Grafana logs and the field notes, and found the cause: in a few scenarios a record was missing an ID in the local database, so the JSON the app sent was not what the server expected, and the server rejected it every time the app retried. Making the parser more lenient would only have hidden the problem. Instead I added an auto-repair step that restores any missing survey ID in the local database before upload, so the server accepts the JSON and the stuck records go through. The lesson: when JSON fails, check the data you’re serialising, not just the parsing code.</p>
</blockquote>
<h3 id="when-the-api-sends-the-wrong-type">When the API sends the wrong type</h3>
<p>Some backends send <code>"id": "42"</code> in one endpoint and <code>"id": 42</code> in another. If you can’t get the backend fixed, read it with a small helper instead of a cast:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#79B8FF">int</span><span style="color:#B392F0"> readInt</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Object</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> v) </span><span style="color:#F97583">=&gt;</span><span style="color:#F97583"> switch</span><span style="color:#E1E4E8"> (v) {</span></span>
<span class="line"><span style="color:#79B8FF">      int</span><span style="color:#E1E4E8"> i </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> i,</span></span>
<span class="line"><span style="color:#79B8FF">      num</span><span style="color:#E1E4E8"> n </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> n.</span><span style="color:#B392F0">toInt</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#79B8FF">      String</span><span style="color:#E1E4E8"> s </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> int</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">parse</span><span style="color:#E1E4E8">(s),</span></span>
<span class="line"><span style="color:#E1E4E8">      _ </span><span style="color:#F97583">=&gt;</span><span style="color:#F97583"> throw</span><span style="color:#79B8FF"> FormatException</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Expected an int, got </span><span style="color:#9ECBFF">$</span><span style="color:#79B8FF">v</span><span style="color:#9ECBFF">'</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">    };</span></span></code></pre>
<p>Keep these helpers few and deliberate. Each one hides a backend inconsistency that someone should eventually fix.</p>
<h2 id="nested-objects-and-lists">Nested objects and lists</h2>
<p>Real responses are nested. Here’s an order with a customer object, a list of items and a list of strings:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="json"><code><span class="line"><span style="color:#E1E4E8">{</span></span>
<span class="line"><span style="color:#79B8FF">  "id"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1042</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "total"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">450</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "customer"</span><span style="color:#E1E4E8">: {</span><span style="color:#79B8FF">"name"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"Sara"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"phone"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">null</span><span style="color:#E1E4E8">},</span></span>
<span class="line"><span style="color:#79B8FF">  "items"</span><span style="color:#E1E4E8">: [</span></span>
<span class="line"><span style="color:#E1E4E8">    {</span><span style="color:#79B8FF">"title"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"Chai"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"qty"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"price"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">150</span><span style="color:#E1E4E8">},</span></span>
<span class="line"><span style="color:#E1E4E8">    {</span><span style="color:#79B8FF">"title"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"Samosa"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"qty"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">"price"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50.0</span><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#E1E4E8">  ],</span></span>
<span class="line"><span style="color:#79B8FF">  "tags"</span><span style="color:#E1E4E8">: [</span><span style="color:#9ECBFF">"express"</span><span style="color:#E1E4E8">, </span><span style="color:#9ECBFF">"paid"</span><span style="color:#E1E4E8">]</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>Each nested object gets its own class with its own <code>fromJson</code>. Lists are decoded as <code>List&lt;dynamic&gt;</code>, so you map each element:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">factory</span><span style="color:#79B8FF"> Order</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt; json) </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> Order</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">      id</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'id'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> int</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      status</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'status'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> String</span><span style="color:#F97583">?</span><span style="color:#F97583"> ??</span><span style="color:#9ECBFF"> 'pending'</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      total</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> (json[</span><span style="color:#9ECBFF">'total'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> num</span><span style="color:#E1E4E8">).</span><span style="color:#B392F0">toDouble</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">      customer</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Customer</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(json[</span><span style="color:#9ECBFF">'customer'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;),</span></span>
<span class="line"><span style="color:#E1E4E8">      items</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> (json[</span><span style="color:#9ECBFF">'items'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> List</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;)</span></span>
<span class="line"><span style="color:#E1E4E8">          .</span><span style="color:#B392F0">map</span><span style="color:#E1E4E8">((e) </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> OrderItem</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(e </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;))</span></span>
<span class="line"><span style="color:#E1E4E8">          .</span><span style="color:#B392F0">toList</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">      tags</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> (json[</span><span style="color:#9ECBFF">'tags'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> List</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;</span><span style="color:#F97583">?</span><span style="color:#F97583"> ??</span><span style="color:#F97583"> const</span><span style="color:#E1E4E8"> [])</span></span>
<span class="line"><span style="color:#E1E4E8">          .</span><span style="color:#B392F0">map</span><span style="color:#E1E4E8">((e) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> e </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> String</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#E1E4E8">          .</span><span style="color:#B392F0">toList</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">      coupon</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'coupon'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> String</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">    );</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">toJson</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#9ECBFF">      'id'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> id,</span></span>
<span class="line"><span style="color:#9ECBFF">      'status'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> status,</span></span>
<span class="line"><span style="color:#9ECBFF">      'total'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> total,</span></span>
<span class="line"><span style="color:#9ECBFF">      'customer'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> customer.</span><span style="color:#B392F0">toJson</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#9ECBFF">      'items'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> items.</span><span style="color:#B392F0">map</span><span style="color:#E1E4E8">((e) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> e.</span><span style="color:#B392F0">toJson</span><span style="color:#E1E4E8">()).</span><span style="color:#B392F0">toList</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#9ECBFF">      'tags'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> tags,</span></span>
<span class="line"><span style="color:#9ECBFF">      'coupon'</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> coupon,</span></span>
<span class="line"><span style="color:#E1E4E8">    };</span></span></code></pre>
<p><code>Customer</code> and <code>OrderItem</code> follow the same pattern as <code>User</code> above, with <code>OrderItem.price</code> read as <code>(json['price'] as num).toDouble()</code>. Note that <code>toJson</code> calls <code>toJson()</code> on the nested objects too, so you get plain maps all the way down.</p>
<h3 id="when-the-top-level-is-a-list">When the top level is a list</h3>
<p>If the endpoint returns an array, cast the decoded value to <code>List&lt;dynamic&gt;</code>:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> users </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> (</span><span style="color:#B392F0">jsonDecode</span><span style="color:#E1E4E8">(body) </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> List</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;)</span></span>
<span class="line"><span style="color:#E1E4E8">    .</span><span style="color:#B392F0">map</span><span style="color:#E1E4E8">((e) </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> User</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(e </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;))</span></span>
<span class="line"><span style="color:#E1E4E8">    .</span><span style="color:#B392F0">toList</span><span style="color:#E1E4E8">();</span></span></code></pre>
<p>Many APIs wrap the list instead: <code>{"data": [...], "page": 1}</code>. Then you cast to a map first and read the list from it:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> map </span><span style="color:#F97583">=</span><span style="color:#B392F0"> jsonDecode</span><span style="color:#E1E4E8">(body) </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;;</span></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> users </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> (map[</span><span style="color:#9ECBFF">'data'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> List</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;)</span></span>
<span class="line"><span style="color:#E1E4E8">    .</span><span style="color:#B392F0">map</span><span style="color:#E1E4E8">((e) </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> User</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(e </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;))</span></span>
<span class="line"><span style="color:#E1E4E8">    .</span><span style="color:#B392F0">toList</span><span style="color:#E1E4E8">();</span></span></code></pre>
<h3 id="large-responses">Large responses</h3>
<p>Decoding a big response on the main isolate can drop frames. Move the parsing to another isolate with <code>Isolate.run</code> (or Flutter’s <code>compute</code>):</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#79B8FF">List</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">User</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">parseUsers</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8"> body) </span><span style="color:#F97583">=&gt;</span><span style="color:#E1E4E8"> (</span><span style="color:#B392F0">jsonDecode</span><span style="color:#E1E4E8">(body) </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> List</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;)</span></span>
<span class="line"><span style="color:#E1E4E8">    .</span><span style="color:#B392F0">map</span><span style="color:#E1E4E8">((e) </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> User</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(e </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;))</span></span>
<span class="line"><span style="color:#E1E4E8">    .</span><span style="color:#B392F0">toList</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> users </span><span style="color:#F97583">=</span><span style="color:#F97583"> await</span><span style="color:#79B8FF"> Isolate</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">run</span><span style="color:#E1E4E8">(() </span><span style="color:#F97583">=&gt;</span><span style="color:#B392F0"> parseUsers</span><span style="color:#E1E4E8">(body));</span></span></code></pre>
<p>The closure and what it captures (here, the <code>body</code> string) are copied into the new isolate, so keep it small and self-contained. Only do this when you’ve seen jank on a real device; for small payloads it adds overhead without any benefit.</p>
<h2 id="json_serializable-let-the-generator-write-fromjson">json_serializable: let the generator write fromJson</h2>
<p>Writing models by hand is fine for a few classes. Past that, the casts get repetitive and a renamed field is easy to miss in <code>toJson</code>. <code>json_serializable</code> generates both methods from annotations.</p>
<p>Add the packages:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="text"><code><span class="line"><span>flutter pub add json_annotation dev:build_runner dev:json_serializable</span></span></code></pre>
<p>Then annotate the model and point it at the file that will be generated:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'package:json_annotation/json_annotation.dart'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">part</span><span style="color:#9ECBFF"> 'product.g.dart'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">@JsonSerializable</span><span style="color:#E1E4E8">(explicitToJson</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#F97583">class</span><span style="color:#79B8FF"> Product</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#79B8FF"> Product</span><span style="color:#E1E4E8">({</span></span>
<span class="line"><span style="color:#F97583">    required</span><span style="color:#79B8FF"> this</span><span style="color:#E1E4E8">.id,</span></span>
<span class="line"><span style="color:#F97583">    required</span><span style="color:#79B8FF"> this</span><span style="color:#E1E4E8">.title,</span></span>
<span class="line"><span style="color:#F97583">    required</span><span style="color:#79B8FF"> this</span><span style="color:#E1E4E8">.price,</span></span>
<span class="line"><span style="color:#79B8FF">    this</span><span style="color:#E1E4E8">.imageUrl,</span></span>
<span class="line"><span style="color:#79B8FF">    this</span><span style="color:#E1E4E8">.inStock </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#F97583">    required</span><span style="color:#79B8FF"> this</span><span style="color:#E1E4E8">.variants,</span></span>
<span class="line"><span style="color:#E1E4E8">  });</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> int</span><span style="color:#E1E4E8"> id;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> String</span><span style="color:#E1E4E8"> title;</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> double</span><span style="color:#E1E4E8"> price;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  @JsonKey</span><span style="color:#E1E4E8">(name</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'image_url'</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> String</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> imageUrl;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  @JsonKey</span><span style="color:#E1E4E8">(name</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'in_stock'</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> bool</span><span style="color:#E1E4E8"> inStock;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  final</span><span style="color:#79B8FF"> List</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">Variant</span><span style="color:#E1E4E8">&gt; variants;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  factory</span><span style="color:#79B8FF"> Product</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt; json) </span><span style="color:#F97583">=&gt;</span></span>
<span class="line"><span style="color:#79B8FF">      _$ProductFromJson</span><span style="color:#E1E4E8">(json);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt; </span><span style="color:#B392F0">toJson</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> _$ProductToJson</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p><code>Variant</code> is another <code>@JsonSerializable()</code> class with the same two one-line methods. Generate the code:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="text"><code><span class="line"><span>dart run build_runner build --delete-conflicting-outputs</span></span></code></pre>
<p>Use <code>watch</code> instead of <code>build</code> to regenerate on every save. The generated <code>product.g.dart</code> reads numbers safely for you:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#79B8FF">Product</span><span style="color:#79B8FF"> _$ProductFromJson</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt; json) </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> Product</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">  id</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> (json[</span><span style="color:#9ECBFF">'id'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> num</span><span style="color:#E1E4E8">).</span><span style="color:#B392F0">toInt</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">  title</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'title'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> String</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">  price</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> (json[</span><span style="color:#9ECBFF">'price'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> num</span><span style="color:#E1E4E8">).</span><span style="color:#B392F0">toDouble</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">  imageUrl</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'image_url'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> String</span><span style="color:#F97583">?</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">  inStock</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> json[</span><span style="color:#9ECBFF">'in_stock'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> bool</span><span style="color:#F97583">?</span><span style="color:#F97583"> ??</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">  variants</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> (json[</span><span style="color:#9ECBFF">'variants'</span><span style="color:#E1E4E8">] </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> List</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;)</span></span>
<span class="line"><span style="color:#E1E4E8">      .</span><span style="color:#B392F0">map</span><span style="color:#E1E4E8">((e) </span><span style="color:#F97583">=&gt;</span><span style="color:#79B8FF"> Variant</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(e </span><span style="color:#F97583">as</span><span style="color:#79B8FF"> Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt;))</span></span>
<span class="line"><span style="color:#E1E4E8">      .</span><span style="color:#B392F0">toList</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span></code></pre>
<p>Things worth knowing:</p>
<ul>
<li><strong><code>explicitToJson: true</code></strong> matters for nested objects. Without it, <code>toJson()</code> puts the <code>Variant</code> objects themselves in the map, not maps. <code>jsonEncode</code> still works because it calls <code>toJson()</code> on them, but anything else that expects a plain map (a local database, a test comparing maps) will not.</li>
<li><strong>Default values</strong> in the constructor (<code>this.inStock = true</code>) are used when the key is missing or null.</li>
<li><strong>Project-wide settings</strong> go in <code>build.yaml</code> at the project root, so you don’t repeat them on every class:</li>
</ul>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="yaml"><code><span class="line"><span style="color:#85E89D">targets</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#85E89D">  $default</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#85E89D">    builders</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#85E89D">      json_serializable</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#85E89D">        options</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#85E89D">          explicit_to_json</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">true</span></span>
<span class="line"><span style="color:#85E89D">          field_rename</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">snake</span></span></code></pre>
<p>With <code>field_rename: snake</code>, a Dart field <code>fullName</code> maps to the JSON key <code>full_name</code> without a <code>@JsonKey</code> on every field.</p>
<p>The cost is the build step: a <code>part</code> directive in every model, generated files in your repo (or a build step in CI), and a few seconds of waiting after each model change.</p>
<h2 id="freezed-when-you-want-more-than-json">freezed: when you want more than JSON</h2>
<p><code>freezed</code> is a different kind of tool. It generates immutable data classes: <code>copyWith</code>, <code>==</code> and <code>hashCode</code> based on values, <code>toString</code>, and sealed unions. For JSON it hands off to <code>json_serializable</code>, so you install both.</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'package:freezed_annotation/freezed_annotation.dart'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">part</span><span style="color:#9ECBFF"> 'product.freezed.dart'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">part</span><span style="color:#9ECBFF"> 'product.g.dart'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">@freezed</span></span>
<span class="line"><span style="color:#F97583">abstract</span><span style="color:#F97583"> class</span><span style="color:#79B8FF"> Product</span><span style="color:#F97583"> with</span><span style="color:#79B8FF"> _$Product</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#F97583"> factory</span><span style="color:#79B8FF"> Product</span><span style="color:#E1E4E8">({</span></span>
<span class="line"><span style="color:#F97583">    required</span><span style="color:#79B8FF"> int</span><span style="color:#E1E4E8"> id,</span></span>
<span class="line"><span style="color:#F97583">    required</span><span style="color:#79B8FF"> String</span><span style="color:#E1E4E8"> title,</span></span>
<span class="line"><span style="color:#F97583">    required</span><span style="color:#79B8FF"> double</span><span style="color:#E1E4E8"> price,</span></span>
<span class="line"><span style="color:#F97583">    @JsonKey</span><span style="color:#E1E4E8">(name</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'image_url'</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">String</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> imageUrl,</span></span>
<span class="line"><span style="color:#F97583">    @JsonKey</span><span style="color:#E1E4E8">(name</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'in_stock'</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">@Default</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">true</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">bool</span><span style="color:#E1E4E8"> inStock,</span></span>
<span class="line"><span style="color:#E1E4E8">  }) </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> _Product</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  factory</span><span style="color:#79B8FF"> Product</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromJson</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Map</span><span style="color:#E1E4E8">&lt;</span><span style="color:#79B8FF">String</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">dynamic</span><span style="color:#E1E4E8">&gt; json) </span><span style="color:#F97583">=&gt;</span></span>
<span class="line"><span style="color:#79B8FF">      _$ProductFromJson</span><span style="color:#E1E4E8">(json);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>With that you get <code>product.copyWith(price: 1999)</code> and <code>a == b</code> comparing values, which is what state management (Bloc, Riverpod) wants when it decides whether to rebuild.</p>
<p>Two notes for current versions (freezed 3.x). The class must be declared <code>abstract</code> (or <code>sealed</code> for unions), which older tutorials don’t show. And <code>@JsonKey</code> on constructor parameters triggers the analyzer warning <code>invalid_annotation_target</code>; freezed’s own docs recommend turning it off in <code>analysis_options.yaml</code>:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="yaml"><code><span class="line"><span style="color:#85E89D">analyzer</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#85E89D">  errors</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#85E89D">    invalid_annotation_target</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">ignore</span></span></code></pre>
<p>Is it worth it? If you only need to parse API responses and show them, no: <code>json_serializable</code> alone is less generated code and fewer concepts. <code>freezed</code> earns its place when your models are also your app state, when you update them with <code>copyWith</code> a lot, or when you want sealed classes like <code>Loading | Loaded | Error</code> with exhaustive <code>switch</code>.</p>
<h2 id="which-approach-for-which-app">Which approach for which app</h2>
<table>
<thead>
<tr>
<th>Situation</th>
<th>Approach</th>
</tr>
</thead>
<tbody>
<tr>
<td>Prototype, small app, a handful of models</td>
<td>Hand-written models (or generated once with the <a href="https://neemii.dev/tools/json-to-dart/">converter</a>)</td>
</tr>
<tr>
<td>Many models, a team, an API that keeps changing</td>
<td><code>json_serializable</code></td>
</tr>
<tr>
<td>Models are also app state; you need <code>copyWith</code>, equality, unions</td>
<td><code>freezed</code> + <code>json_serializable</code></td>
</tr>
</tbody>
</table>
<p>You can mix them. Starting with hand-written models and moving to <code>json_serializable</code> later is a mechanical change, because the public API (<code>fromJson</code> and <code>toJson</code>) stays the same. Code generation is still the standard way to do this in Dart: the macros experiment that promised <code>@JsonCodable</code> without <code>build_runner</code> was stopped by the Dart team in early 2025.</p>
<blockquote>
<p><strong>What I use:</strong> in my own client apps I write plain <code>fromJson</code>/<code>toJson</code> by hand. It keeps the models readable and adds no code generation step to the build. I then check each model against the official Flutter and Dart documentation, and use AI tools as a second reviewer to catch a missed null case or wrong cast.</p>
</blockquote>
<h2 id="common-errors-and-what-they-mean">Common errors and what they mean</h2>
<p>These are the exact messages from the Dart VM (which is what runs your app on Android and iOS), reproduced with the code next to each one.</p>
<p><strong><code>type 'int' is not a subtype of type 'double' in type cast</code></strong>
You cast a whole number to <code>double</code>: <code>json['price'] as double</code> with <code>"price": 450</code>. Fix: <code>(json['price'] as num).toDouble()</code>. Without the <code>as</code> (for example <code>final double price = json['price'];</code>) the message is the same minus “in type cast”.</p>
<p><strong><code>type 'Null' is not a subtype of type 'String' in type cast</code></strong>
A field you declared non-nullable was <code>null</code> or missing. Check the raw response. Either make the field nullable, give it a default with <code>??</code>, or fix the backend.</p>
<p><strong><code>type 'List&lt;dynamic&gt;' is not a subtype of type 'List&lt;String&gt;' in type cast</code></strong>
<code>json['tags'] as List&lt;String&gt;</code>. A decoded JSON list is always <code>List&lt;dynamic&gt;</code>, even if every element is a string. Fix: <code>(json['tags'] as List&lt;dynamic&gt;).map((e) =&gt; e as String).toList()</code>.</p>
<p><strong><code>type '_Map&lt;String, dynamic&gt;' is not a subtype of type 'List&lt;dynamic&gt;' in type cast</code></strong>
You expected an array at the top level, but the API wraps it: <code>{"data": [...]}</code>. Cast to <code>Map&lt;String, dynamic&gt;</code> first and read the list from <code>map['data']</code>. <code>_Map</code> is just the private class <code>jsonDecode</code> uses for objects.</p>
<p><strong><code>type '_Map&lt;String, dynamic&gt;' is not a subtype of type 'Map&lt;String, String&gt;' in type cast</code></strong>
Same root cause as the list case: decoded maps are always <code>Map&lt;String, dynamic&gt;</code>. Cast to that and convert the values, or better, write a class for the nested object.</p>
<p><strong><code>type 'String' is not a subtype of type 'int' in type cast</code></strong>
The API sent <code>"id": "42"</code>. Fix the backend if you can; otherwise use a helper like <code>readInt</code> above.</p>
<p><strong><code>type 'String' is not a subtype of type 'int' of 'index'</code></strong>
You indexed a list with a string key: <code>list['id']</code> where <code>list</code> is the decoded array. Take an element first (<code>list[0]['id']</code>), or map the list into models.</p>
<p><strong><code>FormatException: Unexpected character (at character 1)</code></strong>
The body isn’t JSON at all. Most often it’s an HTML error page from a proxy, a login redirect, or a 500. Check the status code before calling <code>jsonDecode</code>. An empty body gives <code>FormatException: Unexpected end of input (at character 1)</code>.</p>
<h2 id="summary">Summary</h2>
<ul>
<li>Decode once with <code>jsonDecode</code>, convert to typed models right away, and keep <code>dynamic</code> out of your widgets.</li>
<li>Read doubles through <code>num</code>. Decide per field what’s required, optional or defaulted.</li>
<li>Map lists element by element; cast nested objects to <code>Map&lt;String, dynamic&gt;</code>.</li>
<li>Move to <code>json_serializable</code> when the models multiply, and add <code>freezed</code> when they become app state.</li>
</ul>
<p>If you want the boilerplate done for you, paste your API response into the free <a href="https://neemii.dev/tools/json-to-dart/">JSON to Dart model converter</a>. It handles nullable fields, int/double, ISO dates as <code>DateTime</code>, snake_case keys and nested lists, and outputs plain Dart, <code>json_serializable</code> or <code>freezed</code>. And if you’re building a Flutter app and want someone to build it with you, <a href="https://neemii.dev/#contact">tell me about your project</a>.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-flutter-json-parsing.png" type="image/png" length="0" />
    </item>
    <item>
      <title>Flutter Material 3 Theming: ColorScheme.fromSeed Explained</title>
      <link>https://neemii.dev/blog/flutter-material-3-theme-colorscheme/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/flutter-material-3-theme-colorscheme/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>Material 3 theming in Flutter for real apps: ColorScheme.fromSeed, why colours shift from the seed, light and dark themes, colour roles, brand colours and dynamic colour.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> Material 3 is on by default in Flutter, and ColorScheme.fromSeed builds a whole palette from one colour. It doesn’t use your seed as the exact primary colour: it picks each role from a fixed tone, so your brand colour may look lighter or calmer. Read colours from Theme.of(context).colorScheme instead of hard-coding them, and override only the roles that must match your brand exactly.</p>
<p>Most Flutter apps start with one line of theming: <code>ColorScheme.fromSeed(seedColor: Colors.blue)</code>. It works, the app looks fine, and then the client asks why the buttons aren’t the exact blue from their logo.</p>
<p>This post explains what that line actually does, how to build light and dark themes on top of it, which colour role to use where, and how to keep brand colours exact when the generated ones aren’t good enough. All the code is plain Flutter, no packages except where I say so.</p>
<h2 id="material-3-is-already-on">Material 3 is already on</h2>
<p>Since Flutter 3.16, <code>ThemeData.useMaterial3</code> defaults to <code>true</code>. If you create a new app today, you’re on Material 3 whether you asked for it or not. You’ll see it in the rounder buttons, the tinted surfaces and the new <code>NavigationBar</code> style.</p>
<p>You can still set <code>useMaterial3: false</code>, but the Flutter team has said Material 2 support will be removed eventually (see the <a href="https://docs.flutter.dev/release/breaking-changes/material-3-default">migration guide</a>). Don’t build a new app on it.</p>
<p>The minimal Material 3 theme is this:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#79B8FF">MaterialApp</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">  theme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> ThemeData</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">    colorScheme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> ColorScheme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromSeed</span><span style="color:#E1E4E8">(seedColor</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFF1565C0</span><span style="color:#E1E4E8">)),</span></span>
<span class="line"><span style="color:#E1E4E8">  ),</span></span>
<span class="line"><span style="color:#E1E4E8">  home</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> HomePage</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span></code></pre>
<p><code>ThemeData(colorSchemeSeed: ...)</code> is a shortcut for the same thing. I prefer building the <code>ColorScheme</code> explicitly, because you’ll want to reuse it for the dark theme and for overrides.</p>
<h2 id="what-fromseed-does-with-your-colour">What fromSeed does with your colour</h2>
<p><code>ColorScheme.fromSeed</code> doesn’t use your seed as <code>primary</code>. It uses it as input to an algorithm. The <a href="https://api.flutter.dev/flutter/material/ColorScheme/ColorScheme.fromSeed.html">API docs</a> say it directly: the seed colour “may not wind up as one of the ColorScheme colors.”</p>
<p>Here’s what happens, simplified:</p>
<ol>
<li>The seed is converted to <strong>HCT</strong> (hue, chroma, tone). Hue is the colour, chroma is how colourful it is, and tone is lightness from 0 (black) to 100 (white). Tone is designed so that two colours with the same tone have the same perceived lightness, which makes contrast predictable.</li>
<li>From that hue and chroma, the algorithm builds <strong>tonal palettes</strong>: one for primary, secondary, tertiary, neutral, neutral variant and error. Each palette is the same hue at many tones.</li>
<li>Each colour role picks a fixed tone from its palette. In a light scheme, <code>primary</code> is a dark-ish tone (around 40) so that white text on it is readable; in a dark scheme it’s a light tone (around 80).</li>
<li>A <strong>variant</strong> decides how much of the seed’s chroma survives. The default, <code>DynamicSchemeVariant.tonalSpot</code>, deliberately calms colours down into pastel-ish palettes.</li>
</ol>
<p>So if your seed is a bright, saturated orange at tone 65, your <code>primary</code> comes out as a darker, less saturated orange at tone 40. That’s not a bug. It’s the system guaranteeing contrast.</p>
<h3 id="changing-the-variant">Changing the variant</h3>
<p>Newer Flutter versions added a <code>dynamicSchemeVariant</code> parameter, along with <code>contrastLevel</code>:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> scheme </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> ColorScheme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromSeed</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">  seedColor</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFFFF6D00</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  dynamicSchemeVariant</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> DynamicSchemeVariant</span><span style="color:#E1E4E8">.fidelity,</span></span>
<span class="line"><span style="color:#E1E4E8">  contrastLevel</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 0.0</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">// -1.0 to 1.0; 0.5 is medium, 1.0 is high contrast</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span></code></pre>
<p>The options worth knowing:</p>
<ul>
<li><strong><code>tonalSpot</code></strong> (default): soft, low-chroma palettes. Safe and readable, but rarely “on brand”.</li>
<li><strong><code>fidelity</code></strong> and <strong><code>content</code></strong>: keep the palettes much closer to the seed. Use these when the seed is a brand colour and you want the app to feel like it.</li>
<li><strong><code>vibrant</code></strong> and <strong><code>expressive</code></strong>: more colourful, with hue shifts for secondary and tertiary.</li>
<li><strong><code>monochrome</code></strong> and <strong><code>neutral</code></strong>: greyscale or near-greyscale.</li>
<li><strong><code>rainbow</code></strong> and <strong><code>fruitSalad</code></strong>: playful, with rotated hues.</li>
</ul>
<p>Check the <a href="https://api.flutter.dev/flutter/material/DynamicSchemeVariant.html">DynamicSchemeVariant docs</a> for the version you’re on. Even with <code>fidelity</code>, <code>primary</code> is still not guaranteed to be your exact hex value; it’s just much closer.</p>
<p>The fastest way to see the difference is to try it. My free <a href="https://neemii.dev/tools/flutter-theme-generator/">Flutter Material 3 theme generator</a> previews all 34 colour roles in light and dark mode for any seed, so you can see what <code>fromSeed</code> will give you before you write the code.</p>
<h2 id="light-and-dark-themes">Light and dark themes</h2>
<p>One seed, two brightnesses. Build both schemes from the same seed, pass them to <code>theme</code> and <code>darkTheme</code>, and let <code>themeMode</code> choose:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#E1E4E8"> seed </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFF1565C0</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> lightScheme </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> ColorScheme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromSeed</span><span style="color:#E1E4E8">(seedColor</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> seed);</span></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> darkScheme </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> ColorScheme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromSeed</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">  seedColor</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> seed,</span></span>
<span class="line"><span style="color:#E1E4E8">  brightness</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Brightness</span><span style="color:#E1E4E8">.dark,</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">MaterialApp</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">  theme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> ThemeData</span><span style="color:#E1E4E8">(colorScheme</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> lightScheme),</span></span>
<span class="line"><span style="color:#E1E4E8">  darkTheme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> ThemeData</span><span style="color:#E1E4E8">(colorScheme</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> darkScheme),</span></span>
<span class="line"><span style="color:#E1E4E8">  themeMode</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> ThemeMode</span><span style="color:#E1E4E8">.system, </span><span style="color:#6A737D">// or ThemeMode.light / ThemeMode.dark</span></span>
<span class="line"><span style="color:#E1E4E8">  home</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> HomePage</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span></code></pre>
<p><code>ThemeMode.system</code> follows the phone’s setting, and it’s the default. If your app has a theme toggle in settings, store the user’s choice (for example with <code>shared_preferences</code>) and pass it into <code>themeMode</code> from your state management.</p>
<p>Two things to get right:</p>
<ul>
<li><strong>Pass <code>brightness</code> to <code>fromSeed</code>.</strong> Setting <code>brightness: Brightness.dark</code> on <code>ThemeData</code> but giving it a light <code>ColorScheme</code> doesn’t work: <code>ThemeData</code> asserts that the two brightnesses match.</li>
<li><strong>Don’t invert colours yourself.</strong> The dark scheme uses different tones from the same palettes. A light theme’s <code>primary</code> on a dark background is usually too dark to read.</li>
</ul>
<blockquote>
<p><strong>From my own work:</strong> the dark-mode bugs I’ve fixed came from hard-coded colours. Cards and screens mixed fixed colour values with theme colours, so in dark mode some cards didn’t match the design and some text lost contrast. The fix was to choose one proper ColorScheme for light and dark and replace the hard-coded values with its roles, so every screen took its colours from the same source.</p>
</blockquote>
<h2 id="colour-roles-and-what-theyre-for">Colour roles and what they’re for</h2>
<p>A Material 3 <code>ColorScheme</code> is a set of named roles, not a palette of “blue 500, blue 700”. The name tells you where the colour belongs. Every colour that’s meant for a background has an <code>on</code> partner for text and icons on top of it, and the pair is generated to meet contrast requirements.</p>
<table>
<thead>
<tr>
<th>Role</th>
<th>Use it for</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>primary</code> / <code>onPrimary</code></td>
<td>The most important actions: filled buttons, FAB, active states</td>
</tr>
<tr>
<td><code>primaryContainer</code> / <code>onPrimaryContainer</code></td>
<td>Less prominent emphasis: selected chips, highlighted cards, tonal buttons</td>
</tr>
<tr>
<td><code>secondary</code>, <code>tertiary</code> (+ <code>on</code>, containers)</td>
<td>Supporting accents; tertiary for contrasting highlights</td>
</tr>
<tr>
<td><code>error</code> / <code>onError</code>, <code>errorContainer</code></td>
<td>Error states, destructive actions, validation messages</td>
</tr>
<tr>
<td><code>surface</code> / <code>onSurface</code></td>
<td>The default background and the default text colour</td>
</tr>
<tr>
<td><code>onSurfaceVariant</code></td>
<td>Secondary text, icons, captions</td>
</tr>
<tr>
<td><code>surfaceContainerLowest</code> … <code>surfaceContainerHighest</code></td>
<td>Layered backgrounds: cards, sheets, dialogs, nav bars, text fields</td>
</tr>
<tr>
<td><code>surfaceDim</code>, <code>surfaceBright</code></td>
<td>Surfaces that should look slightly darker or brighter than <code>surface</code></td>
</tr>
<tr>
<td><code>outline</code>, <code>outlineVariant</code></td>
<td>Borders; <code>outlineVariant</code> for dividers and decorative lines</td>
</tr>
<tr>
<td><code>inverseSurface</code>, <code>onInverseSurface</code>, <code>inversePrimary</code></td>
<td>Elements that sit “against” the theme, like snackbars</td>
</tr>
<tr>
<td><code>shadow</code>, <code>scrim</code>, <code>surfaceTint</code></td>
<td>Shadows, modal overlays, and the tint used for elevation</td>
</tr>
</tbody>
</table>
<p>The full list with descriptions is in the <a href="https://api.flutter.dev/flutter/material/ColorScheme-class.html">ColorScheme API reference</a>. The rule of thumb: if you put text on <code>X</code>, its colour is <code>onX</code>. Text on <code>primaryContainer</code> is <code>onPrimaryContainer</code>, not <code>onPrimary</code>.</p>
<h3 id="the-surface-roles-changed-in-flutter-322">The surface roles changed in Flutter 3.22</h3>
<p>Flutter 3.22 added the <code>surfaceContainer</code> family (<code>surfaceContainerLowest</code>, <code>surfaceContainerLow</code>, <code>surfaceContainer</code>, <code>surfaceContainerHigh</code>, <code>surfaceContainerHighest</code>) plus <code>surfaceDim</code> and <code>surfaceBright</code>, and deprecated three older roles:</p>
<table>
<thead>
<tr>
<th>Deprecated</th>
<th>Use instead</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>background</code></td>
<td><code>surface</code></td>
</tr>
<tr>
<td><code>onBackground</code></td>
<td><code>onSurface</code></td>
</tr>
<tr>
<td><code>surfaceVariant</code></td>
<td><code>surfaceContainerHighest</code></td>
</tr>
</tbody>
</table>
<p>Components were updated to match: a <code>Card</code> uses <code>surfaceContainerLow</code>, a <code>NavigationBar</code> uses <code>surfaceContainer</code>, dialogs use <code>surfaceContainerHigh</code>. The <a href="https://docs.flutter.dev/release/breaking-changes/new-color-scheme-roles">3.22 breaking change note</a> has the full mapping. Run <code>dart fix --apply</code> and it will rename most of the deprecated usages for you.</p>
<p>In practice, “container” here means “a background that sits on top of <code>surface</code>”. Pick a higher container for things that should stand out more:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#79B8FF">Container</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">  color</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Theme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">of</span><span style="color:#E1E4E8">(context).colorScheme.surfaceContainerHigh,</span></span>
<span class="line"><span style="color:#E1E4E8">  padding</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> EdgeInsets</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">all</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">16</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  child</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Text</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#9ECBFF">    'Order summary'</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">    style</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> TextStyle</span><span style="color:#E1E4E8">(color</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Theme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">of</span><span style="color:#E1E4E8">(context).colorScheme.onSurface),</span></span>
<span class="line"><span style="color:#E1E4E8">  ),</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span></code></pre>
<h2 id="read-colours-from-the-theme-not-from-colors">Read colours from the theme, not from Colors</h2>
<p>This is the habit that makes dark mode work for free. Anywhere you’d type <code>Colors.blue</code> or <code>Color(0xFF...)</code> inside a widget, read the role instead:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#6A737D">// Bad: fixed colours, broken in dark mode</span></span>
<span class="line"><span style="color:#79B8FF">Text</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Total'</span><span style="color:#E1E4E8">, style</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> TextStyle</span><span style="color:#E1E4E8">(color</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Colors</span><span style="color:#E1E4E8">.black87));</span></span>
<span class="line"><span style="color:#79B8FF">Icon</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Icons</span><span style="color:#E1E4E8">.check, color</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Colors</span><span style="color:#E1E4E8">.blue);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// Good: follows the theme in light and dark</span></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> colors </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Theme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">of</span><span style="color:#E1E4E8">(context).colorScheme;</span></span>
<span class="line"><span style="color:#79B8FF">Text</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Total'</span><span style="color:#E1E4E8">, style</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> TextStyle</span><span style="color:#E1E4E8">(color</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> colors.onSurface));</span></span>
<span class="line"><span style="color:#79B8FF">Icon</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">Icons</span><span style="color:#E1E4E8">.check, color</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> colors.primary);</span></span></code></pre>
<p>Better still, often you don’t need a colour at all. A <code>Text</code> with no colour already uses <code>onSurface</code> through the default text theme, and a <code>FilledButton</code> already uses <code>primary</code> and <code>onPrimary</code>. Setting colours by hand on Material widgets is how themes drift apart.</p>
<p>For text styles, do the same with <code>Theme.of(context).textTheme</code>:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#79B8FF">Text</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Checkout'</span><span style="color:#E1E4E8">, style</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Theme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">of</span><span style="color:#E1E4E8">(context).textTheme.titleLarge);</span></span></code></pre>
<h2 id="component-themes">Component themes</h2>
<p><code>ColorScheme</code> sets the colours. Component themes set shape, padding and which roles a widget uses, once, for the whole app. Keep these small; every override is something you maintain.</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#79B8FF">ThemeData</span><span style="color:#B392F0"> buildTheme</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">ColorScheme</span><span style="color:#E1E4E8"> colors) {</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#79B8FF"> ThemeData</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">    colorScheme</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> colors,</span></span>
<span class="line"><span style="color:#E1E4E8">    appBarTheme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> AppBarTheme</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">      backgroundColor</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> colors.surface,</span></span>
<span class="line"><span style="color:#E1E4E8">      foregroundColor</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> colors.onSurface,</span></span>
<span class="line"><span style="color:#E1E4E8">      centerTitle</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> false</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">    ),</span></span>
<span class="line"><span style="color:#E1E4E8">    filledButtonTheme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> FilledButtonThemeData</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">      style</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> FilledButton</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">styleFrom</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">        minimumSize</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> Size</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromHeight</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">48</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">        shape</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> RoundedRectangleBorder</span><span style="color:#E1E4E8">(borderRadius</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> BorderRadius</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">circular</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">12</span><span style="color:#E1E4E8">)),</span></span>
<span class="line"><span style="color:#E1E4E8">      ),</span></span>
<span class="line"><span style="color:#E1E4E8">    ),</span></span>
<span class="line"><span style="color:#E1E4E8">    cardTheme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> CardThemeData</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">      color</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> colors.surfaceContainerLow,</span></span>
<span class="line"><span style="color:#E1E4E8">      elevation</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      margin</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> EdgeInsets</span><span style="color:#E1E4E8">.zero,</span></span>
<span class="line"><span style="color:#E1E4E8">      shape</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> RoundedRectangleBorder</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">        borderRadius</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> BorderRadius</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">circular</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">16</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">        side</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> BorderSide</span><span style="color:#E1E4E8">(color</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> colors.outlineVariant),</span></span>
<span class="line"><span style="color:#E1E4E8">      ),</span></span>
<span class="line"><span style="color:#E1E4E8">    ),</span></span>
<span class="line"><span style="color:#E1E4E8">    inputDecorationTheme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> InputDecorationTheme</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">      filled</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      fillColor</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> colors.surfaceContainerHighest,</span></span>
<span class="line"><span style="color:#E1E4E8">      border</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> OutlineInputBorder</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">        borderRadius</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> BorderRadius</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">circular</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">12</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">        borderSide</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> BorderSide</span><span style="color:#E1E4E8">.none,</span></span>
<span class="line"><span style="color:#E1E4E8">      ),</span></span>
<span class="line"><span style="color:#E1E4E8">    ),</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>Then <code>theme: buildTheme(lightScheme)</code> and <code>darkTheme: buildTheme(darkScheme)</code>. Because every value comes from <code>colors</code>, the same function produces a correct dark theme.</p>
<p>A note on types: <code>cardTheme</code> takes a <code>CardThemeData</code> in current Flutter versions (older code used <code>CardTheme</code>). Some other theme parameters are mid-migration to <code>...ThemeData</code> classes too, so if the analyzer complains after an upgrade, check the <a href="https://api.flutter.dev/flutter/material/ThemeData/ThemeData.html">ThemeData constructor</a> for your version.</p>
<h2 id="text-theme-with-your-own-font">Text theme with your own font</h2>
<p>Set the font family once on <code>ThemeData</code>, and the Material 3 type scale (<code>displayLarge</code> down to <code>labelSmall</code>) uses it:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#79B8FF">ThemeData</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">  colorScheme</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> lightScheme,</span></span>
<span class="line"><span style="color:#E1E4E8">  fontFamily</span><span style="color:#F97583">:</span><span style="color:#9ECBFF"> 'Inter'</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">// declared under fonts: in pubspec.yaml</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span></code></pre>
<p>If you use the <code>google_fonts</code> package instead of bundling the font, apply it to the base text theme so sizes and weights stay Material 3’s:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">final</span><span style="color:#F97583"> base</span><span style="color:#F97583"> =</span><span style="color:#79B8FF"> ThemeData</span><span style="color:#E1E4E8">(colorScheme</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> lightScheme);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> theme </span><span style="color:#F97583">=</span><span style="color:#F97583"> base</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">copyWith</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">  textTheme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> GoogleFonts</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">interTextTheme</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">base</span><span style="color:#E1E4E8">.textTheme),</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span></code></pre>
<p>Building on <code>base.textTheme</code> matters. It already has the right colours for the scheme’s brightness, so the same code works in dark mode. For release builds, bundle the font files rather than downloading them at runtime; the <a href="https://pub.dev/packages/google_fonts">google_fonts docs</a> explain how.</p>
<h2 id="brand-colours-that-must-stay-exact">Brand colours that must stay exact</h2>
<p><code>fromSeed</code> is fine until a designer or client says “the primary button must be <code>#E30613</code>”. (To turn a hex value like that into Flutter code, use the <a href="https://neemii.dev/tools/hex-to-flutter-color/">hex to Flutter Color converter</a>.) You have two options.</p>
<h3 id="option-1-generate-then-override-specific-roles">Option 1: generate, then override specific roles</h3>
<p><code>fromSeed</code> accepts any role as a parameter. Generated values fill everything you don’t pass:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#E1E4E8"> brandRed </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFFE30613</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> lightScheme </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> ColorScheme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromSeed</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">  seedColor</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> brandRed,</span></span>
<span class="line"><span style="color:#E1E4E8">  dynamicSchemeVariant</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> DynamicSchemeVariant</span><span style="color:#E1E4E8">.fidelity,</span></span>
<span class="line"><span style="color:#E1E4E8">  primary</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> brandRed,</span></span>
<span class="line"><span style="color:#E1E4E8">  onPrimary</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Colors</span><span style="color:#E1E4E8">.white,</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span></code></pre>
<p>You can do the same afterwards with <code>copyWith</code>, which is useful if the scheme comes from somewhere else:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">final</span><span style="color:#E1E4E8"> scheme </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> ColorScheme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromSeed</span><span style="color:#E1E4E8">(seedColor</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> brandRed)</span></span>
<span class="line"><span style="color:#E1E4E8">    .</span><span style="color:#B392F0">copyWith</span><span style="color:#E1E4E8">(primary</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> brandRed, onPrimary</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Colors</span><span style="color:#E1E4E8">.white);</span></span></code></pre>
<p>The catch: overriding <code>primary</code> doesn’t update anything else. <code>primaryContainer</code>, <code>inversePrimary</code> and <code>surfaceTint</code> still come from the generated palette, and <code>onPrimary</code> is only correct if you set it. Check the contrast of every pair you touch; WCAG asks for at least 4.5:1 for normal text. And decide separately for dark mode. A saturated brand red that works as a light-mode button is often too intense as a dark-mode <code>primary</code>, where the generated lighter tone usually reads better.</p>
<h3 id="option-2-an-explicit-colorscheme">Option 2: an explicit ColorScheme</h3>
<p>If the design system already defines every colour, skip the generator and write the scheme out:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#E1E4E8"> lightScheme </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> ColorScheme</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">  brightness</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Brightness</span><span style="color:#E1E4E8">.light,</span></span>
<span class="line"><span style="color:#E1E4E8">  primary</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFFE30613</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  onPrimary</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFFFFFFFF</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  primaryContainer</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFFFFDAD5</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  onPrimaryContainer</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFF410001</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  secondary</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFF775651</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  onSecondary</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFFFFFFFF</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  error</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFFBA1A1A</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  onError</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFFFFFFFF</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  surface</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFFFFF8F7</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#E1E4E8">  onSurface</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFF231918</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#6A737D">  // Set the rest too: tertiary, surfaceContainer*, outline, inverse roles...</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span></code></pre>
<p>Only <code>brightness</code>, <code>primary</code>, <code>onPrimary</code>, <code>secondary</code>, <code>onSecondary</code>, <code>error</code>, <code>onError</code>, <code>surface</code> and <code>onSurface</code> are required. Every other role falls back to one of those when you leave it out, which is how you end up with cards, nav bars and text fields that are all the same colour as the background. If you go explicit, fill in all the roles for both light and dark.</p>
<p>Writing 34 roles twice by hand is tedious and easy to get wrong. The theme generator I mentioned above can output either version: <code>fromSeed</code> code, or a full explicit <code>ColorScheme</code> for light and dark that you can then edit.</p>
<blockquote>
<p><strong>What I do for client brands:</strong> when a client’s exact brand colour matters, I write the full ColorScheme out explicitly instead of relying on fromSeed. Every role is then a fixed value the client can approve once, and nothing shifts after a Flutter upgrade or when someone changes the seed.</p>
</blockquote>
<h2 id="dynamic-colour-on-android-12">Dynamic colour on Android 12+</h2>
<p>On Android 12 and later, the system generates a colour scheme from the user’s wallpaper. Material 3 apps can use it so they match the rest of the phone. Flutter doesn’t read it on its own; you need the <a href="https://pub.dev/packages/dynamic_color"><code>dynamic_color</code></a> package from the Material team.</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="text"><code><span class="line"><span>flutter pub add dynamic_color</span></span></code></pre>
<p>Wrap <code>MaterialApp</code> in <code>DynamicColorBuilder</code>. It gives you nullable light and dark schemes: <code>null</code> on iOS, web, and Android versions without dynamic colour, so you always need a fallback.</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="dart"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'package:dynamic_color/dynamic_color.dart'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> 'package:flutter/material.dart'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#E1E4E8"> seed </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> Color</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0xFF1565C0</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">class</span><span style="color:#79B8FF"> App</span><span style="color:#F97583"> extends</span><span style="color:#79B8FF"> StatelessWidget</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#79B8FF"> App</span><span style="color:#E1E4E8">({</span><span style="color:#79B8FF">super</span><span style="color:#E1E4E8">.key});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  @override</span></span>
<span class="line"><span style="color:#79B8FF">  Widget</span><span style="color:#B392F0"> build</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">BuildContext</span><span style="color:#E1E4E8"> context) {</span></span>
<span class="line"><span style="color:#F97583">    return</span><span style="color:#79B8FF"> DynamicColorBuilder</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">      builder</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> (</span><span style="color:#79B8FF">ColorScheme</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> lightDynamic, </span><span style="color:#79B8FF">ColorScheme</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> darkDynamic) {</span></span>
<span class="line"><span style="color:#F97583">        final</span><span style="color:#E1E4E8"> light </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> lightDynamic </span><span style="color:#F97583">??</span><span style="color:#79B8FF"> ColorScheme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromSeed</span><span style="color:#E1E4E8">(seedColor</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> seed);</span></span>
<span class="line"><span style="color:#F97583">        final</span><span style="color:#E1E4E8"> dark </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> darkDynamic </span><span style="color:#F97583">??</span></span>
<span class="line"><span style="color:#79B8FF">            ColorScheme</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">fromSeed</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">              seedColor</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> seed,</span></span>
<span class="line"><span style="color:#E1E4E8">              brightness</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> Brightness</span><span style="color:#E1E4E8">.dark,</span></span>
<span class="line"><span style="color:#E1E4E8">            );</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">        return</span><span style="color:#79B8FF"> MaterialApp</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#E1E4E8">          theme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> ThemeData</span><span style="color:#E1E4E8">(colorScheme</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> light),</span></span>
<span class="line"><span style="color:#E1E4E8">          darkTheme</span><span style="color:#F97583">:</span><span style="color:#79B8FF"> ThemeData</span><span style="color:#E1E4E8">(colorScheme</span><span style="color:#F97583">:</span><span style="color:#E1E4E8"> dark),</span></span>
<span class="line"><span style="color:#E1E4E8">          home</span><span style="color:#F97583">:</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> HomePage</span><span style="color:#E1E4E8">(),</span></span>
<span class="line"><span style="color:#E1E4E8">        );</span></span>
<span class="line"><span style="color:#E1E4E8">      },</span></span>
<span class="line"><span style="color:#E1E4E8">    );</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre>
<p>Two practical points:</p>
<ul>
<li><strong>Brand apps usually shouldn’t use it.</strong> Dynamic colour replaces your brand palette with the user’s wallpaper. That’s great for utilities, notes or reader apps, and wrong for a bank or a food delivery app whose identity is its colour. Ask before adding it.</li>
<li><strong>Keep semantic colours yours.</strong> If you have custom colours like “success green” or a status colour, the package’s <code>harmonized()</code> extension shifts their hue slightly towards the dynamic primary so they don’t clash, without losing their meaning.</li>
</ul>
<p>Also check the result on a real device. Depending on the package and Flutter versions, a dynamic scheme may not fill every one of the newer surface container roles the way <code>fromSeed</code> does. If cards and backgrounds look identical, one workaround is to rebuild the scheme from the dynamic primary: <code>ColorScheme.fromSeed(seedColor: lightDynamic.primary)</code>.</p>
<h2 id="common-mistakes">Common mistakes</h2>
<p><strong>Hard-coded colours in widgets.</strong> <code>Colors.white</code> backgrounds and <code>Colors.black</code> text look fine in light mode and break in dark mode. Search the codebase for <code>Colors.</code> and <code>Color(0x</code> outside your theme file.</p>
<p><strong>A light scheme in the dark theme.</strong> <code>darkTheme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: seed))</code> gives you a light scheme in dark mode. Pass <code>brightness: Brightness.dark</code>.</p>
<p><strong>Expecting <code>primary</code> to equal the seed.</strong> It won’t with the default variant. Use <code>fidelity</code>, override <code>primary</code>, or go explicit.</p>
<p><strong>Overriding <code>primary</code> without <code>onPrimary</code>.</strong> If you change the background role, you own the contrast of its <code>on</code> partner.</p>
<p><strong>Using <code>primary</code> for everything.</strong> If every card, header and chip is <code>primary</code>, nothing stands out. Most of the screen should be <code>surface</code> and <code>surfaceContainer*</code>; keep <code>primary</code> for the actions that matter.</p>
<p><strong>Still using <code>background</code> and <code>surfaceVariant</code>.</strong> They’re deprecated. Move to <code>surface</code> and <code>surfaceContainerHighest</code>, and remember that components now use the container roles, so a custom explicit scheme without them looks flat.</p>
<p><strong>Pairing roles wrongly.</strong> Text on <code>primaryContainer</code> is <code>onPrimaryContainer</code>. Text on <code>surfaceContainerHigh</code> is <code>onSurface</code> or <code>onSurfaceVariant</code>. There’s no <code>onSurfaceContainer</code>.</p>
<p><strong>Building the scheme in <code>build()</code>.</strong> Generating a <code>ColorScheme</code> on every rebuild of <code>MaterialApp</code> is wasted work. Create it once (a top-level <code>final</code>, or cached in your state) unless it really depends on changing input like dynamic colour.</p>
<h2 id="summary">Summary</h2>
<ul>
<li>Material 3 is the default since Flutter 3.16. Start from <code>ColorScheme.fromSeed</code>.</li>
<li><code>fromSeed</code> builds tonal palettes in HCT and picks tones for contrast, so <code>primary</code> usually differs from the seed. <code>dynamicSchemeVariant: DynamicSchemeVariant.fidelity</code> keeps it closer.</li>
<li>Build light and dark schemes from the same seed and let <code>themeMode</code> choose.</li>
<li>Use roles by meaning: <code>primary</code> for key actions, containers for softer emphasis, <code>surface</code> and <code>surfaceContainer*</code> for backgrounds, and always the matching <code>on</code> colour for content.</li>
<li>Read colours from <code>Theme.of(context).colorScheme</code>, never from <code>Colors</code> inside widgets.</li>
<li>For exact brand colours, override specific roles or write an explicit <code>ColorScheme</code> for both brightnesses.</li>
<li>Use dynamic colour only when the app doesn’t depend on a brand palette.</li>
</ul>
<p>To try seeds and variants without running the app, use the free <a href="https://neemii.dev/tools/flutter-theme-generator/">Flutter Material 3 theme generator</a>. And if you’d like a Flutter app built with a theme that works in light mode, dark mode and on brand from day one, see my <a href="https://neemii.dev/services/flutter-app-development/">Flutter app development service</a> or <a href="https://neemii.dev/#contact">tell me about your project</a>.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-flutter-material-3-theme-colorscheme.png" type="image/png" length="0" />
    </item>
    <item>
      <title>Mobile App Development Cost in Pakistan (2026): Real Prices</title>
      <link>https://neemii.dev/blog/mobile-app-development-cost-pakistan/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/mobile-app-development-cost-pakistan/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>What an app costs to build in Pakistan in 2026, in PKR and USD: freelancer vs software house rates, simple to complex price bands, and the running costs after launch.</description>
      <content:encoded><![CDATA[<p>If you are a founder in Lahore, Karachi or Islamabad, or a business in Dubai or the US looking at Pakistani developers, you have probably seen app quotes that range from “PKR 80,000” to “$80,000” for what sounds like the same idea. Both can be honest. They are usually not quoting the same app.</p>
<p>This guide gives you real price bands in PKR and USD, explains where they come from, and shows what to check before you sign. Every hard number links to a source or is clearly labelled as an <strong>estimate</strong>.</p>
<blockquote>
<p><strong>Quick answer:</strong> In 2026, a simple mobile app built in Pakistan costs roughly <strong>PKR 1–6 million ($4,000–$22,000)</strong>, a medium app with payments and an admin panel roughly <strong>PKR 2.5–14 million ($9,000–$50,000)</strong>, and a complex app such as ride-hailing or a marketplace roughly <strong>PKR 6–35 million ($21,000–$125,000)</strong>. Freelancers sit at the lower end of each range, software houses at the higher end. These are estimates from typical hours × Pakistani rates, not fixed quotes.</p>
</blockquote>
<p><strong>Exchange rate used:</strong> about <strong>PKR 277 per USD</strong>, based on the interbank close of <a href="https://mettisglobal.news/RKR-gains-USD-falls-to-Rs27662-64925">PKR 276.62 on November 11, 2026</a>. PKR figures are rounded. If the rupee moves, the USD figures are the more stable reference, because most Pakistani developers and software houses price foreign work in dollars.</p>
<h2 id="how-the-price-is-calculated">How the price is calculated</h2>
<p>Every app quote, whether it is written that way or not, comes down to <strong>hours × hourly rate</strong>, plus running costs after launch.</p>
<p>The hours come from the scope. I use the same planning ranges as in my global guide to <a href="https://neemii.dev/blog/flutter-app-development-cost/">Flutter app development cost</a>. They are <strong>assumptions</strong> for a Flutter app on iOS and Android, including design, backend, testing and store launch:</p>
<ul>
<li><strong>Simple app: 250–450 hours.</strong> 5–10 screens, login, profile, content lists, a managed backend such as Firebase, push notifications, no payments.</li>
<li><strong>Medium app: 600–1,000 hours.</strong> 15–30 screens, two user roles, a web admin panel, payments or subscriptions, and one heavier feature such as maps, chat or a third-party API.</li>
<li><strong>Complex app: 1,400–2,500 hours.</strong> 30+ screens, several user roles, real-time chat or live location, a custom backend, a full admin panel and several integrations.</li>
</ul>
<p>The rate depends on who builds it.</p>
<h2 id="hourly-rates-in-pakistan">Hourly rates in Pakistan</h2>
<p>There is no official, Pakistan-only survey of mobile developer rates. These are the best public data points I could find:</p>
<table>
<thead>
<tr>
<th>Who</th>
<th>Typical rate</th>
<th>Source</th>
</tr>
</thead>
<tbody>
<tr>
<td>Freelance Flutter developers (public profiles)</td>
<td>mostly $10–$30/h, some lower or higher</td>
<td>Sample of Upwork profiles in <a href="https://www.upwork.com/hire/mobile-app-developers/pk/karachi/">Karachi</a>, <a href="https://www.upwork.com/hire/flutter-freelancers/pk/rawalpindi/">Rawalpindi</a> and <a href="https://www.upwork.com/hire/mobile-app-developers/pk/">other cities</a>, November 2026</td>
</tr>
<tr>
<td>Software houses on Clutch (Pakistan)</td>
<td>most list $25–$49/h; a few $50–$99/h</td>
<td><a href="https://clutch.co/pk/app-developers">Clutch Pakistan app developers</a>, November 2026</td>
</tr>
<tr>
<td>South and Southeast Asia, outsourcing firms</td>
<td>$24–$31 junior, $31–$41 senior</td>
<td><a href="https://www.accelerance.com/blog/2026-outsourcing-rate-trends-asia-europe-latam">Accelerance, Nov 2025</a></td>
</tr>
</tbody>
</table>
<p>A few notes:</p>
<ul>
<li><strong>Freelance rates are self-reported.</strong> A profile rate is what someone asks for, not what clients pay on average. Very low rates ($5–$9/h) exist, usually from beginners.</li>
<li><strong>Clutch shows the established end of the market.</strong> Many smaller software houses in Lahore, Karachi and Islamabad charge local clients less, but they do not publish rates, so I cannot give you a sourced number for them.</li>
<li><strong>City matters less than experience.</strong> I found no reliable data showing a clear rate gap between Lahore, Karachi and Islamabad.</li>
</ul>
<p>For the tables below I use <strong>$15–$30/h for an experienced freelancer</strong> and <strong>$25–$50/h for a software house</strong>. Both are <strong>estimates</strong> based on the sources above.</p>
<h2 id="cost-table-freelancer-vs-software-house">Cost table: freelancer vs software house</h2>
<p>Hours × rate, rounded. PKR at about 277 per USD. These are <strong>estimates</strong>, not quotes.</p>
<table>
<thead>
<tr>
<th>App size</th>
<th>Hours</th>
<th>Freelancer ($15–$30/h)</th>
<th>Software house ($25–$50/h)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Simple</td>
<td>250–450</td>
<td>$3,750–$13,500 (PKR 1.0–3.7M)</td>
<td>$6,250–$22,500 (PKR 1.7–6.2M)</td>
</tr>
<tr>
<td>Medium</td>
<td>600–1,000</td>
<td>$9,000–$30,000 (PKR 2.5–8.3M)</td>
<td>$15,000–$50,000 (PKR 4.2–13.9M)</td>
</tr>
<tr>
<td>Complex</td>
<td>1,400–2,500</td>
<td>$21,000–$75,000 (PKR 5.8–20.8M)</td>
<td>$35,000–$125,000 (PKR 9.7–34.6M)</td>
</tr>
</tbody>
</table>
<p>One caveat: <strong>a single freelancer rarely builds a complex app alone.</strong> 2,500 hours is more than a year of full-time work for one person, so for complex apps the freelancer column usually means a small, coordinated team of freelancers.</p>
<blockquote>
<p><strong>My own pricing:</strong> a typical Flutter MVP with me costs about $5,000–$8,000 (roughly PKR 1.4–2.2 million). That sits inside the simple-to-medium freelancer range above, because I work solo and keep an MVP to the features it needs to launch. One real example: a crime-reporting system for a police service, with two apps, a backend and a website, came in at roughly $5,000–$8,000. That was possible because the scope was clear before development started, and both apps shared one backend and one design system.</p>
</blockquote>
<blockquote>
<p><strong>How I quote:</strong> I work in three fixed-price packages, paid in milestones (for example 30/40/30), with prices set by where the client is.</p>
<table>
<thead>
<tr>
<th>Package</th>
<th>What it usually covers</th>
<th>Pakistan (PKR)</th>
<th>International (USD)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Basic</td>
<td>Simple app, up to about 10 screens, Firebase, iOS and Android</td>
<td>PKR 3.5–6 lakh</td>
<td>$3,000–$5,000</td>
</tr>
<tr>
<td>Standard</td>
<td>About 15–25 screens, login, payments or chat, basic admin</td>
<td>PKR 8–14 lakh</td>
<td>$5,000–$8,000</td>
</tr>
<tr>
<td>Advanced</td>
<td>Custom backend, real-time features, admin panel, AI features</td>
<td>PKR 15 lakh+</td>
<td>$10,000+</td>
</tr>
</tbody>
</table>
<p>In every package the client owns the code and the store accounts, and I fix bugs free for the first month after launch.</p>
</blockquote>
<p>If you want a quick number for your own feature list, the free <a href="https://neemii.dev/tools/app-cost-calculator/">app cost calculator</a> uses the same hour assumptions and lets you pick your region.</p>
<h2 id="what-drives-the-price-up-or-down">What drives the price up (or down)</h2>
<h3 id="features-not-screens">Features, not screens</h3>
<p>A “screen” can take two hours or two weeks. A static profile page is cheap. A checkout screen with a local payment gateway, failed-payment handling and receipts is not. When you compare quotes, compare the feature list, not the screen count.</p>
<h3 id="the-admin-panel">The admin panel</h3>
<p>Almost every business app needs a place to manage users, orders and content. Founders often forget it when budgeting, and it can be 20–30% of the work. If a quote does not mention an admin panel, ask whether one is included.</p>
<h3 id="local-integrations">Local integrations</h3>
<p>Apps for the Pakistani market often need local payment options such as JazzCash, Easypaisa or bank card gateways, SMS OTP for phone login, and Urdu or right-to-left text support. Each one adds setup, testing and edge cases. Apps for UAE or US users have their own equivalents. None of this is hard, but it is not free.</p>
<h3 id="real-time-features">Real-time features</h3>
<p>Live location (ride-hailing, delivery) and chat are among the most expensive features to build well, and always take more hours than the screen count suggests.</p>
<h3 id="scope-changes">Scope changes</h3>
<p>The most expensive thing in any project is changing direction halfway through. A short, paid discovery phase with wireframes and a written feature list almost always pays for itself.</p>
<h2 id="flutter-vs-two-native-apps">Flutter vs two native apps</h2>
<p>With native development, you build two separate apps: one in Swift for iOS and one in Kotlin for Android. With Flutter, one codebase runs on both.</p>
<p>That does not halve the total cost, because design, backend, admin panel and project management are shared either way. My planning <strong>assumption</strong> is that two native apps need roughly <strong>1.6–1.9× the client-side hours</strong> of one Flutter app, while backend and design hours stay the same. Maintenance is also cheaper with one codebase: every bug fix and OS update is done once.</p>
<p>For most startups building for both Android and iOS, Flutter is the cost-effective default. Native still makes sense if you only need one platform, or if the app depends heavily on platform-specific features like watch apps, widgets or unusual hardware SDKs.</p>
<h2 id="hidden-and-running-costs">Hidden and running costs</h2>
<p>The build is not the whole bill. Plan for these from the start.</p>
<h3 id="store-fees">Store fees</h3>
<ul>
<li><strong>Google Play developer account:</strong> <a href="https://support.google.com/googleplay/android-developer/answer/6112435">$25, one-time</a>, about PKR 6,900.</li>
<li><strong>Apple Developer Program:</strong> <a href="https://developer.apple.com/programs/whats-included/">$99 per year</a>, about PKR 27,400 a year.</li>
<li><strong>Store commission on digital sales:</strong> if you sell subscriptions or digital content inside the app, Apple’s <a href="https://developer.apple.com/app-store/small-business-program/">Small Business Program</a> and <a href="https://support.google.com/googleplay/android-developer/answer/112622">Google Play</a> generally take 15% for smaller developers. Physical goods and services, like food or rides, usually go through your own payment gateway instead.</li>
</ul>
<p>Pay these with a card in <strong>your own name or your company’s name</strong>. More on that below.</p>
<h3 id="servers-and-third-party-services">Servers and third-party services</h3>
<p>Hosting, database, storage, SMS, maps and AI APIs are billed monthly, usually by usage. <a href="https://firebase.google.com/pricing">Firebase</a> and <a href="https://mapsplatform.google.com/pricing/">Google Maps Platform</a> both have free tiers that often cover an early MVP, and costs grow with users. A domain name and a simple website for your privacy policy and support page are small yearly costs, but they are required, so do not skip them. Note that these services bill in USD, so your monthly cost in PKR moves with the exchange rate.</p>
<p>Ask your developer for an estimated monthly running cost at 1,000, 10,000 and 100,000 users before you agree on the architecture.</p>
<h3 id="maintenance">Maintenance</h3>
<p>A common planning rule is <strong>15–20% of the build cost per year</strong> for maintenance. It is a rule of thumb, not a measured fact (the global cost guide linked above explains where it comes from). On a PKR 2 million app, that means budgeting roughly PKR 300,000–400,000 a year.</p>
<p>This is not optional. Apple and Google raise their requirements every year. For example, from August 31, 2026, new apps and updates on Google Play <a href="https://developer.android.com/google/play/requirements/target-sdk">must target Android 16 (API level 36)</a>. An app nobody updates eventually cannot ship a bug fix.</p>
<h3 id="the-cost-that-surprises-most-sms-otp">The cost that surprises most: SMS OTP</h3>
<p>Phone-number login sends an SMS for every sign-in, and international SMS APIs charge a lot for Pakistani numbers. Twilio lists <a href="https://textbee.dev/sms-pricing/twilio/pk">$0.4734 per SMS to Pakistan</a>, and Plivo lists <a href="https://www.plivo.com/sms/pricing/pk/">$0.26–$0.47 depending on the network</a>. That is roughly $260–$470 (about PKR 72,000–130,000) for every 1,000 OTP messages. At 1,000 logins a day, it adds up to around $7,800–$14,000 a month for login messages alone.</p>
<p>Ways to keep it down:</p>
<ul>
<li>Ask local SMS aggregators for an A2P (application-to-person) rate card. Local routes are usually cheaper than international APIs, but prices are not published reliably, so compare written quotes.</li>
<li>Keep users signed in, so they only need an OTP on a new device.</li>
<li>Offer email, Google or Apple sign-in next to phone login.</li>
<li>Firebase’s <a href="https://firebase.google.com/docs/phone-number-verification/pricing">Phone Number Verification</a> checks the number through the carrier without an SMS. It lists about $0.10 per successful verification in Pakistan, and currently supports one Pakistani network, so check coverage before you rely on it.</li>
</ul>
<p>Prices change often, so treat these as examples from November 2026, not quotes.</p>
<h2 id="freelancer-vs-software-house-vs-in-house-in-pakistan">Freelancer vs software house vs in-house in Pakistan</h2>
<p>There is no single right answer. Here is an honest comparison.</p>
<h3 id="freelancer">Freelancer</h3>
<p><strong>Pros:</strong> lowest cost, direct contact with the person writing the code, fast decisions, and flexible scope.
<strong>Cons:</strong> one person is a single point of failure (illness, other clients, disappearing). Skills vary hugely, and many freelancers are strong in the app but weaker in backend, design or DevOps.
<strong>Best for:</strong> MVPs and simple-to-medium apps with a clear scope, when you can verify the freelancer’s past live apps.</p>
<h3 id="software-house">Software house</h3>
<p><strong>Pros:</strong> a full team (designer, backend, QA, project manager), more continuity if someone leaves, and the capacity for complex apps.
<strong>Cons:</strong> higher rates, and you often talk to a project manager rather than the developer. On smaller budgets, your project may be handed to junior staff.
<strong>Best for:</strong> complex apps, tight deadlines, and companies that need contracts, invoices and a team behind the product.</p>
<h3 id="in-house-developer">In-house developer</h3>
<p>Salaries are the reason many local companies consider this. According to <a href="https://pk.indeed.com/career/mobile-developer/salaries">Indeed Pakistan</a>, the average mobile developer salary is <strong>about PKR 98,700 per month</strong> (73 salaries reported, updated November 4, 2026). <a href="https://www.payscale.com/research/PK/Job=Flutter_Developer/Salary">Payscale</a> puts the median Flutter developer salary at <strong>PKR 550,000 per year</strong> (89 profiles, updated August 2026). Senior developers in Lahore and Karachi earn well above these averages.</p>
<p><strong>Pros:</strong> full control, the knowledge stays in your company, good value if you have years of continuous work.
<strong>Cons:</strong> one developer cannot cover design, backend, iOS release and QA alone. You also pay for hiring, equipment, office or remote setup, benefits and management time. And if that one developer leaves, you are back to square one.
<strong>Best for:</strong> companies whose app is their core product and who already have product ownership in-house.</p>
<p>A sensible path: build the first version externally, then hire in-house once the product is proven.</p>
<h2 id="hiring-from-pakistan-as-a-uae-or-us-client">Hiring from Pakistan as a UAE or US client</h2>
<p>Hiring from Pakistan can work very well for UAE and US businesses. Here is what to check.</p>
<h3 id="check-live-apps-not-screenshots">Check live apps, not screenshots</h3>
<p>Ask for links to apps that are live on the App Store and Google Play, and download them. Ask what exactly the person or team built in each one. Dribbble shots and demo videos are not proof that someone can ship.</p>
<h3 id="you-own-the-accounts-and-the-code">You own the accounts and the code</h3>
<p>This is the single most important point:</p>
<ul>
<li><strong>Store accounts:</strong> your Apple Developer and Google Play accounts should be in <strong>your</strong> or your company’s name. Add the developer as a team member. Never publish under the developer’s personal account, because moving an app later is slow and sometimes painful.</li>
<li><strong>Code:</strong> the source code should live in a Git repository <strong>you</strong> own (GitHub, GitLab or Bitbucket), with the developer invited. The contract should state that you own the code once paid.</li>
<li><strong>Backend and services:</strong> Firebase, cloud hosting, domain and third-party API accounts should be created under your email, with billing on your card.</li>
</ul>
<h3 id="pay-by-milestones">Pay by milestones</h3>
<p>Split the project into milestones tied to working builds you can install, not to time passed. Common payment routes are the freelance platform’s escrow (Upwork, for example), Payoneer, or a direct bank wire. Agree on the currency up front.</p>
<h3 id="red-flags-in-cheap-quotes">Red flags in cheap quotes</h3>
<ul>
<li><strong>A fixed price with no feature list.</strong> If the scope is not written down, every disagreement becomes a “change request.”</li>
<li><strong>No mention of backend, admin panel or testing.</strong> A quote that covers “the app” alone is often only the screens.</li>
<li><strong>“Ready-made script” or “clone” offers</strong> at a fraction of the price. These can work for some projects, but ask who owns the code, what licence it has, and who will maintain it.</li>
<li><strong>No live apps they can show.</strong></li>
<li><strong>The developer wants to publish under their own store account</strong> or keep the code until “final payment” with no repository access during the project.</li>
<li><strong>A timeline that is impossible for the scope.</strong> A medium app in two weeks usually means a demo, not a product.</li>
</ul>
<h2 id="faq">FAQ</h2>
<div class="faq-list">
<details class="faq" name="faq">
<summary>How much does it cost to make an app in Pakistan?</summary>
<p>As an <strong>estimate</strong>, a simple app costs about PKR 1–6 million ($4,000–$22,000), a medium app about PKR 2.5–14 million ($9,000–$50,000), and a complex app about PKR 6–35 million ($21,000–$125,000). The low end of each range is an experienced freelancer, the high end a software house. Your exact cost depends on features, backend and integrations.</p>
</details>
<details class="faq" name="faq">
<summary>What is the Android app development cost in Pakistan?</summary>
<p>An Android-only app is somewhat cheaper than an app for both platforms, because there is no iOS build, testing or App Store review. Backend, design and admin panel cost the same either way. With Flutter, adding iOS later costs much less than building a second native app, so many founders launch on Android first with Flutter and add iOS when they are ready.</p>
</details>
<details class="faq" name="faq">
<summary>Can I get an app made for PKR 100,000?</summary>
<p>You can get something for that money, usually a template app, a very simple informational app or a reskinned “clone” script. For a custom app with user accounts, a backend and an admin panel, the hour estimates above suggest that budget is far too low. Be careful with quotes that seem to promise a full product at that price.</p>
</details>
<details class="faq" name="faq">
<summary>How much does it cost to maintain an app every year?</summary>
<p>A common planning figure is 15–20% of the build cost per year, plus store fees ($99 a year for Apple, $25 once for Google Play) and server costs that grow with your users. Budget for at least one update a year to meet new Apple and Google requirements.</p>
</details>
</div>
<h2 id="get-a-real-estimate">Get a real estimate</h2>
<p>The numbers above are ranges. For your own app, the fastest next step is the free <a href="https://neemii.dev/tools/app-cost-calculator/">app cost calculator</a>. If you want a proper quote, see how I work on <a href="https://neemii.dev/services/flutter-app-development/">Flutter app development</a>.</p>
<p>Or <a href="https://neemii.dev/#contact">send me your idea</a>. I am Muhammad Naeem, a Flutter developer in Lahore with 3+ years of experience and 10+ apps live, building iOS and Android apps for startups in Pakistan, the UAE and worldwide. Tell me what the app should do, and I will reply with a scope, a timeline and a price range in PKR or USD, free and with no obligation.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-mobile-app-development-cost-pakistan.png" type="image/png" length="0" />
    </item>
    <item>
      <title>Publish a Flutter App to the App Store and Google Play (2026)</title>
      <link>https://neemii.dev/blog/publish-flutter-app-app-store-google-play/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/publish-flutter-app-app-store-google-play/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>A practical 2026 release checklist for Flutter apps: current SDK and API level rules, signing, versioning, privacy forms, review times and common rejections.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> To publish a Flutter app you need an Apple Developer account and a Google Play Console account, a unique bundle ID, a version bump for every upload, a signed Android App Bundle (.aab) and an iOS build uploaded through Xcode and TestFlight. Both stores need a privacy policy, accurate privacy forms and, for apps with accounts, in-app account deletion. New personal Google Play accounts must run a closed test with 12 testers for 14 days before production.</p>
<p>Building the app is only half the work. Getting it through Apple’s App Review and Google Play’s review is a separate project with its own rules, forms and deadlines, and those rules change every year. This post is the checklist I use to publish a Flutter app on both stores, updated for the requirements in force in late 2026.</p>
<p>Every requirement below links to the official page it comes from. Store rules change often, so check the linked page before you rely on a date.</p>
<h2 id="before-you-start-accounts-and-identifiers">Before you start: accounts and identifiers</h2>
<p>You need two paid accounts before you can publish anything:</p>
<ul>
<li>An <strong>Apple Developer Program</strong> membership, to create App IDs, sign the iOS build and use App Store Connect.</li>
<li>A <strong>Google Play Console</strong> developer account.</li>
</ul>
<p>Decide early whether the app is published under the client’s own accounts or yours. I recommend the client’s accounts. The listing, reviews and revenue then belong to the business, and changing developers later does not mean transferring the app.</p>
<p>Then pick identifiers that you will never change:</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" disabled> iOS <strong>Bundle ID</strong> (for example <code>com.company.app</code>), registered as an Explicit App ID in the Apple Developer portal</li>
<li class="task-list-item"><input type="checkbox" disabled> Android <strong>application ID</strong>, normally the same string</li>
<li class="task-list-item"><input type="checkbox" disabled> App name, short description and support email</li>
</ul>
<h3 id="the-google-play-closed-testing-rule">The Google Play closed-testing rule</h3>
<p>If the Play account is a <strong>personal</strong> account created after November 13, 2023, you cannot go straight to production. Google requires a <a href="https://support.google.com/googleplay/android-developer/answer/14151465">closed test with at least 12 testers who stay opted in continuously for 14 days</a>. Only then can you click “Apply for production” on the Play Console dashboard. Google says that review of the production access application usually takes seven days or less.</p>
<p>Plan for this. In practice it adds three weeks or more to the first Android launch: 14 days of testing, a production access review, then the normal app review. Start the closed test as soon as you have a stable build, not the week before launch. The application form asks how engaged your testers were and what you changed based on their feedback, so recruit people who will actually use the app.</p>
<h2 id="versioning-in-pubspecyaml">Versioning in pubspec.yaml</h2>
<p>Flutter keeps both platforms’ version numbers in one line of <code>pubspec.yaml</code>:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="yaml"><code><span class="line"><span style="color:#85E89D">version</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">1.4.0+12</span></span></code></pre>
<ul>
<li><code>1.4.0</code> is the version users see. It becomes <code>versionName</code> on Android and <code>CFBundleShortVersionString</code> on iOS.</li>
<li><code>12</code> is the build number. It becomes <code>versionCode</code> on Android and <code>CFBundleVersion</code> on iOS.</li>
</ul>
<p>Both stores reject an upload that reuses a build number, so increase the number after <code>+</code> on every upload, including test builds. You can also override both at build time with <code>--build-name</code> and <code>--build-number</code>, as described in the <a href="https://docs.flutter.dev/deployment/android">Flutter Android release docs</a> and <a href="https://docs.flutter.dev/deployment/ios">iOS release docs</a>.</p>
<h2 id="android-release-checklist">Android release checklist</h2>
<h3 id="1-target-the-right-api-level">1. Target the right API level</h3>
<p>From <a href="https://developer.android.com/google/play/requirements/target-sdk">August 31, 2026, new apps and app updates must target Android 16 (API level 36) or higher</a> to be submitted to Google Play. Wear OS, Automotive, TV and XR apps have lower minimums. Existing apps that target API 34 or lower stop being available to new users on newer Android versions. Google offered an extension to November 1, 2026 for developers who requested it.</p>
<p>In a Flutter project, <code>android/app/build.gradle.kts</code> normally reads <code>targetSdk = flutter.targetSdkVersion</code>. Check what that resolves to with your Flutter version. If it is below 36, upgrade Flutter or set the value yourself, then test, because each Android version brings <a href="https://developer.android.com/about/versions/16/behavior-changes-16">behavior changes</a> for apps that target it.</p>
<h3 id="2-create-an-upload-key-and-sign-the-build">2. Create an upload key and sign the build</h3>
<p>Google Play signs the APKs that users download with an <strong>app signing key</strong> that Google holds (<a href="https://support.google.com/googleplay/android-developer/answer/9842756">Play App Signing</a>). You sign your uploads with a separate <strong>upload key</strong> that you keep. If you lose the upload key, Google can reset it. If you manage the app signing key yourself and lose it, it cannot be reset. That is a good reason to let Google hold it.</p>
<p>Create the upload keystore (macOS/Linux, from the <a href="https://docs.flutter.dev/deployment/android">Flutter docs</a>):</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">keytool</span><span style="color:#79B8FF"> -genkey</span><span style="color:#79B8FF"> -v</span><span style="color:#79B8FF"> -keystore</span><span style="color:#9ECBFF"> ~/upload-keystore.jks</span><span style="color:#79B8FF"> -keyalg</span><span style="color:#9ECBFF"> RSA</span><span style="color:#79B8FF"> \</span></span>
<span class="line"><span style="color:#79B8FF">        -storetype</span><span style="color:#9ECBFF"> JKS</span><span style="color:#79B8FF"> -keysize</span><span style="color:#79B8FF"> 2048</span><span style="color:#79B8FF"> -validity</span><span style="color:#79B8FF"> 10000</span><span style="color:#79B8FF"> -alias</span><span style="color:#9ECBFF"> upload</span></span></code></pre>
<p>Then create <code>android/key.properties</code> with the store password, key password, alias and keystore path, and reference it from a <code>release</code> signing config in <code>android/app/build.gradle.kts</code>. The Flutter docs show the exact Gradle code.</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" disabled> Keystore and <code>key.properties</code> are <strong>not</strong> committed to git</li>
<li class="task-list-item"><input type="checkbox" disabled> Keystore and passwords are backed up somewhere the client can access</li>
<li class="task-list-item"><input type="checkbox" disabled> The release build type uses the release signing config, not debug</li>
</ul>
<h3 id="3-build-an-app-bundle-not-an-apk">3. Build an app bundle, not an APK</h3>
<p><a href="https://developer.android.com/guide/app-bundle">New apps must be published as an Android App Bundle (.aab)</a> since August 2021. Play generates optimized APKs for each device from it.</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> build</span><span style="color:#9ECBFF"> appbundle</span></span>
<span class="line"><span style="color:#6A737D"># output: build/app/outputs/bundle/release/app.aab</span></span></code></pre>
<p>With obfuscation (recommended, see below):</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> build</span><span style="color:#9ECBFF"> appbundle</span><span style="color:#79B8FF"> --obfuscate</span><span style="color:#79B8FF"> --split-debug-info=build/symbols/android</span></span></code></pre>
<h3 id="4-fill-in-the-play-console-forms">4. Fill in the Play Console forms</h3>
<p>Most first-release delays on Android come from forms, not code. Before you can send the app for review, complete:</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" disabled> <strong>Privacy policy URL</strong>. <a href="https://support.google.com/googleplay/android-developer/answer/10787469">Every app needs one</a>, even an app that collects no data. A privacy policy is required to complete the Data safety form.</li>
<li class="task-list-item"><input type="checkbox" disabled> <strong>Data safety form</strong>. Required for every app on closed, open or production tracks. Apps that collect no data still have to complete it and say so. Include data collected by SDKs such as Firebase, analytics and crash reporting.</li>
<li class="task-list-item"><input type="checkbox" disabled> <strong>Account deletion</strong>. If users can create an account in your app, you must <a href="https://support.google.com/googleplay/android-developer/answer/13327111">offer a way to delete the account and its data inside the app, and also a web link</a> where users can request deletion without reinstalling. The web link goes into the Data safety form. Deactivating or “freezing” an account does not count.</li>
<li class="task-list-item"><input type="checkbox" disabled> App access instructions and test credentials if the app needs a login</li>
<li class="task-list-item"><input type="checkbox" disabled> Content rating questionnaire, target audience, ads declaration</li>
<li class="task-list-item"><input type="checkbox" disabled> Store listing: icon, feature graphic, screenshots, descriptions (check the name and descriptions with the free <a href="https://neemii.dev/tools/app-store-listing-checker/">store listing checker</a>, and resize screenshots to every required size with the <a href="https://neemii.dev/tools/app-store-screenshot-sizes/">screenshot sizes tool</a>)</li>
</ul>
<p>If you don’t have a privacy policy yet, my free <a href="https://neemii.dev/tools/app-privacy-policy-generator/">app privacy policy generator</a> gives you a starting draft that covers the usual Flutter SDKs. Have it reviewed if your app handles sensitive data.</p>
<h2 id="ios-release-checklist">iOS release checklist</h2>
<h3 id="1-use-the-current-xcode-and-sdk">1. Use the current Xcode and SDK</h3>
<p>Since <a href="https://developer.apple.com/news/upcoming-requirements/">April 28, 2026, apps uploaded to App Store Connect must be built with Xcode 26 or later using the iOS 26 SDK</a>. Since September 9, 2026, iOS apps must also target iOS 13 or later. Flutter supports iOS 13 and later, so the deployment target is rarely a problem, but an old Mac that cannot run Xcode 26 is. Check this before release day.</p>
<p>You also need a Mac to build and upload the iOS app, or a cloud CI service that provides one.</p>
<h3 id="2-register-the-app-and-check-xcode-settings">2. Register the app and check Xcode settings</h3>
<p>Following the <a href="https://docs.flutter.dev/deployment/ios">Flutter iOS release docs</a>:</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" disabled> Register the Bundle ID in the Apple Developer portal</li>
<li class="task-list-item"><input type="checkbox" disabled> Create the app record in App Store Connect (Apps, then +, then New App) and select that Bundle ID</li>
<li class="task-list-item"><input type="checkbox" disabled> In <code>ios/Runner.xcworkspace</code>, check Display Name, Bundle Identifier, signing Team and Deployment Target on the Runner target</li>
<li class="task-list-item"><input type="checkbox" disabled> Replace the placeholder app icon and launch image in <code>Assets.xcassets</code></li>
</ul>
<h3 id="3-build-the-ipa-and-upload-it">3. Build the IPA and upload it</h3>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> build</span><span style="color:#9ECBFF"> ipa</span><span style="color:#79B8FF"> --obfuscate</span><span style="color:#79B8FF"> --split-debug-info=build/symbols/ios</span></span>
<span class="line"><span style="color:#6A737D"># archive: build/ios/archive/   ipa: build/ios/ipa/</span></span></code></pre>
<p>To set the version explicitly:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> build</span><span style="color:#9ECBFF"> ipa</span><span style="color:#79B8FF"> --build-name=1.4.0</span><span style="color:#79B8FF"> --build-number=12</span></span></code></pre>
<p>Upload with Apple’s Transporter app, by opening the archive in Xcode and using Validate App and then Distribute App, or from the command line with an App Store Connect API key:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">xcrun</span><span style="color:#9ECBFF"> altool</span><span style="color:#79B8FF"> --upload-app</span><span style="color:#79B8FF"> --type</span><span style="color:#9ECBFF"> ios</span><span style="color:#79B8FF"> -f</span><span style="color:#9ECBFF"> build/ios/ipa/</span><span style="color:#79B8FF">*</span><span style="color:#9ECBFF">.ipa</span><span style="color:#79B8FF"> \</span></span>
<span class="line"><span style="color:#79B8FF">  --apiKey</span><span style="color:#9ECBFF"> your_api_key</span><span style="color:#79B8FF"> --apiIssuer</span><span style="color:#9ECBFF"> your_issuer_id</span></span></code></pre>
<p>Apple usually emails you within about 30 minutes, when the build has been processed and is available in TestFlight. Test that exact build on real devices through TestFlight before submitting it.</p>
<h3 id="4-privacy-details-permissions-and-account-deletion">4. Privacy details, permissions and account deletion</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" disabled> <strong>App Privacy details</strong>. <a href="https://developer.apple.com/app-store/app-privacy-details/">Required to submit new apps and updates</a>. You must declare data collected by third-party SDKs in your app, not only your own code.</li>
<li class="task-list-item"><input type="checkbox" disabled> <strong>Privacy policy URL</strong> in App Store Connect, and a link to the policy <a href="https://developer.apple.com/app-store/review/guidelines/#privacy">inside the app, in an easily accessible place</a> (guideline 5.1.1(i)).</li>
<li class="task-list-item"><input type="checkbox" disabled> <strong>Account deletion</strong>. Guideline 5.1.1(v): if the app supports account creation, it must also offer account deletion inside the app.</li>
<li class="task-list-item"><input type="checkbox" disabled> <strong>Purpose strings</strong>. Every permission (camera, photos, location, microphone) needs a clear <code>NS...UsageDescription</code> in <code>Info.plist</code> that explains why. Apple lists <a href="https://developer.apple.com/distribute/app-review/">unclear data access requests</a> as a common issue. Flutter plugins do not write these for you; the <a href="https://neemii.dev/tools/ios-permission-text-generator/">iOS permission text generator</a> writes them, with checks for vague wording.</li>
<li class="task-list-item"><input type="checkbox" disabled> <strong>Privacy manifests and required reason APIs</strong>. Since May 1, 2024, Apple requires <a href="https://developer.apple.com/news/upcoming-requirements/">approved reasons for certain APIs</a>, including use inside third-party SDKs. Keep your plugins up to date so their privacy manifests are current.</li>
<li class="task-list-item"><input type="checkbox" disabled> <strong>Age rating</strong>. Apple introduced <a href="https://developer.apple.com/news/upcoming-requirements/">updated age rating questions</a> in 2026. Answer them in App Information.</li>
</ul>
<h2 id="obfuscation-and-debug-symbols">Obfuscation and debug symbols</h2>
<p><a href="https://docs.flutter.dev/deployment/obfuscate">Flutter’s obfuscation</a> works only in release builds and needs both flags together: <code>--obfuscate</code> and <code>--split-debug-info=&lt;directory&gt;</code>. It works for <code>appbundle</code>, <code>apk</code>, <code>ipa</code> and other targets.</p>
<p>Two things to keep in mind:</p>
<ol>
<li>
<p><strong>Keep the symbols files</strong> for every release you ship. Without them you cannot read crash stack traces from that build. To decode a trace:</p>
<pre class="astro-code github-dark" style="background-color:#24292e;color:#e1e4e8; overflow-x: auto;" tabindex="0" data-language="bash"><code><span class="line"><span style="color:#B392F0">flutter</span><span style="color:#9ECBFF"> symbolize</span><span style="color:#79B8FF"> -i</span><span style="color:#9ECBFF"> stack_trace.txt</span><span style="color:#79B8FF"> -d</span><span style="color:#9ECBFF"> build/symbols/android/app.android-arm64.symbols</span></span></code></pre>
</li>
<li>
<p>Obfuscation only renames symbols. It does not hide API keys or secrets in the app, and code that depends on class names (for example <code>runtimeType.toString()</code>) breaks in obfuscated builds. Test the obfuscated build, not just the debug build.</p>
</li>
</ol>
<h2 id="common-rejection-reasons-and-how-to-avoid-them">Common rejection reasons and how to avoid them</h2>
<p>Apple says that <a href="https://developer.apple.com/distribute/app-review/">over 40% of unresolved issues relate to guideline 2.1, App Completeness</a>: crashes, placeholder content and incomplete information. For every guideline with its exact fix and how to reply to App Review, see <a href="https://neemii.dev/blog/app-store-rejection-reasons-fixes/">App Store rejection reasons and how to fix each one</a>. Most rejections I’d plan for fall into a few groups.</p>
<p><strong>Crashes and broken features (Apple 2.1).</strong> Test the release build on real devices, on the oldest and newest OS versions you support. A release build of a Flutter app can fail where debug works, for example because of obfuscation or a missing <code>Info.plist</code> key.</p>
<p><strong>No working demo account.</strong> Guideline 2.1 asks you to <a href="https://developer.apple.com/app-store/review/guidelines/#app-completeness">include demo account info and “turn on your back-end service”</a> if the app has a login. Google Play has a similar App access section. Give a working account with sample data, and make sure the staging server isn’t switched off during review.</p>
<p><strong>Placeholder content and broken links.</strong> Lorem ipsum, “coming soon” screens, empty tabs and dead support URLs all count. Every link in the app and listing must work.</p>
<p><strong>Privacy policy and data disclosures that don’t match the app.</strong> If you add Firebase Analytics or Crashlytics and the Data safety form or App Privacy details say “no data collected”, that’s a mismatch. Update the forms whenever you add an SDK. (Details: <a href="https://neemii.dev/blog/app-privacy-policy-requirements/">what Apple and Google require in an app privacy policy</a>.)</p>
<p><strong>Missing account deletion.</strong> Both stores require it if users can create accounts. Apple asks for deletion to be offered within the app, and Google also wants a web link.</p>
<p><strong>Third-party login without an equivalent option (Apple 4.8).</strong> If the user’s main account uses Google or Facebook sign-in, Apple requires <a href="https://developer.apple.com/app-store/review/guidelines/#login-services">another login option that limits data to name and email and lets users hide their email</a>. Sign in with Apple meets this.</p>
<p><strong>Screenshots that don’t show the app (Apple 2.3).</strong> Screenshots <a href="https://developer.apple.com/app-store/review/guidelines/#accurate-metadata">must show the app in use</a>, not only the splash or login screen, and must match the current version.</p>
<p><strong>Too little functionality (Apple 4.2).</strong> An app that is only a WebView around a website is likely to be rejected under <a href="https://developer.apple.com/app-store/review/guidelines/#minimum-functionality">minimum functionality</a>. Make sure the app does something useful on its own.</p>
<blockquote>
<p><strong>Two rejections from my own work:</strong></p>
<ul>
<li><strong>A budgeting app rejected as a finance app.</strong> App Review treated a personal budget app of mine as if it managed real money. It only tracks budgets and spending that the user enters, and no money moves through it. I fixed it by replying to App Review in App Store Connect and explaining clearly what the app does and doesn’t do. If a reviewer misreads your app, a clear, polite reply often solves it without code changes.</li>
<li><strong>A government app whose developer account left with an employee.</strong> On a government project (I can’t name it), the app was rejected, and the Apple developer account it was published under belonged to an employee who had since left the company. Before fixing the rejection, the app first needed a new home. We’re republishing it from an individual account and will then transfer it to a new company account. The lesson: <strong>publish client apps under the client’s own organisation account from day one</strong>, never a personal account of someone on the team.</li>
</ul>
</blockquote>
<h2 id="how-long-review-takes">How long review takes</h2>
<ul>
<li><strong>Apple</strong>: App Review says it <a href="https://developer.apple.com/distribute/app-review/">typically reviews at least 50% of submissions in under 24 hours and 90% in under 48 hours</a>. Incomplete submissions take longer. For a critical bug fix or a dated event, you can request an expedited review.</li>
<li><strong>Google Play</strong>: Google says some apps are subject to extended reviews, which <a href="https://support.google.com/googleplay/android-developer/answer/9859751">can take up to seven days or longer in exceptional cases</a>. New apps and new accounts should plan for the longer end. Add the 14-day closed test and the production access review on top for new personal accounts.</li>
</ul>
<blockquote>
<p><strong>My recent timings:</strong> updates to existing apps are usually approved within 1–2 hours. A new app on Google Play takes about 15–20 days in total, mostly because of the closed-testing requirement before production. On the App Store, I keep a new app in TestFlight for testing first. After that, if review finds no issues, approval comes within a week.</p>
</blockquote>
<p>My advice: don’t promise a client a launch date until both apps are approved. Use the store’s manual or scheduled release option, so approval and going live are separate steps.</p>
<h2 id="the-short-version">The short version</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" disabled> Accounts set up in the client’s name, Bundle ID and application ID chosen</li>
<li class="task-list-item"><input type="checkbox" disabled> Personal Play account: 12 testers, 14 continuous days, then apply for production</li>
<li class="task-list-item"><input type="checkbox" disabled> <code>version: x.y.z+build</code> bumped for every upload</li>
<li class="task-list-item"><input type="checkbox" disabled> Android targets API 36, signed with an upload key, built as <code>.aab</code></li>
<li class="task-list-item"><input type="checkbox" disabled> iOS built with Xcode 26 and the iOS 26 SDK, uploaded and tested through TestFlight</li>
<li class="task-list-item"><input type="checkbox" disabled> Privacy policy URL on both stores and inside the app</li>
<li class="task-list-item"><input type="checkbox" disabled> Data safety form and App Privacy details match every SDK in the app</li>
<li class="task-list-item"><input type="checkbox" disabled> In-app account deletion, plus a web deletion link for Google Play</li>
<li class="task-list-item"><input type="checkbox" disabled> Purpose strings for every iOS permission</li>
<li class="task-list-item"><input type="checkbox" disabled> Release built with <code>--obfuscate --split-debug-info</code>, symbols files saved</li>
<li class="task-list-item"><input type="checkbox" disabled> Demo account and review notes provided, backend running</li>
<li class="task-list-item"><input type="checkbox" disabled> Screenshots show the real, current app</li>
</ul>
<p>Publishing is not a one-time job. Every year Apple raises the Xcode minimum and Google raises the target API level, and an app that isn’t updated eventually can’t ship updates or disappears for new users. If you’d rather not track this yourself, my <a href="https://neemii.dev/services/app-maintenance/">app maintenance service</a> covers yearly SDK upgrades, store compliance and releases.</p>
<p>If you have a Flutter app that’s ready, or nearly ready, and you want someone to handle the App Store and Google Play release, <a href="https://neemii.dev/#contact">get in touch</a>.</p>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-publish-flutter-app-app-store-google-play.png" type="image/png" length="0" />
    </item>
    <item>
      <title>How to Build a Women-Only Ride-Sharing App: Features, Stack, Cost</title>
      <link>https://neemii.dev/blog/women-only-ride-sharing-app-development/</link>
      <guid isPermaLink="true">https://neemii.dev/blog/women-only-ride-sharing-app-development/</guid>
      <pubDate>Tue, 17 Nov 2026 00:00:00 GMT</pubDate>
      <description>How to build a women-only ride-sharing app in Flutter: verification, live tracking, fare bidding, safety tools, a practical stack and realistic cost ranges.</description>
      <content:encoded><![CDATA[<p><strong>Short answer:</strong> A women-only ride-sharing app needs verification for both riders and drivers, live tracking, fares or driver bids, an SOS flow and an admin panel, usually as separate rider and driver apps on a real-time backend. With all of that it sits in the complex band, about 1,400–2,500 hours, or roughly $35,000–$100,000 with an experienced South Asian team. A smaller first release in one city, with fixed fares and no bidding, costs less.</p>
<p>A women-only ride-sharing app is a ride-hailing product where the rider and the driver are both verified women. The idea is simple. The build is not. Verification, live location, fare bids and safety tools all have to work together, and they have to work on a phone in a moving car.</p>
<p>This post covers the features to scope first, a practical Flutter stack, and how to estimate cost. The cost section uses the same hour ranges and rates as my <a href="https://neemii.dev/blog/flutter-app-development-cost/">Flutter app development cost</a> guide. I also draw on my work on <a href="https://neemii.dev/work/shedrives/">SheDrives</a>, a women-only ride app in Lahore, where I was one of the Flutter developers on the team.</p>
<h2 id="why-women-only-ride-apps-exist">Why women-only ride apps exist</h2>
<p>Some women avoid app-based rides, or share the trip with a friend by phone, because they do not know who is picking them up or who else will be in the car. A women-only model tries to remove that uncertainty. The rider knows the driver is a woman who has passed verification, and the driver knows the same about the rider.</p>
<p>That promise is also the hardest part to deliver. If verification is weak, or a bug can match a rider with an unverified driver, the product fails at the one thing it exists to do. Build the trust and safety logic first, then the convenience features.</p>
<h2 id="core-features">Core features</h2>
<p>A women-only app needs the usual ride-hailing core: accounts, ride requests, maps, trip status, payments and ratings. On top of that, it needs a layer of trust features. This is the list I would scope first.</p>
<h3 id="1-verification-for-riders-and-drivers">1. Verification for riders and drivers</h3>
<p>Verify both sides, not only drivers. The model depends on both ends being women, so a rider should also go through a check before they can book a ride. Typical steps are phone number verification, a selfie checked against an ID document, and for drivers, licence, vehicle registration and a background check.</p>
<p>Show the status inside the app (pending, verified, rejected) so users know where they stand. Store the verification status in your database, not only in the UI, so the server can refuse ride requests from unverified accounts. A check that exists only on the screen is not a check.</p>
<blockquote>
<p><strong>From SheDrives:</strong> the slowest step was not the app, it was admin approval. An admin had to verify every record by hand, so new drivers waited in a queue. If you build one of these, plan the admin side as carefully as the app: a review screen that shows everything needed for one decision, filters for pending records, and enough admin time for launch week, when sign-ups peak.</p>
</blockquote>
<h3 id="2-live-tracking">2. Live tracking</h3>
<p>Riders need to watch the driver approach, and drivers need to see the pickup point. This needs a map SDK, a location stream from the driver’s phone, and a server that relays positions to the rider. Decide how often the driver’s app sends its location during a trip, and what happens when GPS drops, for example in an underpass or a building with poor signal. Those details matter more than the map style. The code for all of it is in <a href="https://neemii.dev/blog/flutter-live-location-tracking-google-maps/">Flutter live location tracking on Google Maps</a>.</p>
<h3 id="3-fare-bidding-or-fixed-fare">3. Fare bidding or fixed fare</h3>
<p>A fixed fare is simpler. The app estimates a price from distance and time, and the driver accepts or declines. Bidding works differently: the rider posts a ride, drivers send fare offers, and the rider picks one. Bidding is closer to inDrive, and it adds more states to manage, such as open, bid received, accepted and expired.</p>
<p>A sensible first version is a fixed fare with an optional rider counter-offer. Add full bidding once the core trip flow, verification and support process are stable. SheDrives uses bidding, which is why the real-time section below covers it in detail.</p>
<h3 id="4-sos-emergency-contacts-and-trip-sharing">4. SOS, emergency contacts and trip sharing</h3>
<p>A rider should be able to share a live trip with a saved contact, see the driver’s name, photo and vehicle, and send an SOS alert. The SOS button needs a clear path. Decide who receives the alert: the rider’s emergency contacts, your support team, local emergency services, or all three. Then test that path on real devices with the app in the background and the phone locked, because that is when a safety feature gets used.</p>
<h3 id="5-ratings-and-in-app-support">5. Ratings and in-app support</h3>
<p>Both sides should rate each trip. Low ratings should flag an account for admin review rather than remove it automatically. Support should be reachable from inside the app, and every support request should be tied to a trip ID, so the support agent can see the route, the driver and the timestamps without asking the user to explain again.</p>
<h3 id="6-an-admin-panel-for-verification">6. An admin panel for verification</h3>
<p>Verification is a queue. The admin panel needs to list pending users, show the uploaded documents, approve or reject with a reason, and log every decision. Build it as a web app, not as a screen inside the mobile app. Many projects underestimate this part, and the <a href="https://neemii.dev/blog/flutter-app-development-cost/">cost guide</a> explains why admin panels take their own hours.</p>
<h2 id="the-real-time-part">The real-time part</h2>
<p>Real-time is where most of the risk sits. The <a href="https://neemii.dev/work/shedrives/">SheDrives case study</a> describes three things that had to work every time:</p>
<ul>
<li><strong>Live tracking</strong> with no stale positions, so the passenger sees the driver move and the driver sees the pickup point.</li>
<li><strong>Bids on time</strong>, arriving within seconds, because a passenger who waits too long gives up and the driver loses the fare.</li>
<li><strong>Delivery to the exact user.</strong> Each bid and status update has to reach the one driver or passenger it belongs to, not a neighbour, and not twice.</li>
</ul>
<p>Three things made the difference on SheDrives:</p>
<ol>
<li><strong>WebSockets for live data.</strong> Tracking and bids moved onto a WebSocket connection, so updates are pushed as they happen instead of being polled.</li>
<li><strong>Separate layers.</strong> Connection handling, ride state and the UI were split apart. When a bid or location update goes wrong, you can see which layer owns it, and bugs are much easier to find.</li>
<li><strong>Testing in every sprint.</strong> Real-time flows were tested each sprint on real devices and real rides, with a QA engineer, and issues were fixed before the next release.</li>
</ol>
<p>The team was four people: two Flutter developers, one backend developer and one QA engineer. My part was enhancing the app, fixing issues as they came in from real rides, and QA before each release. I did not build the whole system alone. For your own project, budget for the backend and QA as seriously as for the Flutter screens.</p>
<p>On the server side, the same principles apply to any real-time product. Authenticate every socket connection. Address each bid or status message to a specific ride and user, not broadcast it to everyone nearby. And test with two phones in the same area, because a broadcast bug usually shows up only when two people are close to each other.</p>
<blockquote>
<p><strong>From SheDrives:</strong> the most common real-device problem was inaccurate GPS: positions on the map didn’t match where the driver really was. We moved to Google Maps Platform for more accurate location, tested it repeatedly on real rides, and sent the driver’s location over the WebSocket every 3–5 seconds. That interval kept the map smooth without flooding the connection.</p>
</blockquote>
<h2 id="a-flutter-stack-to-consider">A Flutter stack to consider</h2>
<p>These are options, not a fixed recipe. The right choice depends on your team, your hosting preferences and your budget.</p>
<ul>
<li><strong>Flutter</strong> for iOS and Android from one codebase. You can ship riders and drivers as two apps or as one app with two modes. Two apps are common because the driver app carries heavier location and document flows.</li>
<li><strong>Maps:</strong> Google Maps Platform, with the Maps SDK for the map view and the Directions or Distance Matrix APIs for routes and ETAs. Check current pricing before you commit, since map calls are billed by usage.</li>
<li><strong>Real-time backend:</strong> a WebSocket server in a language your team knows well, such as Node.js or Go, or a managed real-time service.</li>
<li><strong>Database and auth:</strong> Firebase or Supabase for a faster start, or a custom Postgres setup for more control. Verification status lives here.</li>
<li><strong>Push notifications:</strong> Firebase Cloud Messaging for ride alerts when the app is in the background.</li>
<li><strong>Payments:</strong> a local payment gateway, cash, or both. A ride is a physical service, so it usually goes through your own gateway rather than in-app purchases, as the cost guide explains.</li>
</ul>
<h2 id="what-it-costs">What it costs</h2>
<p>A women-only ride app with verification, live tracking, bidding, an SOS flow and an admin panel matches the <strong>complex</strong> band in the <a href="https://neemii.dev/blog/flutter-app-development-cost/">Flutter app development cost</a> guide. That band is 1,400–2,500+ hours (an assumption), and ride-hailing is one of its examples. Using the same regional rates from that guide:</p>
<table>
<thead>
<tr>
<th>Scope</th>
<th>Hours</th>
<th>South Asia ($25–$40/h)</th>
<th>Eastern Europe ($35–$75/h)</th>
<th>UAE agency ($55–$95/h)</th>
<th>US agency ($100–$150/h, assumption)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Medium</td>
<td>600–1,000</td>
<td>$15,000–$40,000</td>
<td>$21,000–$75,000</td>
<td>$33,000–$95,000</td>
<td>$60,000–$150,000</td>
</tr>
<tr>
<td>Complex</td>
<td>1,400–2,500</td>
<td>$35,000–$100,000</td>
<td>$49,000–$187,500</td>
<td>$77,000–$237,500</td>
<td>$140,000–$375,000</td>
</tr>
</tbody>
</table>
<p>A smaller first release can move toward the medium band if you limit it to one city, one role per app, a fixed fare and no bidding. That is an assumption, and the real hours depend on your feature list. Bidding and live tracking are the two items most likely to push the build back into the complex range.</p>
<p>For a first range based on your own feature list, use the free <a href="https://neemii.dev/tools/app-cost-calculator/">app cost calculator</a>. The cost guide explains how each band is defined and what the hours include.</p>
<h2 id="legal-and-operations-notes">Legal and operations notes</h2>
<p>These are the points to settle early. This is general guidance, not legal advice, so check the rules where you will operate.</p>
<ul>
<li><strong>Driver background checks.</strong> Decide who runs the checks and what they cover. Get written consent from each applicant, and confirm what local rules allow before you collect any data.</li>
<li><strong>Data privacy.</strong> ID documents and selfies are sensitive. Collect only what verification needs, store it securely, limit admin access, and set a deletion policy. Your privacy policy must match what the app actually collects. See <a href="https://neemii.dev/blog/app-privacy-policy-requirements/">app privacy policy requirements</a>.</li>
<li><strong>Store policies.</strong> Apple and Google review apps that handle accounts, location and safety features. Expect questions about location permissions and data collection, and fill in the App Store privacy details and Google Play data safety form accurately. For the submission process, see <a href="https://neemii.dev/blog/publish-flutter-app-app-store-google-play/">publishing a Flutter app on the App Store and Google Play</a>.</li>
<li><strong>Support for safety reports.</strong> Before launch, decide who answers a safety report, how fast they respond, and what they do with the trip data.</li>
</ul>
<h2 id="frequently-asked-questions">Frequently asked questions</h2>
<div class="faq-list">
<details class="faq" name="faq">
<summary>Can one Flutter app serve both riders and drivers?</summary>
<p>Yes. You can ship one app with a rider mode and a driver mode, or two separate apps that share a backend. Two apps keep the driver’s location and document flows out of the rider’s experience, and each app stays simpler to test and update. Decide this before you design the navigation, because it changes the build.</p>
</details>
<details class="faq" name="faq">
<summary>How long does a women-only ride app take to build?</summary>
<p>It depends on scope. The complex band in the cost guide is 1,400–2,500+ hours (an assumption). Real-time features and verification are the usual reasons a project runs longer than planned. Ask for a timeline only after the feature list is agreed.</p>
</details>
<details class="faq" name="faq">
<summary>Should the first version include bidding?</summary>
<p>Not necessarily. A fixed fare is easier to test, support and explain to users. Add bidding once the trip flow, verification and support process work well in the real world. Bidding is worth building well, and it is also the part of the real-time work described above that needs the most testing.</p>
<p>For a real estimate, <a href="https://neemii.dev/#contact">send me your idea</a>. I am Muhammad Naeem, a Flutter developer in Lahore building iOS and Android apps for startups in the UAE, Pakistan and worldwide. Tell me which features matter most, and I will reply with a scope, a timeline and a price range, free and with no obligation.</p>
</details>
</div>
]]></content:encoded>
      <enclosure url="https://neemii.dev/og/blog-women-only-ride-sharing-app-development.png" type="image/png" length="0" />
    </item>
  </channel>
</rss>
