<?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"><channel><title><![CDATA[Aayush's Blog]]></title><description><![CDATA[Aayush's Blog]]></description><link>https://aayushpaigwar.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 03:48:41 GMT</lastBuildDate><atom:link href="https://aayushpaigwar.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Use Shared Preferences to Keep Users Logged In on Flutter Apps]]></title><description><![CDATA[Need for Managing the Session in Flutter Apps 🤔
Managing user sessions is crucial for providing a seamless user experience in mobile applications. In this blog, you will learn how to store and save the login session using shared_preferences in a Flu...]]></description><link>https://aayushpaigwar.hashnode.dev/how-to-use-shared-preferences-to-keep-users-logged-in-on-flutter-apps</link><guid isPermaLink="true">https://aayushpaigwar.hashnode.dev/how-to-use-shared-preferences-to-keep-users-logged-in-on-flutter-apps</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Shared Preferences]]></category><category><![CDATA[cache]]></category><category><![CDATA[Dart]]></category><category><![CDATA[Google]]></category><category><![CDATA[Open Source]]></category><category><![CDATA[sessionStorage]]></category><dc:creator><![CDATA[Aayush Paigwar]]></dc:creator><pubDate>Sat, 22 Jun 2024 16:51:14 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719074189355/b9700030-3e70-42ff-9126-9d67b587437b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<h3 id="heading-need-for-managing-the-session-in-flutter-apps">Need for Managing the Session in Flutter Apps 🤔</h3>
<p>Managing user sessions is crucial for providing a seamless user experience in mobile applications. In this blog, you will learn how to <strong><em><mark>store and save the login session</mark></em></strong> using <code>shared_preferences</code> in a Flutter application. This includes implementing the login functionality, a <em>"Remember Me"</em> option, and <em>logout</em> functionality.<br />Let's get Started!🚀</p>
<hr />
<h3 id="heading-setting-up-shared-preferences"><strong>Setting Up Shared Preferences:</strong></h3>
<p>First, ensure you have the <a target="_blank" href="https://pub.dev/packages/shared_preferences">shared_preferences</a> package added to your <em>pubspec.yaml:</em></p>
<pre><code class="lang-yaml"><span class="hljs-attr">dependencies:</span>
  <span class="hljs-attr">shared_preferences:</span> <span class="hljs-string">^latest</span>
</code></pre>
<p>Then, import the package in your Dart file:</p>
<pre><code class="lang-dart"><span class="hljs-keyword">import</span> <span class="hljs-string">'package:shared_preferences/shared_preferences.dart'</span>;
</code></pre>
<h3 id="heading-saving-isloggedin-status"><strong>Saving <mark>isLoggedIn</mark> Status:</strong></h3>
<p>When a user logs in, you can save their login status using shared preferences. Here’s a function to save the user’s login status:</p>
<pre><code class="lang-dart">Future&lt;<span class="hljs-keyword">void</span>&gt; saveLoginStatus(<span class="hljs-built_in">bool</span> isLoggedIn) <span class="hljs-keyword">async</span> {
  <span class="hljs-keyword">final</span> SharedPreferences prefs = <span class="hljs-keyword">await</span> SharedPreferences.getInstance();
  <span class="hljs-keyword">await</span> prefs.setBool(<span class="hljs-string">'isLoggedIn'</span>, isLoggedIn);
}
</code></pre>
<h3 id="heading-retrieving-isloggedin-status"><strong>Retrieving <mark>isLoggedIn</mark> Status:</strong></h3>
<p>When the app starts, you need to check if the user is <strong>already logged in</strong>. This function retrieves the stored login status:</p>
<pre><code class="lang-dart">Future&lt;<span class="hljs-built_in">bool</span>&gt; isLoggedIn() <span class="hljs-keyword">async</span> {
  <span class="hljs-keyword">final</span> SharedPreferences prefs = <span class="hljs-keyword">await</span> SharedPreferences.getInstance();
  <span class="hljs-keyword">return</span> prefs.getBool(<span class="hljs-string">'isLoggedIn'</span>) ?? <span class="hljs-keyword">false</span>;
}
</code></pre>
<h3 id="heading-using-the-isloggedin-status"><strong>Using the <mark>isLoggedIn</mark> Status:</strong></h3>
<p>You can use the <strong><em>retrieved login status</em></strong> to determine the <em>initial screen</em> of your app. Here’s how you can modify your main function to check the login status:</p>
<pre><code class="lang-dart"><span class="hljs-keyword">void</span> main() <span class="hljs-keyword">async</span> {
  WidgetsFlutterBinding.ensureInitialized();
  <span class="hljs-keyword">final</span> <span class="hljs-built_in">bool</span> loggedIn = <span class="hljs-keyword">await</span> isLoggedIn();
  runApp(MyApp(isLoggedIn: loggedIn));
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyApp</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  <span class="hljs-keyword">final</span> <span class="hljs-built_in">bool</span> isLoggedIn;
  <span class="hljs-keyword">const</span> MyApp({<span class="hljs-keyword">required</span> <span class="hljs-keyword">this</span>.isLoggedIn});

  <span class="hljs-meta">@override</span>
  Widget build(BuildContext context) {
    <span class="hljs-keyword">return</span> MaterialApp(
      home: isLoggedIn ? DashboardScreen() : LoginScreen(),
    );
  }
}
</code></pre>
<h3 id="heading-logging-out"><strong>Logging Out:</strong></h3>
<p>Finally, implement a logout function <strong><em>to clear the stored login session</em></strong>:</p>
<pre><code class="lang-dart">Future&lt;<span class="hljs-keyword">void</span>&gt; logout() <span class="hljs-keyword">async</span> {
  <span class="hljs-keyword">final</span> SharedPreferences prefs = <span class="hljs-keyword">await</span> SharedPreferences.getInstance();
  <span class="hljs-keyword">await</span> prefs.clear();
}
</code></pre>
<p>To trigger the logout, you can use the onTap / onPressed widget:</p>
<pre><code class="lang-dart">IconButton(
            icon: <span class="hljs-keyword">const</span> Icon(Icons.logout),
            onPressed: () {
              logout(context);
            },
          ),
</code></pre>
<hr />
<h3 id="heading-conclusion"><strong>Conclusion:</strong></h3>
<p>Using shared preferences to manage login sessions is a simple yet effective way to enhance the user experience in your Flutter applications. By storing user login status securely, you can keep users logged in and provide seamless navigation throughout your app.<br />For a complete example, refer to the sample code from <a target="_blank" href="https://github.com/AayushPaigwar/flutter-session-management"><em><mark>this GitHub repository</mark></em></a><em><mark>.</mark></em></p>
]]></content:encoded></item><item><title><![CDATA[Building and Pushing Docker Images from Mac M1 to Azure Container Registry: A Complete Guide]]></title><description><![CDATA[Introduction:
In today's rapidly evolving tech landscape, developers often find themselves working across various platforms and architectures. With the rise of ARM-based Macs like the M1, ensuring compatibility and smooth deployment to cloud services...]]></description><link>https://aayushpaigwar.hashnode.dev/building-and-pushing-docker-images-from-mac-m1-to-azure-container-registry-a-complete-guide</link><guid isPermaLink="true">https://aayushpaigwar.hashnode.dev/building-and-pushing-docker-images-from-mac-m1-to-azure-container-registry-a-complete-guide</guid><category><![CDATA[Docker]]></category><category><![CDATA[Python]]></category><category><![CDATA[deployment]]></category><category><![CDATA[Azure]]></category><category><![CDATA[Azure container registry]]></category><category><![CDATA[azure-devops]]></category><category><![CDATA[APIs]]></category><category><![CDATA[architecture]]></category><category><![CDATA[macOS]]></category><category><![CDATA[ARM]]></category><category><![CDATA[docker images]]></category><dc:creator><![CDATA[Aayush Paigwar]]></dc:creator><pubDate>Sun, 09 Jun 2024 21:19:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1717967571678/9ecddf1a-3aaa-4e38-ae67-878ad80b976f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<h2 id="heading-introduction">Introduction:</h2>
<p>In today's rapidly evolving tech landscape, developers often find themselves working across various platforms and architectures. With the rise of <strong>ARM-based Macs like the M1,</strong> ensuring compatibility and smooth deployment to cloud services such as <strong>Azure Container Registry (ACR)</strong> becomes essential. In this blog post, we'll explore how to build and <strong>push Docker images from a Mac M1 to ACR seamlessly.</strong></p>
<h3 id="heading-understanding-the-architecture-difference"><strong>Understanding the Architecture Difference:</strong></h3>
<p>Mac M1 systems utilize the <strong>ARM64</strong> <strong>architecture</strong>, while most cloud-based infrastructure runs on <strong>x86</strong> <strong>architecture</strong>. This disparity can lead to compatibility issues when <strong>deploying</strong> Docker images from <strong>Mac M1 to ACR.</strong></p>
<p><strong>Solution:</strong><br />Leveraging <strong>Docker Buildx for Multi-Platform Support</strong>. Docker Buildx, a powerful CLI plugin, comes to the rescue by enabling developers to build Docker images for multiple platforms simultaneously. Let's dive into the steps involved:</p>
<h2 id="heading-step-1-set-up-docker-buildx-builder-instance"><strong>Step 1: Set Up Docker Buildx Builder Instance</strong></h2>
<p>Create a Docker Buildx builder instance using the following command:</p>
<pre><code class="lang-plaintext">docker buildx create --name mybuilder --use
</code></pre>
<p>This command initializes a builder instance named <strong>"mybuilder"</strong> for multi-platform builds.</p>
<h2 id="heading-step-2-ide-authentication-to-azure-container-registry">Step 2: IDE Authentication to Azure Container Registry</h2>
<p>Before pushing your image, establish a connection <strong>between your ACR and local IDE. Login to ACR using:</strong></p>
<pre><code class="lang-plaintext">az acr login -n &lt;your-acr-name&gt;
</code></pre>
<p>Make sure you have enabled the <strong><em>admin user</em></strong> in the <strong><em>Azure Portal</em></strong> under <strong><em>Access</em> keys</strong> settings as shown in the image below.</p>
<ul>
<li><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1717966459276/0a1b4fd8-103d-4d44-b0be-f521b7551784.png" alt class="image--center mx-auto" /></li>
</ul>
<h2 id="heading-kio">**</h2>
<p>Step 3: Building and Pushing Docker Image to ACR:**</p>
<p>Now, let's build and push our Docker image to Azure Container Registry. Execute the following command:</p>
<pre><code class="lang-plaintext">docker buildx build --platform linux/amd64,linux/arm64 -t &lt;acr-name&gt;.azurecr.io/my-image:latest --push .
</code></pre>
<p><strong>Explanation of the above command:</strong></p>
<ul>
<li><p><code>docker buildx build</code>: Initiates the build process using Docker Buildx.</p>
</li>
<li><p><code>--platform linux/amd64,linux/arm64</code>: Specifies the target platforms for the build.</p>
</li>
<li><p><code>-t &lt;acr-name&gt;.</code><a target="_blank" href="http://azurecr.io/mac:latest"><code>azurecr.io/mac:latest</code></a>: Tags the resulting image with the specified name and tag.</p>
</li>
<li><p><code>--push .</code> : Pushes the built image to the specified container registry.</p>
</li>
</ul>
<p>Replace <code>&lt;acr-name&gt;</code> with the name of your <strong>Azure Container Registry</strong>. This command builds a <strong>multi-platform image for</strong> <strong>both x86 and ARM architectures</strong> and pushes it to ACR.</p>
<h2 id="heading-how-to-load-the-docker-image-in-docker-desktop">How to load the Docker image in Docker Desktop?</h2>
<p>After pushing the image to the <strong>ACR</strong>, the image is <strong>stored in the build cache</strong> while building it if you want to <strong>load the docker image on the docker desktop</strong> you can use the following command:</p>
<pre><code class="lang-plaintext">
docker buildx build --load -t &lt;your-image-name&gt;:&lt;tag&gt; .
</code></pre>
<hr />
<p>In case of encountering an error shown below.</p>
<pre><code class="lang-plaintext">[+] Building 0.0s (0/0)                               docker:desktop-linux                                                    
ERROR: Multi-platform build is not supported for the docker driver.
Switch to a different driver, or turn on the containerd image store, and try again.
Learn more at https://docs.docker.com/go/build-multi-platform/
</code></pre>
<p>Then, try the following commands:</p>
<pre><code class="lang-plaintext">
docker buildx rm mybuilder
</code></pre>
<p>The above command <strong>removes</strong> the <strong>previously created builder</strong>.<br />Then recreate a builder using:</p>
<pre><code class="lang-plaintext">docker buildx create --name mybuilder --use --driver docker-container
</code></pre>
<h3 id="heading-now-continue-from-step-2-onwards">Now, continue from Step 2 onwards.</h3>
<hr />
<h2 id="heading-conclusion">Conclusion:</h2>
<p>Using <strong>Docker Buildx</strong> makes it easy for developers to create and <strong>send Docker images from Mac M1 computers to Azure Container Registry.</strong> This method guarantees that your software works smoothly on different types of computer systems, making it easier to deploy without running into compatibility issues. Embracing this multi-platform approach is crucial for managing the complexities of today's software development and deployment.</p>
]]></content:encoded></item></channel></rss>