<?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: Flutter Tanzania </title>
    <description>The latest articles on Forem by Flutter Tanzania  (@fluttertanzania).</description>
    <link>https://forem.com/fluttertanzania</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%2F1013854%2Ff79d8830-175a-46b4-8344-a50a08e730a7.PNG</url>
      <title>Forem: Flutter Tanzania </title>
      <link>https://forem.com/fluttertanzania</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/fluttertanzania"/>
    <language>en</language>
    <item>
      <title>Local notifications in flutter</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Wed, 31 Jan 2024 21:09:12 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/local-notifications-in-flutter-3o7n</link>
      <guid>https://forem.com/fluttertanzania/local-notifications-in-flutter-3o7n</guid>
      <description>&lt;p&gt;In this article we will focus on how to create local notifications in flutter by using &lt;a href="https://pub.dev/packages/awesome_notifications"&gt;awesome_notifications&lt;/a&gt; package. &lt;/p&gt;

&lt;p&gt;Local notifications are notifications that are scheduled by the app and delivered on the same device. We use local notifications to get user's attention. With local notifications we can display an alert, play a sound, or badge our app's icon. For example, an app downloading a file on background could ask the system to display an alert when the app finishes downloading the file.&lt;/p&gt;

&lt;p&gt;This article will cover various aspects of local notifications, beginning with Basic Notification. We will then explore Big Picture, Emoji, Action button, progress bar, and scheduled notifications (which are notifications set to repeat at specific date and time).&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a Flutter project
&lt;/h2&gt;

&lt;p&gt;In order to get started we need to create a flutter project. In your terminal you can easily create a flutter project by running the following command &lt;code&gt;flutter create &amp;lt;Project name&amp;gt;&lt;/code&gt;, after creating your project you can open it with your favorite code editor.&lt;/p&gt;

&lt;p&gt;After creation of the project we need to install dependencies that we will need to run our Project, and for our case we will install &lt;a href="https://pub.dev/packages/awesome_notifications"&gt;awesome_notifications&lt;/a&gt;, make sure you add awesome_notifications in &lt;code&gt;pubspec.yaml&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;After that let's continue with the setup on android and iOS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Android setup
&lt;/h2&gt;

&lt;p&gt;For android configuration we'll go to the &lt;code&gt;awesome_notification&lt;/code&gt; page and scroll to the Initial configuration section -&amp;gt; Configuring android for Awesome Notification &lt;a href="https://pub.dev/packages/awesome_notifications#-configuring-android-for-awesome-notifications"&gt;click here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the first step we'll see that we're required to update &lt;code&gt;build.grade&lt;/code&gt; file located inside "android/app/" folder and set &lt;code&gt;minSdkVersion&lt;/code&gt; to 21 and the &lt;code&gt;compileSdkVersion&lt;/code&gt; and &lt;code&gt;targetSdkVersion&lt;/code&gt; to 34.&lt;/p&gt;

&lt;p&gt;The second step is to update &lt;code&gt;AndroidManifest.xml&lt;/code&gt; file located "android/app/src/main" and add the following permissions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;uses-permission android:name="android.permission.VIBRATE"/&amp;gt;
&amp;lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then with in the same file, inside &lt;code&gt;activity&lt;/code&gt; tag make sure &lt;code&gt;exported&lt;/code&gt; is set to true, &lt;code&gt;android:exported="true"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And that's all setup we're required for android.&lt;/p&gt;

&lt;h2&gt;
  
  
  iOS setup
&lt;/h2&gt;

&lt;p&gt;For iOS setup we're have few configuration to do, mhhhh actually we just need to make sure if the following variable have the required values.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build libraries for distribution -&amp;gt; NO&lt;/li&gt;
&lt;li&gt;Only safe API extensions -&amp;gt; NO&lt;/li&gt;
&lt;li&gt;iOS Deployment Target -&amp;gt; NO&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To verify them open you're project iOS folder with Xcode and navigate to Runner -&amp;gt; Target Runner -&amp;gt; Build settings, and you can find the above variables by simply searching them.&lt;/p&gt;

&lt;p&gt;But also we need to make modifications of our &lt;code&gt;Podfile&lt;/code&gt; file you can refer it &lt;a href="https://pub.dev/packages/awesome_notifications#-configuring-ios-for-awesome-notifications"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that's we need in order to get started in iOS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Initialize Awesome Nofification
&lt;/h2&gt;

&lt;p&gt;In this section we will initialize Awesome notification so we can be able to send notification.&lt;/p&gt;

&lt;p&gt;To initialize Awesone notification open &lt;code&gt;main.dart&lt;/code&gt; file and inside our &lt;code&gt;main&lt;/code&gt; function call the &lt;code&gt;AwesomeNotification&lt;/code&gt; constructor and then call &lt;code&gt;initialize&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  AwesomeNotifications().initialize();
  runApp(const MyApp());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we call &lt;code&gt;.initialize()&lt;/code&gt; we'll see that it accepts four parameters which are &lt;code&gt;defaultIcon&lt;/code&gt;, &lt;code&gt;channels&lt;/code&gt;, &lt;code&gt;channelGroups&lt;/code&gt; and &lt;code&gt;debug&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's start with the defaultIcon:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For the defaultIcon we will set &lt;code&gt;null&lt;/code&gt; so that awesome notification wi'll use the default app icon.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then we will pass a list of &lt;code&gt;NotificationChannel&lt;/code&gt; which are used for creating a notification.&lt;/p&gt;

&lt;p&gt;The following is a sample of the NotificationChannel.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NotificationChannel(
    channelKey: "basic_notification",
    channelName: "Basic notifications",
    channelDescription: "Notification channel for basic tests",
    importance: NotificationImportance.Max,
    defaultPrivacy: NotificationPrivacy.Private,
    enableVibration: true,
    defaultColor: Colors.redAccent,
    channelShowBadge: true,
    enableLights: true,
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code defines settings for our notification settings.&lt;/p&gt;

&lt;p&gt;Now our main function will be as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void main() async {
    WidgetsFlutterBinding.ensureInitialized();

    AwesomeNotifications().initialize(
        null,
        [
            NotificationChannel(
                channelKey: "basic_notification",
                channelName: "Basic notifications",
                channelDescription: "Notification channel for basic tests",
                importance: NotificationImportance.Max,
                defaultPrivacy: NotificationPrivacy.Private,
                enableVibration: true,
                defaultColor: Colors.redAccent,
                channelShowBadge: true,
                enableLights: true,
            ),
        ],
        debug: false,
    );
    runApp(const MyApp());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After finishing up setup of our notification we need to request permission for Notification. First we will check if user has granted notification permission else we request it.&lt;/p&gt;

&lt;p&gt;Add the following code in the &lt;code&gt;initState&lt;/code&gt; of you're home page Widget&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@override
void initState() {
  AwesomeNotifications().isNotificationAllowed().then(
    (isAllowed) {
      if (!isAllowed) {
        AwesomeNotifications().requestPermissionToSendNotifications();
      }
    },
  );

  super.initState();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will request permission for our app to send notification to the user.&lt;/p&gt;

&lt;p&gt;And that's it for the initialization of local notification, if we hot restart our project we will see a pop that requests notification permission.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foerx71kwv6gyt57lsbav.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foerx71kwv6gyt57lsbav.png" alt="Image description" width="660" height="1250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic notification
&lt;/h2&gt;

&lt;p&gt;In this section we will create our first Notification, let's get into it.&lt;/p&gt;

&lt;p&gt;First we will need to modify our home page &lt;code&gt;widget&lt;/code&gt; and remove the initial flutter code that comes in when we create our project and add the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Scaffold(
  body: SafeArea(
    child: Center(
      //
      child: ElevatedButton(
        onPressed: ()  {
        },
        child: const Text("Trigger Notification"),
      ),
    ),
  ),
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code we have updated our home &lt;code&gt;widget&lt;/code&gt; and add a button that will be responsible to trigger our notification.&lt;/p&gt;

&lt;p&gt;Now our button wait's for the function that it will be calling. Let's create a function that will be triggering notifications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void localNotification() {
   AwesomeNotifications().createNotification(
      content: NotificationContent(
        id: 1,
        channelKey: 'basic_notification',
        title: "Proc notification",
        body: "Hey awesome prosper",
      ),
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above function we call &lt;code&gt;createNotification&lt;/code&gt; from &lt;code&gt;AwesomeNotifications&lt;/code&gt; which accepts the following parameters&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;id - an ID of the sent notification&lt;/li&gt;
&lt;li&gt;channelKey - this is the channel that we created while initializing our notification&lt;/li&gt;
&lt;li&gt;title - notification title&lt;/li&gt;
&lt;li&gt;body - body of the notification&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And now let's return in to our button and call our function.&lt;/p&gt;

&lt;p&gt;If we hot restart our application and click the button we will the a notification pop.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcm2nlv2dpdyy1c4749bn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcm2nlv2dpdyy1c4749bn.png" alt="Image description" width="800" height="1644"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Let's end here for this article, in our next article we will focus on BigPicture, action button and scheduled notification, for now you can try to play more with the notifications and see what you can do with it.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Flutter Launch Image in iOS</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Sat, 20 Jan 2024 18:33:48 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/flutter-launch-image-in-ios-34p7</link>
      <guid>https://forem.com/fluttertanzania/flutter-launch-image-in-ios-34p7</guid>
      <description>&lt;p&gt;In this article we'll learn how to add a custom Launch Image in Flutter, by default when you run you're Flutter project in iOS simulator or phone you'll notice that it first start's a blank white screen and continues to you're project Splash Screen.&lt;/p&gt;

&lt;p&gt;Here's an outcome of this article&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4bdaudk0z1ej0s20wpxw.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4bdaudk0z1ej0s20wpxw.gif" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's work on that.&lt;/p&gt;

&lt;p&gt;If you have you're app logo you can generate a splash screen Image from this &lt;a href="https://progressier.com/pwa-icons-and-ios-splash-screen-generator"&gt;website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When you upload you're logo image, website will provide a pop where you can adjust logo position and background color, after finishing adjustment click generate asset button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fld9x1uw1ic3ie34tz5lx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fld9x1uw1ic3ie34tz5lx.png" alt="Image description" width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this article we'll focus on Phones screen and not iPad. When assets are generated we'll scroll down until we see phone's splash screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0xcjbmky0ofhlnb83w7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0xcjbmky0ofhlnb83w7.png" alt="Image description" width="800" height="894"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can click any portrait splash screen and download it.&lt;/p&gt;

&lt;p&gt;Now let's switch to Xcode.&lt;/p&gt;

&lt;p&gt;Open you're Flutter project in Xcode and let's through the following process.&lt;/p&gt;

&lt;p&gt;First expand &lt;code&gt;Runner&lt;/code&gt; by clicking the expand Icon on the left side of the &lt;code&gt;Runner&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn0npjbvlj5r6ikj02i93.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn0npjbvlj5r6ikj02i93.png" alt="Image description" width="800" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After expand &lt;code&gt;Runner&lt;/code&gt; You'll see another &lt;code&gt;Runner&lt;/code&gt; folder just below &lt;code&gt;Flutter&lt;/code&gt; folder and expand it again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpojpthvtnive9d6qfzeh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpojpthvtnive9d6qfzeh.png" alt="Image description" width="800" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After expanding the Runner, you'll see a Folder named &lt;code&gt;Assets&lt;/code&gt; click it, and it will give you two options&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AppIcons - for you're app Icon&lt;/li&gt;
&lt;li&gt;LaunchImage - for you're app launch image&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7l7hdqn4msdhioppuusj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7l7hdqn4msdhioppuusj.png" alt="Image description" width="800" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click LaunchImage option and you'll see three options for uploading image but current they're blank.&lt;/p&gt;

&lt;p&gt;Double click each option and select the downloaded splashScreen&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcap6vvfis1hdbwedps34.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcap6vvfis1hdbwedps34.png" alt="Image description" width="800" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And boom we're done, you can now run you're app and you'll see it start's with a custom launch image and not a blank white screen again.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Control flow in Dart - Part 2</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Sun, 19 Nov 2023 10:42:50 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/control-flow-in-dart-part-2-2bnb</link>
      <guid>https://forem.com/fluttertanzania/control-flow-in-dart-part-2-2bnb</guid>
      <description>&lt;h2&gt;
  
  
  Part 2: Control Flow and Loops
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The If Statement
&lt;/h3&gt;

&lt;p&gt;In programming, decisions are crucial. The &lt;code&gt;if&lt;/code&gt; statement lets us control the flow of our program based on conditions. Consider this example:&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;int&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&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;'It&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;s a hot day!'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&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;'It&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;s not too hot.'&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;Here, if the temperature is greater than 30, it prints 'It's a hot day!'; otherwise, it prints 'It's not too hot.' This helps our program adapt to different situations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Else-if Chains
&lt;/h3&gt;

&lt;p&gt;For more complex conditions, we use &lt;code&gt;else if&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;int&lt;/span&gt; &lt;span class="n"&gt;hour&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&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;'Good morning!'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&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;'Good afternoon!'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&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;'Good evening!'&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;This checks the time of day and greets accordingly, offering more nuanced decision-making.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ternary Operator
&lt;/h3&gt;

&lt;p&gt;The ternary operator streamlines simple &lt;code&gt;if-else&lt;/code&gt; statements:&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;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&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;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s"&gt;'You can vote'&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'You cannot vote yet'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If age is 18 or above, it says 'You can vote'; otherwise, it says 'You cannot vote yet'. This enhances code readability, especially for concise conditions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Switch Statements
&lt;/h3&gt;

&lt;p&gt;Switch statements are beneficial for multiple cases:&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;String&lt;/span&gt; &lt;span class="n"&gt;grade&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'B'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;grade&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;'A'&lt;/span&gt;&lt;span class="o"&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;'Excellent!'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;'B'&lt;/span&gt;&lt;span class="o"&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;'Good job!'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&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;'Keep trying!'&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;It provides different feedback based on the grade, offering a clearer alternative to long if-else chains.&lt;/p&gt;

&lt;h3&gt;
  
  
  Loops
&lt;/h3&gt;

&lt;p&gt;Loops help us automate repetitive tasks. Dart offers various types.&lt;/p&gt;

&lt;h3&gt;
  
  
  While Loop
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;while&lt;/code&gt; loops repeat while a condition is true:&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;int&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="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&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;'Count: &lt;/span&gt;&lt;span class="si"&gt;$count&lt;/span&gt;&lt;span class="s"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It prints 'Count: 0', 'Count: 1', and 'Count: 2', showcasing the iterative nature of programming.&lt;/p&gt;

&lt;h3&gt;
  
  
  For Loop
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;for&lt;/code&gt; loops are handy for a fixed number of iterations:&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="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&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="n"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Iteration: &lt;/span&gt;&lt;span class="si"&gt;$i&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It prints 'Iteration: 0', 'Iteration: 1', 'Iteration: 2', and 'Iteration: 3'. This loop structure is efficient when you know the number of iterations in advance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Break Statement
&lt;/h3&gt;

&lt;p&gt;To exit a loop prematurely, use &lt;code&gt;break&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;int&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&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;'Target reached!'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&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;'Current value: &lt;/span&gt;&lt;span class="si"&gt;$i&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This stops the loop when the target value is reached, adding a layer of control to the iteration process.&lt;/p&gt;

&lt;p&gt;Mastering these concepts empowers you to build flexible and dynamic programs, adapting to various scenarios and user inputs. Happy coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Control flow in Dart - Part 1</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Tue, 31 Oct 2023 09:30:56 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/control-flow-in-dar-part-1-1o7i</link>
      <guid>https://forem.com/fluttertanzania/control-flow-in-dar-part-1-1o7i</guid>
      <description>&lt;p&gt;While building a program you will be in a situation where you want tell a computer to do different depend on the scenario. For example you want to check if user age is under 18 the give a message that he/she cannot vote and if user is above 18 he/she can vote.&lt;/p&gt;

&lt;p&gt;So basically what we're doing here is we're controlling the flow of our program and telling it what to do depending on the scenario. Let's get it 🥳.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparing values&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Referring to our example above, we want to know if user is above or under 18, say we have the following (17 &amp;gt; 18), what will answer be?, maybe yes or no?&lt;/p&gt;

&lt;p&gt;Dart has a Data type called &lt;code&gt;bool&lt;/code&gt; which is Boolean that has only to possible result &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Boolean&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Boolean value can have one of two states. While in general&lt;br&gt;
you could refer to the states as yes and no, on and off, or 1 and 0, most programming languages, Dart included, call them true and false.&lt;/p&gt;

&lt;p&gt;Here's how we can define a bool variable&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bool yes = true;
const bool no = false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When comparing values in dart the result is always a boolean so let's learn more about it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Boolean operators
&lt;/h2&gt;

&lt;p&gt;We mostly use bool values to compare.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing equality&lt;/strong&gt;&lt;br&gt;
In dart use can use &lt;code&gt;==&lt;/code&gt; to test equality of two values. For example&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This will return a bool value of false.&lt;/p&gt;

&lt;p&gt;Note: You may use the equality operator to compare int to double, since they both belong to the num type.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testing inequality&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If we use &lt;code&gt;==&lt;/code&gt; we check if two values are equal, but what if we want to check if the values are not equal?, for this we can use &lt;code&gt;!=&lt;/code&gt; and dart will return &lt;code&gt;true&lt;/code&gt; if compared values are not equal and &lt;code&gt;false&lt;/code&gt; if compared values are equal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(3 != 6)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Greater and less than&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In other situation you want to check if a certain value is greater or is less than other value, we can do so by using &lt;code&gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(3 &amp;gt; 6)
(3 &amp;lt; 6)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will return &lt;code&gt;false&lt;/code&gt; and &lt;code&gt;true&lt;/code&gt; respectively, but that's not the case, what if you want check if value is equal or grater than other and if is equal or less that, to perform this we will use &lt;code&gt;&amp;lt;=&lt;/code&gt; for equal or less than and &lt;code&gt;&amp;gt;=&lt;/code&gt; for equal or greater than&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(3 &amp;gt;= 6)
(3 &amp;lt;= 6)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this are very minimal operators, we may be in a situation where we want to combine two or more condition. &lt;/p&gt;

&lt;p&gt;For example we want to check if a student has finished his work and came to school early. We can do so by using &lt;code&gt;AND&lt;/code&gt; operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const finishedHomeWork = true;
const isEarly = false;

const result = finishedHomeWork &amp;amp;&amp;amp; isEarly;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will combine two conditions and give us a result.&lt;/p&gt;

&lt;p&gt;Stop 🤔 what if we want check if a certain condition met or other condition is met and perform a task, to this we can use &lt;code&gt;OR&lt;/code&gt; operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const finishedHomeWork = true;
const isEarly = false;

const result = finishedHomeWork || isEarly;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's end here for this first section of control flow, in the next section we will learn about if statements and loops, how to perform certain task repetitive when a condition is met.&lt;/p&gt;

</description>
      <category>dart</category>
      <category>flutter</category>
    </item>
    <item>
      <title>Types &amp; Operations in Dart</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Sat, 14 Oct 2023 17:36:58 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/types-operations-in-dart-4g85</link>
      <guid>https://forem.com/fluttertanzania/types-operations-in-dart-4g85</guid>
      <description>&lt;p&gt;Life is full of types, in every thing we do we always use types. What kind of shoes do you wear? Boot? Sneakers? or what kind of phone do you use? iPhone? Google pixel?.&lt;br&gt;
With types we're able to differentiate and categories different things.&lt;/p&gt;

&lt;p&gt;This is the same as in computer, in programming types are useful same as in life, They help you to categorize all the different kinds of data you use in your code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data types in Dart&lt;/strong&gt;&lt;br&gt;
In programming types tell our compliers how we want to use data. There are many types of data in Dart and so far we have been able to use some of them including.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;int&lt;/li&gt;
&lt;li&gt;double&lt;/li&gt;
&lt;li&gt;num&lt;/li&gt;
&lt;li&gt;String and&lt;/li&gt;
&lt;li&gt;dynamic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using data types dart helps you to perform wrong operation in data example tying to minus a String and int.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type inference&lt;/strong&gt;&lt;br&gt;
In our previous article we briefly looked at Type inference in dart, so get deep into it.&lt;/p&gt;

&lt;p&gt;One of the best practise while defining a variable is by specifying it's data type like the followings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int myAge = 22;
double random = 0.1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the above code we have defined two variables and we have annotated with int and double respectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Making variable constants&lt;/strong&gt;&lt;br&gt;
In our above example of variables we make them mutable which means they can change within it's life time, but if we do not want that, which means making them immutable we can do that while still keeping the type annotation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const int myAge = 22;
const double random = 0.1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final int myAge = 22;
final double random = 0.1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But it's required to define data type while creating a variable, Dart is smart enough to know which type a variable is using. Through type inference Dart is able to identify a variable data type. See the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myAge = 22;
const random = 0.1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code we did not tell Dart what type of data we want our variable to have, but dart will know that &lt;code&gt;myAge&lt;/code&gt; is an &lt;code&gt;int&lt;/code&gt; and &lt;code&gt;random&lt;/code&gt; is &lt;code&gt;double&lt;/code&gt;, this is called type inference.&lt;/p&gt;

&lt;p&gt;You can run the following to see your variable data type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(myAge.runtimeType);
print(random.runtimeType);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Converting data type&lt;/strong&gt;&lt;br&gt;
While developing your program you may encounter yourself in situation where you want to convert a certain data to another data type.&lt;/p&gt;

&lt;p&gt;We have seen that in Dart if we try to perform the following, Dart will complain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myAge = 22;
const random = 0.1;

myAge = 0.22;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dart will say &lt;code&gt;A value of type 'int' can't be assigned to a variable of type 'double'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As we see Dart is very sensitive in Data type though other programming languages will allow you to do the above without any error. Experience shows this kind of silent, implicit conversion is a frequent source of software bugs and often hurts code performance. Dart disallows you from assigning a value of one type to another and avoids these issues.&lt;/p&gt;

&lt;p&gt;But this does not mean that Dart will disallows you from changing data type. We can do so by doing the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myAge = 22;
const random = 4.1;

myAge = random.toInt();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The assignment now tells Dart, unequivocally, that you want to convert from the original type, double, to the new type, int.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mixed types operations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You'll always encounter in a situation where you want to perform an operation between two different data types. Example you want to make addition between &lt;code&gt;3 + 3.3&lt;/code&gt;, dart is smart enough that it will return double since making it an int could cause a loss of precision.&lt;/p&gt;

&lt;p&gt;But what if you want a result to be an int?, we you can do it by using type conversion for example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myAge = 22;
const random = 4.1;

final result = (myAge + random).toInt();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time we used &lt;code&gt;final&lt;/code&gt; and not &lt;code&gt;const&lt;/code&gt; because &lt;code&gt;toInt()&lt;/code&gt; is a runtime method, which means variable result is not known during compile time which makes it invalid&lt;/p&gt;

&lt;h2&gt;
  
  
  Strings in Dart
&lt;/h2&gt;

&lt;p&gt;In dart we can work with text with a data type known as &lt;code&gt;String&lt;/code&gt;, now let's learn about String data type.&lt;/p&gt;

&lt;p&gt;We have seen String in previous chapters when we printed.&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 Dart world');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's define a variable and assign a string data type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var hello = 'Hello Dart world';
print(hello);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even if we did not defined a data type but still Dart will assign our variable as a String.&lt;/p&gt;

&lt;p&gt;But we can be more specific by defining it's data type, like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const String hello = "Hello Dart";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Concatenation&lt;/strong&gt;&lt;br&gt;
There's a point when you want to perform a certain thing within you're String, well dart knowns that and it allow's us to do it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var hello = 'Hello' + ' Dart ';
const anotherHello = 'World';
hello += anotherHello;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you print hello variable you will see &lt;code&gt;Hello Dart World&lt;/code&gt;, here dart concatenates our Strings to be a single text.&lt;/p&gt;

&lt;p&gt;This is very useful when you have a String in a variable and want to combine it with another String.&lt;/p&gt;

&lt;p&gt;You can also build up a string by using interpolation, which is a special Dart syntax that lets you build a string in a manner that’s easy for other people reading your code to understand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const String language = 'Dart';
const String hello = 'Hello $language';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code does the same thing like the previous one when we used &lt;code&gt;+&lt;/code&gt; to join a text, but this more readable than the previous one&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-line strings&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you have a String with multiple line you can easily display as following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const string = '''
You can have a string
that contains multiple
lines
by
doing this.''';
print(string);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The three single-quotes (''') signify that this is a multi-line string, but you can also use (""") and it will do the same thing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
This is just an introduction to types, you should search for more resources to learn more.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Expressions, Variables &amp; Constants in Dart</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Mon, 02 Oct 2023 22:23:47 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/expressions-variables-constants-in-dart-5129</link>
      <guid>https://forem.com/fluttertanzania/expressions-variables-constants-in-dart-5129</guid>
      <description>&lt;p&gt;In our first article we focused on installation of dart and wrote our first dart "Hello Word".&lt;/p&gt;

&lt;p&gt;Let's start writing code, in this article we will focus on Variable and expressions in dart. Let's go 🥳&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments in dart&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Comment in programming are non executable line's of code which describes what a code is doing.&lt;/p&gt;

&lt;p&gt;Writing comment's in your program describes what was your intention to write a certain block of code and what does that code solving. But also in the future more likely other programmers will be using your code, by commenting it will be easier for them to understand your code.&lt;/p&gt;

&lt;p&gt;Comment's in dart can be single line or multiple line comments, here's an example of a single line comment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// This is a comment, it will never be executed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's see how we can write multiple line comments&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* This is a comment also,
but it's to long
let's break it */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In multiple line's comment the start is denoted by /* and the end is denoted by */.&lt;/p&gt;

&lt;p&gt;You can write comment in may ways in Dart but to make it simple we'll stop here in comments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Printing output&lt;/strong&gt;&lt;br&gt;
When writing a program there's always a point you want to see an output of a certain code. In dart we use &lt;code&gt;print()&lt;/code&gt; function. And this display an out put on the console.&lt;/p&gt;

&lt;p&gt;Adding &lt;code&gt;print&lt;/code&gt; statements into your code is an easy way to monitor what’s happening at a particular point in your code. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Statements and expressions&lt;/strong&gt;&lt;br&gt;
In programming you will often come across these two words so first let's understand them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Statements&lt;/strong&gt; &lt;br&gt;
A statement is a command, something you tell the computer to do, in dart all simple statements end up with a semicolons,  a good example is a &lt;code&gt;print&lt;/code&gt; statement.&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, Dart world');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Semicolons identifies an end of a statement.&lt;/p&gt;

&lt;p&gt;In addition to simple statements, Dart also has complex statements and code blocks that use curly braces, but there’s no need to add semicolons after the braces.&lt;/p&gt;

&lt;p&gt;One example of a complex statement is the if statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (condition) {
  // code block
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will learn more about if statement's in Control Flow section. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Expressions&lt;/strong&gt;&lt;br&gt;
Unlike statements Expressions does not do something, it is something. Expression is a value or something that can be calculated to a value.&lt;/p&gt;

&lt;p&gt;Here are some few examples of expressions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;36
1 + 2
'Hello Dart'
firstName
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Values can be numbers, text, or any other type. They can also be a variable example &lt;code&gt;firstName&lt;/code&gt; who's value is not known during run time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arithmetic operations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let's learn arithmetic operations that dart offers. Let's start with simple operations that we're all familiar with.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add +&lt;/li&gt;
&lt;li&gt;Subtract -&lt;/li&gt;
&lt;li&gt;Multiply *&lt;/li&gt;
&lt;li&gt;Divide /&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 + 2
5 - 2
9 * 2
12 / 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep in mind that all of these operations are expressions because we expect value from them. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decimal numbers&lt;/strong&gt;&lt;br&gt;
Most of programming languages uses integer division by default if you have the following calculation &lt;code&gt;(22 / 7)&lt;/code&gt;, you will expect the result to be &lt;code&gt;3&lt;/code&gt;, However, Dart gives you the standard decimal answer which will be &lt;code&gt;(3.142857142857143)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But in dart if you would want to perform integer division, then you could use the &lt;code&gt;~/&lt;/code&gt; operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;22 ~/ 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This produces a result of 3.&lt;/p&gt;

&lt;p&gt;The ~/ operator is officially called the truncating division operator when applied to numbers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Euclidean modulo operation&lt;/strong&gt;&lt;br&gt;
There's a point where you want to divide a number and get the remainder, in dart we use &lt;code&gt;%&lt;/code&gt;, which will always return a  remainder of a given division calculation.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 \ 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The answer will be 1 which is the remainder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Math functions&lt;/strong&gt;&lt;br&gt;
As you become more pro in Dart you will in a situation you want to perform a complex operation, Dart can help you with that by providing you a &lt;code&gt;math&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;To use these math functions, add the following import to the top of your file:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;dart:math&lt;/code&gt; is one of Dart’s core libraries. Adding the import statement tells the compiler that you want to use something from that library.&lt;/p&gt;

&lt;p&gt;By importing the math library you can now use math functions from the library, for example &lt;code&gt;sin(), cos()&lt;/code&gt; and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;In the simplest form a variable is a name that you give it a value and tell a computer to remember it so you can use it later. The name carries with it an associated type that denotes what sort of data the name refers to, such as text, numbers, or a date.&lt;/p&gt;

&lt;p&gt;For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age = 21;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The statement declares a variable called age which is an int as it's type, which then carries a value of 21. The int part of the statement is known as a type annotation, which tells Dart what the type is.&lt;/p&gt;

&lt;p&gt;Let's pause for a while&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You will always use &lt;code&gt;= and ==&lt;/code&gt; now let's see their differences, The equals sign = is known as the assignment operator because it assigns a value to a variable. This is different than the equals sign you are familiar with from math. That equals sign is more like the == equality operator in Dart. We will learn more on next chapter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To change the value of a variable simple you can assign another value of the same type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age=21;
age=22;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Type safety&lt;/strong&gt;&lt;br&gt;
Dart is a type safe language, which means once you assign a variable it's data type you cannot change it later, example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int age = 21;
age = 21.9; // This is not allowed 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our example above we first defined a variable with type &lt;code&gt;int&lt;/code&gt; and give it value, in the next line we're assigning the same variable with a decimal value which is double in flutter.&lt;br&gt;
If we run this program we will get an error.&lt;/p&gt;

&lt;p&gt;But whenever you find yourself in a situation where you want the same variable to be assigned &lt;code&gt;int&lt;/code&gt; or &lt;code&gt;float&lt;/code&gt; you can use &lt;code&gt;num&lt;/code&gt;. The num type can be either an int or a double, so the first two assignments work. &lt;/p&gt;

&lt;p&gt;And if you don't care about type safety at all you can use &lt;code&gt;dynamic&lt;/code&gt; type which will allow you to use any data type without getting any error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type inference&lt;/strong&gt;&lt;br&gt;
You can define a variable without telling it's type and dart will do that for you. By using &lt;code&gt;var&lt;/code&gt; dart allows you to define a variable without telling it's data type and dart will be smart enough to know what type it is.&lt;/p&gt;

&lt;p&gt;But by using var keyword dart will still apply type safety, example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var age = 10;
age = 15; // OK
age = 3.14159; // No
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Constants&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we define variables we may encounter in a situation where we don't want the variable value to be changed after it's assigned. Dart has two different types of “variables” whose values never change. They are declared with the const and final keywords, and the following sections will show the difference between the two.&lt;/p&gt;

&lt;p&gt;Having variable's that value can change can cause problems in the program, but we use them mostly, this type of variable are called mutable data. It's easy to lose track which variable value can change within our programs, we encourage to use constants whenever possible. Unchangeable variables are known as immutable data.&lt;/p&gt;

&lt;p&gt;We use &lt;code&gt;const&lt;/code&gt; in Dart to create a constant variable, example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const age=22;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we're telling dart that age value will never change. If we try to do the following we will get an error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age=21; // this will result an error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;final constants&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When we use const we always know the value of our variable before running our program, but there's a situation where you want to define a variable as a constant but it's value is unknown until you run your program.&lt;/p&gt;

&lt;p&gt;In Dart const is only used for compile-time constants; that is, for values that can be determined by the compiler before the program ever starts running.&lt;/p&gt;

&lt;p&gt;If you can’t create a const variable because you don’t know its value at compile time, then you must use the final keyword to make it a runtime constant. &lt;/p&gt;

&lt;p&gt;For example, fetching data from the server, asking user data from an input and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
And that's all for our article, before you continue more try to learn more about our topic today from different resource and do more practice.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Hello Dart World 😜</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Thu, 21 Sep 2023 15:27:39 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/hello-dart-world-2bgg</link>
      <guid>https://forem.com/fluttertanzania/hello-dart-world-2bgg</guid>
      <description>&lt;p&gt;Dart is a general purpose programming language that is developed and maintained by Google. With dart one can develop web, server, desktop and mobile applications for iOS and Android.&lt;/p&gt;

&lt;p&gt;Dart is easy to learn, and if you came from C-style languages or object oriented it will be easy to pick up, but if your a beginner in programming then Dart is a good place to start with. One exiting thing about dart is that you can build applications in multiple platforms using a single code base.&lt;/p&gt;

&lt;p&gt;In this first article series will focus on setting up environment and write our first dart Hello, let's get in 🚀.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting up Dart environment:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are several options that we can use to run Dart to, so first let's look at them.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;DartPad: It's a simple browser based tool for writing and running Dart code. It's available in any modern web browser you can access it in &lt;a href="https://dartpad.dev"&gt;https://dartpad.dev&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Visual Studio Code: This is a most used IDE which also supports Dart development by proving Dart extension. We recommend using this tool but if you have another tool you can go with it also.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There many other tools that you can use to run Dart but in our article series we will be using VS Code, you can use any of your preferred IDE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing VS Code&lt;/strong&gt;&lt;br&gt;
Visual studio code is an open source and cross platform IDE which is maintained by Microsoft and it's available in MacOS, Windows and Linux.&lt;/p&gt;

&lt;p&gt;Download Visual Studio Code at &lt;a href="//code.visualstudio.com"&gt;code.visualstudio.com&lt;/a&gt;, and follow the directions provided on the site to install it.&lt;/p&gt;

&lt;p&gt;To run Dart in VS code we need to install Dart SDK first, let's do it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing Dart SDK&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dark SDK is a collection of command line tools that makes it possible to build Dart program.&lt;/p&gt;

&lt;p&gt;To install Dart SDK visit &lt;a href="https://dart.dev/get-dart"&gt;https://dart.dev/get-dart&lt;/a&gt; and you can follow instructions from the site to complete it's installation.&lt;/p&gt;

&lt;p&gt;After you have installed Dart you can run the following command to ensure that everything runs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dart --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will display your current version of Dart.&lt;/p&gt;

&lt;p&gt;Let's explore some of the command that dart offers us and their use. Run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dart help
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will list available commands that we can use in dart.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;analyze: this command analyses your code and tell when you have made a mistake in your code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;compile: this command complies Dart code into a native executable program for Windows, Linux or MacOS. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;create: it's used for creating new dart project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;fix: This command applies automated fixes to your dart code from syntax and more.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;run: this command is use to run your dart file to produce the output.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;test: this command is for performing unit test in your dart project.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Dart comes with many other command that you can use, to learn more about them you run dart help and explore them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write our first code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now let's write our first line of code, but first let's start by creating a Dart project.&lt;/p&gt;

&lt;p&gt;Go the computer location where you want to run your project and run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dart create hello_dart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new directory named hello_dart which contains our project files. Navigation to the project by writing &lt;code&gt;cd hello_dart&lt;/code&gt; in the command.&lt;/p&gt;

&lt;p&gt;To run our first dart project we will run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dart run hello_dart.dart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What was the output?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A dart project contains the following list of files&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;bin: this directory contains all of our executable files&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;hello_dart.dart: which is named as the same name of the project, this file contains Dart code to execute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;pubspec.yaml: pubspec.yaml: Contains a list of the third party Pub dependencies you want to use in your project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;README.md: This describes what our project is about and how it's organized.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;analysis_options.yaml: Holds special rules that will help you detect issues with your code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;.gitignore: Lists all files that won't be needed when your uploading your files in git repository.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that's for this article, but don't stop here you can search online for another resources and learn more about dart.&lt;/p&gt;

&lt;p&gt;In our next article we will focus on Expressions, Variables &amp;amp; Constants, see you then.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting Started with Dart: The Essential First Step for Flutter Beginners</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Tue, 19 Sep 2023 10:25:19 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/getting-started-with-dart-the-essential-first-step-for-flutter-beginners-36e2</link>
      <guid>https://forem.com/fluttertanzania/getting-started-with-dart-the-essential-first-step-for-flutter-beginners-36e2</guid>
      <description>&lt;p&gt;Starting your journey into Flutter development is an exciting adventure. The promise of creating beautiful apps for multiple platforms is awesome. However, there's a aspect that many beginners overlook, just like I did when I first began – learning Dart, the language that powers Flutter. In this article, I'll share why mastering Dart first is crucial and introduce you to our upcoming beginner-friendly Dart tutorial series.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Flutter Rush:&lt;/strong&gt;&lt;br&gt;
When you first hear about Flutter, it's natural to want to jump straight in. After all, who doesn't want to create amazing apps quickly? However, it's easy to forget that behind the magic of Flutter lies Dart, a language that you need to understand to unlock Flutter's true potential.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Dart Matters:&lt;/strong&gt;&lt;br&gt;
Dart is like the magic wand that makes Flutter work. It's the language that helps you create the logic and functionality in your Flutter apps. Before you can become a Flutter pro, you must become a Dart enthusiast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning Dart Step by Step:&lt;/strong&gt;&lt;br&gt;
To make your journey into Dart as smooth as possible, we've designed a beginner-friendly Dart tutorial series. It doesn't matter if you're completely new to programming or just new to Dart – we've got you covered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What We'll Learn:&lt;/strong&gt;&lt;br&gt;
In this series, we'll break down Dart into bite-sized pieces, so it's easy to grasp:&lt;/p&gt;

&lt;p&gt;1: Hello dart - Here we will learn how to install and run dart, and we will write our first Dart Hello Word 😜.&lt;/p&gt;

&lt;p&gt;2: Expressions, Variables &amp;amp; Constants - we will learn how to name data using variables and also get a brief introduction to Dart data types.&lt;/p&gt;

&lt;p&gt;3: Types &amp;amp; Operations - In this series we will learn more about Dart data types.&lt;/p&gt;

&lt;p&gt;4: Control Flow - In this section we’ll learn how to make decisions and repeat tasks in your programs.&lt;/p&gt;

&lt;p&gt;5: Functions - We’ll learn how to write functions in Dart, including both named functions and anonymous functions.&lt;/p&gt;

&lt;p&gt;6: Classes - In this section we will see a more flexible way to create your own types by using classes&lt;/p&gt;

&lt;p&gt;7: Nullability - Ever tried to access data that's not there?, In this section we will learn and how to handle Null values.&lt;/p&gt;

&lt;p&gt;8: Asynchronous Programming - We’ll not only learn&lt;br&gt;
how to deal with code that takes a long time to complete, but along the way, we’ll also see how to handle errors, connect to a remote server and read data from a file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;br&gt;
In conclusion, remember that learning Dart first is your secret weapon in becoming a skilled Flutter developer. Join us on this Dart adventure, and together, we'll unlock the full potential of Flutter. Stay tuned for our beginner-friendly Dart tutorials – we can't wait to get started with you on this exciting journey into app development! 🚀🌟&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Biometric Authentication in Flutter(Face ID/ Fingerprint)</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Tue, 08 Aug 2023 11:41:25 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/biometric-authenticationin-flutterface-id-fingerprint-20gl</link>
      <guid>https://forem.com/fluttertanzania/biometric-authenticationin-flutterface-id-fingerprint-20gl</guid>
      <description>&lt;p&gt;One of the essential thing in mobile application is security especially if your building a finance app, and one of the most used security measure is using biometric authentication, which means you verify user by using phone face ID, Fingerprint or phone password.&lt;/p&gt;

&lt;p&gt;Authentication using biometrics can be challenging. As it requires a good understanding of the underlying platform's APIs and implementation details.&lt;/p&gt;

&lt;p&gt;But also, not all devices support biometric authentication, which requires developers to handle when user device does not have biometric authentication.&lt;/p&gt;

&lt;p&gt;Luck us flutter provides a package for this &lt;a href="https://pub.dev/packages/local_auth"&gt;local_auth&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This package implements biometric security with Face ID and Touch ID/Fingerprint.&lt;/p&gt;

&lt;p&gt;😜 Let's dive in and learn how to implement it in our flutter app.&lt;/p&gt;

&lt;p&gt;But wait we need to go through the following steps to implement this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setting up the project&lt;/li&gt;
&lt;li&gt;Checking biometric availability&lt;/li&gt;
&lt;li&gt;Requesting biometric authentication&lt;/li&gt;
&lt;li&gt;Handling authentication results&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up the project
&lt;/h2&gt;

&lt;p&gt;First thing we need to install local authentication to our project.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Then run the following command to install this plugin, though if your using vsCode you do not need to run this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter packages get
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Android Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add following line under manifest tag in &lt;code&gt;AndroidManifest.xml&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;uses-permission android:name="android.permission.USE_BIOMETRIC"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then Update the &lt;code&gt;MainActivity.kt&lt;/code&gt; file to use &lt;code&gt;FlutterFragmentActivity&lt;/code&gt; instead of &lt;code&gt;FlutterActivity&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//add this import
import io.flutter.embedding.android.FlutterFragmentActivity

//Chnage to FlutterFragmentActivity
class MainActivity: FlutterFragmentActivity() {
      // ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;IOS Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add following code to your &lt;code&gt;info.plist&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;key&amp;gt;NSFaceIDUsageDescription&amp;lt;/key&amp;gt;
&amp;lt;string&amp;gt;Why is my app authenticating using face id?&amp;lt;/string&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;😮‍💨 we're done with the setup now let's write some code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checking biometric availability
&lt;/h2&gt;

&lt;p&gt;We need to make sure that user phone has biometric authentication before we request to use it.&lt;/p&gt;

&lt;p&gt;To check if biometric authentication is available or not. We use &lt;code&gt;canCheckBiometrics&lt;/code&gt; method on the &lt;code&gt;LocalAuthentication&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;statefull&lt;/code&gt; widget called &lt;code&gt;LoginScreen&lt;/code&gt; and add the following functions&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:local_auth/local_auth.dart';

final LocalAuthentication _localAuth = LocalAuthentication();

//Check if biometric auth is available
Future&amp;lt;boolean&amp;gt; hasBiometrics() async {
    try {
        return await _localAuth.canCheckBiometrics;
    } on PlatformException catch (e) {
        return false;
    }
}

//Check type of biometric auth available (Eg - Face ID, fingerprint)
Future&amp;lt;void&amp;gt; checkBiometricType() async {
  final availableBiometrics = await _localAuth.getAvailableBiometrics();
  print('Available biometrics: $availableBiometrics');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;hasBiometrics&lt;/code&gt; functions checks if user device has biometric authentication by using &lt;code&gt;canCheckBiometrics&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authenticate user&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If hasBiometrics function returns true now we can use biometric authentication to verify user.&lt;/p&gt;

&lt;p&gt;Call the &lt;code&gt;authenticate&lt;/code&gt; method of the &lt;code&gt;LocalAuthentication&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;The authenticate method takes 3 parameters - &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;localizedReason - is the message to show to user while prompting them for authentication. This is typically along the lines of: 'Authenticate to access MyApp.'. This must not be empty.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;authMessages - if you want to customize messages in the dialogs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;options - for configuring further authentication related options.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Authenticate using biometric
  Future&amp;lt;bool&amp;gt; authenticate() async {
    final hasBiometric = await hasBiometrics();

    if (hasBiometric) {
      return await _localAuth.authenticate(
        localizedReason: "Scan fingerprint to authenticate",
        options: const AuthenticationOptions(
          //Shows error dialog for system-related issues
          useErrorDialogs: true,
          //If true, auth dialog is show when app open from background
          stickyAuth: true,
          //Prevent non-biometric auth like such as pin, passcode.
          biometricOnly: true,
        ),
      );
    } else {
      return false;
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's build a simple UI for the authentication, we will have a login screen with a button and when a user is verified we will direct them to another page else we will display a snackbar of failure to authenticate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Home screen&lt;/strong&gt;&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/material.dart';

class HomeScreen extends StatelessWidget {

    @override
    Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(title: const Text('Home Screen')),
            body: const Center(
                child: Text('Home Screen'),
            ),
        );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in our LoginScreen return the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Scaffold(
      appBar: AppBar(title: const Text('Login Screen')),
      body: Center(
        child: ElevatedButton(
          onPressed: () async {
            final isAuthenticated = await authenticate();

            if (isAuthenticated) {
              Navigator.push(
                context,
                MaterialPageRoute(builder: (_) =&amp;gt; HomeScreen()),
              );
            } else {
              final snackBar = SnackBar(content: Text('Auth Failed'));
              ScaffoldMessenger.of(context).showSnackBar(snackBar);
            }
          },
          child: const Text('Authenticate'),
        ),
      ),
    );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are good to go, you can test this project in a real device to gain the experience.&lt;/p&gt;

&lt;p&gt;Happy coding 🥳&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Native Splash Screen in Flutter</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Sun, 30 Jul 2023 14:16:56 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/native-splash-screen-in-flutter-3p3c</link>
      <guid>https://forem.com/fluttertanzania/native-splash-screen-in-flutter-3p3c</guid>
      <description>&lt;p&gt;One of the thing that I experienced while building flutter application is a white blank screen that appears when an application starts. To me is very annoying and I do known that it does not bring good user experience. This can be frustrating for users and can make your app feel unprofessional.  &lt;/p&gt;

&lt;p&gt;But the good news is that you can remove the blank white screen and display an image or logo just like other apps that we use in our daily activities.&lt;/p&gt;

&lt;p&gt;In this article we will be using a package known &lt;a href="https://pub.dev/packages/flutter_native_splash"&gt;flutter_native_splash&lt;/a&gt; to display a custom splash screen when our apps starts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Splash Screen?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A splash screen in mobile applications is a graphical element that appears when you launch the app. It is usually displayed for a short period, typically a few seconds, while the app is loading its core components and initialising necessary resources in the background. Splash screens serve as an initial branding or introductory screen for the app, providing a smooth and visually appealing transition from the app launch to the main user interface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add flutter_native_splash package in our project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add flutter_native_splash as dependency to your Flutter project.&lt;/p&gt;

&lt;p&gt;You can do this by adding the following line in &lt;code&gt;pubspec.yaml&lt;/code&gt;&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_native_splash: ^2.3.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then run &lt;code&gt;flutter pub get&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting up Splash Screen&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First thing is to add an image that we want it to appear in our splash screen, this can be a logo or any image.&lt;/p&gt;

&lt;p&gt;Also do not forget to add the following line is 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 plaintext"&gt;&lt;code&gt;flutter:
    assets:
        - assets/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will tell Flutter where it can find our images&lt;/p&gt;

&lt;p&gt;Now let's start the coolest part&lt;/p&gt;

&lt;p&gt;You need to configure flutter_native_splash to use the image for the splash screen.&lt;/p&gt;

&lt;p&gt;Inside you're &lt;code&gt;pubspec.yaml&lt;/code&gt; add flutter_native_splash with following configuration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter_native_splash:
  # Background color of splash screen
  color: "#ffffff"
  # Image that you want to show
  image: assets/splash.png
  # Sizing of image
  fill: true
  # Splash Image to show in dark mode (Optional)
  image_dark: assets/splash_dark.png
  # Background color of dark mode (Optional)
  color_dark: "#000000"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also make sure you do not add this configs under flutter section.&lt;/p&gt;

&lt;p&gt;But wait!!! one more step.&lt;/p&gt;

&lt;p&gt;Run the following command so that flutter_native_splash package can do it's magic 🪄&lt;/p&gt;

&lt;p&gt;&lt;code&gt;flutter pub run flutter_native_splash:create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And that's it, now your user will have an amazing experience when they click your app 🥳.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating shimmer animations using flutter</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Thu, 27 Jul 2023 22:38:42 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/creating-shimmer-animations-using-flutter-1d0n</link>
      <guid>https://forem.com/fluttertanzania/creating-shimmer-animations-using-flutter-1d0n</guid>
      <description>&lt;p&gt;One of the best user experience in any application is a loading indicator, ever used youtube and saw a loading indicator that tells you some is coming??&lt;/p&gt;

&lt;p&gt;One of the best package for shimmer loading is fade_shimmer, and we will be using it in this example.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://pub.dev/packages/fade_shimmer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Install this package in to your project and let's start right away&lt;/p&gt;

&lt;p&gt;Fade shimmer package have a Widget named FadeShimmer which receives the following properties. 👇🏽&lt;/p&gt;

&lt;p&gt;height: Height of the single shimmer&lt;br&gt;
width: Width of the single shimmer&lt;br&gt;
radius: defines border radius of the single shimmer&lt;br&gt;
millisecondsDelay: delay time before update the color&lt;br&gt;
fadeTheme: defines the UI mode of the shimmer&lt;/p&gt;

&lt;p&gt;Write the following code into your project&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:fade_shimmer/fade_shimmer.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Shimmer effect',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const HomeScreen(),
    );
  }
}

void doStuff() {}

class HomeScreen extends StatelessWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final highlightColor = Color(0xFF696C80);
    final baseColor = Color(0xFF4B4D5C);
    return Scaffold(
      backgroundColor: const Color(0xFF353535),
      body: SafeArea(
        child: ListView.builder(
          padding: EdgeInsets.only(top: 20),
          itemBuilder: (_, i) {
            final delay = (i * 300);
            return ShrimmerCard(
                delay: delay,
                highlightColor: highlightColor,
                baseColor: baseColor);
          },
          itemCount: 20,
        ),
      ),
    );
  }
}

class ShrimmerCard extends StatelessWidget {
  const ShrimmerCard({
    Key? key,
    required this.delay,
    required this.highlightColor,
    required this.baseColor,
  }) : super(key: key);

  final int delay;
  final Color highlightColor;
  final Color baseColor;

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(20),
      child: FadeShimmer(
        height: 15,
        width: 150,
        radius: 20,
        millisecondsDelay: delay,
        highlightColor: highlightColor,
        baseColor: baseColor,
      ),
    );
  }
}

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

&lt;/div&gt;



&lt;p&gt;Save and run this file and you will see the following output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cWiX_W-r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2isbq7cl83u9pjfqruu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cWiX_W-r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2isbq7cl83u9pjfqruu.png" alt="Image description" width="800" height="807"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By using shimmer loader provides best user experience of the app to your users.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is null safety? Why is Dart called Null Safety.</title>
      <dc:creator>Flutter Tanzania </dc:creator>
      <pubDate>Sat, 15 Jul 2023 12:20:27 +0000</pubDate>
      <link>https://forem.com/fluttertanzania/what-is-null-safety-why-is-dart-called-null-safety-o6a</link>
      <guid>https://forem.com/fluttertanzania/what-is-null-safety-why-is-dart-called-null-safety-o6a</guid>
      <description>&lt;p&gt;As with any programming language or framework, ensuring code reliability and preventing unexpected errors are crucial for delivering a robust application. One of the significant enhancements introduced in Dart 2.12, the language used by Flutter, is the concept of nullability. In this article, we will explore nullability in Flutter and how it contributes to writing safer code.&lt;/p&gt;

&lt;p&gt;Nullability refers to the ability of an object or variable to hold a null value, which signifies the absence of a value. Historically, null references have been a common source of bugs in software development, often leading to crashes or unexpected behavior. Dart's null safety feature addresses this problem by providing developers with a set of tools and annotations to denote whether a variable can be null or not.&lt;/p&gt;

&lt;p&gt;In previous versions of Dart, all variables were nullable by default, meaning they could hold null values. While this flexibility was useful in certain scenarios, it also introduced the risk of null reference errors. With null safety, Dart introduces two main types of variables: nullable and non-nullable. Non-nullable variables cannot hold null values, thereby reducing the chances of null-related issues.&lt;/p&gt;

&lt;p&gt;To denote the nullability of variables explicitly, Dart introduces two operators: the question mark (&lt;code&gt;?&lt;/code&gt;) and the exclamation mark (&lt;code&gt;!&lt;/code&gt;). When a question mark is appended to a type, it signifies that the variable can be null. Conversely, the exclamation mark denotes a non-nullable type, ensuring that the variable cannot hold null values.&lt;/p&gt;

&lt;p&gt;Let's consider a simple example to illustrate the usage of nullability in Flutter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String? nullableString;
String nonNullableString = 'Hello, Flutter!';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code snippet, &lt;code&gt;nullableString&lt;/code&gt; is explicitly marked as nullable using the &lt;code&gt;?&lt;/code&gt; operator, while &lt;code&gt;nonNullableString&lt;/code&gt; is a non-nullable variable. This distinction makes it clear to the developer and the compiler about the intention behind the variable usage.&lt;/p&gt;

&lt;p&gt;Null safety also introduces a new syntax for handling null values called the null-aware operator. This operator, denoted by the question mark followed by a period (&lt;code&gt;?.&lt;/code&gt;), allows developers to safely access properties or methods of an object that might be null. If the object is null, the expression evaluates to null rather than throwing an exception.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String? nullableString;
int? length = nullableString?.length;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code snippet above, &lt;code&gt;nullableString?.length&lt;/code&gt; retrieves the length of the string if &lt;code&gt;nullableString&lt;/code&gt; is not null. If &lt;code&gt;nullableString&lt;/code&gt; is null, the expression evaluates to null, preventing a potential null reference error.&lt;/p&gt;

&lt;p&gt;The null safety feature in Dart is not only limited to variables but also extends to function parameters and return types. By annotating parameters and return types as nullable or non-nullable, developers can ensure clarity and avoid null-related issues.&lt;/p&gt;

&lt;p&gt;Additionally, Dart's null safety feature provides an improved type system that can infer nullability based on variable initialization and usage. This type inference reduces the need for explicit nullability annotations in many cases, resulting in cleaner and more concise code.&lt;/p&gt;

&lt;p&gt;While null safety in Dart brings numerous benefits in terms of code reliability and reduced bugs, it is important to note that migrating existing codebases to embrace null safety can be a non-trivial task. The migration process involves thoroughly analyzing the codebase, updating dependencies, and addressing potential nullability issues. However, the effort is worthwhile, as it leads to more stable applications and a better developer experience in the long run.&lt;/p&gt;

&lt;p&gt;In conclusion, nullability in Flutter, powered by Dart's null safety feature, is a significant step forward in writing safer and more reliable code. By explicitly denoting the nullability of variables, leveraging the null-aware operator, and embracing the improved type system, developers can prevent null-related bugs and enhance the overall quality of their Flutter applications. As Flutter continues to evolve, embracing null safety becomes increasingly important for developers aiming to build robust and high-performing applications.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
