<?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>DEV Community: mustafa3252</title>
    <description>The latest articles on DEV Community by mustafa3252 (@mustafa3252).</description>
    <link>https://dev.to/mustafa3252</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%2F342377%2F346236c9-7803-41f9-8537-83dce4b03a29.png</url>
      <title>DEV Community: mustafa3252</title>
      <link>https://dev.to/mustafa3252</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mustafa3252"/>
    <language>en</language>
    <item>
      <title>Understanding Future, Async, and Await in Flutter </title>
      <dc:creator>mustafa3252</dc:creator>
      <pubDate>Sat, 18 Dec 2021 22:18:18 +0000</pubDate>
      <link>https://dev.to/mustafa3252/understanding-future-async-and-await-in-flutter-4i5b</link>
      <guid>https://dev.to/mustafa3252/understanding-future-async-and-await-in-flutter-4i5b</guid>
      <description>&lt;p&gt;Does your Flutter app need to perform some networking operations? Perhaps download some file or load an image? Maybe perform some heavy database queries or run some long operations? Well, Future, Async, and Await APIs are here to help you with such Asynchronous programming tasks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Asynchronous Programming in an Android Application
&lt;/h2&gt;

&lt;p&gt;In an Android application, whenever you run the app, a &lt;strong&gt;default process&lt;/strong&gt; is created. Attached to that, a &lt;strong&gt;default main UI thread&lt;/strong&gt; is created. Whenever you interact with your application, you do it with the help of the &lt;strong&gt;main UI thread&lt;/strong&gt;. Within it, you can perform small operations such as user interaction, clicking a button or checking a checkbox, and maybe some small animations. These operations take considerably less amount of time. &lt;/p&gt;

&lt;p&gt;However, when you want to perform some heavy operations such as downloading or uploading a file, in that case, parallel to the main thread, you create a separate &lt;strong&gt;"Worker thread."&lt;/strong&gt; This thread can be used to perform long-running operations such as heavy database queries, loading an image, etc. &lt;/p&gt;

&lt;h2&gt;
  
  
  Asynchronous Programming in Dart
&lt;/h2&gt;

&lt;p&gt;Android is &lt;strong&gt;multi-threaded&lt;/strong&gt;, however Dart/Flutter is &lt;strong&gt;single-threaded&lt;/strong&gt;. What it means is that in Dart/Flutter, you can only have the main UI thread, while you cannot have a separate "Worker thread." Now the question arises, how can we perform long-running operations like the ones mentioned previously in Flutter without making our app janky?&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;For performing Asynchronous programming in Flutter, you have Future, Async, and Await APIs with which you can perform heavy operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining Future
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;future&lt;/strong&gt; is defined in the same way as a function is in Dart, except instead of void, you use Future. If you wish to return a value from the Future, you must provide it with a type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future voidFuture() {}
Future&amp;lt;String&amp;gt; typedFuture() {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using Future
&lt;/h2&gt;

&lt;p&gt;Let us define a dummy long-running operation that returns the Future type String.&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; downloadFile(){
    Future&amp;lt;String&amp;gt; result = Future.delay(Duration(second: 6)){
         return "My file content";
     }
  return result;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we created a dummy function that will return a &lt;strong&gt;String&lt;/strong&gt; after six seconds.&lt;/p&gt;

&lt;p&gt;After six-second, the value of &lt;strong&gt;result&lt;/strong&gt; variable will be assigned as a String instead of a Future.&lt;/p&gt;

&lt;p&gt;A point to note here is that until the &lt;strong&gt;Future.delay()&lt;/strong&gt; function return the String and assigns it to result, the datatype of result will still be a Future type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining Async and Await
&lt;/h2&gt;

&lt;p&gt;Let us define another function which uses the &lt;strong&gt;downloadFile()&lt;/strong&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void printFileContent(){
     Future&amp;lt;String&amp;gt; fileContent = downloadFile();
     print("The file content is -&amp;gt; $filecontent");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On running the function, the &lt;strong&gt;downloadFile()&lt;/strong&gt; function just returns the Future object and not the valid String since it has yet to assign the String to the result variable, but it has been returned immediately instead of waiting for six seconds.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;fileContent&lt;/strong&gt; variable, in this case, will be assigned an &lt;strong&gt;"Instance of Future"&lt;/strong&gt; and not the actual value the function has to return.&lt;/p&gt;

&lt;p&gt;To solve this problem, you should use &lt;strong&gt;await&lt;/strong&gt; keyword while working with a Future function. The await keyword can only be used if we mark the function as &lt;strong&gt;async&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Await and Async
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void printFileContent() _async_{
     String fileContent = _await_ downloadFile();
     print("The file content is -&amp;gt; $filecontent");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Doing this for the function means that unless you get a valid String result from the &lt;strong&gt;downloadFile()&lt;/strong&gt; function, do not execute the next statement.&lt;/p&gt;

&lt;p&gt;Also, since we are getting only a valid result and not expecting an instance of Future, we can reassign the datatype of &lt;strong&gt;fileContent&lt;/strong&gt; as just String rather than Future.&lt;/p&gt;

&lt;p&gt;This concept can also be expanded when working with live data from the internet or waiting for any operation to be performed Asynchronously.&lt;/p&gt;

&lt;p&gt;Below mentioned are some more resources which can help you understand the concepts better:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=OTS-ap9_aXc"&gt;Dart Futures - Flutter in Focus&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=SmTCmDMi4BY"&gt;Async/Await - Flutter in Focus&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can always visit the official Flutter docs&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.flutter.dev/"&gt;Flutter Doc&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>future</category>
      <category>async</category>
      <category>await</category>
    </item>
    <item>
      <title>Week-1 into Machine Learning and my dopamine addiction.</title>
      <dc:creator>mustafa3252</dc:creator>
      <pubDate>Fri, 29 May 2020 19:13:22 +0000</pubDate>
      <link>https://dev.to/mustafa3252/week-1-into-machine-learning-and-my-dopamine-addiction-4da0</link>
      <guid>https://dev.to/mustafa3252/week-1-into-machine-learning-and-my-dopamine-addiction-4da0</guid>
      <description>&lt;p&gt;Hey influential developers! As I promised you, that every Friday, I'm going to upload a new blog, this just "Another" guy who wants to learn machine learning is back again, excited to tell more about my machine learning journey as well as an app I built with the help of Flutter. &lt;/p&gt;

&lt;p&gt;But there is also something else I wanna tell you. I'd like to express what I've felt this last week. I write these blogs here on Dev.to because I feel that we, The aspirants, the learner and the leaders of change are a family, and so writing something here will add value to our community.&lt;/p&gt;

&lt;p&gt;My city is been under complete lockdown since like three months now. I even had to celebrate my 18th birthday at home video calling my friends! These last couple of months have been terrible on my mental health. I felt like I was squandering my time and procrastinating! I had like a crush and I don't how I gathered the courage to message her! But I did! We continued texting for like two weeks and I found myself doing nothing but waiting for her reply all day. It was like I needed that dopamine shot every minute. Until I realised that going through this emotional turmoil is not worth it. I was feeling useless.&lt;/p&gt;

&lt;p&gt;But I have been trying to turn things around and I have found ways to be productive even during these tough times.&lt;/p&gt;

&lt;p&gt;I'll share with you how I was able to do it in the next blog because now, it's time for..... Machine Learning!!&lt;/p&gt;

&lt;p&gt;I've been able to do quite a lot of progress in my course. I've learned below mentioned things this week:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cost and Hypothesis function.&lt;/li&gt;
&lt;li&gt;Linear regression algorithm.&lt;/li&gt;
&lt;li&gt;Gradient descent.&lt;/li&gt;
&lt;li&gt;Matrices and vectors.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I know this doesn't seem too much but I would rather like to dive deep into the concepts, to take little more time with things and create a strong base than just trying to finish a course.&lt;/p&gt;

&lt;p&gt;Furthermore, this week I also made a quiz app and a personality tester app using Flutter. Flutter is a pretty neat framework. Everything in Flutter is a widget! I mean what else could a developer want! It also has awesome documentation on its site. I think I'll like to see what more Flutter has and so I'll also be learning Flutter side by side.&lt;/p&gt;

&lt;p&gt;For the next week, you'll have the following reasons to read my blog:&lt;/p&gt;

&lt;p&gt;In the coming week, I plan to make personal expenses manager app and also learn multivariable linear regression. Also, don't you all forget about the resources, tips and tricks I'll give you, which I used to overcome my dopamine addiction and procrastination. I'll also tell you if I was able to complete one of the goals on the goal chart, which is, read any four books by this Sunday.&lt;/p&gt;

&lt;p&gt;Please support me by liking my blogs and following me.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>flutter</category>
      <category>appdevelopment</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Journey Begins...</title>
      <dc:creator>mustafa3252</dc:creator>
      <pubDate>Thu, 21 May 2020 22:26:41 +0000</pubDate>
      <link>https://dev.to/mustafa3252/journey-begins-170j</link>
      <guid>https://dev.to/mustafa3252/journey-begins-170j</guid>
      <description>&lt;p&gt;Hi fellow programmers !! This is Mustafa. I am an 18 years old computer engineering student from India. Guys machine learning gets me excited, and when I saw videos of Code Bullet on Youtube, I knew I had to dig in and learn all about machine learning and AI. So recently I took a step towards my goal of becoming next Geoff Hinton and enrolled in Andrew Ng's class on Coursera.com. &lt;/p&gt;

&lt;p&gt;I've been introduced to terms like supervised, unsupervised, reinforcement learning and also recommender systems. So far, it seems exciting!!! By the end of the week, I'll make sure to be done with the second section which is linear algebra and linear regression with one variable. I don't how the journey ahead is going to be, but I think with this lovely community by my side, I won't ever be stopping when I get hit by a bump on this long road. &lt;/p&gt;

&lt;p&gt;So make sure to stick with this "Another" guy who wants to jump in machine learning's journey. And who knows one day you might be able to say that I followed Mustafa's blogs when no one else did and I soo am proud of him for what he's doing! Ahh, just kidding.&lt;/p&gt;

&lt;p&gt;Wait for the blog that's going come next Friday. Signing off, this was Mustafa( Just "Another" guy who wants to learn machine learning.)&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
