<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Atharva Patwardhan on Medium]]></title>
        <description><![CDATA[Stories by Atharva Patwardhan on Medium]]></description>
        <link>https://medium.com/@codesadhu?source=rss-1a1619704de9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*I-D5Y_Ba95HZJuVgGmjhrw.jpeg</url>
            <title>Stories by Atharva Patwardhan on Medium</title>
            <link>https://medium.com/@codesadhu?source=rss-1a1619704de9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 11 Jun 2026 08:12:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@codesadhu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Dart Extensions: Improve code readability]]></title>
            <link>https://codesadhu.medium.com/dart-extensions-improve-code-readability-3d89a73103b3?source=rss-1a1619704de9------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d89a73103b3</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter-community]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart-extension]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Atharva Patwardhan]]></dc:creator>
            <pubDate>Tue, 21 Nov 2023 17:25:05 GMT</pubDate>
            <atom:updated>2023-11-21T18:11:21.528Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Thumbnail image for the article" src="https://cdn-images-1.medium.com/max/1024/1*Ezzpq1TP_SJk_j9aVTYMjA.png" /></figure><p>So, let’s say you’re writing an app using <em>Flutter</em> and you need to develop a widget that takes up 40% of the total screen width. What solution comes to mind? If you thought immediately about using <strong><em>MediaQuery</em></strong>, bravo; go get yourself a soda!</p><p>So now you use the <strong><em>MediaQuery</em></strong> class to fetch the size of the screen.</p><pre>Size size = MediaQuery.of(context).size;<br>double screenWidth = size.width;</pre><p>Now, if you’re a dev who’s been working with <em>Flutter</em> for a while, you’ll know that this is a quite frequent operation. I have seen projects where almost every widget file has these two lines in the build method, in one way or another.</p><p>But it gets tedious to copy and paste these lines in every single dart file, right? What if there was a way to do this in a simpler way; a way that’s more readable and easier to use along with that sick autocomplete you got going in your <em>VSCode</em> (<em>Android Studio</em> users don’t hate me).</p><p>Turns out, there actually is! After all, you read the title before clicking on this blog, didn’t you? 😉</p><h3>How To: Use Extensions optimally</h3><p>Let’s refer to the example snippet we saw earlier above. The same can be achieved using an extension on the class <strong><em>BuildContext</em></strong> like this:</p><pre>extension ContextExtensions on BuildContext {<br>  Size get screenSize =&gt; MediaQuery.of(this).size;<br>}</pre><p>So next time you want to get the screen size using <strong><em>MediaQuery</em></strong>, you can just do this:</p><pre>@override<br>Widget build(BuildContext context) {<br>  Size screenSize = context.screenSize;<br>  <br>  return Container(<br>    height: screenSize.height * 0.9,<br>    width: screenSize.width,<br>  );<br>}</pre><p>Easy, right? Now, to conclude, I would like to offer a bit of friendly advice. Just because extensions methods exist, doesn’t mean you have to spam and use it every time every where. What do I mean? Let me elaborate.</p><p>Here’s another example of when you <strong><em>SHOULD</em></strong> use extensions.</p><pre>// Without Extension<br>String capitalize(String input) {<br>  return input.isEmpty ? &#39;&#39; : input[0].toUpperCase() + input.substring(1);<br>}<br><br>// With Extension<br>extension StringCapitalization on String {<br>  String capitalize() {<br>    return isEmpty ? &#39;&#39; : this[0].toUpperCase() + substring(1);<br>  }<br>}</pre><p>And here’s an example of when you <strong><em>SHOULD NOT</em></strong> be using extensions.</p><pre>// Without Extension<br>class Circle {<br>  double radius;<br><br>  Circle(this.radius);<br><br>  double calculateArea() {<br>    return 3.14 * radius * radius;<br>  }<br>}<br><br>// With Extension (unnecessary in this case)<br>extension CircleAreaCalculation on Circle {<br>  double calculateArea() {<br>    return 3.14 * radius * radius;<br>  }<br>}</pre><p><em>Dart</em> <em>extensions</em> are a powerful feature, but they are not always necessary, and using them when simpler alternatives are available might lead to code complexity, which will be ironical (LOL) because the very reason you turned to extensions was to save precious time and avoid tedious effort.</p><p>And… that’s it. You now bear the power of Dart extensions! Go build great apps!</p><p>Until next time.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FiIiSLPvuxZROdBsCPE%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FiIiSLPvuxZROdBsCPE%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FiIiSLPvuxZROdBsCPE%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="243" frameborder="0" scrolling="no"><a href="https://medium.com/media/850ffee0f8e9ae0b97a135aaa924b97e/href">https://medium.com/media/850ffee0f8e9ae0b97a135aaa924b97e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d89a73103b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Websockets — What are those and how to use them in Flutter?]]></title>
            <link>https://codesadhu.medium.com/websockets-what-are-those-and-how-to-use-them-in-flutter-4e049f1d1075?source=rss-1a1619704de9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e049f1d1075</guid>
            <category><![CDATA[flutter-websocket]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <dc:creator><![CDATA[Atharva Patwardhan]]></dc:creator>
            <pubDate>Wed, 10 May 2023 06:51:50 GMT</pubDate>
            <atom:updated>2023-05-10T06:51:50.684Z</atom:updated>
            <content:encoded><![CDATA[<h3>Websockets — What are those and how to use them in Flutter?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gyBRfCNneiO8BdokY1HkEQ.png" /></figure><p>If you’re someone who’s been developing mobile apps for a while, you’ve probably used <strong><em>REST APIs</em></strong> for fetching/storing data on a remote server somewhere. These APIs use something that we in the tech biz call <strong><em>HTTP</em></strong> <strong><em>protocols</em></strong>, so the calls that we make to these APIs are often called as <strong><em>HTTP</em></strong> requests.</p><p>Why are we talking about <strong><em>HTTP</em></strong> requests in an article about <strong><em>Websockets?</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*XTNXfdMR_PzZzJ1_ymVCLg.gif" /></figure><blockquote>“Before one learns something, one must learn WHY it exists in the first place.” — Unknown</blockquote><h3>Why do we need websockets?</h3><p>As it turns out, HTTP requests are uni-directional or one-way requests. That means, once an HTTP request is sent, the sender needs to wait for a response from the receiver. This sounds perfectly fine, but now imagine using this in a chat application. Two devices chatting with each other would have to constantly keep making HTTP requests to keep track of each other’s messages. This is not just tedious but also a costly operation to perform.</p><p>Does this mean HTTP cannot be used for messaging apps? No. Take Gmail, or any other email service for instance. The sender of the email simply needs to send an email, without the need of an immediate reply from the receiver. HTTP is more than sufficient enough to be applied in this case.</p><p>Coming back to the chat application case, it is quite clear that HTTP isn’t the best option to go through. We would need to use a protocol that can pass information both ways, in realtime.</p><p>Enter, the websocket. <strong><em>WebSocket</em></strong> is a communications protocol for a persistent, bi-directional, full duplex TCP connection from a client to a server.</p><h3>How a Websocket works</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*FCJtotI8iJrvtaxwLo2cUw.jpeg" /></figure><p>A WebSocket connection is initiated by sending a WebSocket handshake request from a browser’s HTTP connection to a server to upgrade the connection. From that point, the connection is binary and does not conform to the HTTP protocol. A server application is aware of all WebSocket connections and can communicate with each one individually.</p><p>As WebSocket remains open, either the server or the client can send messages at any time until one of them closes the session. The communication can be initiated at either end, which makes event-driven programming possible.</p><h3>Common applications of websockets</h3><p>You’d be surprised to learn how many things we use on a daily basis harness the power of websockets. Some of them are:</p><ul><li>Realtime Chatting apps <em>(duh) </em>eg. WhatsApp, Messenger, Telegram, etc</li><li>Multiplayer games eg. Valorant, CS:GO, Apex Legends, PUBG, etc</li><li>Collaborative apps eg. Figma, Google Docs</li><li>Audio/Video Chats eg. Skype, Google Meet</li><li>Realtime location apps eg. Google Maps, Apple Maps</li></ul><p>You get the point. Without websockets, most of us wouldn’t be living the same convenient lives we are living right now.</p><h3>Fun Fact</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*E-PFCwl2nxtonSiE4RvNsQ.png" /><figcaption>Common issues faced by players with bad internet connection</figcaption></figure><p>If you’re someone who plays online multiplayer games, you must’ve faced Ping issues at least once. This <strong><em>“Ping”</em></strong>, is a term used in the ping-pong method to ensure that the websocket is connected to the server. The approach goes something like this:</p><ol><li>The client sends a “ping” type of message with some dummy data to the server</li><li>The server receives this “ping” and simply returns the same dummy data back to the client with a “pong” type of message</li><li>The client receives this “pong” and thus acknowledges that the connection is active</li></ol><p>The total roundabout time taken to receive the response from the server is denoted to us as the <strong><em>“Ping”.</em></strong> Another word used to describe this process is <strong><em>“Latency”</em></strong> and the lesser the number, the better it results in performance.</p><h3>Implementation in Flutter</h3><p>Alright. So we have a pretty good idea of what a websocket is used for. Let’s move on to implementing a basic socket in Flutter.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F8sQo2c9NwHkvNoIMcJ%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F8sQo2c9NwHkvNoIMcJ%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F8sQo2c9NwHkvNoIMcJ%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/4385faa5e3d04260bb776e2169b57d14/href">https://medium.com/media/4385faa5e3d04260bb776e2169b57d14/href</a></iframe><h4>1. Install the package</h4><p>For implementation of websockets in our Flutter app, we’ll be using the package <a href="https://pub.dev/packages/web_socket_channel"><strong><em>web_socket_channel</em></strong></a><strong><em>.</em></strong></p><h4>2. Basic implementation</h4><pre>import &#39;package:web_socket_channel/io.dart&#39;;<br><br>class WebsocketService {<br>  static final WebsocketService _webSocketService =<br>      WebsocketService._internal();<br>  factory WebsocketService() {<br>    return _webSocketService;<br>  }<br>  WebsocketService._internal();<br><br>  IOWebSocketChannel? channel;<br>  // DUMMY URL; DO NOT TRY TO IMPLEMENT<br>  String websocketUrl = &#39;ws://test.example.com?token=eySjks7sadjklwaskfjtAw8sS&#39;;<br><br>  void init() {<br>    // INITIATE A CONNECTION THROUGH AN IOWebsocketChannel channel<br>    channel = IOWebSocketChannel.connect(websocketUrl);<br>    if (channel != null) {<br>      // IF CHANNEL IS INITIALIZED AND WEBSOCKET IS CONNECTED<br>      // LISTEN TO WEBSOCKET EVENTS<br>      channel!.stream.listen(_eventListener).onDone(_reconnect);<br>    }<br>  }<br><br>  void transmit(dynamic data) {<br>    // THIS METHOD CAN BE CALLED ANYWHERE THROUGHOUT THE APP<br>    // AND CAN BE USED TO SEND DATA FROM THE CLIENT TO THE SERVER<br>    // VIA THE WEBSOCKET<br>    if (channel != null) {<br>      channel!.sink.add(data);<br>    }<br>  }<br><br>  void _eventListener(dynamic event) {<br>    if (event == &#39;message&#39;) {<br>      // PERFORM OPERATIONS ON THE EVENT PAYLOAD<br>    }<br>  }<br><br>  void _reconnect() {<br>    // IF CONTROL HAS TRANSFERRED TO THIS FUNCTION, IT MEANS<br>    // THAT THE WEBSOCKET HAS DISCONNECTED.<br>    if (channel != null) {<br>      // CLOSE THE PREVIOUS WEBSOCKET CHANNEL AND ATTEMPT A RECONNECTION<br>      channel!.sink.close();<br>      init();<br>    }<br>  }<br>}</pre><p>Let’s go through this code step-by-step.</p><pre>static final WebsocketService _webSocketService = WebsocketService._internal();<br>factory WebsocketService() {<br>  return _webSocketService;<br>}<br>WebsocketService._internal();<br><br>IOWebSocketChannel? channel;<br>// DUMMY URL; DO NOT TRY TO IMPLEMENT<br>String websocketUrl = &#39;ws://test.example.com?token=eySjks7sadjklwaskfjtAw8sS&#39;;</pre><p>First, we create a websocket service using the singleton pattern (i.e. only one instance of the service can be created throughout the app). Read more about <strong><em>Singletons</em></strong> <a href="https://medium.flutterdevs.com/singletons-in-flutter-f232865fdcb3#:~:text=Singleton%20is%20a%20creational%20design%20pattern%20that%20guarantees%20that%20a,application%20into%20a%20weird%20state.">here</a>.</p><p>We’ll be using the <strong><em>IOWebsocketChannel</em></strong> class to initialize our websocket channel through which our data will be passed.</p><p>The websocketUrl stores the endpoint of our websocket, quite similar to the url endpoint we use in HTTP requests. For this example, I’ve used a dummy url.</p><p><strong>TLDR</strong>: Don’t use the dummy url, it won’t work</p><pre>void init() {<br>    // INITIATE A CONNECTION THROUGH AN IOWebsocketChannel channel<br>    channel = IOWebSocketChannel.connect(websocketUrl);<br>    if (channel != null) {<br>      // IF CHANNEL IS INITIALIZED AND WEBSOCKET IS CONNECTED<br>      // LISTEN TO WEBSOCKET EVENTS<br>      channel!.stream.listen(_eventListener).onDone(_reconnect);<br>    }<br>  }</pre><p>Then, inside the <em>init()</em> method, we’ll initialize our websocket channel by passing our websocket url endpoint to the <em>connect() </em>method.</p><p>After the websocket is initialized, we can start listening to the events emitted inside the websocket. Since all events coming from the websocket server are emitted inside a stream, we’ll be using <em>channel.stream.listen()</em> method to listen to these events.</p><pre>void _eventListener(dynamic event) {<br>  if (event == &#39;message&#39;) {<br>    // PERFORM OPERATIONS ON THE EVENT PAYLOAD<br>  }<br>}</pre><p>We create a method <em>_eventListener()</em> and pass this to the <em>channel.stream.listen()</em> method. By doing so, all events can be caught inside the <em>_eventListener().</em> These events are generally received in the form of JSON objects, so it’s quite easy to parse the data and perform operations on it like one would using HTTP GET requests.</p><pre>void transmit(dynamic data) {<br>  // THIS METHOD CAN BE CALLED ANYWHERE THROUGHOUT THE APP<br>  // AND CAN BE USED TO SEND DATA FROM THE CLIENT TO THE SERVER<br>  // VIA THE WEBSOCKET<br>  if (channel != null) {<br>    channel!.sink.add(data);<br>  }<br>}</pre><p>Cool, we’ll be able to receive data from the websocket, but what about sending data to the server via the websocket? For this, we created another method <em>transmit(). </em>Similar to how data is <strong><em>received</em></strong> via a <strong><em>stream</em></strong>, data can be <strong><em>sent</em></strong> via a <strong><em>sink, </em></strong>and so, adding data to the sink is all that this method does. This method is better kept public instead of private, since we might need to send data from anywhere inside the app.</p><pre>void _reconnect() {<br>  // IF CONTROL HAS TRANSFERRED TO THIS FUNCTION, IT MEANS<br>  // THAT THE WEBSOCKET HAS DISCONNECTED.<br>  if (channel != null) {<br>    // CLOSE THE PREVIOUS WEBSOCKET CHANNEL AND ATTEMPT A RECONNECTION<br>    channel!.sink.close();<br>    init();<br>  }<br>}</pre><p>Now, if the websocket disconnects suddenly due to some network problems, we attempt a reconnection by using the <em>_reconnect()</em> method. We close the previous connection using <em>channel.sink.close()</em> and call the <em>init()</em> method to re-initialize our websocket connection.</p><p>Lastly, we need to call the <em>init()</em> method somewhere for the service to be initialized in the first place. Generally speaking, most websockets require a kind of token or a key to be passed inside the url endpoint. In case of your app, you’ll just have to decide which is the best place to initialize your websocket. It has to be some point in the app where you have the token/key that’s required in the url. Once you’re there, just add this one line and you are good to go.</p><pre>WebsocketService().init();</pre><p>And, that’s it! This is pretty much all you need to get a websocket connection up and running inside your app.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl0MYt5jPR6QX5pnqM%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl0MYt5jPR6QX5pnqM%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExenBsaHprdnU1eGFjOXUyMXA3Z2dnN3pmdXQwMHRtbW5yenZpc3hiaSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2Fl0MYt5jPR6QX5pnqM%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/726109d2528153d5ccce41d66f0cb726/href">https://medium.com/media/726109d2528153d5ccce41d66f0cb726/href</a></iframe><p>Kudos! You now possess the knowledge of the websocket. Please comment below your suggestions/feedback and share this article if you found it useful. Claps are always appreciated 🥹</p><p>Until next time.</p><p>Adios.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e049f1d1075" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Provider — The easiest state management approach one could ask for]]></title>
            <link>https://codesadhu.medium.com/flutter-provider-the-easiest-state-management-approach-one-could-ask-for-7575d20f9e6?source=rss-1a1619704de9------2</link>
            <guid isPermaLink="false">https://medium.com/p/7575d20f9e6</guid>
            <category><![CDATA[flutter-state-management]]></category>
            <category><![CDATA[flutter-provider]]></category>
            <category><![CDATA[mobile-app-dev]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Atharva Patwardhan]]></dc:creator>
            <pubDate>Fri, 05 May 2023 14:17:54 GMT</pubDate>
            <atom:updated>2023-05-05T14:27:58.230Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter Provider — The easiest state management approach one could ask for</h3><p>When it comes to building apps using Flutter, creating responsive and beautiful User Interfaces is not all there is. Animations, data flow and state management are core parts that cannot be ignored.</p><p>In this article, we’ll take a look at the state management approach recommended by Flutter itself — <a href="https://pub.dev/packages/provider">Provider</a>.</p><h3>State management — What exactly is it?</h3><p>Everything is a widget in Flutter. So what is a widget? It could be said that a widget is a component. It could be as simple as a Text widget that shows text, or it could be a button that triggers a function when tapped on it. Or it could be an entire screen that holds multiple children widgets under it.</p><p>For the sake of answering the question at hand, we’ll consider the last example. Let’s say we have a screen like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QwADziS2NKWekRzdTx58bw.png" /><figcaption>Banking App UI — <a href="https://dribbble.com/shots/21343217-Mobile-Banking-App">https://dribbble.com/shots/21343217-Mobile-Banking-App</a></figcaption></figure><p>In the above image, the entire screen can be a parent widget that contains multiple child widgets like the Text widget to display the total balance, the Switch widget to toggle between Send and Receive modes, etc.</p><p>The “Total Balance” value might change in the Future, so if it does change its value, how will it reflect and update in the screen? The parent widget cannot magically know that the Text value has changed unless it is informed that such a change has happened. This is precisely where “State” comes in. If we can provide a state to this widget, it can then maintain the current value and track any changes made to it.</p><p>Flutter provides a way to do exactly this — using a Stateful Widget. When we use a Stateful Widget, all the variables we declare inside its “State” can be updated and reflected on the UI by calling the <strong><em>setState()</em> </strong>method. When the <strong><em>setState()</em></strong> method is called, the widget is rebuilt with the values of the state variables.</p><p>Perfect! Sounds like a charm! So what’s the issue with this? Why do we need something like provider at all?</p><p>The thing is, when <strong><em>setState()</em></strong> is called, the entire widget and all the corresponding children widgets are rebuilt. Apart from the very fact that this is a heavy operation, it’s also unnecessary. If only the value of the Text widget has changed, it makes no sense to be rebuilding the entire <strong>Widget Tree</strong> again. It would instead be much better if there was a way to just update the state of the Text widget, no?</p><p>Well, one way to tackle this is to extract the Text widget into a separate widget all by itself and then set its independent state whenever we need to. But how do we do this? Even if we extract the Text widget out into a reusable Stateful widget, how do we manipulate its state from outside the widget itself? We would have to use an <strong>InheritedWidget</strong> implementation to lift the state outside the widget and make it accessible outside. Turns out, this implementation is actually quite tedious to implement.</p><h3>Why Provider?</h3><p>Enter, provider. The provider approach does exactly this. As per its official <a href="https://pub.dev/packages/provider">documentation</a>, it is a wrapper around an <strong>InheritedWidget </strong>implementation. Using provider, we can modify the values of a widget without having to rebuild the entire <strong>Widget Tree</strong>.</p><h3>Implementing the Provider approach:</h3><p>Great! So now we know that the Provider approach can solve the issue at hand. Let’s get to know more about what goes in implementing the provider.</p><p>First off, we need to decide what exactly the provide<strong>r</strong> is going to provide and to what widget(s). For simplicity, we’ll keep the value for the text widget in our provider, i.e. the value for total balance.</p><p>Now that we’ve decided what value is to be stored, we need to create a class that extends <strong>ChangeNotifier</strong>. This is absolutely essential for implementing provider since this <strong>ChangeNotifier</strong> will broadcast the values wherever we need them. Here’s what an implementation of the provider class will look like:</p><blockquote><em>bank_screen_provider.dart</em></blockquote><pre>import &#39;package:flutter/material.dart&#39;;<br><br>class BankScreenProvider extends ChangeNotifier {<br>  String _balance = &#39;&#39;;<br>  String get totalBalance =&gt; _balance;<br><br>  void setBalance(String balance) {<br>    _balance = balance;<br>    notifyListeners();<br>  }<br>}</pre><p>In the above code, <strong>BankScreenProvider</strong> which extends the <strong>ChangeNotifier</strong> is our provider class which will act as a central repository for storing data and performing operations on it. The method <strong><em>setBalance()</em></strong> is used to assign value to the variable we’ve created to map the total balance.</p><p>You must have noticed that the function is not returning a value. How then, you might ask, will the value be read outside the class? For exactly that purpose, we’ve created the getter <strong>totalBalance. </strong>Using this getter, we can keep our actual variable (<strong>_balance) </strong>private and safe and still expose its value wherever needed. This is mostly done to prevent modification of these values from outside the class.</p><p>Finally, the last major thing to notice is that the function is calling the <strong><em>notifyListeners()</em></strong> method. Calling this method broadcasts a notification that the values inside the <strong>BankScreenProvider</strong> has changed.</p><p>Now, how do we consume this value from the <strong>BankScreenProvider</strong>? For that, we need to wrap the relevant widget(s) with a <strong>Consumer</strong> widget. The <strong>Consumer</strong> comes along with the provider package and it listens for notifications from the type of Provider we pass to it.</p><blockquote>bank_screen.dart</blockquote><pre>Consumer&lt;BankScreenProvider&gt;(<br>  builder: (context, provider, child) {<br>    String balance = provider.totalBalance;<br>    return Text(balance);<br>  },<br>);</pre><p>As can be seen in above code, we need to give our <strong>Consumer</strong> a type of our provider (<strong>BankScreenProvider</strong> in this case). If we do not do this, we won’t be able to access the data inside our provider. Then, the builder parameter of the <strong>Consumer</strong> widget requires three parameters:</p><p><em>context</em>: An instance of <strong>BuildContext</strong> which is accessible in every build method</p><p><em>provider</em>: An instance of the provider we’re using (<strong>BankScreenProvider </strong>in this case)</p><p><em>child</em>: A widget instance that we don’t really need for our use case</p><p>Now that we have our <strong>Consumer </strong>in place, you might ask how do we update the widget inside it whenever we want to? Remember earlier in our provider, we called a function<em> </em><strong><em>notifyListeners()</em> </strong>whenever we make changes to our data? This is precisely what it’s for. Whenever <strong><em>notifyListeners()</em></strong> is called, it sends a notification to all Consumers listening to that provider, telling them to rebuild the widget(s) inside them.</p><h4>The Final Step</h4><p>Great! So now we got a <strong>Consumer </strong>to consume our provider values and a Provider class to supply these values. All that’s left is one last step — Setting the provider scope. Whenever we write a provider, we also need to tell flutter the scope of this provider for it to understand how far up the widget tree the states need to be lifted. This is a crucial step and if missed, will result in an Exception. Go to your <em>main.dart </em>file and wrap your root app widget with a <strong>ChangeNotifierProvider</strong> widget like this:</p><blockquote>main.dart</blockquote><pre>import &#39;package:provider/provider.dart&#39;;<br><br>void main(){<br>  runApp(<br>    ChangeNotifierProvider(<br>      create: (context) =&gt; BankScreenProvider(),<br>      child: MyApp(),<br>    ),<br>  );<br>}</pre><p>In the future, you might need to add multiple provider scopes for different screens. In that case, you’ll just need to convert this <strong>ChangeNotifierProvider</strong> widget to a <strong>MultiProvider</strong> widget and pass it a list of all providers you want to be scoped, like this:</p><pre>import &#39;package:provider/provider.dart&#39;;<br><br>void main(){<br>  runApp(<br>    MultiProvider(<br>      providers: [<br>        ChangeNotifierProvider(<br>          create: (context) =&gt; BankScreenProvider(),<br>          child: MyApp(),<br>        ),<br>        ChangeNotifierProvider(<br>          create: (context) =&gt; HomeScreenProvider(),<br>          child: MyApp(),<br>        ),<br>      ],<br>      child: MyApp(),<br>    ),<br>  );<br>}</pre><p>You might ask — “By placing the <strong>ChangeNotifierProvider</strong> on top of the root widget, aren’t we polluting the scope of the provider?” Yes we are. What we are doing right now will allow the entire app to access values from <strong>BankScreenProvider</strong> and listen to its events. But, it’s not necessary that the provider data will be required in every single screen. So it is usually better to wrap a widget (with <strong>ChangeNotifierProvider</strong>) two steps above the subject widget in the widget tree.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FBQAk13taTaKYw%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FBQAk13taTaKYw%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FBQAk13taTaKYw%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="234" frameborder="0" scrolling="no"><a href="https://medium.com/media/82e2882e6b7f8005d1376224ecf559ec/href">https://medium.com/media/82e2882e6b7f8005d1376224ecf559ec/href</a></iframe><p>Alright, with that, you’ve officially learnt how to use the provider state management approach in Flutter! Adios till the next time! If you feel this article was helpful, please share it. Claps are always appreciated as well :)</p><p>Adios!</p><p>Credits (UI Screen Ref): <a href="https://dribbble.com/shots/21343217-Mobile-Banking-App">https://dribbble.com/shots/21343217-Mobile-Banking-App</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7575d20f9e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get a Microsoft Certification for free (Limited time)]]></title>
            <link>https://codesadhu.medium.com/get-a-microsoft-certification-for-free-limited-time-2d36ffa027b0?source=rss-1a1619704de9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d36ffa027b0</guid>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[free-certification]]></category>
            <category><![CDATA[microsoft-ignite]]></category>
            <category><![CDATA[microsoft-certification]]></category>
            <category><![CDATA[microsoft-exams]]></category>
            <dc:creator><![CDATA[Atharva Patwardhan]]></dc:creator>
            <pubDate>Wed, 23 Sep 2020 14:42:27 GMT</pubDate>
            <atom:updated>2020-09-23T14:42:27.929Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone! I hope you’re doing well and staying safe. This article is going to walk you through how you can get Microsoft Certified for free. I’ll try to keep this article short and to the point.</p><p>Microsoft is a huge name. If you’re reading this, you already know why. Getting Microsoft Certified is a huge thing and it shows that you are of an exploratory nature and venture into extra-curricular stuff. It might not necessarily guarantee a job, but it certainly shows you’re curious.</p><h3>What is this Certification?</h3><p>Microsoft provides certifications on a wide range of topics. Some of these topics are <strong>Python, Java, JavaScript</strong> and also Microsoft technologies like <strong>Azure, PowerApps, Dynamics 365</strong>, etc.</p><p>You can choose whichever topic/technology you feel appearing for and prepare for it accordingly. When you’re ready, you give the exam for that specific topic and if you pass, voila; you get the certificate.</p><h3>How do I get this free offer!?</h3><p>Every year, Microsoft conducts two major events —<strong> Microsoft Build </strong>and <strong>Microsoft Ignite</strong>. Microsoft Ignite is <strong>currently active </strong>(as of 23rd September 2020). You can <strong>participate </strong>in the <strong>Cloud Skills Challenge </strong>here and complete the challenge <strong>before October 7th 2020</strong>. If you do, you get a free Microsoft certification voucher.</p><p><strong><em>Important: You get the voucher through which you can appear for an exam. You don’t get the certificate directly.</em></strong></p><h3>What do I have to do?</h3><p>You just have to complete all <strong>Microsoft Learn</strong> modules listed under the challenge before the deadline. That’s it. A really cool reward for learning right!? Win — Win!</p><h3>Stepwise Guide:</h3><ol><li>Head over to <a href="http://myignite.microsoft.com"><strong>myignite.microsoft.com</strong></a><strong> </strong>and in the top navigation, click on <strong>Connection Zone</strong> and choose <strong>Learning Zone</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GLhOwaKGap2gczrDLJKN-Q.jpeg" /></figure><p>You should be able to see the <strong>Cloud Skills Challenge</strong> card over there. Hit <strong>Sign Up.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8jVI1Hyj0_vSuDd-k4d2mA.jpeg" /></figure><p>This will redirect you to the Ignite Cloud Skills Challenge Page. Scroll down to see available challenges and select whichever challenge you feel most interested about (or challenged about ;P) and click on <strong>Go to Challenge.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3yi0lYayBe6n_KDhBLGraQ.png" /></figure><p>You’ll see a countdown timer now. Click on <strong>Join the challenge</strong> to start learning. Just make sure to complete the modules before the countdown ends and hopefully you should receive your voucher!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A0UN8f_kqogaky1VsPaH5Q.jpeg" /></figure><p>Thanks for reading this article! Give a clap if it helped you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d36ffa027b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Golang and How do we Install it]]></title>
            <link>https://codesadhu.medium.com/what-is-golang-and-how-do-we-install-it-bea9f4a66bcc?source=rss-1a1619704de9------2</link>
            <guid isPermaLink="false">https://medium.com/p/bea9f4a66bcc</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang-install]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <dc:creator><![CDATA[Atharva Patwardhan]]></dc:creator>
            <pubDate>Thu, 14 Nov 2019 17:21:44 GMT</pubDate>
            <atom:updated>2019-11-14T17:21:44.513Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Golang </em></strong>is basically how the language <strong><em>C </em></strong>would be if it (<strong><em>C</em></strong>)<strong><em> </em></strong>was written in <strong><em>Python</em></strong>.</p><p>If that confused you, don’t worry. Just hang on till we get to the interesting stuff.</p><p><em>Note:- I am going to use the terms “</em><strong>Golang</strong><em>” and “</em><strong><em>Go</em></strong><em>” alternatively further down this article. They both essentially mean the same.</em></p><h3>What is Golang</h3><p><strong><em>Golang </em></strong>is a programming language that is (like most languages) statically typed and compiled language. What does this mean? This means that unlike interpreted languages like <strong><em>Python </em></strong>(which uses line by line execution via the interpreter), <strong><em>Golang </em></strong>programs are written and compiled as a whole to be able to run them.</p><p>If you have prior experience with programming in <strong><em>Python </em></strong>or <strong><em>Java</em></strong>, you’ll know that both <strong><em>Python </em></strong>and <strong><em>Java </em></strong>are not compiled and executed as whole. <strong><em>Java </em></strong>generates a <strong><em>byte-code </em></strong>and in order to run this bytecode, you need something called as the <strong><em>Java Virtual Machine</em></strong> (included in the <strong><em>Java Development Kit</em></strong>). On the other hand, <strong><em>Python </em></strong>isn’t compiled in the classical sense, it is interpreted (by the <strong><em>Python </em></strong>interpreter). This means that <strong><em>Python </em></strong>code is executed line by line, and even though this proves to be fast most of the times, compiled code is faster, because it is basically binary (which is the easiest for computers to understand).</p><h3><strong>Why Golang</strong></h3><p>For one, it is easy to learn as compared to <strong><em>Java</em></strong>. <a href="http://jetbrains.com"><strong><em>Jetbrains</em></strong></a><strong><em> </em></strong>conducted a <a href="https://www.jetbrains.com/lp/devecosystem-2019/">survey</a> among 7000 developers recently which led to the following result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LU0lMqmpdq7g1EGRqdn2TA.png" /></figure><p>As you can see above, <strong><em>Go</em></strong> has been called <strong><em>“The most promising programming language”</em></strong>. This is because it has a small set of features which can be used in a lot of ways.</p><p>If this doesn’t make sense to you, let’s consider a realistic analogy — The <strong><em>USB</em></strong>. The <strong><em>USB</em></strong> is an interface that is extremely simple, yet its applications are limitless. It is literally <strong>EVERYWHERE!</strong></p><p>There is also a lot of talk being going on about how <strong><em>Go </em></strong>will be the <strong><em>“future language for the Web”</em></strong>. The statistics project the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4pACI61Qcw-eJKvfJb1jxg.png" /></figure><h3>Golang Installation</h3><p>Alright. Enough chit-chat, now let’s get to work.</p><p>Installing <strong><em>Golang </em></strong>to your machine is relatively easy, but it depends on the Operating System you’re using. Don’t worry if you’re a beginner. This is a step-by-step installation guide, so I’ll be covering all aspects of the installation (including install verification).</p><p>Regardless of the OS you are using, you’ll need to go the official <strong><em>Golang </em></strong>download page to download your OS compatible <strong><em>Golang </em></strong>package.</p><p><a href="https://golang.org/dl/"><strong><em>Download Here</em></strong></a></p><p>You’ll face a screen like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D9bEiZ2VQg63Wc8Yr2_OZg.png" /></figure><p>Under the section “<strong><em>Featured Downloads</em></strong><em>”</em>, select the package compatible to your Operating System.</p><h3>For Windows</h3><figure><img alt="Microsoft Windows Logo" src="https://cdn-images-1.medium.com/max/256/1*Q8akyHPI_6qdalTr4PXQJg.png" /></figure><p><strong><em>Step 1: </em></strong><em>Run the downloaded package.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*4QiKzNx0KG-g78PVAruDEQ.jpeg" /></figure><p><strong><em>Step 2:</em></strong><em> Keep clicking Next till you see a screen specifying the </em><strong><em>“Destination Folder”.</em></strong></p><p><em>Here, you can choose the directory/folder in your computer where you want </em><strong><em>Go </em></strong><em>to be installed.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*uOHBsWaqYxn0VLhsVlbKRg.png" /></figure><p><strong><em>Step 3:</em></strong> <em>Once this is done, click </em><strong><em>Next </em></strong><em>till the installation starts. After </em><strong><em>Go </em></strong><em>has been installed, click on the </em><strong><em>Finish </em></strong><em>button.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*bTDACEU2zYLD0_5kWeLi3Q.jpeg" /></figure><p>To check if Go has been installed successfully, just pull up your command line or cmd and type in the command <strong>go version</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*0z3uJiuovGetjW4Fpu-17w.png" /></figure><h3>For Linux</h3><p>I do not own a Linux machine myself, so I will link some good installation guides (ones with screenshots/commands attached) so you don’t have to stress on the OS availability.</p><p><a href="https://golang.org/doc/install">Golang Official Documentation</a></p><p><a href="https://www.tecmint.com/install-go-in-linux/">Techmint</a></p><h3>For MacOS</h3><p>Again, I do not own a MacOS/Apple machine myself, so I will link some good installation guides.</p><p><a href="https://golang.org/doc/install">Golang Official Documentation</a></p><p><a href="https://medium.com/golang-learn/quick-go-setup-guide-on-mac-os-x-956b327222b8">Medium</a></p><h3>Baby Steps</h3><p>That’s it! <strong><em>Go</em></strong> is now successfully installed on your computer! Here are some resources to learn <strong><em>Go</em></strong>:</p><p><a href="https://www.youtube.com/watch?v=SqrbIlUwR0U">Traversy Media</a></p><p><a href="https://www.youtube.com/watch?v=ty49_v1tV44">Telusko</a></p><p>You can refer any other tutorial you feel comfortable with, but I posted these two because I personally found them comfortable for beginners.</p><p>To get started on with <strong><em>Go</em></strong>, open any text/code editor you feel comfortable with, I recommend <a href="https://www.sublimetext.com/"><strong><em>Sublime Text</em></strong></a> if you’re a beginner.</p><p>Open Sublime Text and type the code as shown in the image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*Pjr7_QvKme9YZdHUU8zFUg.png" /></figure><p><strong><em>Note:</em></strong> <strong><em>“fmt”</em></strong> <em>stands for</em> <strong><em>“format”</em></strong></p><p>Save the file on your Desktop with the filename <strong><em>helloWorld.go </em></strong>or any other filename you like. Just make sure to save it with the extension <strong>“<em>.go”.</em></strong></p><p>Open your command line or cmd and navigate to your Desktop</p><p>Enter the command: <strong><em>go run helloWorld.go</em></strong></p><p>The output should appear on your screen as shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*d4nzYZSD4_Y6On9b3LBwyQ.png" /></figure><p>Do not panic if it takes a while for the output to be displayed. It’s completely normal.</p><p>Hooray! You’ve written your first few lines of <strong><em>Golang</em></strong> code! Take up the tutorials mentioned above to advance through the basics of <strong><em>Golang</em></strong>.</p><p>Hope this article helped somewhat informing you about the revolutionary <strong>Golang</strong>! Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bea9f4a66bcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>