<?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 Omar Elhbrouk on Medium]]></title>
        <description><![CDATA[Stories by Omar Elhbrouk on Medium]]></description>
        <link>https://medium.com/@omar.elhbrouk2?source=rss-64a84e50245b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*P7e-ACdyH0uwIueBTyqmrw.jpeg</url>
            <title>Stories by Omar Elhbrouk on Medium</title>
            <link>https://medium.com/@omar.elhbrouk2?source=rss-64a84e50245b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 01:03:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@omar.elhbrouk2/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[Beyond Wi-Fi: Building a Truly Connected Flutter App with internet_connection_checker_plus and BLoC]]></title>
            <link>https://medium.com/@omar.elhbrouk2/beyond-wi-fi-building-a-truly-connected-flutter-app-with-internet-connection-checker-plus-and-bloc-e2a04521d3da?source=rss-64a84e50245b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2a04521d3da</guid>
            <category><![CDATA[internet-connectivity]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[user-experience-ux]]></category>
            <category><![CDATA[flutter-bloc-pattern]]></category>
            <dc:creator><![CDATA[Omar Elhbrouk]]></dc:creator>
            <pubDate>Mon, 23 Sep 2024 12:02:12 GMT</pubDate>
            <atom:updated>2024-09-23T12:02:12.058Z</atom:updated>
            <content:encoded><![CDATA[<p>In a world dominated by connectivity, a Flutter app that merely detects Wi-Fi or mobile data isn’t enough. We need to know if our apps are genuinely online and can communicate with the outside world. That’s where the power duo of <a href="https://pub.dev/packages/internet_connection_checker_plus">internet_connection_checker_plus </a>and <a href="https://pub.dev/packages/flutter_bloc">BLoC </a>comes into play.</p><p><strong>The Need for True Connectivity Awareness</strong></p><p>While packages like connectivity_plus are excellent for determining the type of connection, they don’t guarantee internet access. A user might be connected to Wi-Fi with no internet, leading to a frustrating app experience.</p><p>internet_connection_checker_plus, on the other hand, goes the extra mile. It verifies whether your app can actually reach the internet, providing a much more reliable connectivity status.</p><p><strong>Harnessing the Power of BLoC</strong></p><p>To effectively manage and react to connectivity changes, we’ll leverage the BLoC (Business Logic Component) pattern. BLoC helps us separate our app’s business logic from the UI, making our code more organized, maintainable, and testable.</p><p><strong>Implementation Breakdown</strong></p><p><strong>1. Project Setup:</strong></p><ul><li>Install the necessary packages:</li></ul><pre>flutter pub add flutter_bloc internet_connection_checker_plus</pre><p><strong>2. Internet Event (internet_event.dart):</strong></p><pre>part of &#39;internet_bloc.dart&#39;;<br><br>@immutable<br>sealed class InternetEvent {}<br><br>class ConnectedEvent extends InternetEvent {}<br><br>class NotConnectedEvent extends InternetEvent {}</pre><ul><li>We define sealed classes for InternetEvent to represent connection state changes.</li></ul><p><strong>3. Internet State (internet_state.dart):</strong></p><pre>part of &#39;internet_bloc.dart&#39;;<br><br>@immutable<br>sealed class InternetState {}<br><br>final class InternetInitial extends InternetState {} // Add initial state<br><br>final class ConnectedState extends InternetState {}<br><br>final class NotConnectedState extends InternetState {}</pre><ul><li>Similarly, we define sealed classes for InternetState to represent the current connection status.</li></ul><p><strong>4. The Connectivity Brain — internet_bloc.dart:</strong></p><pre>import &#39;dart:async&#39;;<br><br>import &#39;package:bloc/bloc.dart&#39;;<br>import &#39;package:internet_connection_checker_plus/internet_connection_checker_plus.dart&#39;;<br>import &#39;package:meta/meta.dart&#39;;<br><br>part &#39;internet_event.dart&#39;;<br>part &#39;internet_state.dart&#39;;<br><br>class InternetBloc extends Bloc&lt;InternetEvent, InternetState&gt; {<br>  StreamSubscription? internetSubscription;<br>  InternetBloc() : super(ConnectedState()) {<br>    on&lt;InternetEvent&gt;(<br>      (event, emit) {<br>        if (event is ConnectedEvent) {<br>          emit(ConnectedState());<br>        } else if (event is NotConnectedEvent) {<br>          emit(NotConnectedState());<br>        }<br>      },<br>    );<br>    internetSubscription =<br>        InternetConnection().onStatusChange.listen((InternetStatus status) {<br>      switch (status) {<br>        case InternetStatus.connected:<br>          //* The internet is now connected<br>          add(ConnectedEvent());<br>          break;<br>        case InternetStatus.disconnected:<br>          //* The internet is now disconnected<br>          add(NotConnectedEvent());<br>          break;<br>      }<br>    });<br>  }<br>  @override<br>  Future&lt;void&gt; close() {<br>    internetSubscription!.cancel();<br>    return super.close();<br>  }<br>}</pre><ul><li><strong>Initialization (createInstance)</strong>: We create an instance of InternetConnectionCheckerPlus with customizable timeout and check intervals.</li><li><strong>Stream Subscription (onStatusChange):</strong> Subscribe to the onStatusChange stream to listen for connectivity changes.</li><li><strong>Event Handling:</strong> Map the InternetConnectionStatus to our custom ConnectedEvent or NotConnectedEvent and add them to the BLoC.</li><li><strong>State Updates:</strong> Define on methods for events, updating the state to ConnectedState or NotConnectedState accordingly.</li><li><strong>Cleanup (close):</strong> Don’t forget to cancel the subscription in the close method to avoid memory leaks.</li></ul><p><strong>5. Integrating with UI (main.dart):</strong></p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter_bloc/flutter_bloc.dart&#39;;<br>import &#39;package:your_app/internet_bloc.dart&#39;; // Import your BLoC<br><br>void main() {<br>  runApp(MyApp());<br>}<br><br>class MyApp extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    return BlocProvider(<br>      create: (context) =&gt; InternetBloc(),<br>      child: MaterialApp(<br>        home: Builder(<br>          builder: (context) {<br>            return BlocBuilder&lt;InternetBloc, InternetState&gt;(<br>              builder: (context, state) {<br>                if (state is ConnectedState) {<br>                  return HomeView();<br>                } else if (state is NotConnectedState) {<br>                  return NotConnectedToInternetView();<br>                } else {<br>                  return LoadingView(); // Show a loading indicator initially<br>                }<br>              },<br>            );<br>          }<br>        ),<br>      ),<br>    );<br>  }<br>}<br><br>class HomeView extends StatelessWidget {<br>  // ... Your home screen widget ...<br>}<br><br>class NotConnectedToInternetView extends StatelessWidget {<br>  // ... Your no internet connection widget ...<br>}<br><br>class LoadingView extends StatelessWidget {<br>  // ... Your loading indicator widget ...<br>}</pre><ul><li>Wrap your app with BlocProvider to provide the InternetBloc.</li><li>Use BlocBuilder to rebuild the UI based on the InternetState emitted by the BLoC.</li></ul><p><strong>Enhanced User Experience:</strong></p><p>By accurately determining and reacting to internet connection status, we can:</p><ul><li><strong>Display informative messages:</strong> Let users know when they are offline, preventing them from performing actions that require internet access.</li><li><strong>Implement offline modes:</strong> Cache data locally or offer limited functionality even when offline.</li><li><strong>Enable automatic retries:</strong> Resend failed requests when the connection is restored, providing a seamless experience.</li></ul><p><strong>Conclusion:</strong></p><p>With internet_connection_checker_plus and BLoC, we’ve moved beyond basic connectivity checks. We’ve built a Flutter app that truly understands its online status, empowering us to create more resilient, user-friendly, and feature-rich mobile experiences.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2a04521d3da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Flutter App Broke: It’s Kotlin’s Fault (Probably)]]></title>
            <link>https://medium.com/@omar.elhbrouk2/my-flutter-app-broke-its-kotlin-s-fault-probably-fa725e23bb48?source=rss-64a84e50245b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa725e23bb48</guid>
            <dc:creator><![CDATA[Omar Elhbrouk]]></dc:creator>
            <pubDate>Thu, 05 Sep 2024 23:39:09 GMT</pubDate>
            <atom:updated>2024-09-05T23:44:09.875Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter’s Latest Update Got You Down? Let’s Fix That Kotlin Error!</h3><p>So, you decided to be a responsible Flutter developer and update to the latest shiny version (3.24, anyone?). You pat yourself on the back… and then BAM! Your console throws up a wall of errors, all screaming about incompatible Kotlin versions.</p><p>Don’t worry, we’ve all been there. Upgrading Flutter can feel like navigating a minefield sometimes. That’s why I’m here to help you squash this pesky bug.</p><p>Let’s break down the problem. You’re probably seeing something like this:</p><pre>e: C:/Users/osama/.gradle/caches/transforms-3/c683cde5b1f5377825fe27da54e1b718/transformed/fragment-1.7.1/jars/classes.jar!/META-INF/fragment_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.<br>// ... (a bunch of similar errors) ...<br>e: C:/Users/osama/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.8.22/1a8e3601703ae14bb58757ea6b2d8e8e5935a586/kotlin-stdlib-common-1.8.22.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.</pre><p>Or maybe you’re getting this message:</p><pre>┌─ Flutter Fix ────────────────────────────────────────────────────────────┐<br>│                                                                          │<br>│ [!] Your project requires a newer version of the Kotlin Gradle plugin.   │<br>│ Find the latest version on                                               │<br>│ https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then update │<br>│ &lt;path-to-app&gt;/android/build.gradle:                                      │<br>│ ext.kotlin_version = &#39;&lt;latest-version&gt;&#39;                                  │<br>│                                                                          │<br>└──────────────────────────────────────────────────────────────────────────┘</pre><p>Basically, your Flutter project’s components (Android, Kotlin, Gradle) are having a disagreement about which Kotlin version they want to use. Time to play mediator!</p><h3>Deep Dive: A Step-by-Step Solution</h3><p>Here’s the good news: the fix isn’t that complicated; it just involves a bit of version alignment.</p><p><strong>1. The Kotlin Conundrum (and Android, Too!)</strong></p><ul><li>Open up your project and navigate to android\settings.gradle.</li><li>Since Flutter 3.19, they’ve switched things up. You’ll need to update the Kotlin and Android versions.</li><li><strong>Old Kotlin Version:</strong></li></ul><pre>id &quot;org.jetbrains.kotlin.android&quot; version &quot;1.7.10&quot; apply false</pre><ul><li><strong>Updated Kotlin Version:</strong></li></ul><pre>id &quot;org.jetbrains.kotlin.android&quot; version &quot;1.9.10&quot; apply false</pre><ul><li><strong>Old Android Version:</strong></li></ul><pre>id &quot;com.android.application&quot; version &quot;7.3.0&quot; apply false</pre><ul><li><strong>Updated Android Version:</strong></li></ul><pre>id &quot;com.android.application&quot; version &quot;8.1.0&quot; apply false</pre><p><strong>2. Gradle Needs an Update</strong></p><ul><li>Head over to android\gradle\wrapper\gradle-wrapper.properties.</li><li>You’ll need to update the Gradle distribution URL.</li><li><strong>Old Gradle Version:</strong></li></ul><pre>distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip </pre><ul><li><strong>Update Gradle Version:</strong></li></ul><pre>distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip </pre><p><strong>3. Java: The Final Frontier</strong></p><ul><li>Finally, navigate to android\app\build.gradle.</li><li>We need to update the Java version and the minimum SDK version.</li><li><strong>Old Java &amp; minSdkVersion:</strong></li></ul><pre>sourceCompatibility = JavaVersion.VERSION_1_8<br>targetCompatibility = JavaVersion.VERSION_1_8<br>jvmTarget = JavaVersion.VERSION_1_8<br>minSdk = flutter.minSdkVersion </pre><ul><li><strong>Updated Java &amp; minSdkVersion:</strong></li></ul><pre>sourceCompatibility = JavaVersion.VERSION_17<br>targetCompatibility = JavaVersion.VERSION_17<br>jvmTarget = JavaVersion.VERSION_17 <br>minSdk = 24</pre><ul><li><strong>Important Note:</strong> Before making these changes, I highly recommend checking the Gradle <a href="https://docs.gradle.org/current/userguide/compatibility.html">Compatibility Matrix</a> to confirm the latest compatible versions for your setup.</li><li><strong>And That’s a Wrap!</strong></li><li>After those changes, give your project a good clean and rebuild. Hopefully, those pesky Kotlin errors have vanished!</li><li>Upgrading Flutter can be a bit of a rollercoaster, but by carefully aligning versions, you can overcome most hurdles. Now you’re equipped to handle this specific error like a pro. See you next time when we tackle another Flutter adventure!</li><li><strong>References:</strong></li></ul><ul><li><a href="https://docs.gradle.org/current/userguide/compatibility.html">Compatibility Matrix</a></li><li><a href="https://docs.amplify.aws/flutter/start/platform-setup/#android">Platform setup - Flutter - AWS Amplify Gen 2 Documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa725e23bb48" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>