<?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 Singhprashant99 on Medium]]></title>
        <description><![CDATA[Stories by Singhprashant99 on Medium]]></description>
        <link>https://medium.com/@singhprashant7506?source=rss-90a00be5c15a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PeZ_m9MJo8zAMQLgqJ7fDQ.jpeg</url>
            <title>Stories by Singhprashant99 on Medium</title>
            <link>https://medium.com/@singhprashant7506?source=rss-90a00be5c15a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 19:56:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@singhprashant7506/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[SOLID: Keeping AI-Generated Flutter Code Maintainable]]></title>
            <link>https://medium.com/@singhprashant7506/solid-keeping-ai-generated-flutter-code-maintainable-0fec9ddb4f37?source=rss-90a00be5c15a------2</link>
            <guid isPermaLink="false">https://medium.com/p/0fec9ddb4f37</guid>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[bloc]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Singhprashant99]]></dc:creator>
            <pubDate>Tue, 11 Aug 2026 18:00:46 GMT</pubDate>
            <atom:updated>2026-08-11T18:00:46.530Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Problem</h3><p>I built <strong>FoodMate</strong>, a Flutter AI chat app with around 60 Dart files, 5 AI providers, streaming responses, chat history, favourites, and 43 tests.</p><p>🔗 <strong>GitHub:</strong> <a href="https://github.com/singhprashant1/food_mate_ai">https://github.com/singhprashant1/food_mate_ai</a></p><p>The app uses:</p><ul><li>Gemini Flash</li><li>Llama 3.3 via Groq</li><li>Llama 3.2 via Ollama</li><li>GPT-OSS via OpenRouter</li><li>An offline model</li></ul><p>Three providers broke on the same day. Surprisingly, the fixes required only <strong>three files and about five lines of code</strong>.</p><p>The reason was simple: each responsibility had a clear place in the architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ggjbKC9sOn80wYlHvMB8SA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3kDl1IuRnyGYVZOOxYvRNQ.png" /></figure><h3>How SOLID Helped</h3><h3>1. Single Responsibility</h3><p>Each class/file has one clear responsibility.</p><p>For example, all providers need to convert streaming bytes into text. That logic exists in one file:</p><pre>Stream&lt;String&gt; sseLines(Stream&lt;List&lt;int&gt;&gt; source) =&gt;<br>    const LineSplitter().bind(utf8.decoder.bind(source));</pre><p>Every provider uses it instead of implementing the logic again.</p><p><strong>Result:</strong> when the streaming code broke, there was only one place to fix.</p><h3>2. Open/Closed Principle</h3><p>New AI models are added through the AiModel enum.</p><p>The model picker automatically gets the new model from AiModel.values, while an exhaustive switch ensures every new model is properly wired.</p><p>If something is missing, the compiler tells us immediately.</p><p><strong>Result:</strong> fewer runtime surprises and less code modification.</p><h3>3. Liskov Substitution</h3><p>Every AI provider follows the same AiRemoteDataSource contract.</p><p>Each provider must:</p><ul><li>Stream text fragments in order</li><li>Close the stream when finished</li><li>Convert provider errors into AppException</li></ul><p>This allows the repository to work with any provider without knowing which provider is being used.</p><h3>4. Interface Segregation</h3><p>Instead of one large interface, the project uses separate contracts for normal and streaming operations:</p><pre>UseCase&lt;T, Params&gt;<br>StreamUseCase&lt;T, Params&gt;</pre><p>A normal use case doesn’t need to implement streaming functionality it doesn’t use.</p><h3>5. Dependency Inversion</h3><p>The application depends on abstractions instead of concrete implementations.</p><p>Dependency injection is centralized in injection.dart, which maps interfaces to their implementations.</p><p>This makes it easier to replace implementations without changing the rest of the application.</p><h3>The Real Payoff</h3><p>Two AI providers broke because their model IDs changed. Fixing them required changing only the model IDs.</p><p>Then the streaming layer had a type mismatch:</p><pre>Utf8Decoder is not a subtype of<br>StreamTransformer&lt;Uint8List, String&gt;</pre><p>The fix was one line:</p><pre>const LineSplitter().bind(utf8.decoder.bind(source));</pre><p>Because all providers shared the same streaming utility, fixing it once fixed all three providers.</p><p>That’s the real benefit of good architecture:</p><blockquote><strong><em>SOLID doesn’t eliminate bugs. It makes bugs easier and cheaper to find.</em></strong></blockquote><h3>How to Keep AI Coding Inside the Architecture</h3><p>When working with AI assistants:</p><ol><li><strong>Define the architecture first.</strong></li><li><strong>Tell the AI exactly which files it can modify.</strong></li><li><strong>Use interfaces to define clear contracts.</strong></li><li><strong>Let the compiler enforce exhaustive cases.</strong></li><li><strong>Keep strict linting and analysis enabled.</strong></li><li><strong>Keep dependency injection easy to understand.</strong></li><li>Always ask: <strong>“Where does this belong?” before “How should I implement it?”</strong></li></ol><h3>Takeaway</h3><p>AI can generate code faster than humans can review it.</p><p>So the challenge isn’t simply <strong>writing code quickly</strong>. It’s being able to <strong>find and fix incorrect code quickly</strong>.</p><p>In FoodMate, five AI providers share only two implementations, and multiple failures were fixed in a few files because every responsibility had a clear place.</p><p><strong>That’s what good architecture gives you: fewer places to look when something breaks.</strong></p><p>🔗 <strong>Explore the complete FoodMate project on GitHub:</strong><br><a href="https://github.com/singhprashant1/food_mate_ai">https://github.com/singhprashant1/food_mate_ai</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0fec9ddb4f37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secure Your Flutter App’s Images with Easy Encryption Techniques]]></title>
            <link>https://medium.com/@singhprashant7506/secure-your-flutter-apps-images-with-easy-encryption-techniques-6440ede6ac0c?source=rss-90a00be5c15a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6440ede6ac0c</guid>
            <dc:creator><![CDATA[Singhprashant99]]></dc:creator>
            <pubDate>Tue, 12 Nov 2024 09:11:16 GMT</pubDate>
            <atom:updated>2024-11-12T11:12:24.407Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L0SI4HluYWcKGRkp" /></figure><p><strong>Introduction</strong></p><p>In today’s digital world, data security is a top priority. One aspect of securing sensitive data involves encrypting images, especially when dealing with personal or confidential information. In this article, we’ll explore how to encrypt and decrypt images in Flutter using the encrypt package. Whether you&#39;re building an app that handles photos, documents, or other media, understanding image encryption can give you the confidence to handle sensitive data securely.</p><h3>Why Image Encryption?</h3><p>Image encryption is essential when you need to store or transmit images securely, preventing unauthorized access. For instance, a healthcare app storing patient images or a private messaging app sharing user photos would benefit from encryption to ensure data remains confidential. Encrypting an image transforms its contents into an unreadable format. Only users with the correct decryption key can revert it to its original form, making it extremely difficult for hackers to extract useful information.</p><p>In this guide, we’ll cover both the encryption and decryption of images using the encrypt package, which provides an easy interface for AES (Advanced Encryption Standard) encryption in Dart.</p><h3>Getting Started</h3><p>To get started, first add the encrypt package to your pubspec.yaml:</p><pre>dependencies:<br>  encrypt: ^5.0.0</pre><p><strong>Then, import the necessary libraries in your Dart file.</strong></p><pre>import &#39;dart:convert&#39;;<br>import &#39;dart:typed_data&#39;;<br>import &#39;dart:io&#39; as io;<br>import &#39;package:encrypt/encrypt.dart&#39; as encrypt;<br>import &#39;package:your_project/utility/constants.dart&#39;;</pre><p>Make sure to replace your_project/utility/constants.dart with the actual path where you’ll store your encryption keys.</p><h3>Step 1: Setting Up the Encryption Class</h3><p>To handle encryption, let’s create an Encryption class with methods for both encrypting and decrypting text and images.</p><pre>class Encryption {<br>  // Method to encrypt text<br>  String encryptText(String plainText) {<br>    final key = encrypt.Key.fromBase64(<br>      base64Encode(utf8.encode(Constants.textEncryptionKey)),<br>    );<br>    final iv = encrypt.IV.fromBase64(<br>      base64Encode(utf8.encode(Constants.textInitialisationVector)),<br>    );<br><br>    final encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));<br>    final encrypted = encrypter.encrypt(plainText, iv: iv);<br>    return encrypted.base64;<br>  }<br><br>  // Method to decrypt text<br>  String decryptText(String encryptedText) {<br>    final key = encrypt.Key.fromBase64(<br>      base64Encode(utf8.encode(Constants.textEncryptionKey)),<br>    );<br>    final iv = encrypt.IV.fromBase64(<br>      base64Encode(utf8.encode(Constants.textInitialisationVector)),<br>    );<br><br>    final encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));<br>    final decrypted = encrypter.decrypt64(encryptedText, iv: iv);<br>    return decrypted;<br>  }<br><br>  // Method to encrypt an image<br>  Encrypted encryptImage(List&lt;int&gt; imageInBytes) {<br>    final key = encrypt.Key.fromBase64(<br>      base64Encode(utf8.encode(Constants.textEncryptionKey)),<br>    );<br>    final iv = encrypt.IV.fromBase64(<br>      base64Encode(utf8.encode(Constants.textInitialisationVector)),<br>    );<br><br>    final encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));<br>    final encrypted = encrypter.encryptBytes(imageInBytes, iv: iv);<br>    return encrypted;<br>  }<br><br>  // Method to decrypt an image<br>  List&lt;int&gt; decryptImage(Encrypted encryptedData) {<br>    final key = encrypt.Key.fromBase64(<br>      base64Encode(utf8.encode(Constants.textEncryptionKey)),<br>    );<br>    final iv = encrypt.IV.fromBase64(<br>      base64Encode(utf8.encode(Constants.textInitialisationVector)),<br>    );<br><br>    final encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc));<br>    final decrypted = encrypter.decryptBytes(encryptedData, iv: iv);<br>    return decrypted;<br>  }<br>}</pre><h4>Explanation</h4><ol><li><strong>Keys and IV (Initialization Vector)</strong>: Both the encryption key and IV are generated from base64-encoded strings. These provide security by ensuring that each encryption output is unique.</li><li><strong>AES Encryption</strong>: We’re using AES in CBC (Cipher Block Chaining) mode, which is a strong, reliable encryption standard.</li><li><strong>encryptText &amp; decryptText</strong>: These methods convert text data to and from an encrypted format, useful for encrypting plain strings like usernames or notes.</li><li><strong>encryptImage &amp; decryptImage</strong>: These methods handle image encryption and decryption by taking image data as a byte array and transforming it securely.</li></ol><h3>Step 2: Encrypting and Saving an Image</h3><p>With our Encryption class ready, let&#39;s see how we can encrypt an image. Suppose we have an image file; here’s how to encrypt and save it:</p><pre>Future&lt;void&gt; saveEncryptedImage(io.File file) async {<br>  Encryption encryption = Encryption();<br>  final tempFile = await file.readAsBytes();<br>  <br>  // Encrypt the image<br>  Encrypted encryptedImage = encryption.encryptImage(tempFile);<br>  <br>  // Save encrypted bytes back to file<br>  Uint8List encryptedBytes = Uint8List.fromList(encryptedImage.bytes);<br>  await file.writeAsBytes(encryptedBytes);<br>}</pre><p>This method reads an image file, encrypts the content using our encryptImage method, and saves the encrypted data back to the file. This approach ensures that even if someone accesses the file, it won’t be usable without decryption.</p><h3>Step 3: Decrypting and Converting Image to Base64</h3><p>To work with the encrypted image, we need to decrypt it. Here’s how to retrieve the image in its original form and convert it to a Base64 string for easy transmission or display:</p><pre>String? getImageToBase64(String? imagePath) {<br>  String? img64;<br>  try {<br>    if (imagePath != null &amp;&amp; imagePath.isNotEmpty) {<br>      Encryption encryption = Encryption();<br>      final bytes = io.File(imagePath).readAsBytesSync();<br>      <br>      // Convert to base64 for encryption<br>      String base64String = base64Encode(bytes);<br>      Encrypted encryptedImage = Encrypted.from64(base64String);<br>      <br>      // Decrypt the image<br>      List&lt;int&gt; decryptedImage = encryption.decryptImage(encryptedImage);<br>      Uint8List decryptedBytes = Uint8List.fromList(decryptedImage);<br>      <br>      // Convert decrypted image to base64<br>      img64 = base64Encode(decryptedBytes);<br>    }<br>  } catch (e) {<br>    img64 = null;<br>    debugPrint(&quot;Error converting image to Base64: $e&quot;);<br>  }<br>  return img64;<br>}</pre><h3>Final Thoughts</h3><p>Encrypting images can provide strong protection for sensitive media, safeguarding your app and your users. With the encrypt package, it’s easy to implement AES encryption in Flutter, protecting files both at rest and during transmission. Whether you’re building an app for secure messaging, healthcare, or document storage, understanding and applying encryption is a powerful tool for ensuring data privacy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6440ede6ac0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>