<?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 Naveed Ullah on Medium]]></title>
        <description><![CDATA[Stories by Naveed Ullah on Medium]]></description>
        <link>https://medium.com/@naveedullah?source=rss-f09b7fecc985------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*WOmbsZCpVbFabyqz</url>
            <title>Stories by Naveed Ullah on Medium</title>
            <link>https://medium.com/@naveedullah?source=rss-f09b7fecc985------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:49:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@naveedullah/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[Exploring Beyond Flutter: Why Flutter Alone Might Not Be Enough]]></title>
            <link>https://naveedullah.medium.com/exploring-beyond-flutter-why-flutter-alone-might-not-be-enough-9c22c7a9efd1?source=rss-f09b7fecc985------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c22c7a9efd1</guid>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[mobile-apps]]></category>
            <dc:creator><![CDATA[Naveed Ullah]]></dc:creator>
            <pubDate>Mon, 08 Jan 2024 07:37:09 GMT</pubDate>
            <atom:updated>2024-01-08T07:37:09.765Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*10RECXGTH5NyaeBg5yD1pw.png" /></figure><p>In recent years, Flutter has emerged as a popular framework for developing cross-platform mobile applications. Developed by Google, Flutter is known for its expressive UI, hot-reload feature, and the ability to create native-like experiences on both Android and iOS platforms. While Flutter has gained widespread acclaim, it’s essential to recognize that it might not be the ultimate solution for every mobile development scenario. In this blog post, we’ll explore the strengths of Flutter and discuss why, in some cases, it may not be sufficient on its own.</p><p>The Strengths of Flutter:</p><ol><li>Single Codebase, Dual Platforms: Flutter’s key advantage lies in its ability to maintain a single codebase for both Android and iOS applications. This not only streamlines the development process but also reduces the likelihood of bugs and inconsistencies between platforms.</li><li>Expressive UI with Widgets: Flutter’s widget-based architecture allows developers to create highly customizable and expressive user interfaces. The extensive catalog of pre-built widgets simplifies the UI development process and ensures a consistent look and feel across devices.</li><li>Hot-Reload Feature: Flutter’s hot-reload feature is a developer’s dream, enabling real-time code changes and instant updates in the app. This significantly speeds up the development cycle, making it easier to experiment, iterate, and debug.</li><li>Growing Community and Ecosystem: The Flutter community is rapidly expanding, contributing to an ever-growing ecosystem of packages, plugins, and resources. This ensures that developers have access to a wide range of tools and solutions to enhance their Flutter applications.</li></ol><p>Why Flutter Alone Might Not Be Enough:</p><ol><li>Specialized Native Functionality: While Flutter excels in providing a consistent UI across platforms, there may be scenarios where applications require specialized native functionality. Certain device-specific features or integrations may be better handled through native development languages like Kotlin for Android or Swift for iOS.</li><li>Performance Considerations: Flutter provides excellent performance for most applications, but for graphics-intensive or resource-demanding apps, native development might offer better optimization. Native languages have a closer connection to the underlying platform, potentially yielding superior performance in specific use cases.</li><li>Learning Curve for Web and Desktop: Although Flutter has expanded its capabilities to include web and desktop applications, developers accustomed to web or desktop development may face a learning curve when transitioning to Flutter. In such cases, using frameworks or technologies specialized for those platforms might be more efficient.</li><li>Platform-Specific Design Guidelines: Flutter’s flexibility in UI design can be a double-edged sword. While it allows for creative freedom, adhering to platform-specific design guidelines may require extra effort. Native development, on the other hand, ensures automatic adherence to each platform’s design principles.</li></ol><p>Conclusion:</p><p>Flutter undeniably offers a robust solution for cross-platform mobile development, with its single codebase, expressive UI, and rapid development capabilities. However, it’s crucial to recognize that it might not be a one-size-fits-all solution. Depending on the project requirements, considerations such as specialized native functionality, performance optimization, and adherence to platform-specific design guidelines may lead developers to explore alternative or complementary solutions.</p><p>In the dynamic landscape of mobile development, choosing the right tools depends on the specific needs of the project. Developers should assess the requirements, weigh the pros and cons, and determine whether Flutter alone is enough or if additional technologies should be incorporated for a more tailored and optimized solution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c22c7a9efd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 Secrets of Emotionally Stable People: Unlocking Inner Resilience]]></title>
            <link>https://naveedullah.medium.com/5-secrets-of-emotionally-stable-people-unlocking-inner-resilience-8ed8f8f94737?source=rss-f09b7fecc985------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ed8f8f94737</guid>
            <category><![CDATA[life]]></category>
            <category><![CDATA[relationships]]></category>
            <category><![CDATA[mental-health]]></category>
            <category><![CDATA[physcology]]></category>
            <category><![CDATA[self-improvement]]></category>
            <dc:creator><![CDATA[Naveed Ullah]]></dc:creator>
            <pubDate>Fri, 02 Jun 2023 16:53:20 GMT</pubDate>
            <atom:updated>2023-06-02T16:53:20.958Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong>: Emotional stability is a sought-after quality that enables individuals to navigate life’s ups and downs with grace and resilience. While some may naturally possess this trait, emotional stability is also a skill that can be developed and nurtured. In this article, we will uncover five secrets of emotionally stable people that can help anyone cultivate inner strength and emotional well-being.</p><ol><li><strong>Cultivating Self-Awareness</strong>: Emotionally stable individuals understand the power of self-awareness. They make a conscious effort to understand their emotions, triggers, and thought patterns. By paying attention to their inner world, they can effectively manage their emotional responses and make conscious choices rather than reacting impulsively. Practices like meditation, journaling, and therapy can aid in developing self-awareness and emotional intelligence.</li><li><strong>Practicing Mindfulness</strong>: Mindfulness is a powerful tool that emotionally stable individuals utilize to stay grounded in the present moment. They are aware that dwelling on past regrets or worrying about the future only leads to unnecessary stress and anxiety. By embracing mindfulness techniques such as deep breathing, body scans, and mindful observation, they can maintain a sense of calm and clarity amidst life’s challenges.</li><li><strong>Building Strong Support Systems</strong>: Emotionally stable individuals understand the importance of healthy relationships and surround themselves with a strong support system. They cultivate deep connections with family, friends, mentors, or therapists who provide them with emotional support, guidance, and perspective. They actively seek help and advice when needed, recognizing that vulnerability is a strength, not a weakness.</li><li><strong>Developing Coping Mechanisms</strong>: Life inevitably throws curveballs, but emotionally stable people are equipped with effective coping mechanisms. They have identified healthy ways to manage stress, such as engaging in physical exercise, practicing hobbies, or engaging in creative outlets. They understand the importance of self-care and prioritize activities that nurture their mental and emotional well-being.</li><li><strong>Embracing a Growth Mindset</strong>: Emotionally stable individuals possess a growth mindset — the belief that challenges are opportunities for growth and learning. They view setbacks as temporary and use them as stepping stones for personal development. They embrace change, adaptability, and resilience. This mindset allows them to approach life’s adversities with a positive attitude and an unwavering belief in their ability to overcome obstacles.</li></ol><p><strong>Conclusion</strong>: Emotional stability is not a fixed trait but rather a skill that can be cultivated and strengthened over time. By incorporating these secrets of emotionally stable people into our lives, we can enhance our ability to manage emotions, build resilience, and lead more fulfilling lives. Remember, developing emotional stability is a journey, and small steps taken consistently can lead to significant positive changes in our well-being.</p><p>So, let’s embark on this journey of self-discovery, self-care, and self-growth, and unlock the secrets to becoming emotionally stable individuals.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ed8f8f94737" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mental Peace: How to Find It and Keep It]]></title>
            <link>https://naveedullah.medium.com/mental-peace-how-to-find-it-and-keep-it-5d1b15fb7828?source=rss-f09b7fecc985------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d1b15fb7828</guid>
            <category><![CDATA[meditation]]></category>
            <category><![CDATA[peace]]></category>
            <category><![CDATA[mental]]></category>
            <category><![CDATA[health]]></category>
            <category><![CDATA[hope]]></category>
            <dc:creator><![CDATA[Naveed Ullah]]></dc:creator>
            <pubDate>Fri, 02 Jun 2023 16:40:32 GMT</pubDate>
            <atom:updated>2023-06-02T16:40:32.302Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hlLx9naWpex7BmU-8IHOFg.jpeg" /></figure><p>Mental peace is a state of mind where you feel calm, relaxed, and at ease. It is a state where you are not stressed, anxious, or worried. Mental peace is important for your overall well-being. It can help you to:</p><ul><li>Reduce stress and anxiety. When you are mentally peaceful, you are less likely to experience stress and anxiety. This is because you are not dwelling on the past or worrying about the future. You are simply focused on the present moment.</li><li>Improve your sleep. Mental peace can help you to sleep better at night. When you are mentally peaceful, you are more likely to relax and fall asleep quickly.</li><li>Boost your immune system. Mental peace can help to boost your immune system. When you are mentally peaceful, your body is better able to fight off illness.</li><li>Increase your productivity. Mental peace can help you to be more productive at work or school. When you are mentally peaceful, you are able to focus better and concentrate for longer periods of time.</li><li>Improve your relationships. Mental peace can help you to improve your relationships with family and friends. When you are mentally peaceful, you are more likely to be patient, understanding, and forgiving.</li></ul><p>There are many things you can do to find and keep mental peace. Here are a few tips:</p><ul><li>Practice mindfulness. Mindfulness is the practice of paying attention to the present moment without judgment. There are many different ways to practice mindfulness, such as meditation, yoga, and tai chi.</li><li>Spend time in nature. Spending time in nature has been shown to reduce stress and anxiety. When you are in nature, you are able to relax and de-stress.</li><li>Get enough sleep. When you are well-rested, you are better able to cope with stress and anxiety. Most adults need around 7–8 hours of sleep per night.</li><li>Eat a healthy diet. Eating a healthy diet can help to improve your overall well-being, including your mental health. Make sure to eat plenty of fruits, vegetables, and whole grains.</li><li>Exercise regularly. Exercise is a great way to reduce stress and anxiety. It can also help to improve your sleep and mood. Aim for at least 30 minutes of moderate-intensity exercise most days of the week.</li><li>Connect with others. Social support is important for your mental health. Make time for friends and family, and don’t be afraid to reach out for help when you need it.</li></ul><p>If you are struggling to find mental peace, there are many resources available to help you. Talk to your doctor, a therapist, or a mental health professional. They can help you to develop a plan to improve your mental health.</p><p>I hope this blog post has helped you to understand the importance of mental peace and how to find it. Remember, mental peace is a journey, not a destination. There will be ups and downs along the way, but it is important to keep going. With time and effort, you can find lasting mental peace.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d1b15fb7828" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 packages, every flutter developer must know about]]></title>
            <link>https://naveedullah.medium.com/10-packages-every-flutter-developer-must-know-about-2d69e9155f7e?source=rss-f09b7fecc985------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d69e9155f7e</guid>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-package]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-libraries]]></category>
            <dc:creator><![CDATA[Naveed Ullah]]></dc:creator>
            <pubDate>Sat, 13 Jun 2020 16:51:37 GMT</pubDate>
            <atom:updated>2021-01-04T16:25:08.399Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*nDZPxMmmPM3ynz8n2p0Txw.png" /></figure><h4>(1) Dio</h4><p>Dio is really strong and powerful http client library which is used for downloading files, handling errors, post requests and get requests. It can save you from handling http requests and http errors pain. It is lot easier than using HTTP client and wiring up the code.</p><h4><strong>(2) Shimmer</strong></h4><p>Your UI may be dependent on async data and you may using loading widget for that. But using shimmer is always the best way of showing async wait for data on the UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*xdSC4kr1W_0Je6rQ9VX4_g.gif" /></figure><h4>(3) <strong>Screenshot</strong></h4><p>This library is very useful when you need to save image format of your widget in the gallery. You can use this to save image of docs, winning status images to share on social media or may be using to college the images.</p><h4>(4) Tutorial_Coach_Mar<strong>k</strong></h4><p>If you are developing an app where you need to guide the user about buttons or actions. Or you want to show a tutorial of your app so they know the app more clearly and easy to get started with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*O_HvGcL1eje6KIznAv1aQg.gif" /></figure><h4>(5) Local_auth</h4><p>Make your app more secure with this package. This can be used for authenticating users in the app with biometric: fingerprint and Face.<br>You must add this feature into your app as optional if your app is chat app, social app or some confidential data storing app. It can increase user’s trust towards the app.</p><h4>(6) Timeago</h4><p>This package can save you from lot of pain. This library is used for showing fuzzy timestamps. If you are showing time information about a user that he/she was online moment ago, minute ago, hour ago or may be yesterday. Same can be used for showing the history of any posts in your social app.</p><h4>(7) Flutter_launcher_icons</h4><p>Flutter launcher icons is very good and helping library when it comes to setting icon for app (IOS &amp; android) . Without setting icons manually for each platform you can use this library to set icons for both platforms for your app.<br>It saves time from navigating into the folder for icons.</p><h4>(8) Auto_Size_Text</h4><p>Sometimes widgets are smaller and they are responsive and you want the text inside the widget also responsive, then use this package. It has different formats to auto size the text. You can choose the one that suits your widget best. It will avoid the overflow error.</p><h4>(9) Android_Intent</h4><p>We can share data from our app to other apps but what if we need data to be shared in our app? This library can help us in the situation where we can make other apps that are already shares outside the app, share in to our app.<br>This plugin is working for android only.</p><h4>(10) Hive</h4><p>Use hive as your app’s local database, if your app is not using strong queries. Hive is very fast to read and write data. If your app is using shared_preferences then you must replace it with hive for a great performance.</p><p>I hope at least one of the above packages will help you in your projects or at least you came to know about it. Please follow me for more weekend flutter blogs. Thanks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/210/1*ojWUzuhUmC9WJm8e9iuZ7A.png" /><figcaption><a href="https://ko-fi.com/naveedullah"><strong>Buy me a coffee</strong></a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d69e9155f7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MobX State Management Solution]]></title>
            <link>https://naveedullah.medium.com/mobx-state-management-solution-22168d9152ad?source=rss-f09b7fecc985------2</link>
            <guid isPermaLink="false">https://medium.com/p/22168d9152ad</guid>
            <category><![CDATA[flutter-mobx]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-bloc]]></category>
            <category><![CDATA[flutter-state-management]]></category>
            <category><![CDATA[mobx]]></category>
            <dc:creator><![CDATA[Naveed Ullah]]></dc:creator>
            <pubDate>Sun, 07 Jun 2020 11:31:05 GMT</pubDate>
            <atom:updated>2020-06-07T11:31:05.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8kukaVI6MY7L6rgve9Zhdg.png" /></figure><p>I am writing this article with complete experience with different state management solutions and came with one of the best solution to avoid later boiler plate code. As you will be growing your application, handling the code and structure is really hard to control.</p><p>New to flutter? Don’t worry explaining from very basic level to intermediate / advance level.</p><p>You may spend a little longer on this article but I promise after reading this you will be good to go developing your projects for deployment. This will save your project from being leaved incomplete and growing your application will be no more pain.</p><p>We will be first starting with a simple project to understand the concept of state management and then we will set up a new project for implementing the mobX.</p><p>Let’s start, be with me until last line of article, so this article helps you in your projects.</p><h4>Understanding the concept</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*U7K0dvxEglg8JsVwYWep6g.png" /></figure><p>The build method is responsible to build the UI (user interface) element.<br>If the build method can be called again and again somehow, the UI element will be rendered again and again.</p><p>Why would some one call build method again and again? Lets see an example</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*_HWvSng_8LiqM-qCgGpjwQ.png" /></figure><p>In this example, number is int type variable initialized with zero. Data types explained nicely at <br><a href="https://medium.com/@naveedullah/best-practices-to-follow-while-declaring-variables-in-dart-31af9d084527">https://medium.com/@naveedullah/best-practices-to-follow-while-declaring-variables-in-dart-31af9d084527</a></p><p>The UI for example will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*zP1liW1Mj5CP7-cg5PA-Pw.png" /></figure><p>On tapping the increment button, the variable number gets incremented to 1 then to 2 and so on. If you check the debug console the number printed on every tap will be increased but your UI did not respond. In order to make UI respond to increment, build method should also be called so it renders again the element and will show the latest incremented value.</p><p>Also the class Home is giving kinda warning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*NEEzF9RYY6lB9vf3-S1ftQ.png" /></figure><p>This warning is here because the variable number is declared as “ var “ which means it can be change later. Also we are extending our Home class from StatelessWidget which means that once this widget gets render, we don’t need to re-render it. BUT at the same time the number is variable and it can be changed and it may be used in UI and should also update the UI which means re-render. For StatelessWidgets the properties should always final because on change for that variable StatelessWidget can not run the build function again.</p><p>But in our case the number is variable and UI should also update on change. So we need to call build method on change in number. To call the build function we need to extend the Home class from Stateless to StatefulWidget.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*2XiUEQliJKZugjgb9Fuwkw.png" /></figure><p>Now there is no warning for variable number because the Home is extended from StatefulWidget which means build method can be called. To call build method again, we need to call setState( ) function. You can pass your own function in setState so it calls the build with your method. This function will be incrementing the number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*BDk7t2KdkMhWQZqmJ6w2yg.png" /></figure><p>Now on tapping on increment method, setState calls the build function and rebuilds the UI to updated data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*Yn8EahjOipSxsojyjjWyMg.png" /></figure><p>So now it’s updating. 😍</p><h3><strong>What is State Management?</strong></h3><p>This difference between Stateless and StatefulWidget is known as state management.</p><h3><strong>Why StatefulWidget is not enough for State Management?</strong></h3><p>The example explained above is very simple so can be handled with setState and of course will be using it for simple widgets. But as the app is growing it is really hard to handle the states.</p><p>Think of a situation where a user enters email and password in Sign In screen and then pushes the login button. The sequence of series will be like Sign In screen than loading screen when authenticating and if authenticated the state will be to the home of app otherwise login failed screen.</p><p>This situation is really hard to handle the states. For these state problems there are many state management solutions.</p><ul><li>Provider</li><li>BLoC</li><li>Inherited Widget &amp; Inherited Model</li><li>Scoped Model</li><li>Redux</li><li>MobX</li></ul><p>I have experienced each of these state management solutions and the most convenient and easy solution I found is MobX. Before I recommend you the MobX you should also check overview of each of them, so you get also the better idea which suits you the most.</p><h3>Why I recommend MobX?</h3><p>When you are working more focused with state management solution you have to write a lot of boiler plate code. 😳</p><p>But in case of MobX you should not worry about boiler plate code because MobX takes care of it by itself.😊</p><h3>Let’s see some MobX terms before going for a new project</h3><p>There are four important terms to understand for working in MobX.</p><ol><li><strong>Observable</strong></li><li><strong>Action</strong></li><li><strong>Computed</strong></li><li><strong>Reaction</strong></li></ol><h4>Observable</h4><p>To understand observable bring that number variable back into mind, we wanted to update the UI for that number on increment. Those variables which we want to listen UI for are observable. In the previous case we can say number is observable.</p><h4>Action</h4><p>Those methods which somehow update Observables are known as actions. For example the function in above case</p><pre>( ){<br>number++<br>}</pre><p>is action because this will update the observable in UI.</p><h4><strong>Computed</strong></h4><p>Those getters or methods that are used to return some data using observables. For example if number is observable and we are using some getter that returns me “Number is: $number” so that method or getter is computed.</p><p>Confused? Do not worry, Everything will be crystal clear while we are on project.</p><h4>Reaction</h4><p>In reaction we can autoRun or schedule run for any method or disposing our listeners.</p><h3>Let’s start our project with MobX</h3><p>Our project will be like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*zKTotjwvTIP-Pn2l2iYhDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*uGklAo8Ot3eFqEUMhM4flA.png" /></figure><p>Please clone or download this modeled project from <a href="https://github.com/Naveed-dev30/mobx_example.git">https://github.com/Naveed-dev30/mobx_example.git</a><br>to start mobX.</p><h4>Overview</h4><p><strong>Folder</strong> <strong>Structure: </strong>Lib has 2 folders for home screen and modals and one main file. Main file runs the app with initial Screen as home screen that is in home_screen folder. I have extracted 3 widgets from home screen to widgets folder that is inside home_screen folder. Cart widget will show the number of items added in cart. Image_view widget just has the image for each product. The product widget is each tile card in the list. On red eye icon tap we will remove the product from the list and on cart tap we will add the product to the cart, so cart will updated.</p><p>I am getting all data from fake api store. In modals folder there is one modal for product as product_item which contains cost, title and url for image.</p><h4>Adding MobX dependencies</h4><p>Open pubspec.yaml file and add the following dependencies</p><pre>dio: ^3.0.9<br>#Add under dio<br>mobx: ^1.0.2+2<br>flutter_mobx: ^1.0.1 </pre><pre>#Add under dev_dependencies<br>build_runner: ^1.8.0<br>mobx_codegen: ^1.0.2</pre><p>Now get packages by running flutter pub run command.</p><p>Build runner will build the code generated by mobx_codegen. Let’s see it.</p><p>In main file we are returning the material app which contains HomeScreen widget. Open this Home_screen.dart under home_screen folder. This screen contains the UI and the getData function. Our target is to add the products to the cart so cart updates its state and to remove the products from the list.</p><p>Under the home_screen folder create new file as home_store.dart . This file will contain all the business logic of home_screen.dart .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/229/1*oJA_n1mvM3upIviaiR1I2Q.png" /></figure><p>Create a class which extends an abstract class mixing it with the generated class. For example:</p><pre>class HomeStore extends _HomeStore with _$HomeStore{}</pre><p>HomeStore class will be the instance that will be used to access the business logic and properties. Create _HomeStore class as an abstract class which holds all the business logic.</p><pre>abstract class _HomeStore with Store{}</pre><p>Still seeing errors? No worries they will just leave. <br>Import the package for Store.</p><pre>import ‘package:mobx/mobx.dart’;</pre><p>_$HomeStore class will be created by mobx_codegen automatically once we run build_runner for that. _HomeStore mix ins with Store so this class can use the properties from Store.</p><p>Before we run build runner, first mention a part for generated file like</p><pre>part ‘home_store.g.dart’;</pre><p>The g means it will be generated file. Now run following command</p><pre>flutter packages pub run build_runner build</pre><p>It will take a while to generate a file for your project. Now a file will be generated as home.g.dart</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*nxcUcQgddjnyKw8vHXH4HQ.png" /></figure><p>We will be running again this command once we work with observables, actions and computed. As we are working with lists but to observe the lists we use observable lists. Open the home_store.dart</p><p>Declare an observable list which will contain the products.</p><pre><em>ObservableList</em> oProducts = <em>ObservableList</em>&lt;<em>ProductItem</em>&gt;();</pre><p>Now cut the getData function from HomeScreen to _HomeStore. Ignore all the errors at this stage. They will be getting fixed.</p><p>Import the dio package in _HomeStore</p><pre>import ‘package:dio/dio.dart’;</pre><p>The getData function for now is returning the products after they are fetched. Now we will update the function that it would return nothing but adds the fetched products to the observable list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*J86U6Q8AjH5K97WSYQCJVA.png" /><figcaption>Ignore @observable notation on ObservableList, we don’t need it here.</figcaption></figure><p>Now in homeScreen, We will run this getData method on init so it fetches the data when Screen is opened. To call the getData method in init we must change widget from Stateless to Stateful. Now Declare an instance for HomeStore so we can access the methods and properties from HomeStore.</p><p>Those widgets which can be changed with respect to observables we need to wrap observer widget around it, So it knows that it contains observable and will be updated or re-render.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*p0uVGvXeocY_rWWrBpgIsg.png" /></figure><p>Now this should be the code at your side. So observer renders the CircularProgressIndicator when the observable list of products is empty.<br>As getData method is completed it adds all the elements in observable list and observer observes this update and renders the ListView. Because of ternary operator which checks the condition.</p><p>To learn more about dart cool operators please visit <a href="https://medium.com/@naveedullah/operators-for-shorten-code-dart-a81e760e7d7a">https://medium.com/@naveedullah/operators-for-shorten-code-dart-a81e760e7d7a</a></p><p>But we have not even run the build runner then why it is working?<br>It is because of observable list. Observable list automatically observes it. But let’s change the logic.</p><p>Declare a bool which is initially false indicating no data and when the data gets loaded we re-render the observer.</p><p>Open the _HomeStore and change ObservableList to list.</p><pre>var oProducts = &lt;<em>ProductItem</em>&gt;[];</pre><p>Now if we run the app, Screen is not updating and shows what is rendered for very first on build that is ProgressIndicator. Run the build runner again.</p><p>Declare a bool as</p><pre>@observable<br>var isLoaded = false;</pre><p>Now after when data is loaded we switch isLoaded to true. That is why we have mentioned @action on the method. Which defines that it will update or change the data of @observable. So the _HomeStore is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*kZmZmHy1RXHlAGyfS8zxWA.png" /></figure><p>In HomeScreen now we will use isLoaded in observer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*vEpqd4rtCr4DycfLTnYOIw.png" /></figure><pre>//Run this command again so builds the boiler plate for you<br>flutter packages pub run build_runner build</pre><p>Wait for a while until it’s completed and then run the app.</p><p>So initially the isLoaded was false, it showed CircularProgressIndicator as soon as isLoaded updated to true, observer renders ListView.</p><p>Now as you have learned the actual mechanism, setting the cart would not be a problem. It can be done with ObservableList.length but I am doing it using @computed so things are more clear. Once you understand these terms then you can use any approach that suits you the best.</p><p>Let’s update the cart with computed. 😎</p><p>Open the HomeStore so we add a method for this.<br>Declare an ObservableList for cart products. (If you are using lists in mobx and using it or it’s any property in UI, use observable list instead of list).</p><pre><em>var</em> cartProducts = <em>ObservableList</em>&lt;<em>ProductItem</em>&gt;();</pre><pre><em>//The following function receives ProductItem and adds it in cartProducts</em></pre><pre><em>void</em> addItemToCart(<em>ProductItem</em> item) {<br>  cartProducts.add(item);<br>  print(cartProducts);<br>}</pre><p>This method should be call when shopping cart in List tile is tapped. To call this function we must pass the HomeStore instance to the list tile. So make a final instance of HomeStore which is initialized by constructor and pass the HomeStore instance when calling this product widget.</p><blockquote>Wy we are not declaring new HomeStore instance rather than passing the old one? It is because if we declare new instance of HomeStore then its properties are very initial and will not get the right updated UI. Becoming difficult? It is not, it may take a while but practicing pair of screens with mobX can make all crystal clear.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*B72K8ivh_6uapX_-jun5Dw.png" /><figcaption>Passing HomeStore instance through constructor of Product</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*Xy_unPK26QYFGF--sGlPTA.png" /><figcaption>Receiving HomeStore instance through constructor</figcaption></figure><p>Now call the addToCart method on cart_icon tap.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*IdkWpH8Q3CFqHJEGgkWz1w.png" /><figcaption>Calling addToCart method</figcaption></figure><p>All we are setup just need to show the updated cart in the app bar. Ofc we will pass the instance of HomeStore to the cart same as we did for product widget.<br>And then we can show the cartProducts.length, but let’s do this through computed way. Computed are those getters or methods which returns something depending on observable. Let’s create a getter which returns the length of cart products.</p><p>Open the HomeStore and add</p><pre><em>@computed<br>int</em> get cartItemCount =&gt; cartProducts.length;</pre><p>Pass the HomeStore instance to Cart widget, and wrap the Container that is second child of Stack with Observer. Use homeStore.cartItemCount instead of cartProducts.length .</p><p>I hope things are understandable now, if still there is confusion then try the last functionality with MobX by yourself that is removing a product from list on red eye tap.</p><p>You can get the completed MobX task repository from <a href="https://github.com/Naveed-dev30/Mobx_implementation_simple.git">https://github.com/Naveed-dev30/Mobx_implementation_simple.git</a> .</p><p>If you learned something, follow for more weekend blogs. Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22168d9152ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best practices to follow while declaring variables in Dart]]></title>
            <link>https://naveedullah.medium.com/best-practices-to-follow-while-declaring-variables-in-dart-31af9d084527?source=rss-f09b7fecc985------2</link>
            <guid isPermaLink="false">https://medium.com/p/31af9d084527</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[data-types-in-dart]]></category>
            <category><![CDATA[dart-data-types]]></category>
            <dc:creator><![CDATA[Naveed Ullah]]></dc:creator>
            <pubDate>Sat, 06 Jun 2020 10:16:56 GMT</pubDate>
            <atom:updated>2020-06-06T10:16:56.249Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kDnqXjorVkkoKYss2asfvw.jpeg" /></figure><p>Since dart programming language allows you to declare variables with and without defining its type, here are some good approaches to declare them.</p><p>If you are declaring a variable but you may initialize it later than the best practice is to define its type. Eg</p><pre>int number;<br>String name;<br>//later<br>number = 3;<br>name = &quot;Danial&quot;</pre><p>But if the variables are declared with its value then you should not define its type. Eg</p><pre>var number = 3;<br>var name = “Danial”;</pre><p>When a variable is declared and given it a value, then the type of a variable becomes the type of a value. So in the above example var number will be int type and var name will be String type.</p><pre>print(number.runtimeType); //int<br>print(name.runtimeType); //String</pre><p>But for the final declaratives, we have to initialize it when it is declared because final ones cannot be changed later, It is initialized for once.</p><pre>//Bad Practice <br>final int number = 3;<br>final String name = “Danial”;<br>//Good Practice<br>final number = 3;<br>final name = “Danial”;</pre><p>Using naming conventions rules are also the best practice while declaring variables. Variables and finals should have camelcase naming convention.</p><pre>//Incorrect<br>var MyNumber = 3;<br>var MyName = “Danial”;<br>//Bad Practice<br>var my_number = 3;<br>var my_name = “Danial”;<br>//Good Practice<br>var myNumber = 3;<br>var myName = “Danial”;</pre><p>Use “ _ ” while declaring names for files. eg <em>user_profile.dart</em></p><p>Same is the case with constants, as they are initialized when they are declared. So here also avoid defining types for constants. Naming convention for constants should be all uppercase.</p><pre>//Bad Practice<br>const number = 3;<br>const name = “Danial”;<br>//Good Practice<br>const NUMBER = 3;<br>const NAME = “Danial”;</pre><p>but wait, What is the difference between final and constant? 😳</p><blockquote>For final declaratives they can be initialized either when its declared or either through constructor. But constants are always initialized at the instance when they are declared. Both can not assigned a value after it is once initialized.</blockquote><p>When you are declaring the list and not initializing it, you should give the type and also the type of data it will contain.<br>For example a list that will contain some String names later.</p><pre>List&lt;String&gt; names;</pre><p>But let say you are initializing a list with empty data and will contain data later. In this case don’t define type for list but for data it will contain. For example an empty list that will contain String type data later.</p><pre>//Good Practice<br>var name = &lt;String&gt;[ ];</pre><p>Map data type is more interesting and can create some type errors on run time if not defined correctly. Map is a data type which contains some value against a key. The values can be accessed from map variable through keys.</p><pre>var dataMap = {<br>‘name’ : ‘Danial’,<br>‘number’ : 1,<br> };<br>//print(dataMap[‘name’] ) =&gt; Danial<br>//print(dataMap[‘number’]) =&gt; 1</pre><p>If maps are declared but not initialized, then we need to define the type of it and also the type of data it will contain. To define types for data inside the map we need to decide which type of data it will contain. As map has key-value pairs. So the type of map will be the type of key and type of value. In the above example name and number are they keys and Danial and 1 are the values.<br>The type of keys is String here but the type of value is dynamic. Dynamic and object data typed variables can receive and store any type of data. In above example value is dynamic because for the first pair the value is String and in second pair value is int.</p><pre>print(dataMap.runtimeType);<br> //Map&lt;String, dynamic&gt; or //Map&lt;String, object&gt;</pre><p>So for a map which will contain String value against String key then the map is type of Map&lt;String, String&gt; .</p><pre>//Map is defined but not initialized which will contain int values agains String keys<br>Map&lt;String, int&gt; data;</pre><p>Map defined and initialize with empty data which will contain data of type int against String keys later</p><pre><br>var data = &lt;String, int&gt;{};</pre><p>I hope it works interesting for many of you guys. Play directly with these data types at <a href="https://dartpad.dev/">https://dartpad.dev/</a> without setting up a project. Thanks 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31af9d084527" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Five things you must know about Container]]></title>
            <link>https://naveedullah.medium.com/five-things-you-must-know-about-container-c77dda1c34fb?source=rss-f09b7fecc985------2</link>
            <guid isPermaLink="false">https://medium.com/p/c77dda1c34fb</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <dc:creator><![CDATA[Naveed Ullah]]></dc:creator>
            <pubDate>Fri, 05 Jun 2020 22:52:09 GMT</pubDate>
            <atom:updated>2020-06-05T22:52:09.097Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fMIvGrL6Z1oB8GGFEP4-Eg.jpeg" /></figure><p>In this article you will learn 5 important things to keep in mind while working with container widget in flutter.</p><p><strong>1) Child &amp; parent of a Container<br></strong>If the child of a container is null and the constraints of a container is also unbounded or height &amp; width is not specified, the container tends to fill all available space in parent. But also if the parent of container has unbound constraints.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*XuSwVlX0jYXtgpo3jeLN-Q.png" /></figure><p>As the container has no height &amp; width specified and child is null. Also parent has unbounded constraints so the container fills the whole scaffold.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*KXv4oIBgrQ4abwqWG0tYDQ.png" /></figure><p>but if the container gets the child and has no height &amp; width, it gets wrapped to its child.</p><p>If the parent of container is constraints bounded and container has no child and no height &amp; width , the container will squeeze to minimum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*4zzB7qF7ewGaPkeTvIkM4g.png" /></figure><p>The column is constraint bounded widget. So the container gets to minimum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*5_eQVsxcgag6LkaBfEpEiw.png" /></figure><p><strong>2) Color a Container<br></strong>Color can be given to a container by passing Colors value to color argument in container until and unless there is no box decoration. If box decoration is not null color should be define in BoxDecoration object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*yyYlItvcerNgC16B4KcaNA.png" /><figcaption>color in box decoration</figcaption></figure><p>and if its box decoration is defined for styling a container but color is defined straight inside container than it will generate error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*Y7s0Ubcpn2zida6MZMe80A.png" /></figure><p>So in this case compiler throws an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*3ZFm56S7B67rOrjLnIfKiQ.png" /></figure><p><strong>3) Container for Padding<br></strong>If you are using container just to give padding for a child and using no more properties of container. Then batter to use Padding widget. Padding widget has padding argument and receives EdgeInsets type value for applying padding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*iAR-WnI_nWOP5F5s9TMpqA.png" /></figure><p><strong>4) Not resizing Container<br></strong>Some times on extracting widgets to new files the container do not respond to the given height and width. Simply wrap it in Center, Row, Column or a stack. It will start responding. 😎</p><p><strong>5) Border Radius for container having Image<br></strong>Container can be rounded with the borderRadius argument in BoxDecoration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*4EpQ3d1ZJO3i67VhNcCELA.png" /></figure><p>the container becomes as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/1*Tr0OyHZwgaoIUcZDD4w82w.png" /></figure><p>But what if the container contains an Image?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*WtI-bZVZk3ZPlTchpSfdeQ.png" /></figure><p>The result would be 🥺</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*wnILrHIEwNgs-jM3kqyZ_g.png" /></figure><p>In order to give image an radius we need to wrap container with ClipRRect</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*pt5U6zNFhwDa28EkZnibXQ.png" /></figure><p>And now it will make the borders of image round</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*IUk6ANkhCWhQaEOKjqebtQ.png" /></figure><p>Basic but important ones. Play around container directly at<a href="https://dartpad.dev/flutter"> https://dartpad.dev/flutter</a> without setting up project for it.</p><p>Thanks😋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c77dda1c34fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Operators for shorten code, Dart]]></title>
            <link>https://naveedullah.medium.com/operators-for-shorten-code-dart-a81e760e7d7a?source=rss-f09b7fecc985------2</link>
            <guid isPermaLink="false">https://medium.com/p/a81e760e7d7a</guid>
            <category><![CDATA[dart-operator]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[spread-operator]]></category>
            <category><![CDATA[null-aware-operator]]></category>
            <dc:creator><![CDATA[Naveed Ullah]]></dc:creator>
            <pubDate>Fri, 05 Jun 2020 16:10:09 GMT</pubDate>
            <atom:updated>2020-06-05T20:26:38.211Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*niJxUyipSO9KiwRpAXdMOA.jpeg" /></figure><p>Decent developers always recommend to keep their code as simple, clean, short and understandable as possible. For sure this approach is always a good practice.</p><p>You must also know about some advance dart operators to shorten your code and avoid boiler plate code. Lets start with these operators 🤩</p><p><strong>Null aware operators</strong></p><ul><li><strong>?? operator<br></strong>Use this operator if you are returning any object just in case if it is not null, otherwise return some value.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*ldBbKu_83vMgF2zsgbJ5bw.png" /><figcaption>Example for ?? operator</figcaption></figure><p>It is same as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*yM-DnHv2S_wETxJsebK5tg.png" /></figure><ul><li><strong>?? = operator<br></strong>It also works almost the same as above but for assignment.<br>For example you have a variable and you want to assign a value to it only if it is null.<br>In the example below only if the number is null then 3 gets assigned to number.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*fg0ZToJZXeWfhs-EEsRakg.png" /></figure><p>The boiler plate for this example is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*2SY66EWF1m3yBAeaOMYpiA.png" /></figure><p>Using these operators, code became shorter and nicer. ✌️</p><ul><li><strong>?. operator<br></strong>This operator is very important to avoid some unexpected errors with the first go of execution. Some times you have faced an error like</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DBh8G8YbX2YIFjOKXuDLCA.png" /><figcaption>Called on null error</figcaption></figure><p>This called on null error came on</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*uYXfFo4yUb7mM2NU7feEQQ.png" /></figure><p>As you can see the names is null. When ever methods are called for a null object it gives called on null error. To avoid this error, we need to check the object if it is null or not and for this purpose we will use ‘ <strong>.? </strong>’ operator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*YFkTMJjUNvNiVuJif3zGww.png" /><figcaption>Avoiding call on null error with single operator</figcaption></figure><p><strong>More Operators</strong></p><ul><li><strong>Ternary operator<br></strong>This one is a hack let’s say, very use full operator. It is handy operator to run expressions based on decision. If the situation is like</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*uFDGnG_HP-J9FRVjqX9rdQ.png" /></figure><p>Then this can be shorten very smartly using ternary operator. eg</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*B5DiJb761QCtPk1n0QXYWg.png" /></figure><ul><li><strong>.. operator<br></strong>This is called cascade notation. It’s is used when more than one functions are being called for a single object. For example adding names to a list like this</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*iuwOVIk7dpgx27kN5S3q0g.png" /></figure><p>will be as same as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*PgkhKLTKOa7Yj55cJGgOhw.png" /><figcaption>Cascade notation example</figcaption></figure><ul><li><strong>Spread operator ( … )<br></strong>Spread operator is used when all the properties from a map or all the elements in list is poured to a new object or to a new list. For example we have two lists one containing name of vegetables and other containing names of fruits. Let’s say we have one more array containing the names of eatables and contains all elements from fruits and vegetables. Here spread operator helps us as</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*bmY23JK_z2YddPmCJSccjA.png" /></figure><p>or same for map,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*t4XiHJhzUoimESKHVC-lGQ.png" /></figure><ul><li><strong>Null aware spread operator<br></strong>What if we are spreading elements from an object or list to another, but the source is null? Of course it will give us an error. Yes we can use if-else for checking for null, but OPERATORS. This ?… operator is used for null aware for spreading. Eg</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*X0v51BNxPy1S9_bCS5nbrA.png" /></figure><p>This for sure helps you in certain places while coding in your dart project. 😎You can play around these operators quickly at <a href="https://dartpad.dev/">https://dartpad.dev/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a81e760e7d7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>