<?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 Samia Ashraf on Medium]]></title>
        <description><![CDATA[Stories by Samia Ashraf on Medium]]></description>
        <link>https://medium.com/@samiaashraf?source=rss-d5586c44ae4a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KEqx0rYn2O-wZFVnDdJVyA.jpeg</url>
            <title>Stories by Samia Ashraf on Medium</title>
            <link>https://medium.com/@samiaashraf?source=rss-d5586c44ae4a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 00:55:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samiaashraf/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[Simplify Barcode and QR code Scan in Flutter apps]]></title>
            <link>https://samiaashraf.medium.com/simplify-barcode-and-qr-code-scan-in-flutter-apps-be8f936f1b64?source=rss-d5586c44ae4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/be8f936f1b64</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[qr-code]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <dc:creator><![CDATA[Samia Ashraf]]></dc:creator>
            <pubDate>Thu, 12 Jan 2023 16:54:28 GMT</pubDate>
            <atom:updated>2023-01-12T16:54:28.425Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WZzpvYWJ7KMJsc-T-xAqhA.gif" /></figure><p>Ever came across a scenario where you wanted your Flutter app to scan QR codes and Barcodes? In this article, I will walk you through the steps required to scan and read QR codes and Barcodes in Flutter app with the help of an example.</p><p>In the example, we are going to build a simple UI that scans Barcodes and QR codes and records the value in a TextField box. We can then store this value and use anywhere in the program.</p><ol><li>We will begin by importing the <a href="https://pub.dev/packages/qr_code_scanner">qr_code_scanner</a> package in a newly created Flutter project.</li></ol><p>Run the following command in the terminal to make sure that the latest version of the package is imported:</p><pre> $ flutter pub add qr_code_scanner</pre><p>This <em>package</em> scans both <strong>QR codes</strong> and <strong>barcodes</strong>.</p><p>2. Since the package uses camera to scan the codes, follow the <a href="https://pub.dev/packages/qr_code_scanner">documentation</a> to make some platform specific changes(updating gradle and minSdkVersion on <em>Android</em> and addingNSCameraUsageDescription in <em>Info.plist</em> file)</p><p>3. Once step 1 &amp; 2 are complete, we can now start with the QR code.</p><p>If the camera permission is allowed, the camera will start scanning for the codes. Once the code is scanned, the camera will be paused and the code will be recorded for future use as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*0y8MEFd64LEy2zqay-ad0g.gif" /><figcaption>QR Scan app gif</figcaption></figure><p>The code can be stored in a TextField using a TextEditingController which can also be edited(manually entered by user) in case the camera could not capture a damaged QR/Barcode. We will also allow the user to toggle <strong><em>flash</em></strong> option of Camera.</p><pre>TextEditingController scannedCode = TextEditingController(text: ‘QR Code’);</pre><p>4. In case you want to rescan the code or if by any chance the barcode was incorrectly read(very rare), we will add a button to rescan the QR/barcode. This will resume the camera to record the barcode again and also replace the TextEditingController value and the process repeats.</p><p>We will also use a QRViewController to read the incoming barcode data stream.</p><pre>QRViewController? controller;</pre><p>5. buildQrView<strong> </strong>is a widget that passes the current context to build a QR view in the UI. You can set the height and width of the QRView window here as per the device dimensions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*msiAZ5o7cj__EHW25olTQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t0xb12uLzmMvuwJicWIIZQ.png" /><figcaption><strong>buildQrView </strong>widget</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OKLyABoLsrQ7nElvVM1-LQ.png" /><figcaption><strong><em>onPermissionSet</em></strong> function</figcaption></figure><p>This widget also confirms if the camera permission is set or not. You can display a custom message in case the permission was denied.</p><p>6. The QRView has a parameter onQRViewCreated that runs a function when the QRView is created. This function uses the QRController to start scanning the incoming camera data, in streams. When an object of type Barcode is detected, the scanned code from this object is then assigned to the TextEditingController.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WtOrlJsFaB9To5Rj_t5hjQ.png" /><figcaption><strong>onQRViewCreated</strong> function</figcaption></figure><p>7. Lastly, don’t forget to dispose the controllers to avoid memory leak.</p><pre>controller?.dispose();<br>scannedCode.dispose();</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*39-Hg0BHMLXUA4wEk_lpBQ.png" /><figcaption>courtesy: <a href="https://commons.wikimedia.org/">https://commons.wikimedia.org/</a></figcaption></figure><h4><strong>Thank you for reading!</strong></h4><p>Did I miss something? Feel free to leave them in the comments and I shall work on them.</p><p>You can connect with me <a href="https://twitter.com/SamiaAshraff">Twitter</a>, <a href="https://www.linkedin.com/in/samia-ashraf-2a1a79149/">LinkedIn</a> and <a href="https://github.com/SamiaAshraff">Github</a>.</p><p>Stay tuned!<a href="https://emojipedia.org/waving-hand/#:~:text=Emoji%20Meaning,to%20Emoji%201.0%20in%202015.">👋</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be8f936f1b64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auto Size any widget in Flutter]]></title>
            <link>https://medium.com/flutter-community/auto-size-any-widget-in-flutter-1386567c444?source=rss-d5586c44ae4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1386567c444</guid>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Samia Ashraf]]></dc:creator>
            <pubDate>Sat, 17 Sep 2022 19:43:20 GMT</pubDate>
            <atom:updated>2022-09-19T00:35:12.756Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*PC4Ow5xkIJ-BES2TBmEVog.gif" /><figcaption>auto_size_widget.gif</figcaption></figure><p>Have you ever come across a scenario where you wanted the user to resize a widget and didn’t know how to execute it? Well, I was in a similar situation some time ago and I decided to build a package as a solution.</p><p>The <a href="https://pub.dev/packages/auto_size_widget">auto_size_widget</a> allows the user to resize any Flutter widget. This is especially helpful for textfields if the user wants to extend the field, or an image to zoom in for better visibility, and many more.</p><h4><strong>Following are the attributes of the package:</strong></h4><p><strong>— </strong><strong>showIcon: </strong>(boolean) the auto_size_widget by defaults has a resize icon, if you wish to not have it in the widget, set to false, however, it is true by default.</p><p><strong>— </strong><strong>initialWidth:</strong> the initial width of the widget, that can later be resized.</p><p>Set same value as maxWidth to keep the widget width constant.</p><p><strong>— </strong><strong>initialHeight: </strong>the initial height of the widget, that can later be resized.</p><p>Set same value as maxHeight to keep the widget height constant.</p><p><strong>— </strong><strong>maxWidth: </strong>the maximum value that can reach during the resize. If same as initialWidth, user cannot change width of the widget.</p><p><strong>— </strong><strong>maxHeight: </strong>the maximum value that can reach during the resize. If same as initialHeight, user cannot change height of the widget.</p><p><strong>— </strong><strong>child: </strong>widget that will be resized</p><p><strong>— </strong><strong>borderColor:</strong> <em>optional parameter</em> that sets the border colour of the AutoSizeWidget</p><p><strong>— </strong><strong>boxDecoration: </strong><em>optional parameter</em> that sets the decoration for the AutoSizeWidget box.</p><h4>Some of the common widgets with which you can use <em>auto_size_widget</em>:</h4><ol><li><strong>Auto Size Image:</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/232/1*sSFzFNF6_cmA2kaOwHCSmw.gif" /><figcaption>Auto Height and Width Example</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff96335d77320aab41436130eb43b060/href">https://medium.com/media/ff96335d77320aab41436130eb43b060/href</a></iframe><p>This widget can resize the child widget(image). Here, I have set equal values for maxWidth and maxHeight. And different equal values for initialWidth and initialHeight.</p><p>This resizes both the height and the width of the widget.</p><p><strong>2. Auto Size TextField(constant height):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*kRCK_s8spZ5j_hYNGJvLjQ.gif" /><figcaption>Auto Width Example</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d87804355cea85ba175fca9cbdfc6df7/href">https://medium.com/media/d87804355cea85ba175fca9cbdfc6df7/href</a></iframe><p>Here, a TextField is wrapped with AutoSizeWidget, the TextField width can be resized from value 180 to 300. The height however, remains constant and does not change during the resize.</p><p><strong>3. Auto Size Text(constant width):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*WpFJZMRsattcUacY8HoCIA.gif" /><figcaption>Auto Height Example</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21886a771df3d3ae39f52f5263cfa1b9/href">https://medium.com/media/21886a771df3d3ae39f52f5263cfa1b9/href</a></iframe><p>Here, the Text widget is wrapped with AutoSizeWidget. The Text widget height can be resized from 120 to 280. The width here remains constant and does not change during the resize.</p><p>The AutoSizeWidget comes with a boxDecoration by default that acts as a guide when user resizes the widget.</p><p>You can skip the box by passing your own value for the boxDecoration parameter, or by setting the borderColor as Colors.transparent. However, it is recommended to keep the default value as it serves a purpose.</p><p>This is how the widget would look like after the box is removed and when the showIcon is true:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*MiR7jd2AnoBwya0gH5oi9A.gif" /></figure><p>You can wrap AutoSizeWidget around any Flutter widget that can later be resized by the user. This package can be helpful especially when you’re building a web app.</p><p>That’s all for now. Feel free to leave any suggestions in the comments and share as much if you found it helpful!</p><p>Follow Flutter Community on Twitter: <a href="https://www.twitter.com/FlutterComm">https://www.twitter.com/FlutterComm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1386567c444" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/auto-size-any-widget-in-flutter-1386567c444">Auto Size any widget in Flutter</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[6 Tips for Your Next Flutter Project]]></title>
            <link>https://medium.com/better-programming/6-tips-for-your-next-flutter-project-1bf7e055029e?source=rss-d5586c44ae4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bf7e055029e</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Samia Ashraf]]></dc:creator>
            <pubDate>Sun, 07 Aug 2022 07:16:41 GMT</pubDate>
            <atom:updated>2022-08-12T15:00:32.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*24qE3MvnMZubq1aLv7YP6w.gif" /></figure><p>With more companies shifting towards cross-platform development, Flutter is inevitably on its way to becoming the most preferred cross-platform technology. Most of the Flutter updates include improved platform compatibilities which contribute to its growth.</p><blockquote>Flutter is an open-source UI software development kit created by Google. It is used to develop cross platform applications for Android, iOS, Linux, macOS, Windows, Google Fuchsia, and the web from a single codebase.</blockquote><p>If you’re new to Flutter, follow the instructions in this link to complete installation and to get started with Flutter.</p><p><a href="https://docs.flutter.dev/get-started/install">Choose your development platform to get started</a></p><p>If you have just started with Flutter or built applications in Flutter, then these tips will surely help you at some point, maybe in your next project. Feel free to share your tips in the comments.</p><h3>1. Build apps that are less package dependent</h3><p>Do not rely heavily on packages as they can deprecate certain features leaving you with additional work to create a fix.</p><p>Although it depends on the complexity of the feature, certain packages like adding animation to containers can be avoided as this can be something you can code from scratch. This will let you to have more control over the widget allows you to make changes to it easily.</p><p>Regularly update the pubspec.yaml<em> file</em>, remove packages that have been added earlier but are not used in the project anymore.</p><h3>2. Customize repeating widgets</h3><p>Widgets that keep repeating in the project can be extracted into a separate widget and used in multiple places. This avoids re-writing the same widget and saves time and effort.</p><p>Let us take an example of a screen with 4 buttons. Instead of writing the button code with onPress, colour, and other properties 4 times, I will extract the button into a separate widget and then pass these variable properties.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18d7d208fd83509cf16f4119277465e0/href">https://medium.com/media/18d7d208fd83509cf16f4119277465e0/href</a></iframe><p>The CommonButton widget is called 4 times, and every time it is called, onPress, colour and text properties are passed. Let us now look at the code for CommonButton widget:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4da8db25778086c38a178611cd501349/href">https://medium.com/media/4da8db25778086c38a178611cd501349/href</a></iframe><p>The variables will be different every time the CommonButton is called, and this is how we can reuse the CommonButton widget multiple times in the project.</p><h4>3. Use log() over print()</h4><p>Flutter 2.5 and above comes with the <a href="https://pub.dev/packages/flutter_lints"><em>flutter_lints</em></a> package, a package that identifies possible problems in your dart source code.</p><p>Every time you use print(), it shows a warning that reads “Avoid ‘print’ calls in production code”. The package flags it as a warning because print logs in release builds might log sensitive information. In order to avoid this, use log(), dart’s built-in function, which helps in finding errors in the code, checks for performance issues, coding styles, and formatting.</p><h3>4. Stateless or Hooks over Stateful widget</h3><p>Stateful widgets cause more load on the application compared to Stateless and Hook widgets as they are involved in rebuilding the widget.</p><p>Avoid using Stateful widgets as much as possible. If you are new to Flutter Hooks, I have <a href="https://samiaashraf.medium.com/flutter-hook-widgets-over-stateful-widgets-for-better-app-performance-938861d5ea94">written an article</a> where I explain how to use Hook widgets over Stateful widgets.</p><h3>5. Common file for constants</h3><p>A common file to place all constants, such as Colours, Asset strings, Decorations, TextStyles can make the entire process of designing smooth.</p><p>Here is an example of a constants file,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e50c6352ef4dd4653a444944e5490834/href">https://medium.com/media/e50c6352ef4dd4653a444944e5490834/href</a></iframe><p>Now throughout the program, you don’t need to define a constant every single time. Define it once in constants.dart<em> </em>file and use it in multiple places. You can reuse the constants file for multiple projects.</p><h3>6. SizedBox widget for no widget</h3><p>Use SizedBox with 0 height to hide a widget.</p><p>In the below code, I only want to show the text widget when showButton property is true, otherwise a SizedBox widget with height 0 will be drawn, in short, nothing will be shown in UI if showButton is false.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e45646027f59187dcfba2c679ef124d/href">https://medium.com/media/0e45646027f59187dcfba2c679ef124d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*umUY2wARjekJbFxiPp0cOA.gif" /></figure><p>Another approach to show/hide widgets is using Visibility() widget.</p><p>Following Text widget will only be shown if index is 0 <em>(visible is true)</em>, otherwise, the Text widget becomes invisible <em>(visible is false)</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e66da49a1d9956da0473f221295c802f/href">https://medium.com/media/e66da49a1d9956da0473f221295c802f/href</a></iframe><p>Do you have a tip that you want to share? Feel free to leave them in the comments and share as much if you found it helpful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bf7e055029e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/6-tips-for-your-next-flutter-project-1bf7e055029e">6 Tips for Your Next Flutter Project</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Realtime weather app in Flutter — using FutureBuilder]]></title>
            <link>https://medium.com/flutter-community/build-a-realtime-weather-app-in-flutter-using-futurebuilder-90959c47c399?source=rss-d5586c44ae4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/90959c47c399</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Samia Ashraf]]></dc:creator>
            <pubDate>Sun, 24 Jul 2022 18:05:01 GMT</pubDate>
            <atom:updated>2022-09-12T02:57:28.725Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a Realtime weather app in Flutter — using FutureBuilder</h3><p>In this article, we will explore FutureBuilder to build a weather app from realtime data using OpenWeatherMap API that displays weather data for user’s current location as well as any other location. We will also explore how FutureBuilder lets the widget enter different states during the API call.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ESQ-oOw7YDg9jcUqANMToQ.gif" /></figure><p>I will breakdown the different steps to get realtime data from OpenWeatherMap API and display in our app using FutureBuilder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*fcwLWixk10G27dEqiHOM-Q.gif" /></figure><p>The steps include:</p><ol><li>get the <strong>apiKey</strong></li><li>building a simple<strong> UI </strong>using <strong>Stateful</strong> <strong>widget and FutureBuilder</strong>— although you can have full control here and build your own UI</li><li><strong>http</strong> — to make http request to the api</li><li><strong>Get user’s current location</strong>(latitude, longitude) using <a href="https://pub.dev/packages/geolocator"><strong>geolocator</strong></a> package and <a href="https://pub.dev/packages/geocoding"><strong>geocoding</strong></a><strong> </strong>package<strong> </strong>to get the current city of the user</li><li>Using<strong> FutureBuilder</strong> to call the api asynchronously</li><li><a href="https://pub.dev/packages/anim_search_bar"><strong>anim_search_bar</strong></a> to call api with different city names and to add some animation to our app</li></ol><h4>Following is the File Structure of the project:</h4><p><strong>— api_key.dart : </strong>consists of the API key from the OpenWeatherMap api registration.</p><p><strong>— constants.dart :</strong> this file consists of TextStyle constants</p><p>— <strong>models</strong> folder consists of the weather_model</p><p><strong>— call_to_api.dart :</strong> this file has the code for the call to api</p><p><strong>— weather_page.dart :</strong> this file consists of the code for the UI of the project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*qeRisOEXmCDyywcp0f633Q.jpeg" /><figcaption>file structure</figcaption></figure><h4>1. Get the apiKey:</h4><p>Register with your email in <a href="https://home.openweathermap.org/users/sign_in">OpenWeatherMap</a>. Then you will have access to the API key <a href="https://home.openweathermap.org/api_keys">here</a>. You will not have access to the weather data without the API key.</p><p>Once you get the API key, store it in api_key.dart,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*FvHksyrRpoMNmwwiEPelxw.png" /></figure><h4>2. Building simple UI with Stateful widget</h4><p>I have kept the UI very simple with the text widgets representing the data from the API and some background colour gradient to add some interesting element to the screen.</p><p>The UI makes use of FutureBuilder widget,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb8401a443585e5cb29a120471d538bc/href">https://medium.com/media/cb8401a443585e5cb29a120471d538bc/href</a></iframe><p>The above design code yields the following UI,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*oOnJfI_2BkKk5tUAU_MzJw.jpeg" /></figure><h4>3. <strong>http</strong> — to make http request to the api</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7060f9c26a8e979ebfcc47da0a6e57a8/href">https://medium.com/media/7060f9c26a8e979ebfcc47da0a6e57a8/href</a></iframe><p><strong>Uri</strong> class helps to encode and decode different parts of URI(Uniform Resource Identifier) such as the host, scheme, port and so on.</p><p>I have used the https scheme with URI, and therefore have used Uri.https() constructor. The final url looks like this —</p><pre>https://api.openweathermap.org/data/2.5/weather?q=Dubai&amp;units=metric&amp;appid=&#39;your api key&#39;</pre><p>Using the get request from the http package, we will call the api. The response from the api is stored in Response object, and then the response body is decoded.</p><p>The data from api will be converted into WeatherModel object using the WeatherModel.fromMap() method to use later in the view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88ecff6166e7a57c46a5a0db9da63710/href">https://medium.com/media/88ecff6166e7a57c46a5a0db9da63710/href</a></iframe><p>WeatherModel stores the current temperature, city name and the weather description.</p><p>The API call must be enclosed within a try catch block in order to handle errors, either from the API or the user’s device.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe47e78d5389f39554a0130820f86a04/href">https://medium.com/media/fe47e78d5389f39554a0130820f86a04/href</a></iframe><p>In case the API returns error, the control will enter the catch block and return the error with a message.</p><h4>4. <a href="https://pub.dev/packages/geolocator"><strong>geolocator</strong></a> package and <a href="https://pub.dev/packages/geocoding"><strong>geocoding</strong></a> package to get the current location of the user</h4><p>If currentCity is true, then user’s current city is obtained using getCurrentPosition(). The getCurrentPosition() function returns a Position object which contains user’s current position details, including latitude and longitude. Using these values and geocoding package, the user’s current city is obtained and then assigned to the cityName parameter which then calls the api.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0220ad0af5ed25aa15325e63572959e5/href">https://medium.com/media/0220ad0af5ed25aa15325e63572959e5/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ccf17a6cf718a272db88334c495084c/href">https://medium.com/media/8ccf17a6cf718a272db88334c495084c/href</a></iframe><pre>var url = Uri.https(‘api.openweathermap.org’, ‘/data/2.5/weather’,{‘q’: cityName, “units”: “metric”, “appid”: apiKey});</pre><h4>5. Using FutureBuilder to call the api asynchronously</h4><blockquote><strong>FutureBuilder</strong> <strong>—</strong> is a widget which lets you determine the current state of a Future and choose what to show during that state.</blockquote><p>When the widget first builds, <em>initState()</em> function calls getData() function which calls the API to get the data.</p><pre>getData(bool isCurrentCity, String cityName) </pre><p><strong>isCurrentCity — <em>true</em></strong> if api is called using the user’s current city, <strong><em>false</em></strong> when api is called using search text</p><p><strong>cityName — <em>“”</em></strong>(empty string) when location is obtained using geolocator package, otherwise, <strong>search text</strong> is passed</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10ed97c366e811d363f6828a1dea8e67/href">https://medium.com/media/10ed97c366e811d363f6828a1dea8e67/href</a></iframe><p>The function returns WeatherModel.</p><p>The FutureBuilder handles the different states of the app during the api call where it runs into one of the three states:</p><ul><li>waiting state</li><li>connection done state</li><li>error state</li></ul><h4>Waiting state</h4><p>Before calling the api, there will be no data because Future is busy fetching data, so the waiting state is entered. The user will know this when you return <em>CircularProgressIndicatior()</em> indicating that the api call is not complete and that the data is still being fetched.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/662ec503eed371dabf79aec3043413a4/href">https://medium.com/media/662ec503eed371dabf79aec3043413a4/href</a></iframe><h4>Connection done state</h4><p>Once the data is fetched, Future returns data, it is then checked for errors. If error is encountered then appropriate message is displayed. For example, if the city name is incorrect, then it enters <strong>snapshot.hasError</strong> and displays the error message in UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*tw0s8GgO54Zaa6-e5no42A.gif" /></figure><p>If there are no errors, then UI is rebuilt with the data from the API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef69a92f9316c120c6b9992b84aa3a78/href">https://medium.com/media/ef69a92f9316c120c6b9992b84aa3a78/href</a></iframe><h4>6. anim_search_bar to call api with different city names and to add some animation to the app</h4><p>Not only can you search for current location weather data, but you can also search for weather data based on city name.</p><p>I have used a package anim_search_bar to add a search bar that reads the city name and then calls the api when done.</p><p>Once the api is called with search text city name, the Future returns a new WeatherModel and the widget rebuilds with the latest snapshot of Future.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*eGp-2XUzQV2NXW6mIaaYwQ.gif" /></figure><p>I hope you got a basic idea of what FutureBuilders are how it can help you to build apps. It is comparatively easier as it handles various states during api call. Read the <a href="https://api.flutter.dev/flutter/widgets/FutureBuilder-class.html"><em>docs</em></a> to find more information on FutureBuilder.</p><p>You can find the full code on <a href="https://github.com/SamiaAshraff/WeatherCast">https://github.com/SamiaAshraff/WeatherCast</a></p><p>Feel free to leave a comment and share as much if you found it helpful!</p><p>Follow Flutter Community on Twitter: <a href="https://www.twitter.com/FlutterComm">https://www.twitter.com/FlutterComm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90959c47c399" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/build-a-realtime-weather-app-in-flutter-using-futurebuilder-90959c47c399">Build a Realtime weather app in Flutter — using FutureBuilder</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Hook widgets over Stateful widgets — for better app performance]]></title>
            <link>https://levelup.gitconnected.com/flutter-hook-widgets-over-stateful-widgets-for-better-app-performance-938861d5ea94?source=rss-d5586c44ae4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/938861d5ea94</guid>
            <category><![CDATA[hooks-state]]></category>
            <category><![CDATA[hooks]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Samia Ashraf]]></dc:creator>
            <pubDate>Wed, 06 Jul 2022 20:23:12 GMT</pubDate>
            <atom:updated>2022-08-07T21:53:27.116Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter Hook widgets over Stateful widgets for better app performance</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*n-mt2T04ywygGUcxQINwfg.png" /></figure><p>Everything in Flutter is made up of widgets. In this article, we will explore the different types of widgets<em>(Stateless and Stateful)</em>and also look into <em>Hook widgets</em>, an extension to Stateless widgets. We will also explore the differences and see how Hook widgets can be used over Stateful widgets to improve app performance.</p><p><strong><em>What is a widget in Flutter?</em></strong></p><blockquote>Flutter widgets are built using a modern framework that takes inspiration from <a href="https://reactjs.org/">React</a>. The central idea is that you build your UI out of widgets. Widgets describe what their view should look like given their current configuration and state.</blockquote><p>If any action on the UI requires the widget to be rebuilt, then this is where you should use Stateful widget. But if the widget only displays data, and any action on the UI does not need to rebuild the widget, then you can use the Stateless widget.</p><p><strong><em>Stateless widgets</em></strong> are the easy to use widgets and you cannot really do much with them in terms of adding logic, because as the name suggests, they are stateless. Once the UI builds, no action in the UI can trigger a rebuild of the widget.</p><p>But when we talk about <strong><em>Stateful widgets</em></strong>, there’s a lot that happens behind the scenes, any change in the UI triggers the widget to rebuild.</p><p>Let us consider the example of a Counter app,</p><h4>1. Counter app using Stateful widget</h4><p>In this app, I can change the counter value by tapping the “-” and the “+” buttons. Every tap changes the UI and rebuilds the widget to update the value of the counter. I will store the value of the counter and display it in two places in the UI</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*0gIvGEegUfnmB0JArgH6WQ.gif" /></figure><p>The code for the above screen is</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/587da915a70bcf2ef0c3df6670b0c857/href">https://medium.com/media/587da915a70bcf2ef0c3df6670b0c857/href</a></iframe><p>Note that I have heavily used setState wherever I am updating the counter value. This is because I am informing the widget to update the value of the variable and rebuild the widget with the updated value.</p><p>If I do not include setState, then the counter value will get updated but the UI will not be rebuilt as a result of which the UI will not change at all and you will only see the old counter value in the UI.</p><p>While this is a straightforward technique to manage states, stateful widgets may not be an optimal choice when building complex widgets. This is because continuously rebuilding the widgets can bring down the app performance and causes the app to consume lots of resources during rebuild.</p><p>This is when you should consider using Hook widgets, an extension to Stateless widgets.</p><h4>2. Counter app using Hook widgets</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/191/1*MBKItGu9YcaYl0BQw9twPg.jpeg" /></figure><blockquote>Hooks are a new kind of object that manage the life-cycle of a Widget. They exist for one reason: increase the code-sharing <em>between</em> widgets by removing duplicates.</blockquote><p>When using Hooks, we only make use of one class, which makes it easy to maintain the code. The <a href="https://pub.dev/packages/flutter_hooks">flutter_hooks</a> gives us access to list of reusable hooks, some of which include:</p><ul><li><a href="https://pub.dartlang.org/documentation/flutter_hooks/latest/flutter_hooks/useEffect.html"><strong>useEffect</strong></a><strong> —</strong> <em>Useful for side-effects and optionally canceling them.</em></li><li><a href="https://pub.dartlang.org/documentation/flutter_hooks/latest/flutter_hooks/useState.html"><strong>useState</strong></a> <strong>—</strong><em> Creates a variable and subscribes to it.</em></li><li><a href="https://pub.dartlang.org/documentation/flutter_hooks/latest/flutter_hooks/useMemoized.html"><strong>useMemoized</strong></a><strong> —</strong> <em>Caches the instance of a complex object.</em></li><li><a href="https://pub.dartlang.org/documentation/flutter_hooks/latest/flutter_hooks/useAnimationController.html"><strong>useAnimationController</strong></a><strong> — </strong><em>Creates an </em><em>AnimationController which will be automatically disposed.</em></li><li><a href="https://pub.dev/documentation/flutter_hooks/latest/flutter_hooks/useTextEditingController-constant.html"><strong>useTextEditingController</strong></a><strong> — </strong><em>Creates a </em><em>TextEditingController.</em></li><li><a href="https://pub.dartlang.org/documentation/flutter_hooks/latest/flutter_hooks/useTabController.html"><strong>useTabController</strong></a><strong> — </strong><em>Creates and disposes a </em><em>TabController.</em></li></ul><p>For the same counter example, when we use Hooks, the app runs in the same manner. However, the main difference is that we will be using the useState<em> </em>hook for the counter variable which ensures that any change in the UI will be notified.</p><pre>final count = useState(0);</pre><ul><li>the <strong>count</strong> variable is an instance of <strong>ValueNotifier</strong>.</li><li><strong>useState</strong> — hook</li><li><strong>0</strong> — initialData</li></ul><p>To access the value of the variable count, use count.value</p><blockquote>Whenever <strong>ValueNotifier.value</strong> updates, it will mark the caller HookWidget as needing a build. On the first call, it initializes <a href="https://api.flutter.dev/flutter/foundation/ValueNotifier-class.html">ValueNotifier</a> to initialData. initialData is ignored on subsequent calls.</blockquote><p>When the Hook widget renders for the first time, the ValueNotifier is set to initialData , as the value changes, the subsequent calls will use the updated value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*tqS7qLnqTIyMgC2ejAPaEw.gif" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1b114b248d284f4be5b936d52ac88f9/href">https://medium.com/media/a1b114b248d284f4be5b936d52ac88f9/href</a></iframe><p>In the above widget, the count value initially is set to 0, which comes from the initialData that was set when initializing the hook. As the counter keeps updating, the ValueNotifier.value<strong>(count)</strong> changes and the widget rebuilds.</p><blockquote>During the rebuild, the impact of performance is negligible since hooks allow you to remove the need for initState, dispose and setState, as everything related to the state is initialized with the hook functions in the build method.</blockquote><h4>useEffect()</h4><p>To load data during the initState of a widget, or to dispose data, we use useEffect() hook.</p><p>Just like initState and dispose, <strong><em>useEffect()</em></strong> will be</p><ul><li>only called once during the lifetime of the widget,</li><li>the return statement will be executed when the widget is disposed,</li><li>the const [] means that until the widget is not disposed, don’t call the effect. There can be a list of parameters, and when one of the parameters change, the useEffect will call the callback again.</li></ul><p>Below is the code for Timer with Hook widget:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9effc2051a327c4a5b83f66f37fd45f8/href">https://medium.com/media/9effc2051a327c4a5b83f66f37fd45f8/href</a></iframe><p>Below is the code for Timer with Stateful widget:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2ad329955ecbe9ef452824464e9dff1/href">https://medium.com/media/e2ad329955ecbe9ef452824464e9dff1/href</a></iframe><p>Hooks are an easy way to maintain simple logic and I have used it in most of my projects. It avoids complex logic and promotes better app performance. If you wish to learn more about hooks, Flutter docs provide plenty of resources at <a href="https://pub.dev/packages/flutter_hooks">https://pub.dev/packages/flutter_hooks</a></p><p>Feel free to leave a comment and share as much if you found it helpful!</p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=938861d5ea94" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/flutter-hook-widgets-over-stateful-widgets-for-better-app-performance-938861d5ea94">Flutter Hook widgets over Stateful widgets — for better app performance</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build better games with Flutter Casual Games Toolkit — a Google I/O ’22 update]]></title>
            <link>https://samiaashraf.medium.com/build-better-games-with-flutter-casual-games-toolkit-a-google-i-o-22-update-cd3d39bda371?source=rss-d5586c44ae4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd3d39bda371</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[flutter-game]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Samia Ashraf]]></dc:creator>
            <pubDate>Sat, 02 Jul 2022 04:49:27 GMT</pubDate>
            <atom:updated>2022-08-07T07:47:06.878Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Build better games with Flutter Casual Games Toolkit — a Google I/O ’22 update</strong></h3><p>This years Google I/O event was just as exciting as the previous ones. With so many new devices and updates to talk about, I am particularly interested in the Casual Games Toolkit that was introduced to provide resources to game developers to build beautiful, complex games.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OXXU8rOQtZe8rxQN" /></figure><p>As we all know, Flutter is an open source platform for app development where you can build mobile, web, desktop and embedded apps, and it is now having an increase in popularity towards game development.</p><p>One of the challenges faced by Flutter game developers that Google is trying their best to tackle is — lack of resources for building Flutter games.</p><p>If you try to google flutter games, the resources you will find are limited. And it is actually true because Game Development was never really an official use case until Google I/O ‘22. So that’s why this year’s I/O update is big for game developers and also to flutter developers that are planning to start with building games.</p><p>One very common question that game developers often get asked is <strong>“<em>why flutter for games?”</em></strong></p><p>A study was conducted on Fluter developers who had released Flutter games and they shared their experience which said that:</p><p><strong><em>1. Flutter is simple to learn and easy to use , especially if it was a casual game, building UI was a lot simpler</em></strong></p><p>So if you compare Flutter with other game development softwares, building the UI could be faster and could save up a lot of time as you can reuse the widgets.</p><p><strong><em>2. Ability to look into the framework source code (no “black boxes”) and have full control of the canvas</em></strong></p><p><strong><em>3. The ability to design a widget and then reuse it in other parts of the game, which ensured data persistence</em></strong></p><p><strong><em>4. Some developers consider Flutter’s audio capabilities superior to other cross-platform UI toolkits</em></strong></p><p>And thats because the audio integration is one such feature that Google is trying to improve in every update</p><p><strong><em>5. Flutter is portable — you write your code once and the game runs on multiple platforms</em></strong></p><p>So that was some of the feedback shared by the flutter game developers.</p><h4>Community contributions</h4><p>There are multiple games that were built using Flutter such as <strong>4 pics 1 word</strong>, <strong>Kelimelik</strong> etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*HYM-WpFpOaUc6UtO13Hw3Q.png" /></figure><p><strong><em>Flame, </em></strong>by definition<strong><em> </em></strong>is a minimalist 2D game engine built on top of Flutter — a library of solutions to tackle problems that arise during game development.</p><p><em>Flame</em> offers features such as animations, physics, collision detection, and more. A package that can be used to build games that require high level features.</p><p>For example, if you’re building an action-based game, you can use the flame package, <em>forge2d</em> to control the physics of the game.</p><h4>Types of games in Flutter:</h4><p>Games in Flutter can be classified into roughly two types:</p><ol><li><strong><em>App-like</em> games</strong> include casual games such as board games, card games, puzzles, and strategy games.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/0*5UrwwQPSteKCbvci" /><figcaption>courtesy: flutterflow.com</figcaption></figure><p>— these kind of games respond to a user input, which can be a screen tap or a text input</p><p>— so you will see in the video here, every time the screen is tapped, the game is responding to that tap</p><p>2.<strong><em> Video games</em> </strong>include arcade-style games that include shooters, racing games, and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*_yMVevypi0evdp7rNEnyfA.gif" /><figcaption>courtesy: github.com</figcaption></figure><p>— these are action based and they require a continuous input device, like a joystick</p><p>— such games require high level animations, collision detection, and so on, which can be achieved by using packages like <strong>flame</strong>.</p><blockquote>You might want to explore and plan every module ahead of building the game by exploring all the features that flame offers</blockquote><h4>Casual Games Toolkit</h4><p>With that let’s look at what is Casual Games Toolkit, and why did Google decide to add it as an update in this years list of I/O updates</p><ol><li>A growing community of developers use Flutter for casual game development, by taking advantage of the hardware-accelerated graphics support that Flutter provides.</li><li>Flutter becomes a great choice for user interaction games such as puzzles and word games</li><li>For games that use game loop, <em>Flame</em> can be a helpful tool</li></ol><p>So even if you want to build simple games, you can use flutter as it is a great choice, and for complex games, <em>flame</em> packages can be used to achieve the high level features.</p><p>So no matter what type of game you’re building, you can always consider Flutter to be a good option.</p><p>4. Casual Games Toolkit can be considered as a resource provided by google for the game developers, almost like a reference</p><p>Now let us now look at what is included in Casual Games Toolkit and how it is going to help game developers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GDXBjpWYsVTGOAwLuBH7gQ.png" /></figure><p>So google used the existing resources along with the new ones to speed up game development of casual games in flutter — <strong>click on Get the template to get a repository of resources with a detailed Readme file that explains how to integrate the features into your game</strong></p><ol><li>comes with a full repository for the underlying code to help developers see how it was accomplished</li><li>The game template app includes the following in-built features:</li></ol><p>— main menu</p><p>— sound &amp; music</p><p>— ads</p><p>— in-app purchases</p><p>— achievements and leader boards</p><p>— crashlytics support</p><p>4. The template is open source</p><p>5. And you can use the repository to make changes as per your game requirements</p><p>6. This repo has a working game that you can use as a reference for your next game, it has state management and also audio integration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/0*E977DlT-EE9exxIe" /></figure><h4>Google I/O Pinball</h4><ol><li>Google I/O pinball is a Flutter web game that was launched ahead of the I/O event ‘22</li><li>It works on any platform that has a browser</li><li>It also uses firebase as the hosting platform and also to track the high score of the player</li><li>The source code is available, you can use it as a starter project for your next big game!</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*xG6h_mIiyvIM96YQfpva0A.png" /><figcaption>courtesy: medium.com/vgv_team</figcaption></figure><p>You can take the existing features and add those to your game to build your own game! This game is an example that you can create such powerful games with Flutter.</p><p>The game uses <em>Flame</em> package and it’s out of the box features to make the game running, some of those packages include:</p><ol><li><strong><em>forge2d</em></strong>: a package for collision detection between game objects. Also to power the physics of the game</li><li><strong><em>flame_bloc</em></strong> : a package that bridges blocs with flame components. flame_bloc to keep track of the number of rounds left to play, any bonuses achieved through the game, as well as the current game score.</li></ol><blockquote>The game is available to play at : <a href="https://pinball.flutter.dev/">https://pinball.flutter.dev/</a></blockquote><p>By now, you should have an idea of what the Casual Games Toolkit contains and how it can speed up the game development, especially for simpler games. This could be the start of building greater games in Flutter and I hope you’re equally excited for that!</p><p>If you wish to learn more about games, Flutter docs provide plenty of resources at <a href="https://docs.flutter.dev/resources/games-toolkit">https://docs.flutter.dev/resources/games-toolkit</a></p><p><em>Also, you can find my talk on this topic at </em><a href="https://youtu.be/qZtqMujsE3I"><strong><em>https://youtu.be/qZtqMujsE3I</em></strong></a></p><h4>Some of the resources that helped me write this article:</h4><ol><li>Perspectives from early adopters of Flutter as a game development tool — @taodong</li></ol><p>— <a href="https://medium.com/flutter/perspectives-from-early-adopters-of-flutter-as-a-game-development-tool-f95fb3406d51">https://medium.com/flutter/perspectives-from-early-adopters-of-flutter-as-a-game-development-tool-f95fb3406d51</a></p><p>2. Announcing the Flutter Casual Games Toolkit — @zoeyfan_43394</p><p>— <a href="https://medium.com/flutter/announcing-the-flutter-casual-games-toolkit-c22e401d8fee">https://medium.com/flutter/announcing-the-flutter-casual-games-toolkit-c22e401d8fee</a></p><p>3. I/O Pinball Powered by Flutter and Firebase — @vgv_team</p><p>— <a href="https://medium.com/flutter/i-o-pinball-powered-by-flutter-and-firebase-d22423f3f5d">https://medium.com/flutter/i-o-pinball-powered-by-flutter-and-firebase-d22423f3f5d</a></p><p>Feel free to leave a comment and share as much if you found it helpful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd3d39bda371" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancing Flutter apps with Animations]]></title>
            <link>https://medium.com/flutter-community/enhancing-flutter-apps-with-animations-28c1c6d0de80?source=rss-d5586c44ae4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/28c1c6d0de80</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-animation]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <dc:creator><![CDATA[Samia Ashraf]]></dc:creator>
            <pubDate>Mon, 20 Jun 2022 16:45:42 GMT</pubDate>
            <atom:updated>2022-06-22T23:29:01.728Z</atom:updated>
            <content:encoded><![CDATA[<p>Animations in simplest words are visual elements that add up to enhance the user’s experience using an app. Apps with animations keeps the user more engaged and can also attract new users as they tend to be more informative and visually appealing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*caPACZ9VAbHBzAQrt997vQ.gif" /></figure><h4>Animations in Flutter can be classified into two types:</h4><ol><li>code based — animations here are written in code</li><li>drawing based — animations are first drawn, and then animated but without code</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tt7shF1QT5_EchsK" /></figure><h3><strong>Code based animations:</strong></h3><p>As the name suggests, here, the animations are written in code. In the screen image below, the containers when clicked upon have a certain bounce effect. This effect was achieved by adding animation code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/0*CFq-MYgMCbwM-w3i" /></figure><p>This type of animation can be performed on existing widgets like container, stack, row, column, etc and styles like color, textStyle, etc.</p><p><strong>Types</strong></p><ul><li>Implicit animation — <em>for simpler animations</em></li><li>Explicit animation — <em>gives user the control to control the animation</em></li></ul><h4>Implicit animations:</h4><p>This type of animation is preferred when you want to add simple animations, for example, changing the size and color of the container. However, once animated, you cannot go back to the original position. Hence, the user has no control over the animation once animated.</p><p>a.<strong> Built-in implicit animations</strong> — also called as AnimatedFoo widgets, they are animated versions of the flutter widgets where Foo are the flutter widgets. Some AnimatedFoo widgets can commonly be:</p><ul><li><a href="https://api.flutter.dev/flutter/widgets/AnimatedContainer-class.html">AnimatedContainer</a></li><li><a href="https://api.flutter.dev/flutter/widgets/AnimatedAlign-class.html">AnimatedAlign</a></li><li><a href="https://api.flutter.dev/flutter/widgets/AnimatedOpacity-class.html">AnimatedOpacity</a></li><li><a href="https://api.flutter.dev/flutter/widgets/AnimatedPositioned-class.html">AnimatedPositioned</a></li></ul><p>Target value can be set and the widget animates from old value to target value in the given duration. Comparatively easier as you only have to set the target value and the rest of the work is done by Flutter.</p><p>Only supports animations that can go forward. If you want to reverse the animation, or repeat the animation forever, then you have to use <strong>Explicit animation</strong></p><figure><img alt="Implicit animation example" src="https://cdn-images-1.medium.com/max/270/0*KZdF3MFM-SibP6MM" /></figure><p>In the screen image above, once the button is clicked, random size is generated using Random() and it is assigned to the width and height of the AnimatedContainer, the color is also randomly generated.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53e12d347cd5ed36e547ab013ec08310/href">https://medium.com/media/53e12d347cd5ed36e547ab013ec08310/href</a></iframe><p>As for the AnimatedContainer, the size and the color change with every button click.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96f821adc98ecd7049041b792bb11d83/href">https://medium.com/media/96f821adc98ecd7049041b792bb11d83/href</a></iframe><p>However, with this type of animation you will notice that there is no way to go back to the starting position of the AnimatedContainer.</p><p>b.<strong> Custom implicit animations</strong> — using Tweens and TweenAnimationBuilder. Tween simply means “in-between”. Tween object allows you to specify a range of values to animate between.</p><p>TweenAnimationBuilder returns the animated widget at any given point in time.</p><p>Let’s take the example of a slider, every time the value changes, the slider will change. We can add animation to such widgets using Tween class. It basically adds animation between a start and an end value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/0*TUTH00EIVEa6KnDk" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0bb6bd52b6c8a33f2292b035301c88f9/href">https://medium.com/media/0bb6bd52b6c8a33f2292b035301c88f9/href</a></iframe><p>The builder takes context, value and a child. The value here is the new value that was generated when the slider was updated.</p><p>And because the widget needs to be rebuilt every time the slider value changes, the TweenAnimationBuilder rebuilds the widget.</p><h4>Explicit animations:</h4><p>We saw earlier in implicit animation that once the animation occurs you can never go back to the original state from where you started, and that is because implicit animations are one way. You cannot reverse or repeat the animation.</p><p>But sometimes you might want to reverse/repeat the animation, then we can use explicit animations. Here, the user can control the state of the animation, using <strong>AnimationController.</strong></p><p><strong>AnimationController</strong> class requires</p><ul><li>SingleTickerProviderStateMixin</li><li>vsync</li></ul><p>that tells Flutter that there is some animation in this widget and this widget needs to be notified about the animation frames of flutter.</p><p>If the widget uses more than one controller, then you should be using TickerProviderStateMixin.</p><p>It is always a best practice to dispose the controller using the <em>dispose()</em> method to avoid memory leaks.</p><p>You must be thinking how do we control the animation using AnimationController?</p><p><strong><em>AnimationController</em></strong> provides several methods for “driving” an animation:</p><ul><li><strong>repeat() —</strong> <em>starts and finishes the animation and then repeats itself</em></li><li><strong>forward() </strong>— <em>starts and waits till the animation finishes and then stops</em></li><li><strong>reverse() — </strong><em>starts and when reverse is applied, stops at the current state and reverses the animation till it stops, does not repeat</em></li><li><strong>stop()</strong> — <em>stops</em> <em>at current state</em></li><li><strong>reset()</strong> <em>— stops at current state and resets</em></li></ul><p>They are an extension of <em>AnimatedWidget.</em></p><p>They are also called as FooTransition widgets, where Foo is the Flutter widget that will be animated. Some common FooTransition widgets are:</p><ul><li><strong>FadeTransition</strong></li><li><strong>RotationTransition</strong></li><li><strong>PositionedTransition</strong></li><li><strong>SlideTransition</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/0*StEAKw8kEJZP5uBl" /></figure><p>The above screen image has a container that fades when the different buttons are clicked.</p><p>When the <strong>Start</strong> button is clicked, the container starts animating where it fades, once it completely fades, it resets the animation.</p><p>When the <strong>Pause</strong> button is clicked, the container pauses the animation at the current state.</p><p>When the <strong>Stop</strong> button is clicked, the container stops the animation at the current state.</p><p>Simply wrap the Container with the FooTransition widget(here, <em>FadeTransition</em>) and provide the duration of animation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0905c6d0acb8436c5766222df44c2fc7/href">https://medium.com/media/0905c6d0acb8436c5766222df44c2fc7/href</a></iframe><h3>Drawing based animations:</h3><p>Sometimes we prefer to use animations that are drawn and do not require coding, in such situations we can import these files using third party package, like</p><ul><li><strong>Lottie — </strong><a href="https://lottiefiles.com/featured"><em>https://lottiefiles.com/featured</em></a></li><li><strong>Rive —</strong> <a href="https://rive.app/community/"><em>https://rive.app/community/</em></a></li></ul><p>There are two ways to use these types of animations:</p><ol><li>Download the animation file and place it in assets folder, and declare the folder in pubspec.yaml and use it like this:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ae1a025d23fdab1897db76517b6ddad/href">https://medium.com/media/9ae1a025d23fdab1897db76517b6ddad/href</a></iframe><p>2. Use the url of the file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fc7d62153fc9e8815f2c35288e2e393/href">https://medium.com/media/5fc7d62153fc9e8815f2c35288e2e393/href</a></iframe><p>They provide high-level animations, something which is difficult to code, and they are extremely easy to import in flutter apps.</p><p>By now, you should at least have an idea of what animations are and why it is better to have them in apps. If you wish to learn more about animations, Flutter docs provide plenty of resources at <a href="https://docs.flutter.dev/development/ui/animations">https://docs.flutter.dev/development/ui/animations</a></p><p><em>Also, you can find my talk on this topic at </em><a href="https://youtu.be/-9kVd6tsyyo"><strong><em>https://youtu.be/-9kVd6tsyyo</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*xEOghXGj7qsVTfL_te4OEw.gif" /><figcaption>courtesy: c.tenor.com</figcaption></figure><p>Feel free to leave a comment and share as much if you found it helpful!</p><p>Follow Flutter Community on Twitter: <a href="https://www.twitter.com/FlutterComm">https://www.twitter.com/FlutterComm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28c1c6d0de80" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/enhancing-flutter-apps-with-animations-28c1c6d0de80">Enhancing Flutter apps with Animations</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FlutterFire UI — Simplifying Social Logins in Flutter]]></title>
            <link>https://medium.com/flutter-community/flutterfire-ui-simplifying-social-logins-in-flutter-27cc0f17890a?source=rss-d5586c44ae4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/27cc0f17890a</guid>
            <dc:creator><![CDATA[Samia Ashraf]]></dc:creator>
            <pubDate>Sat, 23 Apr 2022 07:53:07 GMT</pubDate>
            <atom:updated>2022-05-01T01:16:24.097Z</atom:updated>
            <content:encoded><![CDATA[<h3>FlutterFire UI — Simplifying Social Logins in Flutter</h3><p>Social authentication is a multi-step authentication flow, allowing you to sign a user into an account or link them with an existing one.</p><p>With mobile apps emerging everyday more than ever, apps with social logins have skyrocketed. Social logins ease the user experience in apps by avoiding extra steps of authentication.</p><p>What is FlutterFire UI and how is it different?</p><blockquote>FlutterFire UI for Auth provides a simple and easy way to implement authentication in your Flutter app. The library provides fully featured UI screens to drop into new or existing applications, along with lower level implementation details for developers looking for tighter control.</blockquote><p>FlutterFire UI provides ready to use UI for Login, Signup and Forgot password.</p><h3>Steps:</h3><ol><li>Create a new project and run the following command:</li></ol><pre>curl -sL https://firebase.tools | bash</pre><p>This command installs Firebase CLI which is used to run firebase commands from the project terminal.</p><p>2. Add <a href="https://pub.dev/packages/flutterfire_ui">flutterfire_ui</a> to <em>pubspec.yaml, </em>a package with widgets and utilities designed to help you build and integrate your user interface with Firebase.</p><pre>flutter pub add flutterfire_ui</pre><p>3. Now that the dependency is installed, let&#39;s activate the FlutterFireCLI</p><pre>dart pub global activate flutterfire_cli</pre><p>which gives you a warning with a string, we can either add it along with other path variables for use in future projects or simply run in terminal for this particular project.</p><p>4. Next step is to either create a new Firebase project or select an existing one. Run the following command:</p><pre>flutterfire configure</pre><p>In case you&#39;re not logged in to firebase, you can run firebase login which will then ask you to authenticate. Make sure to follow step 3 after login.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*X6MVV8wwjmrlNGTGixq1mQ.png" /></figure><p>5. Let&#39;s create a new project and call it flutterfireuiauth, make sure to follow the naming convention(no underscore).</p><p>Let&#39;s enable the social logins on android, ios and web platforms. Next, you will be asked to enter the ios bundle ID, enter the one you prefer. There is no such configurations at this step for android and web platforms.</p><p>Once the files are created, click yes to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EL7PfsUv8AiKP3yMN-Arxg.png" /><figcaption>flutter configure command</figcaption></figure><p>6. After few seconds, the project will be created. Navigate to the firebase dashboard to see the project and the platform configurations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*ec6uUfc-1jMdP66GHInmRA.jpeg" /></figure><p>7. That completes all the initial steps and we can finally start coding! In <strong><em>main.dart, </em></strong>initialise Firebase by adding the following code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/695c2d97d5f7996e5dd43c6a8d395c94/href">https://medium.com/media/695c2d97d5f7996e5dd43c6a8d395c94/href</a></iframe><p>Import firebase_core package. Remove the default MyHomePage widget and create a new widget called <em>AuthGate</em> such that MyApp returns <em>AuthGate()</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/666a4c5319e60cf58b2f19a1a7386c78/href">https://medium.com/media/666a4c5319e60cf58b2f19a1a7386c78/href</a></iframe><p>8. The AuthGate() is a stateless widget that is used to check the state of the user. It returns Stream of User object (from Firebase Auth package) which tells if a user is logged in or not.</p><p>The authStateChanges API returns a Stream with either the current user (if they are signed in), or null if they are not.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7dca42cf99bae03af3309fc1b128267/href">https://medium.com/media/e7dca42cf99bae03af3309fc1b128267/href</a></iframe><p>If the user is logged in, the snapshot will contain the User instance, or null if the user is not logged in. The snapshot.hasData property can be checked to take the user to SignInScreen in case they are not logged in.</p><pre>builder: (context, snapshot) {</pre><pre><em>// User is not signed in</em></pre><pre><em>if</em> (!snapshot.hasData) {</pre><pre><em>// ...</em></pre><pre>}</pre><pre><em>// Render your application if authenticated</em></pre><pre><em>return</em> HomeScreen();</pre><pre>},</pre><p>9. FlutterFire UI for Auth currently supports the following providers:</p><ul><li><a href="https://firebase.flutter.dev/docs/ui/auth/configuring-providers/#email">Email/Password</a></li><li><a href="https://firebase.flutter.dev/docs/ui/auth/configuring-providers/#email-link">Email link</a></li><li><a href="https://firebase.flutter.dev/docs/ui/auth/configuring-providers/#phone-number">Phone Number</a></li><li><a href="https://firebase.flutter.dev/docs/ui/auth/configuring-providers/#google">Google</a></li><li><a href="https://firebase.flutter.dev/docs/ui/auth/configuring-providers/#facebook">Facebook</a></li><li><a href="https://firebase.flutter.dev/docs/ui/auth/configuring-providers/#twitter">Twitter</a></li><li><a href="https://firebase.flutter.dev/docs/ui/auth/configuring-providers/#apple">Apple</a></li></ul><p>but in this article, I will explain about the <strong>email/password</strong> provider and <strong>Google SignIn</strong>. I will include the others in a future article.</p><h3>Email/Password Provider</h3><ol><li>Let us start by implementing the EmailProvider, edit the providerConfigs parameter of SignInScreen by providing the EmailProvider</li></ol><pre>providerConfigs: [EmailProviderConfiguration()],</pre><p><strong><em>For android:</em></strong> In [project-name]/android/app/build.gradle, I had to change minSdkVersion to 19 and enable the multiDexEnabled</p><pre>minSdkVersion 19</pre><pre>multiDexEnabled true</pre><p><strong>Hot restart</strong> the app and you should now see Sign In Screen which also takes you to Register screen and Forgot Password screen as well.</p><p>2. In order to start using the authentication service, let&#39;s first enable the Email provider in firebase</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J3Su2sW1dPynrGM-Io82tA.png" /></figure><p>Your app should now open to a Sign in screen by default.</p><p>This is the code to my HomeScreen(), a Stateless widget that also contains the SignOutButton.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54d0bafc7734849c0e2fcd11143a0c2e/href">https://medium.com/media/54d0bafc7734849c0e2fcd11143a0c2e/href</a></iframe><p>Let us begin by registering a user,</p><h4><strong>Register:</strong></h4><p>Enter the credentials for the new user and upon successful registration the user is taken to the HomeScreen()</p><p>The user will be recorded in the list of users tab in Firebase</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*4zzlNJ-nyuw_c3OLRRQ2uQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kdcfq8ZKgMWYiYrbLMDasQ.png" /></figure><h4>Login:</h4><p>Enter the registered user credentials and and upon successful authentication the user is taken to the HomeScreen()</p><p>Upon clicking the SignOutButton the user will be taken back to the SignInScreen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*3Nu4f52WSTpXzYfcEFNzHA.gif" /></figure><p>In order to access User credentials, we can pass the snapshot.data which contains user information to the HomeScreen()</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c9e6d1de6fa3a2abf54691054742578/href">https://medium.com/media/1c9e6d1de6fa3a2abf54691054742578/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*2h-p41g4KVhKTn1DiV5DhQ.png" /></figure><p>This is how we can implement the Email/Password authentication using FlutterFire UI.</p><h3>Google Provider</h3><ol><li>In order to support Google as a provider, we need to first install the official <a href="https://pub.dev/packages/google_sign_in">google_sign_in</a> plugin, also, follow the iOS integration for the plugin which requires the <em>GoogleService-Info.plist</em> file to be downloaded from Firebase under the iOS app and paste the code into Info.plist.</li><li>Enable Google Provider in Firebase</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jw0LMMFN11Ip2Z3NpsAxqw.png" /></figure><p>3. Drag and drop the <em>GoogleService-Info.plist</em> file to [project-name]/ios/Runner folder.</p><p>4. Copy the <strong>CLIENT_ID</strong> string and paste it in AuthGate() as <em>clientId</em> parameter and also replace the <strong>REVERSED_CLIENT_ID</strong> that was added in Info.plist in previous step.</p><p><strong><em>Stop the app completely and run again.</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69843d01cf1835455bc30935c6d82ee7/href">https://medium.com/media/69843d01cf1835455bc30935c6d82ee7/href</a></iframe><p>3. At this point, the iOS app should run perfectly fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*T_Bh3kLMjYTC0ZTQDmH-Vg.gif" /></figure><p>As for android, the next step is crucial, if you skip the next step, you will get an error in the UI saying <strong><em>“An unknown error occurred”</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*NN9AHH7gcJzVxoMNWV-a-g.jpeg" /></figure><p>The additional step for android is <strong>adding</strong> <strong>SHA keys</strong>. Get the project’s SHA keys by running the following command in terminal:</p><pre>keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android</pre><p>Add the SHA keys in Firebase under android app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*qPztZRKg4O-EYYmimLOwMA.jpeg" /></figure><p><strong><em>Stop the app completely and run again.</em></strong></p><p>The android app should also run perfectly fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*VWJTCOn92hhgIkCyyIJD2A.gif" /></figure><p>And that is how we can configure <strong>Email</strong> and <strong>Google</strong> social login with the aid of <strong>FlutterFire UI</strong>. This is an excellent package when you don’t want to spend more time and effort on the social authentication part of your app.</p><blockquote>Please note that as of 18th April, 2022, FlutterFire UI is still in beta and is subject to change.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*FNlqe79ghW3-UTOFH3LQPQ.gif" /><figcaption>courtesy: imgur.com</figcaption></figure><p>Feel free to leave a comment and share as much if you found it helpful!</p><p><a href="https://twitter.com/FlutterComm">https://twitter.com/FlutterComm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27cc0f17890a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/flutterfire-ui-simplifying-social-logins-in-flutter-27cc0f17890a">FlutterFire UI — Simplifying Social Logins in Flutter</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Carousel Slider Sliding in opposite directions]]></title>
            <link>https://samiaashraf.medium.com/carousel-slider-sliding-in-opposite-directions-c9857a50fce?source=rss-d5586c44ae4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9857a50fce</guid>
            <dc:creator><![CDATA[Samia Ashraf]]></dc:creator>
            <pubDate>Fri, 08 Apr 2022 05:42:07 GMT</pubDate>
            <atom:updated>2022-04-08T05:42:07.579Z</atom:updated>
            <content:encoded><![CDATA[<p>Widgets is one of Flutter&#39;s best features. Safe to say that almost every functionality has a widget related to it in Flutter. One such widget is <a href="https://pub.dev/packages/carousel_slider">carousel_slider</a>, one of Flutter&#39;s most used widgets.</p><p>Carousel Slider is a feature that most of the social media apps possess. It makes viewing multiple multimedia files easy, swiping left and right to change the files.</p><p>In this article, I will use the carousel_slider package and implement a design that I found is worth sharing. Follow along with the steps to create the design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*SwvMupPb7Vt7xtjk2JClnA.gif" /></figure><h3><strong>Steps to create Carousel Sliders sliding in opposite directions:</strong></h3><ol><li>Import the <a href="https://pub.dev/packages/carousel_slider">carousel_slider</a> package.</li></ol><pre>flutter pub add carousel_slider</pre><p>Then, run the command</p><pre>flutter pub get</pre><p>2. Once the package is installed, let&#39;s start with the design.</p><p>The below code is for carousel slider in one direction, here, left to right.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06ca4ba53c24b271438d8cf5d0054333/href">https://medium.com/media/06ca4ba53c24b271438d8cf5d0054333/href</a></iframe><p>For the second carousel, the code will remain same, but there will be an additional parameter ,</p><pre>reverse: true,</pre><p>This will ensure that one carousel slider moves in one direction, while the other will move in opposite direction.</p><p>Alternatively, you can modify the code like below if you want the scrolling to be user controlled,</p><pre>autoPlay: false,</pre><p>3. The <strong>autoPlay</strong> parameter when set to <strong>true</strong> moves the slides automatically without user interaction.</p><p>The autoPlayInterval sets the duration between slides transition.</p><blockquote>Duration(seconds: 5) — 5 seconds between slides transition.</blockquote><blockquote>Duration(milliseconds: 10), 10 milliseconds between slides transition.</blockquote><pre>autoPlay: true, autoPlayInterval: Duration(seconds: 5),</pre><p>This design idea can be used in number of places, social media apps to display multiple images, e-commerce app to display campaigns, etc.</p><p>Feel free to leave a comment! Do you know of any such designs using Carousel Slider?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9857a50fce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigation in Flutter using AutoRoute, injectable and getIt]]></title>
            <link>https://medium.com/flutter-community/navigation-in-flutter-using-autoroute-injectable-and-getit-3f7efb09d342?source=rss-d5586c44ae4a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f7efb09d342</guid>
            <dc:creator><![CDATA[Samia Ashraf]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 18:12:07 GMT</pubDate>
            <atom:updated>2022-05-01T01:24:02.482Z</atom:updated>
            <content:encoded><![CDATA[<p>Navigation in Flutter is a vast topic with everyone having a different opinion on how to ace it. I’ve also explored few articles and tutorials and each one stands out on its own, but this one method of Navigation makes routing a lot simpler in complex apps.</p><p>It maybe because I am used to it, but I always keep going back to this particular method and in this article I want to share the details step by step. The process is broken down into 12 different steps, and every step here is crucial.</p><p>This article explains Navigation in Flutter using <a href="https://pub.dev/packages/auto_route"><strong><em>auto_route</em></strong></a>, <a href="https://pub.dev/packages/injectable"><strong><em>injectable</em></strong></a>, and <a href="https://pub.dev/packages/get_it"><strong><em>get_it</em></strong></a><strong><em> </em></strong>packages<strong><em>. </em></strong>Combination of these packages simplify Navigation in Flutter with little boilerplate code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*v5tVH3d-YFsC0YWz3h4syg.gif" /></figure><p><strong>Why should you use this method?</strong></p><p>If your App requires deep-linking or guarded routes or just a clean routing setup you’ll need to use named/generated routes and you’ll end up writing a lot of boilerplate code for mediator argument classes, checking for required arguments, extracting arguments and a bunch of other stuff. AutoRoute does all that for you and much more.</p><p><strong>Steps to create a new Route using Auto Route, injectable and getIt :</strong></p><ol><li>First things first, there is a list of packages we need to import before going to Step2,<br> — <a href="https://pub.dev/packages/freezed_annotation"><em>freezed_annotation</em></a><br> — <a href="https://pub.dev/packages/auto_route"><em>auto_route</em></a><br> — <a href="https://pub.dev/packages/get_it"><em>get_it</em></a><br> — <a href="https://pub.dev/packages/injectable"><em>injectable</em></a></li><li>Next step is to import some dev_dependencies:<br> — <a href="https://pub.dev/packages/freezed"><em>freezed</em></a><br> — <a href="https://pub.dev/packages/build_runner"><em>build_runner</em></a><br> — <a href="https://pub.dev/packages/injectable_generator"><em>injectable_generator</em></a><br> — <a href="https://pub.dev/packages/auto_route_generator"><em>auto_route_generator</em></a></li><li>Now that we have imported dependencies as well as dev_dependencies, create 2 simple widgets, HomePage() and DashboardScreen().</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21688833e375e09d540915d0b0746098/href">https://medium.com/media/21688833e375e09d540915d0b0746098/href</a></iframe><p>Similarly, create DashboardScreen().</p><p>4. Next, create a new file <strong>injection.dart </strong>and add the following code,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dd1d48215381cfc1a78997a6f94387e/href">https://medium.com/media/1dd1d48215381cfc1a78997a6f94387e/href</a></iframe><p>Through this, any call to instance in any package of a project will get the same instance of GetIt.</p><blockquote>Once the code is added, run the flutter command in the terminal:</blockquote><blockquote><strong>flutter pub run build_runner build — delete-conflicting-outputs</strong></blockquote><p><strong>5. Create a new file and call it <em>router.dart</em> and register the two newly created widgets:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfc665ee91ede68b3d41ba99c7955728/href">https://medium.com/media/cfc665ee91ede68b3d41ba99c7955728/href</a></iframe><p><strong>AutoRoute</strong> — It’s a Flutter navigation package, it allows for strongly-typed arguments passing, effortless deep-linking and it uses code generation to simplify routes setup, with that being said it requires a minimal amount of code to generate everything needed for navigation inside of your App.</p><p>In Step 6 and Step 7, we will discuss the parameters of AutoRoute.</p><blockquote>After registering the routes, run the flutter command:</blockquote><blockquote><strong>flutter pub run build_runner build — delete-conflicting-outputs</strong></blockquote><p><strong>6. AutoRoute(page: HomePage, initial: true)</strong></p><p>Here, AutoRoute takes in two parameters, <strong><em>page</em></strong> and <strong><em>initial</em></strong>.</p><p><em>page</em> — Name of the widget that needs to be registered</p><p><em>initial</em> — if this is the starting widget of the app, set it true.</p><p>HomePage is the starting point in the program, and that’s why the initial parameter is set to true.</p><p><strong>7. AutoRoute(page: DashboardScreen, guards: [AuthGuard])</strong></p><p>However, for DashboardScreen, initial parameter is not set, and that is because there can only be one initial widget in the app.</p><blockquote>Also, there is another parameter called as <strong><em>guards</em></strong><em>, this parameter is used to ensure that only authenticated users can have access to this widget. Since we have no guards parameter for HomePage, both authenticated as well as unauthenticated users can enter HomePage.</em></blockquote><p><strong>8. At this point, you must be thinking how will my app know if a user is authenticated or not?</strong></p><p>The following code is where the app checks if a user is authenticated or not. In my case, <strong>getUserToken() </strong>function<strong> </strong>is used to check for user’s token that was saved during last login. This part of authentication may be different for your app, and that is completely ok.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37d7a337e289333794843dc3a346cce0/href">https://medium.com/media/37d7a337e289333794843dc3a346cce0/href</a></iframe><p>If the user is <strong>unauthenticated</strong>, push them back to HomePageRoute(),<em>(</em> <em>route once registered using autoroute is referenced as WidgetNameRoute()), </em>otherwise, if the user is <strong>authenticated</strong>, push them to the desired widget.</p><blockquote>Once again, run the flutter command:</blockquote><blockquote><strong>flutter pub run build_runner build — delete-conflicting-outputs</strong></blockquote><p><strong>9. main.dart() modification</strong></p><p>Call configureInjection in your main function before running the app,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5077cc1f31c2e9fcce0a87581639f7aa/href">https://medium.com/media/5077cc1f31c2e9fcce0a87581639f7aa/href</a></iframe><p><strong>10. add app_widget.dart that registers AppRouter</strong></p><p>main.dart() calls AppWidget, and this is where AppRouter is registered and the navigation is set.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab4b07c4bc77890f4bef7431c7e5ac99/href">https://medium.com/media/ab4b07c4bc77890f4bef7431c7e5ac99/href</a></iframe><p>11. At this point, DashboardScreenRoute() can be navigated from anywhere in the program using the command,</p><pre>getIt&lt;AppRouter&gt;().push(DashboardScreenRoute())</pre><p>Since we have registered the route inside AppRouter in step 3, we will be navigating to the route and not the widget using getIt, and this is how we introduce <strong>dependency injection </strong>in the app using getIt.</p><p>12. In order to pop the route off, use the command:</p><pre>getIt&lt;AppRouter&gt;().pop()</pre><p><strong>Check out the complete code on Github —</strong> <a href="https://github.com/SamiaAshraff/flutter_routing">https://github.com/SamiaAshraff/flutter_routing</a></p><p>Did I miss something? Feel free to leave a comment! Do you use a technique that uses little boilerplate code and simplifies Navigation?</p><p><a href="https://twitter.com/FlutterComm">https://twitter.com/FlutterComm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f7efb09d342" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/navigation-in-flutter-using-autoroute-injectable-and-getit-3f7efb09d342">Navigation in Flutter using AutoRoute, injectable and getIt</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>