<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Oddmentiusmaximus on Medium]]></title>
        <description><![CDATA[Stories by Oddmentiusmaximus on Medium]]></description>
        <link>https://medium.com/@pimpalkhare.sawan?source=rss-99389c6a7d2d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*JH3cJOB1KtJYW9JV.</url>
            <title>Stories by Oddmentiusmaximus on Medium</title>
            <link>https://medium.com/@pimpalkhare.sawan?source=rss-99389c6a7d2d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 03:38:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pimpalkhare.sawan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Mystery of unawaited()]]></title>
            <link>https://medium.com/@pimpalkhare.sawan/the-mystery-of-unawaited-63c635f07075?source=rss-99389c6a7d2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/63c635f07075</guid>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[asynchronous-programming]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Oddmentiusmaximus]]></dc:creator>
            <pubDate>Fri, 20 Nov 2026 04:17:20 GMT</pubDate>
            <atom:updated>2026-11-20T04:50:32.713Z</atom:updated>
            <content:encoded><![CDATA[<p><em>What changes when you wrap a Future in </em><em>unawaited()?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y0tafMmAmbQgElsQTDHsOg.png" /></figure><p>I was reviewing a PR with a colleague when I noticed a call wrapped in unawaited().</p><p>“Why did you use it here?”</p><p>“AI added it.”</p><p>“What does it do?”</p><p>“It makes it unawaited.”</p><p>“Okay, what happens if we remove the wrapper?”</p><p>“Not sure.</p><pre>//lets see whats inside <br>@Since(&quot;2.15&quot;)<br>void unawaited(Future&lt;void&gt;? future) {}</pre><p>Interesting right, sometimes we know what expected to happen, but the question can’t be answered when the question is simplified. So lets understand this topic-</p><pre>main(){<br>unawaited(initializeAnalytics());<br>//vs<br>initializeAnalytics();<br> <br> runApp(const App());<br>}</pre><p>Both versions run the same way: Dart starts initializeAnalytics() and immediately moves on to runApp() without waiting for it to finish.</p><p>Removing unawaited() doesn&#39;t change how the code executes, so you should keep it for two reasons:</p><ul><li><strong>Prevent linter warnings:</strong> It stops the Dart analyzer from flagging the unawaited Future.</li><li><strong>Communicate intent:</strong> It signals to other developers that skipping await was a deliberate choice, not a mistake.</li></ul><p>During a code review, seeing unawaited() changes the conversation from <em>&quot;Did you forget to await this?&quot;</em> to <em>&quot;Why is it safe for the app to keep running before this finishes?&quot;</em></p><p>Let see the sequencing to better understand all three -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E-JKMLirPKr_8352AJj70w.png" /><figcaption>Detail of the call sequence</figcaption></figure><p>And thats it we see a lot of articles explaining await vs unawaited , unawaited doesnt just magically make a function side track the future it performs. It’s just good hygiene for scalable codebases. It makes no difference in actual sequencing of future.<br>Plain and simple.</p><blockquote>So the next time your agent writes the unawaited line , you exactly now how your code flows regardless of the function wrap.</blockquote><h3>Thats it Folks ! Thank You soo much for reading , hope to see you soon</h3><h3>My references—</h3><p><a href="https://api.dart.dev/dart-async/unawaited.html">unawaited function</a></p><blockquote><em>Stay Tuned and thanks for Engaging , Until Next time ✌️</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63c635f07075" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Quiet Throttle]]></title>
            <link>https://medium.com/miles-megabytes/the-quiet-throttle-1f578668fb1b?source=rss-99389c6a7d2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f578668fb1b</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Oddmentiusmaximus]]></dc:creator>
            <pubDate>Wed, 17 Jun 2026 09:33:38 GMT</pubDate>
            <atom:updated>2026-06-17T09:33:38.699Z</atom:updated>
            <content:encoded><![CDATA[<h4>How a Warm Phone During a Payment Scan Sparked a Four-Layer Thermal Investigation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3kxcnpGWZ9r2Uh02TMykw.png" /></figure><h3><strong>The phone that felt too hot</strong></h3><p>A user flagged something that does not show up in most dashboards: their phone got uncomfortably warm during a UPI payment scan. Not crash-warm. Not “the app is broken” warm. Just the kind of warmth that makes someone put the phone down and not come back. That was the uncomfortable part. We could not answer the most basic question:<br><em>Was this one device, or was this happening to everyone?</em></p><p>Device overheating, battery drain, and animation jank are silent retention killers. Unlike crashes, thermal issues do not leave behind a neat stack trace. The OS quietly throttles the CPU. Frames drop. Touch response feels heavier. The app starts feeling worse before anything technically “fails.” <br>At that point, we had no thermal monitoring, no baseline, and no way to separate a warm device from an app that was making the device warm.</p><h3>Why thermal bugs are hard to debug</h3><p>Thermal performance is not a bug with one owner. It is the aggregate cost of everything running at the same time: camera streams, animations, platform channels, analytics SDKs, monitoring hooks, video decoders, network calls, and rendering work.</p><p>The operating systems also make this difficult in different ways.<br>iOS gives severity states but no temperature. Android gives better native thermal APIs only on newer versions. Older Android versions require battery-temperature based heuristics. Two devices in the same room can reach “severe” at different physical temperatures because each OEM has its own thermal model.<br>So before fixing anything, we had to build a measurement system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGIMKFp4HxDxIe6ehoJOUQ.png" /></figure><h3>Building the lab before writing fixes</h3><p>We controlled the starting temperature before every run.</p><ul><li>Cooling packs brought devices to a verified cold baseline.</li><li>Heat packs simulated a real India summer use case: a phone pulled from a hot bag before payment.</li><li>Wireless debugging was mandatory because USB charging adds heat and contaminates drain measurements.</li><li>Every run started with a thermal-gun-confirmed temperature.</li><li>Integrated <a href="https://pub.dev/packages/thermal">Thermal</a> package which exposes native APIs to Flutter.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TpJrjJlos_du7Kv85f_-OQ.png" /></figure><p>Then we built two instruments.</p><h4>Developer thermal overlay</h4><p>An internal-only floating badge showed live thermal state and FPS inside the app. Since attaching debuggers and profiling tools can alter thermal behaviour, the overlay allowed release-build testing while recording thermal state throughout long-running scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*SMv39NaoDoeAumPPOFwN_Q.gif" /></figure><h4>Production thermal session summary</h4><p>We added a production analytics event: thermal_session_summary.<br>It fired at session end, when the device was already cooling — never at the moment of escalation. Triggering a network call while the phone is already hot would have changed the measurement. The most important field was session_start_state. Without that field, production thermal metrics are noise. You cannot distinguish “the user opened the app on an already-hot phone” from “the app heated a cold phone.”</p><h3>The S0–S5 test matrix</h3><p>We ran six controlled scenarios for 20 minutes each, or until severe escalation. Each scenario removed or isolated one layer of the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_iNUzfazk6rxzFSFJktocg.png" /></figure><h4>What the data revealed</h4><p>Once the scenarios proved there was no single smoking gun, the investigation moved layer by layer.</p><p>The important pattern was cumulative cost. No individual layer looked catastrophic in isolation. Together, they consumed enough CPU, GPU, and thermal headroom to make payment flows uncomfortable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pWcNSmQSBkYAry3R4_qqew.png" /></figure><h3>Layer 1 : Camera pipeline</h3><p>The overheating became undeniable when UPI integration shipped because the flow combined continuous camera, animation overlays, SDK initialisation, analytics, and monitoring in one place. But UPI did not create the problem. It made the existing cost visible.</p><p>The first fixes were straightforward but high impact:</p><ul><li><strong>Released camera hardware fully on tab switch:</strong> fixed residual camera load by calling full stop, dispose, and recreate on tab return.</li><li><strong>Disabled continuous auto zoom:</strong> removed conflicting AVFoundation zoom calls firing frame after frame.</li><li><strong>Replaced scan overlay saveLayer:</strong> moved from ClipPath + saveLayer() to a static CustomPainter with shouldRepaint: false.</li><li><strong>Throttled gyroscope polling:</strong> moved from 33ms callbacks to 150ms callbacks.</li></ul><h4>The open-source finding</h4><p>mobile_scanner was dispatching camera frames through the main queue. It meant 30fps barcode analysis callbacks were competing with Flutter rendering, touch handling, and platform channel dispatch on the main thread.</p><p>The finding became an upstream contribution. The fix was merged as <a href="https://github.com/juliansteenbakker/mobile_scanner/pull/1696">PR #1696</a> in the mobile_scanner repository, so every Flutter team using the package benefits from the investigation.</p><h3>Layer 2: Home rendering</h3><p>S3 showed that the home screen was not innocent. Even without the camera, it reached light escalation at around 18 minutes.<br>Flutter DevTools repaint highlighting made the cause visible: local animations and media changes were triggering repaint work across parts of the screen that had no visible change.</p><ul><li><strong>Repaint cascades:</strong> added RepaintBoundary around nav bar, video containers, and action buttons.</li><li><strong>Hidden video decode:</strong> paused video work when the tab was not visible instead of decoding inside Offstage.</li><li><strong>Reduced Rebuilds:</strong> Eliminated avoidable rebuild cascades caused by broad MediaQueryData subscriptions.</li><li><strong>Muted audio decode:</strong> stripped audio tracks from muted video assets.</li><li><strong>Cold-start Data models loaded:</strong> moved models loading to lazy initialization or removed them from caching on launch.</li></ul><h3>Layer 3: Monitoring overhead</h3><p>NewRelic instrumentation operated at two levels.</p><ul><li><strong>Android/IOS native layer:</strong> runtime network hooks wrapped network calls from SDKs across the process.</li><li><strong>Dart layer:</strong> global HttpOverrides intercepted requests and created platform-channel overhead.</li></ul><p>Approximately 60 million third-party SDK calls per week were being intercepted — and 45.6% of all data NewRelic collected came from SDKs we did not own. Monitoring was not just observing app behavior; it was adding measurable runtime cost to sessions.</p><p>The fixes came at both levels:</p><ul><li><strong>Flutter:</strong> Custom ScapiaNewRelicHttpOverrides routed analytics SDK domains to a plain HttpClient .</li><li><strong>Android:</strong> Nine analytics and Firebase SDKs were excluded from Android bytecode instrumentation.</li><li><strong>iOS:</strong> NRFeatureFlag_NSURLSessionInstrumentation was disabled natively — this flag swizzles NSURLSession at the OS level and intercepts every HTTP call from every SDK in the process.</li><li>iOS event harvest interval was increased from 60 seconds to 300 seconds.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LnLc6MLtxj9l8jcaodvTTw.png" /></figure><h3>Layer 4: Rive and the cost of idle animation</h3><p>The Dart CPU profiler collected 5,927 samples at 419 Hz during a home-screen idle session. Rive consumed 20.47% of total CPU time while the screen sat idle — no user interaction, no navigation. PipelineOwner.flushPaint accounted for a further 23.18% of frame time because RepaintBoundary was absent from the Rive widget tree, causing every Rive frame tick to propagate a full repaint cascade through the parent tree. Across all animation callbacks combined, 82% of sampled time was spent in animation frame work.</p><p>The issue was not simply “animation is expensive.” The deeper problem was that the runtime could keep work alive even when the UI appeared settled. The core issue — a zero-duration Timer.periodic that never settled and painters that could accidentally revive settled siblings — was documented upstream as <a href="https://github.com/rive-app/rive-flutter/issues/411">issue #411</a>. Rive addressed this directionally in the 0.14.x series: version 0.14.0 replaced the Dart runtime with the underlying C++ runtime, and 0.14.8 specifically fixed the settling issue where painters sharing a texture could fail to reach a settled state.</p><p>We were still on Rive 0.13.20 during this investigation. That context matters: the 0.14.x runtime rewrite is not a minor patch. It directly relates to the class of issues we were observing.</p><p>The cleanest proof came from Run 7: full app, Rive removed, 21 minutes 29 seconds, zero thermal escalation. The device stayed nominal for the entire run.</p><h3>The workflow that worked:</h3><ul><li>Collect native traces, Dart CPU snapshots, and tracker files first.</li><li>Use AI to summarize and compare patterns. AI accelerated the investigation</li><li>Verify every claim against actual traces.</li><li>Only then make code changes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ASPuaWoZci5kEVl49NVQw.png" /><figcaption><strong>Left: iOS intrumentation trace ; Right: Perfetto System trace</strong></figcaption></figure><h3>Impact created in production</h3><p>The production numbers moved materially.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NmQ2CiaZj7tOeISBQ0WHWA.png" /></figure><p><strong>23.0 % → 15.1 % </strong>Severe-or-worse sessions reduced in production</p><p><strong>12.1 % → 3.3 % </strong>Genuine cold-device escalation reduced by roughly 70%</p><p><strong>134k+ </strong>Daily sessions observed through the thermal measurement framework.</p><p>Battery drain reduced from <strong>0.60</strong>%/min to <strong>0.35</strong>%/min (42% improvement).</p><h3>Why this mattered beyond heat</h3><p>The fixes touched four independent layers: SDK instrumentation, animation runtime, camera pipeline, and rendering architecture.</p><p>The effects compounded beyond thermal performance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UnKtU3V1voa9HrcpT4lMNQ.png" /></figure><ul><li><strong>Over 2 TB/month of monitoring traffic removed:</strong> NewRelic-measured across all analytics SDKs — bandwidth previously consumed by invisible telemetry now goes to checkout, card data, and payment APIs. Users on limited mobile data plans in India stopped paying for data silently consumed by SDKs they never interacted with.</li><li><strong>User data usage improved:</strong> fewer background SDK calls matter on limited mobile data plans.</li><li><strong>Open-source contribution merged:</strong> the mobile_scanner threading fix (<a href="https://github.com/juliansteenbakker/mobile_scanner/pull/1696">PR #1696</a>) now helps the wider Flutter ecosystem.</li></ul><h3>Closing thoughts</h3><p>The investigation started with one warm phone during a payment scan. It ended with far more than a thermal fix.</p><p>The changes reduced battery drain, eliminated unnecessary background work, improved observability, and contributed fixes back to the Flutter ecosystem. More importantly, they leave behind a framework for measuring, understanding, and preventing performance regressions before users feel them.</p><p>The measurement framework now runs across production sessions and can catch future regressions much more quickly. This is currently under the works and is expected to be released as soon as our baseline stabilises.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f578668fb1b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/miles-megabytes/the-quiet-throttle-1f578668fb1b">The Quiet Throttle</a> was originally published in <a href="https://medium.com/miles-megabytes">Scapia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linear Interpolations or “lerp” in Dart]]></title>
            <link>https://medium.com/@pimpalkhare.sawan/linear-interpolations-or-lerp-in-dart-2454bdd7c8a9?source=rss-99389c6a7d2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2454bdd7c8a9</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[interpolation]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[lerp]]></category>
            <dc:creator><![CDATA[Oddmentiusmaximus]]></dc:creator>
            <pubDate>Sat, 10 Sep 2022 09:39:19 GMT</pubDate>
            <atom:updated>2022-09-13T06:53:18.990Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gNL-aAtDJEYs_fGD0URlnA.png" /><figcaption><strong>lerp.dart</strong></figcaption></figure><h3>What does Interpolation mean?</h3><p>— Interpolation means the process of calculating an approximate value based on values that are already known.</p><h3>Linear Interpolation -</h3><p>So now that we understand the meaning of interpolation lets understand what is linear interpolations. Linear Interpolation or <em>lerp</em> is commonly used in animations in dart. <br>“lerp” method -“eases” the transition between two values over time, using some simple math. We use this to change shapes, sizes, colors, opacity etc of UI element. In lerp method you pass 3 parameter , <strong>a</strong> — is the point of beginning ,<strong> b</strong> — is the end point and<strong> t</strong> — is the animating value.</p><blockquote>For eg —</blockquote><blockquote>Consider an element which is white in current state , and in the next state it is supposed to be black in color. Without a proper animating mechanism, the transition will be sudden and would be a very unpleasant experience for the user. lerp allows the white to smoothly transition into black over several frames.</blockquote><h4>The conditions for lerping are -</h4><ol><li>Neither of the values should be null or non finite</li><li>Interpolation can’t happen between finite and non-finite values</li><li>The <strong>a</strong> value and the <strong>b</strong> value should not change during the interpolation</li><li>The value of <strong>t</strong> will always be in between 0.0 to 1.0 that will be the distance between two values.</li><li>The t will never be constant as it returns the value of the line point.</li><li>Value of <strong>t</strong> that is 0.0 will always return the value of <strong>a</strong>.</li><li>Value of <strong>t</strong> that is 1.0 will always return the value of <strong>b</strong>.</li><li>Value of <strong>t</strong> that is 0.5 will be the middle point between <strong>a</strong> and <strong>b</strong>.</li></ol><h4>Formula —</h4><blockquote>lerp(a, b, t) = a + (b — a) * t</blockquote><p>Where , a is the start , b-a is the distance between a to b and multiplied into the percentage t .</p><h3>Coming back to Flutter —</h3><p>In flutter we can lerp so many properties beyond Colors, Shapes, such as Decoration, TextStyle, Theme ,BeveledRectangleBorder, BoxBorder, CircleBorder, RoundedRectangleBorder, StadiumBorder ,AlignmentGeometryand many more.These classes are made upon hierarchy of components that themselves can interpolate. Hence it makes complex interpolations much simpler .</p><p>A simple <em>lerp</em> method won’t understand all the defined types instantaneously therefore dart has <em>lerpFrom</em> and <em>lerpTo</em> method that <em>lerp</em> defers to. The benefit of this is , lets take example of shapes — when a shape elements wants to <em>lerp</em> from shape circle to shape triangle in this context circle will be <strong>a</strong> and triangle will be <strong>b</strong> ,first b is asked if it can <em>lerpFrom</em> <strong>a</strong>, if it cannot, <strong>a</strong> is instead asked if it can <em>lerpTo</em> <strong>b</strong>.If both can’t be done if percentage t is less than 0.5 it returns value on point to <strong>a</strong> , if its greater than 0.5 then it returns value on point to <strong>b</strong>.</p><p>There’s a Tween class in flutter which behaves similar to this because in that as well we have to define a begin and end .It supports this mutation from begin to end in this percentage t .</p><p>Thank You for reading !</p><p>I tried to simplify lerp in dart as I hadn’t found many resources to explain this in terms of flutter.</p><h3>Code Snippet Examples —</h3><p>If you wanted to fetch a value between two colors which returns a gradient.</p><pre>var color = Color.lerp(Colors.white, Colors.black, 0.5);</pre><p>here the value of color will be exactly in between black and white .</p><p>You can do this for double as well -</p><pre>Text(lerpDouble(10, 20, 0.3).toString() // 13,),</pre><p>here the value of double will be exactly the 0.3 point between 10 to 20 which is 13 . so output will be 13.</p><p>Let’s take a bit of complex example this time , suppose you want to transition between brightness in a custom Color Scheme.</p><pre>class ColorBrightness{</pre><pre>// Brightness decribes contrast of a theme or color palette.<br>// It has two types - light and dark</pre><pre>final Brightness brightness; <br>// declaring a final variable type brightness,<br>final color a; <br>// declaring a final variable type for color.<br>                                  <br> <br>ColorBrightness({required this.brightness, required this.a });</pre><pre>// creating a class constructor with named required type brightness // so that this value is compulsory to pass when class is <br>// referenced.</pre><pre>//------------------------------------------------------------------<br>factory ColorBrightness.light({Color a = Colors.white,}){<br>    return ColorBrightness(<br>  brightness: Brightness.light,<br>  a: a);<br>}</pre><pre>// creating a factory constructor that returns a new instance type // light<br>// We are passing a optional parameter named a and assigning white // color to it as a default value<br>// we will be returning light brightness value by default when <br>// ColorBrightness.light is called. <br>//------------------------------------------------------------------</pre><pre>// we will be doing same for dark but the brightness type will be<br>// dark and color will be black</pre><pre>factory ColorBrightness.dark({Color a = Colors.black,}){<br>    return ColorBrightness(<br>  brightness: Brightness.dark,<br>  a: a);<br>}</pre><pre>//------------------------------------------------------------------<br>// lets create a lerp method -</pre><pre>static ColorBrightness <em>lerp</em>(ColorBrightness a, ColorBrightness b, double t) {<br>  return ColorBrightness(<br>        brightness: t &lt; 0.5 ? a.brightness : b.brightness,<br>        a: Color.<em>lerp</em>(a.a, b.a, t),<br>       );<br>  }</pre><pre>// lets break this down<br>// first we declare this method static as it should be accessed by // reference<br>// then we declare the name of method as lerp and as defined pass <br>// values a -  begin, b -  end, t - percentage.<br>// In that we are returning class ColorBrightness with its required // named parameters and in brightness as theres no lerp method <br>// defined if percentage is less than 0.5 it will be a else <br>// transition will be b.<br>// and as color in dart has Color.lerp taking adavantage of that we <br>// will pass the transition from a to b </pre><h3>Thats it Folks ! Thank You soo much for reading , hope to see you soon</h3><h4>commonly used lerp methods —</h4><ul><li><a href="https://api.flutter.dev/flutter/dart-ui/Color/lerp.html">lerp method - Color class - dart:ui library - Dart API</a></li><li><a href="https://api.flutter.dev/flutter/painting/EdgeInsetsGeometry/lerp.html">lerp method - EdgeInsetsGeometry class - painting library - Dart API</a></li><li><a href="https://api.flutter.dev/flutter/painting/Gradient/lerp.html">lerp method - Gradient class - painting library - Dart API</a></li><li><a href="https://api.flutter.dev/flutter/material/ListTileThemeData/lerp.html">lerp method - ListTileThemeData class - material library - Dart API</a></li></ul><p>My references —</p><ul><li><a href="https://docs.flutter.dev/resources/inside-flutter">Inside Flutter</a></li><li><a href="https://www.febucci.com/2018/08/easing-functions/#:~:text=Easing%20Functions%20for%20Animations&amp;text=Easing%20(or%20interpolation)%20equations%20are,want%20simply%20using%20easing%20equations.">Easing Functions (Lerp) Tutorial | Febucci</a></li></ul><blockquote><em>Stay Tuned and thanks for Engaging , Until Next time ✌️</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2454bdd7c8a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter: Defining a Structure for GetX -Part 3( Get Connect )]]></title>
            <link>https://medium.com/@pimpalkhare.sawan/flutter-defining-a-structure-for-getx-part-3-get-connect-ad0bf6785a9c?source=rss-99389c6a7d2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad0bf6785a9c</guid>
            <category><![CDATA[structure]]></category>
            <category><![CDATA[getx]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[getconnect]]></category>
            <dc:creator><![CDATA[Oddmentiusmaximus]]></dc:creator>
            <pubDate>Sun, 19 Dec 2021 17:04:55 GMT</pubDate>
            <atom:updated>2021-12-19T17:48:58.213Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XGyh7kMgFRTHXQRN" /></figure><p>Greetings! fellow learner last time we understood models and observable models in Flutter and Getx .You can fetch that <a href="https://medium.com/@pimpalkhare.sawan/flutter-defining-a-structure-for-getx-part-2-understanding-models-ff9559d73e8b">here</a> . So now how do we get the data from the API , We use REST- API calls such as GET , POST ,PUT etc.</p><p>In today’s post, we will learn what is <strong>GetConnect</strong> in GetX and how do we set it up.</p><h3>Let’s Dive In-</h3><p><strong>GetConnect</strong> is an easy way to communicate from your back to your front with http or websockets.To be able to handle the API calls we will create a class that extends from the GetConnect class. This class by default will contain components from GetConnect to serve the api call.We will have to import the get_connect library available in get package.</p><pre>import &#39;package:get/get_connect.dart&#39;;<br><br>class ApiHelper extends GetConnect{<br>  factory ApiHelper() =&gt; instance;<br><br>  ApiHelper.init();<br>  <br>}<br>//This is how we initiate a class extending GetConnect .</pre><p>There are two types of configuration available for GetConnect -</p><h3>1) .Default configuration -</h3><p>In the default config getconnect provides a variety of ready elements for —</p><p>REST API —</p><ul><li>GET</li></ul><pre>// Get request<br>  Future get(String route,<br>    {Map&lt;String, String&gt;? header,<br>    Map&lt;String, dynamic&gt;? query}) async {<br>  try {<br>    final response = await get(<br>      route ,<br>      headers: header,<br>      query: query,<br>    );<br>  return response;  <br>} catch (ex) {<br>    print(ex.toString());<br>    return ex;<br>  }<br>}</pre><ul><li>POST</li></ul><pre>// Post request<br>Future post(<br>  String route,<br>  dynamic body, {<br>  Map&lt;String, String&gt;? header,<br>}) async {<br>  try {<br>    final response = await super<br>        .post(<br>          route,<br>          body,<br>          headers: header ,<br>        );<br><br>    return response;<br>  } catch (ex) {<br>    print(ex);<br>    return ex;<br>  }<br>}</pre><pre>// Post request with File<br>  Future postReqWithFile(String route,List&lt;int&gt; image) async {<br>try{<br>    final form = FormData({<br>      &#39;file&#39;: MultipartFile(image, filename: &#39;avatar.png&#39;),<br>      &#39;otherFile&#39;: MultipartFile(image, filename: &#39;cover.png&#39;),<br>    });<br>    var res = await post(route, form);<br>    return res;<br>   } catch(ex){<br>     print(ex);<br>   }  <br>}</pre><ul><li>PUT</li></ul><pre>//Put request <br>Future putData(<br>  String route,<br>  dynamic body, {<br>  Map&lt;String, String&gt;? header,<br>}) async {<br>  try {<br>    Response response = await put( route, body,<br>        headers: header );<br>    return handleResponce(response);<br>  } catch (ex) {<br>    print(ex);<br>    return ex;<br>  }<br>}</pre><ul><li>DELETE</li></ul><pre>//Delete request <br>Future deleteData(<br>  String route, {<br>  Map&lt;String, String&gt;? header,<br>}) async {<br>  try {<br>    final response = await delete( route,<br>        headers: header );<br>    return response;<br>  } catch (ex) {<br>    print(ex);<br>    return ex;<br>  }<br>}</pre><p>WebSocket —</p><ul><li>SOCKET</li></ul><p>— To name socket function they have to start with GetSocket and then the function name and its parameter.</p><p>— then we pass the socket route and ping duration.</p><pre>class ApiHelper extends GetConnect {</pre><pre>//Socket<br>  GetSocket userMessages(String route, Duration ping) {</pre><pre>    return socket(route , ping: ping);<br>  }<br>}</pre><h3>2). Custom configuration-</h3><p>You can define base Url, as answer modifiers, as Requests modifiers, define an authenticator, and even the number of attempts in which it will try to authenticate itself, in addition to giving the possibility to define a standard decoder that will transform all your requests into your Models without any additional configuration.</p><h4>Base URL</h4><p>To configure the base URL for all api communication you just need to set it in the init() function.</p><pre>@override<br>void init(){</pre><pre>httpClient.baseUrl = &#39;https://api.covid19api.com&#39;<br>// It define baseUrl to<br>// Http and websockets if used with no [httpClient] instance<br>}</pre><h4>RequestModifier-</h4><pre>httpClient.addRequestModifier((request,response) {<br>      //adding key in headers.<br>      request.headers[&#39;apikey&#39;] = &#39;uniqueKey&#39;;<br>      print(&quot;URL - ${request.url}&quot;);</pre><pre>//We can even add checks to remove data from response before it is delivered.<br>    return request;<br>});</pre><h4>To add Authenticator with requests-</h4><pre>httpClient.addAuthenticator((request) async {<br>      final response = await get(&quot;http://covidApi/token&quot;);<br>      final token = response.body[&#39;token&#39;];<br>      // Set the header<br>      request.headers[&#39;Authorization&#39;] = &quot;$token&quot;;<br>      return request;<br>    });</pre><pre>// to set max retries for authenticator<br>httpClient.maxAuthRetries = 3;<br>/Autenticator will be called 3 times if HttpStatus is<br>//HttpStatus.unauthorized<br></pre><h4>Default decoder -</h4><pre>//Call your model with the extension fromJson function defined in it.<br>//assign the standard decoder in init and <br>//that will transform all your requests into your Models.</pre><pre>httpClient.defaultDecoder = CasesModel.fromJson;</pre><p>There are many other httpclient properties that will allow you to customise it even further check out the<a href="https://github.com/jonataslaw/getx#default-configuration"> official getX documentation</a> for more..</p><h3>To Call these ApiHelper functions in an Repository function —</h3><ul><li>In your getX Repository dart file import the apihelper class path .</li><li>Aftet that intiate a reference for that class .</li><li>After that you can just call the functions in your function defined in your repository class with asynchronous methodology .</li></ul><pre>import &#39;package:neodove/src/web_services/api_helper.dart&#39;;<br><br><br>class Repository {<br>  Future fetchDetails() async {<br>    String route = &quot;https://route.com&quot;;<br>    final apiResponse = await ApiHelper.<em>instance</em>.getData(route);<br>    return apiResponse;<br>  }</pre><p>and thats it your done .</p><h3>Summary -</h3><p>Yay ! we made it so in this post we learned about GetConnect and how to set it up for default configuration and custom configuration with its properties in detail .We also learned how to access those rest calls using and fetch response in return in an asynchronous manner.Good going see you soon !</p><blockquote><em>Stay Tuned and thanks for Engaging , Until Next time ✌️</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad0bf6785a9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter: Defining a Structure for GetX -Part 2 ( Understanding Models )]]></title>
            <link>https://medium.com/@pimpalkhare.sawan/flutter-defining-a-structure-for-getx-part-2-understanding-models-ff9559d73e8b?source=rss-99389c6a7d2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff9559d73e8b</guid>
            <category><![CDATA[model-class]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[getx]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Oddmentiusmaximus]]></dc:creator>
            <pubDate>Sun, 03 Oct 2021 14:26:59 GMT</pubDate>
            <atom:updated>2021-10-03T14:40:38.477Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FSWjF9zQ4CTktab8HQN%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FSWjF9zQ4CTktab8HQN%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FSWjF9zQ4CTktab8HQN%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/18cccf7eb93b7cfe907b98c3095ba2bf/href">https://medium.com/media/18cccf7eb93b7cfe907b98c3095ba2bf/href</a></iframe><p>In the last <a href="https://medium.com/@pimpalkhare.sawan/flutter-defining-a-structure-for-getx-part-1-594800476e4e"><em>article</em></a><em>,</em> we learned about how to define a basic structure and a complex structure when starting a new page in flutter using GetX.</p><p>In today&#39;s post, we will discuss when integrating API calls how to structure <strong>Models</strong>.</p><h3>Let’s Dive In</h3><h3>Models-</h3><ul><li>So, there are many complex definitions of data model but in its simplest form data model is a way of visualizing data and setting its defined types so you can create functions to process and format it.</li><li>When we add data to a model instance it acts as a temporary memory holder until the app is closed or until the memory cache is cleared.</li><li>Models are required because very frankly when you call an API you can receive multiple fields or data and you can’t just directly use the data response as is bypassing its defined types from the type of data received such as JSON or List.</li><li>Models are going to be required for most of your API calls in general, so how do we structurize them.</li><li>From a directory structure perspective once a model directory is created you can add as many models and once a model is defined we don&#39;t need to edit them frequently if done correctly. It&#39;s a set it and forget kinda objective.</li></ul><blockquote>My structure for a Model directory looks like this -<br>Directory — models -</blockquote><blockquote>— — — — — \user_model.dart</blockquote><blockquote>— — — — — \login_model.dart</blockquote><blockquote>— — — — — \ demo_model.dart</blockquote><p>If a structure response has multiple lists or the response is very long it a single page can get too long or a single model class would need multiple model classes to support the base model class in that instance I like to separate those models into a subdirectory.</p><ul><li>Example-</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vSMjtJhtY0HwiK3r8izKWg.png" /></figure><p>or</p><blockquote>Directory — models -</blockquote><blockquote>— — — — — \login_model</blockquote><blockquote>— — — — — — — — — \login_model.dart</blockquote><blockquote>— — — — — — — — — \login_data_model.dart</blockquote><ul><li>In the current example, we segregated our data models which serve for the response of the same API call but for clarity of those two we put them in two files.</li><li>When models are being defined in flutter it&#39;s a good practice to declare them null safe using ‘?’ -</li></ul><blockquote>Example-</blockquote><blockquote><em>String name </em>becomes <em>String? name</em></blockquote><blockquote>int i becomes int? i</blockquote><blockquote>bool isTrue becomes bool? isTrue</blockquote><ul><li>These are useful when any kind of null value is passed to the model it will handle it and avoid throwing an error.</li></ul><blockquote>When the type of data is being received is ambiguous or is unknown you can set it to <em>dynamic </em>or<em> var .</em></blockquote><ul><li>As var and dynamic are by default null safe so need to define them with ‘?’.</li></ul><blockquote>Example -</blockquote><blockquote>var data1;</blockquote><blockquote>dynamic data2;</blockquote><p>If you have a JSON model defined you can auto-generate model class for it in a flutter — Some of the favorite sites are.</p><ul><li>To parse string JSON into proper format -</li></ul><p><a href="https://jsonformatter.org/json-parser">JSON Parser Online to parse JSON</a></p><ul><li>To create Model Class from JSON -</li></ul><ul><li><a href="https://javiercbk.github.io/json_to_dart/">JSON to Dart</a></li><li><a href="https://app.quicktype.io/">Instantly parse JSON in any language | quicktype</a></li></ul><p>The app.quicktype.io provides lots of tools to get your model right and just the way you want it. Please do feel free to play around.</p><h3>Converting Model Class to Observable in GetX -</h3><ul><li>So we understood how a normal model is defined and structured but in GetX we can define a Model class as observable.</li><li>There are two ways we can do this —</li></ul><ol><li>You can convert your class values to obs—</li></ol><ul><li>In this model we set every variable type extended with “.obs”.</li></ul><p>For Example —</p><pre>class RxUser {<br>  final name = &quot;Odd&quot;.obs;<br>  final age = 2.obs;<br>}</pre><ul><li>So by observable, we mean that whenever the value in the Model changes through GetStreams it will get notified and automatically updated.</li></ul><p>2. You can convert the entire class to be an observable -</p><ul><li>In this we instead of declaring every variable we convert the entire class to observable using “obs”.</li></ul><p>For Example —</p><pre>class User {<br>  User({String name, int age});<br>  String? name;<br>  int? age;<br>}<br><br>// when instantianting:<br>final user = User(name: &quot;Odd&quot;, age: 2).obs;</pre><p><strong>When you are making your own classes observable, there is a different way to update them:</strong></p><p>Let&#39;s take this Step by Step —</p><ol><li>First, we are going to make the entire class observable instead of each attribute-</li></ol><pre>class User() {<br>  User({this.name = &#39;&#39;, this.age = 0});<br>  String name;<br>  int age;<br>}<br>// as we predefining a value to the variable we dont need to make them nullsafe</pre><p>2. Then in the controller file we need to declare an object and make it observable.</p><ul><li>After that, we will pass the parameters we need to update.</li></ul><pre>class UserController  extends GetxController{<br>final user = User().obs;</pre><pre>user.update( (user) {<br>user.name = &#39;Minnie&#39;;<br>user.age = 12;<br>});<br>}</pre><p>An alternate way of doing this would be directly passing the parameter in the Model itself.</p><pre>// an alternative way of update the user variable:<br>user(User(name: &#39;Josh&#39;, age: 45));</pre><p>3. Using it in your View or UI —</p><pre>class UserPage extends StatelessWidget {<br>  final logic = Get.put(UserController());<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Obx(() {<br>      return Text(&quot;Name ${user.value.name}: Age: ${user.value.age}&quot;);<br>    });<br>  }<br>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxUPOqo6E1XvWXwlCyQ%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fspacejam-space-jam-movie-xUPOqo6E1XvWXwlCyQ&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExa2tpZ3dzbGJ2N3J0NndrNjQ3em91YW9sY2ZqNGphMHJvNTdob3l5eSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FxUPOqo6E1XvWXwlCyQ%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cb4d5e7f42ae858a6cd411b149c29d6/href">https://medium.com/media/8cb4d5e7f42ae858a6cd411b149c29d6/href</a></iframe><h3>Summary -</h3><p>Yay ! we made it so in this post we learned about model class, how to declare variables in the model class, how to structure your model classes for simple and complex projects, and finally how to define observable models using GetX and implementing them in our build View through controllers.</p><blockquote><em>Stay Tuned and thanks for Engaging , Until Next time ✌️</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff9559d73e8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter: Defining a Structure for GetX -Part 1(Creating a New Page)]]></title>
            <link>https://medium.com/@pimpalkhare.sawan/flutter-defining-a-structure-for-getx-part-1-594800476e4e?source=rss-99389c6a7d2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/594800476e4e</guid>
            <category><![CDATA[getx]]></category>
            <category><![CDATA[coding-style]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Oddmentiusmaximus]]></dc:creator>
            <pubDate>Thu, 30 Sep 2021 18:07:37 GMT</pubDate>
            <atom:updated>2021-10-02T16:21:17.389Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xtEWIKO4I_b3A3k2" /></figure><p>Flutter has been one of my most favorite frameworks that I worked on over the years. So, when I learned about Getx state management I was truly in love. It gave me soo much control over states and provided me with a ton of utilities right out of the box.</p><p>One of the first challenged I faced while getting into Getx was defining a sound structure that is scalable as industry-level projects can go from 0 to 1000 in a matter of weeks and having sound control over your code is very important. So after experimenting and deploying multiple applications using Getx Flutter here’s my insight.</p><h3>Let&#39;s start with a brief on GetX —</h3><ul><li>GetX is a state management micro-framework, it not only enables us to build applications for android, iOS, web, Linux, macOS and Linux, with GetX you can build server applications with the same syntax as Flutter.</li><li>GetX is efficient and performance-oriented and has developed its own GetStream and GetValue to improve response time and reduce RAM consumption.</li><li>Less Boilerplate code its very clean and clear in its approach.</li><li>In GetX everything is reactive, and nothing depends on code generators, increasing your productivity in all aspects of your development.</li><li>It&#39;s very well maintained and updates are frequent the community is very active around GetX and enjoys growing around it.</li></ul><h3>Ok! So we had a brief intro now let&#39;s see what we came here for —</h3><ul><li>When using GetX you need to create multiple classes for your stateless/stateful widgets, your bindings, controller, etc.</li></ul><p>My structure for a single page looks like this -<br>Directory — Page1 -</p><p>— — — — — \controller.dart</p><p>— — — — — \page_view.dart</p><p>— — — — —\ binding.dart</p><ul><li>This is one of the simplest ways to define a page for a small-level project.</li><li>On a page, you have to first define a directory with the name of the screen.</li><li>Then define the controller where all your logical code functional code will be written along with the declaration of controller and variables.</li><li>Next will be your design file where all your code that will be rendered will be written.</li><li>Last will be the bindings will you can bind your controllers.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1SBAgIzLP87NOcO1RBacWg.png" /></figure><p>It&#39;s simply elegant and fast but for bigger projects, I would recommend segregating your applicative and design files into two different directories as -</p><p>Complex Directory — Page1</p><p>— — — — \ui</p><p>— — — — — \login_page.dart</p><p>— — — — — \forgot_password_page.dart</p><p>— — — — \application</p><p>— — — — — \controller.dart</p><p>— — — — — \ binding.dart</p><ul><li>As if pages are connected we can inject one controller into multiple views to maintain the logic if they are interdependent.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IXTp201GQ3DcvrZ8LhL9UA.png" /></figure><h3>End of Line -</h3><p>Phew that was a lot to take in but we made it and hopefully, it helped you a little in your journey to understand a page structure for small and large-scale projects using GetX. In the following post, we will learn about API Calls directory setups, models directory setup, and much more ….</p><blockquote>Stay Tuned and thanks for Engaging</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=594800476e4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>