<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ahmad Darwish</title>
    <description>The latest articles on Forem by Ahmad Darwish (@ahmaddarwish).</description>
    <link>https://forem.com/ahmaddarwish</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F260881%2Fb376b144-2bd9-44cf-a2a8-7fb3bc2c8b71.jpg</url>
      <title>Forem: Ahmad Darwish</title>
      <link>https://forem.com/ahmaddarwish</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ahmaddarwish"/>
    <language>en</language>
    <item>
      <title>Comprehensive Guide to Using GetX in Flutter</title>
      <dc:creator>Ahmad Darwish</dc:creator>
      <pubDate>Sat, 20 Jul 2024 21:14:19 +0000</pubDate>
      <link>https://forem.com/ahmaddarwish/comprehensive-guide-to-using-getx-in-flutter-1nnj</link>
      <guid>https://forem.com/ahmaddarwish/comprehensive-guide-to-using-getx-in-flutter-1nnj</guid>
      <description>&lt;p&gt;GetX is a powerful and lightweight solution for Flutter that provides state management, route management, and dependency injection. This article will guide you through the essential features of GetX, including state management, route management, navigation, localization, and dialogs/bottom sheets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction to GetX&lt;/li&gt;
&lt;li&gt;State Management&lt;/li&gt;
&lt;li&gt;Route Management&lt;/li&gt;
&lt;li&gt;Navigation&lt;/li&gt;
&lt;li&gt;Localization&lt;/li&gt;
&lt;li&gt;Dialogs and Bottom Sheets&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Introduction to GetX
&lt;/h2&gt;

&lt;p&gt;GetX is an all-in-one Flutter package that simplifies the development process by providing a robust and easy-to-use API for managing states, routes, dependencies, and more. Its simplicity and performance make it an excellent choice for Flutter developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;To start using GetX, add it to your &lt;code&gt;pubspec.yaml&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;dependencies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;^4.6.6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, run &lt;code&gt;flutter pub get&lt;/code&gt; to install the package.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. State Management
&lt;/h2&gt;

&lt;p&gt;GetX offers a reactive state management solution that is both simple and efficient. Let's start with a basic example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;Create a controller class to manage the state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:get/get.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CounterController&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;GetxController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;obs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your widget, use the &lt;code&gt;Obx&lt;/code&gt; widget to reactively display the state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter/material.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:get/get.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'counter_controller.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CounterApp&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StatelessWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;CounterController&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CounterController&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;MaterialApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;home:&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;appBar:&lt;/span&gt; &lt;span class="n"&gt;AppBar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;title:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'GetX Counter'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
        &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;Center&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Obx&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Count: &lt;/span&gt;&lt;span class="si"&gt;${controller.count}&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="nl"&gt;floatingActionButton:&lt;/span&gt; &lt;span class="n"&gt;FloatingActionButton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;onPressed:&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Icon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Icons&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;Obx&lt;/code&gt; widget automatically updates the count whenever it changes.&lt;br&gt;
Note: to impelement more advance state management for http call response and firebase integration search about:&lt;br&gt;
&lt;code&gt;RxStatus&lt;/code&gt; with &lt;code&gt;StateMixin&amp;lt;T&amp;gt;&lt;/code&gt; and &lt;code&gt;controller.obx&lt;/code&gt; widget in Getx&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Route Management
&lt;/h2&gt;

&lt;p&gt;GetX simplifies route management by allowing you to define routes in a single place and navigate without context.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;Define your routes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter/material.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:get/get.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'home_page.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'details_page.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;runApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;GetMaterialApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nl"&gt;initialRoute:&lt;/span&gt; &lt;span class="s"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;getPages:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="n"&gt;GetPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;name:&lt;/span&gt; &lt;span class="s"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;page:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;HomePage&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt;
      &lt;span class="n"&gt;GetPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;name:&lt;/span&gt; &lt;span class="s"&gt;'/details'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;page:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;DetailsPage&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate between pages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter/material.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:get/get.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HomePage&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StatelessWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;appBar:&lt;/span&gt; &lt;span class="n"&gt;AppBar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;title:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Home'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
      &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;Center&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;ElevatedButton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;onPressed:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;toNamed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'/details'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
          &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Go to Details'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DetailsPage&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StatelessWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;appBar:&lt;/span&gt; &lt;span class="n"&gt;AppBar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;title:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Details'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
      &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;Center&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;ElevatedButton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;onPressed:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;back&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
          &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Back to Home'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Navigation
&lt;/h2&gt;

&lt;p&gt;GetX provides a simple way to navigate without requiring a &lt;code&gt;BuildContext&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;Navigate to a new page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NextPage&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate back to the previous page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;back&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate and remove all previous routes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;offAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NextPage&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Localization
&lt;/h2&gt;

&lt;p&gt;GetX makes it easy to handle localization in your app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;Define your translations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:get/get.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Messages&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;Translations&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="n"&gt;keys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;'en_US'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="s"&gt;'hello'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Hello'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="s"&gt;'es_ES'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="s"&gt;'hello'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'Hola'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize localization in &lt;code&gt;main.dart&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;runApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;GetMaterialApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nl"&gt;translations:&lt;/span&gt; &lt;span class="n"&gt;Messages&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nl"&gt;locale:&lt;/span&gt; &lt;span class="n"&gt;Locale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'en'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'US'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nl"&gt;fallbackLocale:&lt;/span&gt; &lt;span class="n"&gt;Locale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'en'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'US'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nl"&gt;home:&lt;/span&gt; &lt;span class="n"&gt;HomePage&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use translations in your widgets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter/material.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:get/get.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HomePage&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StatelessWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;appBar:&lt;/span&gt; &lt;span class="n"&gt;AppBar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;title:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Localization Example'&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
      &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;Center&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'hello'&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;tr&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Dialogs and Bottom Sheets
&lt;/h2&gt;

&lt;p&gt;GetX provides easy methods to show dialogs and bottom sheets.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;Show a dialog:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;defaultDialog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nl"&gt;title:&lt;/span&gt; &lt;span class="s"&gt;'Dialog Title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;middleText:&lt;/span&gt; &lt;span class="s"&gt;'Dialog content goes here'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;textConfirm:&lt;/span&gt; &lt;span class="s"&gt;'Confirm'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;textCancel:&lt;/span&gt; &lt;span class="s"&gt;'Cancel'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;onConfirm:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Confirmed'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nl"&gt;onCancel:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Canceled'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Show a bottom sheet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;bottomSheet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nl"&gt;color:&lt;/span&gt; &lt;span class="n"&gt;Colors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;white&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Wrap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;children:&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Widget&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;[&lt;/span&gt;
        &lt;span class="n"&gt;ListTile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;leading:&lt;/span&gt; &lt;span class="n"&gt;Icon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Icons&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;music_note&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
          &lt;span class="nl"&gt;title:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Music'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
          &lt;span class="nl"&gt;onTap:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;ListTile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;leading:&lt;/span&gt; &lt;span class="n"&gt;Icon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Icons&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;videocam&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
          &lt;span class="nl"&gt;title:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Video'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
          &lt;span class="nl"&gt;onTap:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;GetX is a versatile and efficient solution for Flutter applications. It streamlines state management, route management, navigation, localization, and dialogs/bottom sheets, allowing developers to focus on building high-quality apps with less boilerplate code. By following the examples provided, you can quickly integrate GetX into your Flutter projects and take advantage of its powerful features.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Flutter Getx Clean Architecture</title>
      <dc:creator>Ahmad Darwish</dc:creator>
      <pubDate>Sat, 16 Sep 2023 12:53:25 +0000</pubDate>
      <link>https://forem.com/ahmaddarwish/flutter-getx-clean-architecture-4ppk</link>
      <guid>https://forem.com/ahmaddarwish/flutter-getx-clean-architecture-4ppk</guid>
      <description>&lt;p&gt;Flutter has established itself as a premier framework for developing cross-platform mobile applications. However, as applications grow in complexity, managing code becomes a significant challenge. Clean architecture is a software design pattern that addresses this challenge by promoting code separation into distinct layers, facilitating maintainability and scalability. In this article, we'll delve into the practical implementation of clean architecture in Flutter using the GetX library, a potent state management and dependency injection tool.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Understanding Clean Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Clean architecture revolves around separating code into layers, each with a distinct responsibility. The primary layers include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Presentation Layer&lt;/strong&gt;: This layer concerns itself with the user interface and interactions. It includes widgets, views, and controllers responsible for user input and data display.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Application Layer&lt;/strong&gt;: The application layer contains the application's core business logic. It serves as an intermediary between the presentation and domain layers, coordinating data flow and enforcing business rules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Domain Layer&lt;/strong&gt;: The domain layer defines the fundamental business logic and domain models of the application. It remains independent of specific UI frameworks or databases, ensuring high reusability and testability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Layer&lt;/strong&gt;: This layer manages data storage, retrieval, and interactions with external APIs. It encompasses repositories, data sources, and API clients.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Implementing Clean Architecture with GetX&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's break down how to structure your Flutter app using GetX and clean architecture principles, supported by real-world examples:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Presentation Layer&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Utilize GetX's &lt;code&gt;GetView&lt;/code&gt; and &lt;code&gt;GetController&lt;/code&gt; to construct UI components and controllers. For instance, to create a simple counter application:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CounterController&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;GetxController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;obs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Navigation is simplified using GetX's &lt;code&gt;Get.to()&lt;/code&gt; and &lt;code&gt;Get.off()&lt;/code&gt; methods, which offer intuitive routing capabilities:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt; &lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AnotherScreen&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Achieve responsive UI updates using GetX's reactive state management:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt; &lt;span class="n"&gt;Obx&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Count: &lt;/span&gt;&lt;span class="si"&gt;${controller.count}&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;.&lt;br&gt;
.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Application Layer&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Develop controllers for each feature or screen, housing the business logic. These controllers manage interactions between the presentation and domain layers. For example, in a to-do list application:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight dart"&gt;&lt;code&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TodoListController&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;GetxController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;_todos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Todo&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;[]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;obs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;addTodo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="n"&gt;_todos&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Todo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Leverage GetX's dependency injection to supply controllers with necessary dependencies, like repositories or data sources:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight dart"&gt;&lt;code&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TodoListBinding&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="n"&gt;Bindings&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nd"&gt;@override&lt;/span&gt;
   &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;dependencies&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="n"&gt;Get&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;lazyPut&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;TodoListController&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Implement use cases in the application layer to execute business operations, such as fetching data, processing it, and updating the UI:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight dart"&gt;&lt;code&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FetchTodosUseCase&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;TodoRepository&lt;/span&gt; &lt;span class="n"&gt;_repository&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="n"&gt;FetchTodosUseCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;_repository&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

   &lt;span class="n"&gt;Future&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Todo&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;async&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_repository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fetchTodos&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;.&lt;br&gt;
.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Domain Layer&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Define domain models to represent the core data structures. These models should remain independent of the presentation and data layers. In our to-do list example:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight dart"&gt;&lt;code&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Todo&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;completed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="n"&gt;Todo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;completed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Create interfaces or abstract classes for repositories, specifying methods for data retrieval and manipulation:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight dart"&gt;&lt;code&gt; &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TodoRepository&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="n"&gt;Future&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Todo&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;fetchTodos&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
   &lt;span class="n"&gt;Future&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;addTodo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Todo&lt;/span&gt; &lt;span class="n"&gt;todo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;.&lt;br&gt;
.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data Layer&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Implement data sources that interact with external APIs, databases, or local storage. For instance, fetching todos from an API:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight dart"&gt;&lt;code&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApiTodoDataSource&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="n"&gt;Future&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Todo&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;fetchTodos&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;async&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="c1"&gt;// Fetch data from API&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Develop repositories that encapsulate data retrieval and caching logic, implementing the interfaces defined in the domain layer:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight dart"&gt;&lt;code&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TodoRepositoryImpl&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="n"&gt;TodoRepository&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;ApiTodoDataSource&lt;/span&gt; &lt;span class="n"&gt;_dataSource&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="n"&gt;TodoRepositoryImpl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;_dataSource&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

   &lt;span class="nd"&gt;@override&lt;/span&gt;
   &lt;span class="n"&gt;Future&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Todo&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;fetchTodos&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;async&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_dataSource&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;fetchTodos&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="c1"&gt;// ...&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ul&gt;




&lt;p&gt;.&lt;br&gt;
.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Using GetX Clean Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Modularity&lt;/strong&gt;: Clean architecture with GetX enables your codebase to be organized into discrete modules, promoting code clarity and maintainability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Testability&lt;/strong&gt;: The separation of concerns inherent to clean architecture facilitates unit testing. GetX's reactive state management simplifies testing UI components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: As your app grows, clean architecture allows you to add new features and modules without tightly coupling them to existing code, promoting scalability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reusability&lt;/strong&gt;: The separation of concerns also enhances code reusability, enabling you to reuse domain models and use cases across different parts of your app or in future projects.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Combining Flutter, GetX, and clean architecture principles provides a robust foundation for building maintainable and efficient mobile applications. By segmenting your code into distinct layers and utilizing GetX's state management, navigation, and dependency injection features, you can develop Flutter apps that are visually appealing and easy to maintain, scale, and test. Embracing clean architecture and GetX will result in more structured and sustainable Flutter projects, saving you time and effort as your app evolves and expands.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Setting Up Dynamic Links in Flutter: A Quick Detailed Guide</title>
      <dc:creator>Ahmad Darwish</dc:creator>
      <pubDate>Sat, 22 Apr 2023 08:20:13 +0000</pubDate>
      <link>https://forem.com/ahmaddarwish/setting-up-dynamic-links-in-flutter-a-quick-detailed-guide-49c0</link>
      <guid>https://forem.com/ahmaddarwish/setting-up-dynamic-links-in-flutter-a-quick-detailed-guide-49c0</guid>
      <description>&lt;p&gt;Dynamic links are a powerful tool for mobile app developers to drive user engagement and retention. With dynamic links, you can create links that deep-link directly to specific content within your app, even if the user doesn't have the app installed yet. In this article, we'll show you how to set up dynamic links in Flutter.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Step 1: Set up Firebase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first step in setting up dynamic links in Flutter is to set up Firebase. Firebase is a mobile and web application development platform that provides a variety of tools and services to help you build high-quality apps. To set up Firebase, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the Firebase Console and sign in with your Google account.&lt;/li&gt;
&lt;li&gt;Click on "Add project" and enter a name for your project.&lt;/li&gt;
&lt;li&gt;Follow the prompts to set up your project.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once you've set up your Firebase project, you'll need to add the Firebase SDK to your Flutter project.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Step 2: Add the Firebase SDK to your Flutter project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To add the Firebase SDK to your Flutter project, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open your Flutter project in Android Studio or Visual Studio Code.&lt;/li&gt;
&lt;li&gt;Open the pubspec.yaml file and add the following dependencies:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
  firebase_core: ^1.0.0
  firebase_dynamic_links: ^2.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;flutter pub get&lt;/code&gt; to install the dependencies.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Step 3: Create a dynamic link&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create a dynamic link, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the Firebase Console and select your project.&lt;/li&gt;
&lt;li&gt;Click on "Dynamic Links" in the left-hand menu.&lt;/li&gt;
&lt;li&gt;Click on "Get Started" and follow the prompts to create a new dynamic link.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When creating a dynamic link, you'll need to specify the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The link URL: This is the URL that the user will be directed to when they click on the dynamic link.&lt;/li&gt;
&lt;li&gt;The iOS and Android package names: These are the package names for your app on iOS and Android.&lt;/li&gt;
&lt;li&gt;The link behavior: This determines what happens when the user clicks on the dynamic link. You can choose to open the link in your app, on the web, or in another app.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Step 4: Handle the dynamic link in your Flutter app&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To handle the dynamic link in your Flutter app, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the following code to your main.dart file:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  handleDynamicLinks();
  runApp(MyApp());
}

void handleDynamicLinks() async {
  FirebaseDynamicLinks.instance.onLink(
    onSuccess: (PendingDynamicLinkData dynamicLink) async {
      final Uri deepLink = dynamicLink?.link;
      // Handle the deep link here.
    },
    onError: (OnLinkErrorException e) async {
      print('onLinkError');
      print(e.message);
    }
  );
  final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink();
  final Uri deepLink = data?.link;
  // Handle the deep link here.
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;In the &lt;code&gt;onSuccess&lt;/code&gt; callback, you can handle the deep link by extracting the relevant data from the &lt;code&gt;Uri&lt;/code&gt; object.&lt;/li&gt;
&lt;li&gt;In the &lt;code&gt;onError&lt;/code&gt; callback, you can handle any errors that occur when processing the dynamic link.&lt;/li&gt;
&lt;li&gt;In the &lt;code&gt;getInitialLink&lt;/code&gt; method, you can retrieve the initial dynamic link that launched the app.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;And that's it! With these steps, you can set up dynamic links in your Flutter app and drive user engagement and retention.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Comparing GoLang and Python, Which is the Best Choice for Your Project</title>
      <dc:creator>Ahmad Darwish</dc:creator>
      <pubDate>Fri, 21 Apr 2023 21:14:27 +0000</pubDate>
      <link>https://forem.com/ahmaddarwish/compare-golang-with-python-ici</link>
      <guid>https://forem.com/ahmaddarwish/compare-golang-with-python-ici</guid>
      <description>&lt;p&gt;Comparing programming languages can be a difficult task as each language has its own unique strengths and weaknesses. In this article, we'll compare two popular programming languages, Go and Python, and explore their similarities and differences to help you choose the best language for your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;Go is a statically-typed, compiled language developed by Google in 2009. It was designed to be fast, efficient, and easy to read and write, with a focus on concurrency and simplicity. Go is commonly used for building network and system tools, web servers, and other high-performance applications.&lt;/p&gt;

&lt;p&gt;Python, on the other hand, is an interpreted language first released in 1991. It is dynamically-typed, meaning that data types are inferred at runtime, and is known for its readability and ease of use. Python is widely used for web development, scientific computing, machine learning, and other applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go: C-like syntax with curly braces and semicolons; requires explicit variable declarations and type annotations.&lt;/li&gt;
&lt;li&gt;Python: Uses whitespace indentation to delimit code blocks; does not require variable declarations or type annotations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's an example of a "Hello, World!" program in Go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's the same program in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("Hello, World!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, Python code is generally more concise and easier to read, while Go code may be more verbose but also more explicit and easier to maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go: Compiled language optimized for speed and efficiency; ideal for building high-performance applications.&lt;/li&gt;
&lt;li&gt;Python: Interpreted language executed at runtime; may have slower performance; has a large ecosystem of libraries and frameworks to improve performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Concurrency
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go: Supports concurrency with "goroutines" that allow for efficient and scalable concurrent applications.&lt;/li&gt;
&lt;li&gt;Python: Supports concurrency through libraries such as asyncio and multiprocessing, but may require more effort to write efficient concurrent code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Community
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Go: Young community growing quickly; strong focus on performance, reliability, and simplicity.&lt;/li&gt;
&lt;li&gt;Python: Large and mature community with a vast ecosystem of libraries and tools; emphasis on code readability and maintainability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choosing between Go and Python ultimately depends on your project's specific requirements and goals. Go is an excellent choice for building high-performance, concurrent applications, while Python is well-suited for scientific computing, web development, and other applications that require ease of use and readability.&lt;/p&gt;

&lt;p&gt;Both languages have their own unique strengths and weaknesses, and both have active and supportive communities of developers. Ultimately, the best language for your project is the one that meets your specific needs and helps you achieve your goals.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Detect Root And Jailbreak In Flutter App</title>
      <dc:creator>Ahmad Darwish</dc:creator>
      <pubDate>Fri, 21 Apr 2023 21:05:03 +0000</pubDate>
      <link>https://forem.com/ahmaddarwish/detect-root-and-jailbreak-in-flutter-app-iod</link>
      <guid>https://forem.com/ahmaddarwish/detect-root-and-jailbreak-in-flutter-app-iod</guid>
      <description>&lt;p&gt;You can detect root access on Android devices by checking for the presence of certain files or binaries that are typically only accessible with root privileges, while detecting jailbreak on iOS devices involves checking for the presence of certain files or system configurations that are typically modified during the jailbreaking process. One way to perform these checks is by using the flutter_device_info package.&lt;/p&gt;




&lt;p&gt;1- Add the flutter_device_info package to your project by adding it to your pubspec.yaml file and running flutter pub get.&lt;/p&gt;

&lt;p&gt;2- Import the package in your code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter_device_info/flutter_device_info.dart';

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3- Create an instance of the FlutterDeviceInfo class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FlutterDeviceInfo flutterDeviceInfo = FlutterDeviceInfo();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;To determine whether a device is rooted, you can use the isRooted method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool isDeviceRooted = await flutterDeviceInfo.isRooted;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The isRooted method returns a boolean value indicating whether the device is rooted. If the device is rooted, the method will return true; otherwise, it will return false.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;

&lt;p&gt;For iOS devices, you can check if it's jailbroken by calling the isJailBroken method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bool isDeviceJailbroken = await flutterDeviceInfo.isJailBroken;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The isJailBroken method returns a boolean value indicating whether the device is jailbroken. If the device is jailbroken, the method will return true; otherwise, it will return false.&lt;/p&gt;




&lt;p&gt;It's important to note that detecting jailbreak on iOS devices or root access on other devices is not a foolproof method of determining whether a device has been modified, as there are ways to hide these modifications from detection. Furthermore, detecting such modifications may not be necessary or appropriate for all apps, and may potentially violate platform policies or user privacy. Therefore, before attempting to detect jailbreak or root access, it's important to carefully consider the potential risks and benefits.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Bito the AI plugin and How to add it to JetBrains IDEs</title>
      <dc:creator>Ahmad Darwish</dc:creator>
      <pubDate>Sun, 26 Mar 2023 13:15:08 +0000</pubDate>
      <link>https://forem.com/ahmaddarwish/bito-ai-plugin-and-how-to-add-it-to-jetbrains-ides-5ao</link>
      <guid>https://forem.com/ahmaddarwish/bito-ai-plugin-and-how-to-add-it-to-jetbrains-ides-5ao</guid>
      <description>&lt;p&gt;Bito is a powerful AI plugin that helps developers write code, explain code, create tests, and more using ChatGPT. Bito integrates with JetBrains IDEs such as IntelliJ IDEA, Android Studio, PyCharm, and others, and allows you to access ChatGPT’s models without having an OpenAI key. Bito can save you an hour a day by accelerating your coding tasks and providing you with helpful insights.&lt;/p&gt;

&lt;p&gt;In this article, we will show you how to install Bito on your JetBrains IDE and how to use its features to boost your productivity and creativity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to install Bito on Jetbrains IDEs&lt;/strong&gt;&lt;br&gt;
Installing Bito on your JetBrains IDE is very easy and takes less than two minutes. Here are the steps:&lt;/p&gt;

&lt;p&gt;Open your JetBrains IDE and go to Settings &amp;gt; Plugins.&lt;br&gt;
Search for Bito in the Marketplace tab and click Install.&lt;br&gt;
Restart your IDE to activate the plugin.&lt;br&gt;
You will see a Bito icon on the right side of your editor. Click on it to open the Bito panel.&lt;br&gt;
If you are the first user for your organization, Bito will ask you to create a workspace. You can set it so that everyone with the same domain can automatically join or you can add teammates to your workspace to collaborate. Bito works best when you have a few teammates to collaborate with.&lt;br&gt;
Alternatively, you can access the Bito extension directly from the&lt;br&gt;
 JetBrains marketplace at: &lt;a href="https://plugins.jetbrains.com/plugin/18289-bito--chatgpt-to-write-code-explain-code-create-tests" rel="noopener noreferrer"&gt;https://plugins.jetbrains.com/plugin/18289-bito--chatgpt-to-write-code-explain-code-create-tests&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to use Bito on Jetbrains IDEs&lt;/strong&gt;&lt;br&gt;
Once you have installed Bito on your JetBrains IDE, you can start using its features to enhance your coding experience. Here are some of the things you can do with Bito:&lt;/p&gt;

&lt;p&gt;Ask any technical question: You can type any question related to programming languages, frameworks, libraries, algorithms, data structures, etc. and Bito will try to answer it using ChatGPT. For example, you can ask “how to implement a binary search tree in Python” or “what is the difference between abstract classes and interfaces in Java”.&lt;/p&gt;

&lt;p&gt;Generate code: You can ask Bito to generate code for you based on your specifications. For example, you can ask “code in Java to convert a number from one base to another” or “code to implement a simple REST API in Go”. Bito will show you the generated code in a diff view against your existing code, and you can choose which lines or sections you want to integrate.&lt;/p&gt;

&lt;p&gt;Explain code: You can ask Bito to explain code that you are unfamiliar with or want to learn more about. For example, you can ask “explain this code &amp;lt; insert code &amp;gt;” or “explain how this function works”. Bito will give you a detailed summary of the code’s logic, purpose, inputs, outputs, and potential errors.&lt;/p&gt;

&lt;p&gt;Comment code: You can ask Bito to comment code for you based on best practices and standards. For example, you can ask “comment this method &amp;lt; insert method &amp;gt;” or “comment this class &amp;lt; insert class &amp;gt;”. Bito will generate comments for the method or class and its parameters, return values, exceptions, etc.&lt;/p&gt;

&lt;p&gt;Create tests: You can ask Bito to create test cases for your code based on different scenarios and edge cases. For example, you can ask “generate test cases for this code &amp;lt; insert code &amp;gt;” or “generate test cases for this function &amp;lt; insert function &amp;gt;”. Bito will generate test cases in the same language as your code and show them in a diff view against your existing tests.&lt;/p&gt;

&lt;p&gt;Bito also provides one-click shortcuts for some of these features so that you don’t have to type anything. For example, you can select some code and click on the Explain Code button in the Bito panel to get an explanation of that code.&lt;/p&gt;

&lt;p&gt;Bito also allows you to share your results with your colleagues via Slack or email. You can also access your history of queries and results in the Bito panel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Bito is an innovative AI plugin that brings ChatGPT to your Jetbrains IDEs and helps you write code faster, better, and easier. It can answer your technical questions, generate code for you, explain code for you, comment code for you, create tests for you, and more. It also lets you collaborate with your teammates and share your results with them.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>chatgpt</category>
      <category>jetbrains</category>
      <category>plugin</category>
    </item>
    <item>
      <title>Handling HTTP Requests with DIO and Refresh Tokens in Flutter</title>
      <dc:creator>Ahmad Darwish</dc:creator>
      <pubDate>Sun, 26 Mar 2023 13:00:12 +0000</pubDate>
      <link>https://forem.com/ahmaddarwish/handling-http-requests-with-dio-and-refresh-tokens-in-flutter-4mif</link>
      <guid>https://forem.com/ahmaddarwish/handling-http-requests-with-dio-and-refresh-tokens-in-flutter-4mif</guid>
      <description>&lt;p&gt;In this article, we'll demonstrate how to use the DIO package to make GET and POST requests in a Flutter application, while leveraging refresh tokens to maintain a persistent user session. We'll cover the following topics:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Setting up DIO&lt;/li&gt;
&lt;li&gt;Creating a DIO instance with interceptors&lt;/li&gt;
&lt;li&gt;Making GET and POST requests&lt;/li&gt;
&lt;li&gt;Implementing automatic token refresh with DIO interceptors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. Setting up DIO&lt;/strong&gt;&lt;br&gt;
First, add the DIO package to your pubspec.yaml file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
  flutter:
    sdk: flutter
  dio: ^4.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, run flutter packages get to install the package.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Creating a DIO instance with interceptors&lt;/strong&gt;&lt;br&gt;
To create a DIO instance with interceptors, first import the DIO package:&lt;br&gt;
&lt;code&gt;import 'package:dio/dio.dart';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, create a DIO instance with a default configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dio dio = Dio(
  BaseOptions(
    baseUrl: 'https://your-api-url.com',
    connectTimeout: 5000,
    receiveTimeout: 3000,
  ),
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Making GET and POST requests&lt;/strong&gt;&lt;br&gt;
Now that we have a DIO instance, we can use it to make GET and POST requests. Here's an example of making a GET request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;void&amp;gt; fetchData() async {
  try {
    Response response = await dio.get('/path/to/your/endpoint');
    print(response.data);
  } on DioError catch (e) {
    print(e.message);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make a POST request, we can use the post method as shown below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;void&amp;gt; postData() async {
  try {
    Response response = await dio.post(
      '/path/to/your/endpoint',
      data: {'key': 'value'},
    );
    print(response.data);
  } on DioError catch (e) {
    print(e.message);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Implementing automatic token refresh with DIO interceptors&lt;/strong&gt;&lt;br&gt;
To implement automatic token refresh, we'll add an interceptor to the DIO instance. This interceptor will handle token refresh logic whenever it detects a 401 (Unauthorized) response from the server.&lt;/p&gt;

&lt;p&gt;First, create a function to refresh the access token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;String&amp;gt; refreshToken() async {
  // Perform a request to the refresh token endpoint and return the new access token.
  // You can replace this with your own implementation.
  return 'your_new_access_token';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, add an interceptor to the DIO instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dio.interceptors.add(
  InterceptorsWrapper(
    onRequest: (options, handler) {
      // Add the access token to the request header
      options.headers['Authorization'] = 'Bearer your_access_token';
      return handler.next(options);
    },
    onError: (DioError e, handler) async {
      if (e.response?.statusCode == 401) {
        // If a 401 response is received, refresh the access token
        String newAccessToken = await refreshToken();

        // Update the request header with the new access token
        e.requestOptions.headers['Authorization'] = 'Bearer $newAccessToken';

        // Repeat the request with the updated header
        return handler.resolve(await dio.fetch(e.requestOptions));
      }
      return handler.next(e);
    },
  ),
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this interceptor in place, your application will automatically refresh the access token and retry requests whenever a &lt;code&gt;401 response&lt;/code&gt; is received.&lt;/p&gt;

&lt;p&gt;That's it! You've now implemented a DIO instance with interceptors for handling GET and POST requests, as well as automatic token refresh. This will help you maintain a persistent user session and improve the user experience in your Flutter application.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>dio</category>
      <category>http</category>
    </item>
    <item>
      <title>Flutter - securing http requests</title>
      <dc:creator>Ahmad Darwish</dc:creator>
      <pubDate>Tue, 20 Apr 2021 04:43:12 +0000</pubDate>
      <link>https://forem.com/ahmaddarwish/flutter-securing-http-requests-d2o</link>
      <guid>https://forem.com/ahmaddarwish/flutter-securing-http-requests-d2o</guid>
      <description>&lt;p&gt;In today's digital era, web security is of utmost importance. One of the most common attacks on web applications is the Cross-Site Request Forgery (CSRF) attack. This attack occurs when an attacker tricks the user's browser into sending a request to a web application without their knowledge or consent. To prevent CSRF attacks, it is essential to secure HTTP requests.&lt;/p&gt;

&lt;p&gt;Flutter is a popular mobile app development framework that allows developers to build high-performance, cross-platform apps. It provides a rich set of tools and features to secure HTTP requests, including CSRF protection.&lt;/p&gt;

&lt;p&gt;To secure HTTP requests in Flutter, developers can use the csrf package, which provides middleware to prevent CSRF attacks. The package generates a unique token for each user session and adds it to the HTTP request header. The server then verifies the token before processing the request.&lt;/p&gt;

&lt;p&gt;To use the csrf package in Flutter, follow these steps:&lt;/p&gt;

&lt;p&gt;Add the csrf package to your project dependencies in the pubspec.yaml file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
  csrf: ^1.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Import the package in your code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:csrf/csrf.dart';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the middleware to your HTTP requests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final csrfToken = await getCsrfToken(); // Get the CSRF token
final response = await http.post(
  url,
  headers: {'X-CSRF-Token': csrfToken}, // Add the token to the HTTP request header
   body: {...},
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the server side, verify the token before processing the request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function verifyCsrfToken(req, res, next) {
  const csrfToken = req.headers['x-csrf-token'];
  if (!csrfToken || csrfToken !== req.session.csrfToken) {
    return res.sendStatus(403);
  }
  next();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the server verifies the token by comparing it to the token stored in the user's session. The server sends a &lt;code&gt;403 Forbidden&lt;/code&gt; response if the tokens do not match.&lt;/p&gt;

&lt;p&gt;In conclusion, securing HTTP requests with CSRF protection is essential to prevent attacks on web applications. Flutter provides robust tools and features to secure HTTP requests, including the csrf package. By implementing these security measures, developers can ensure that their mobile apps are protected from CSRF attacks and provide a secure user experience.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>security</category>
      <category>csrf</category>
    </item>
  </channel>
</rss>
