<?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 Zubair Rehman on Medium]]></title>
        <description><![CDATA[Stories by Zubair Rehman on Medium]]></description>
        <link>https://medium.com/@zubairehman?source=rss-88dd94cb5b31------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Zi7zV_9X0FymwZRmblpKPQ.jpeg</url>
            <title>Stories by Zubair Rehman on Medium</title>
            <link>https://medium.com/@zubairehman?source=rss-88dd94cb5b31------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 10:54:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zubairehman/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[How to use ModelMapper in Spring Boot]]></title>
            <link>https://zubairehman.medium.com/how-to-use-modelmapper-in-spring-boot-8a494e316840?source=rss-88dd94cb5b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a494e316840</guid>
            <category><![CDATA[modelmapper]]></category>
            <category><![CDATA[springboot-3]]></category>
            <category><![CDATA[objectmapper]]></category>
            <dc:creator><![CDATA[Zubair Rehman]]></dc:creator>
            <pubDate>Sat, 28 Jan 2023 14:16:17 GMT</pubDate>
            <atom:updated>2023-01-28T14:16:17.634Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J9rd0XRW86KAxKlJ" /><figcaption>Photo by <a href="https://unsplash.com/@marjan_blan?utm_source=medium&amp;utm_medium=referral">Marjan Blan | @marjanblan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>ModelMapper is a Java library that helps in mapping objects from one model to another, reducing the need for manual mapping code. It is a highly configurable library that uses conventions to automatically map objects, but can also be configured to provide custom mapping rules. In this article, we will demonstrate how to use ModelMapper in a Spring Boot application.</p><h4>Integrating ModelMapper with Spring Boot</h4><p>To use ModelMapper in a Spring Boot application, we first need to add it to our project’s dependencies. This can be done by adding the following to the pom.xml file for a Maven-based project:</p><pre>&lt;dependency&gt;<br> &lt;groupId&gt;org.modelmapper&lt;/groupId&gt;<br> &lt;artifactId&gt;modelmapper&lt;/artifactId&gt;<br> &lt;version&gt;3.1.1&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>If you are using Gradle, you can add the following to your build.gradle file:</p><pre>implementation &#39;org.modelmapper:modelmapper:2.3.8&#39;</pre><p>Next, we need to create a configuration class that will initialize ModelMapper and makes it available as a Bean in our application context.</p><pre>@Configuration<br>public class ModelMapperConfig {<br>  @Bean<br>  public ModelMapper modelMapper() {<br>    return new ModelMapper();<br>  }<br>}</pre><h4>Mapping Objects with ModelMapper</h4><p>Now that we have ModelMapper set up in our application, we can start using it to map objects from one model to another. Let’s consider an example of a simple model class Person:</p><pre>public class Person {<br>  private String firstName;<br>  private String lastName;<br>  private int age;<br><br>// Getters and setters<br>}</pre><p>And another model class PersonDTO:</p><pre>public class PersonDTO {<br>  private String fullName;<br>  private int age;<br><br>// Getters and setters<br>}</pre><p>We can map the Person object to a PersonDTO object using ModelMapper as follows:</p><pre>@Autowired<br>private ModelMapper modelMapper;<br><br>Person person = new Person();<br>person.setFirstName(&quot;John&quot;);<br>person.setLastName(&quot;Doe&quot;);<br>person.setAge(30);<br><br>PersonDTO personDTO = modelMapper.map(person, PersonDTO.class);</pre><p>In this example, we use the map method of the ModelMapper instance to map the Person object to a PersonDTO object. ModelMapper uses conventions to automatically map the properties that have the same name in both classes. In this case, the firstName and lastName properties of the Person object is automatically mapped to the fullName property of the PersonDTO object.</p><h4>Custom Mapping Rules</h4><p>In some cases, we may need to provide custom mapping rules, such as mapping a property to multiple target properties or converting a property value before mapping it. ModelMapper provides several methods to configure custom mapping rules, including typeMap, addMappings, and validate.</p><p>Let’s consider an example of a custom mapping rule for mapping the firstName and lastName properties of the Person object to the fullName property of the PersonDTO.</p><p>By default, Model Mapper maps properties from the source object to the target object based on their names and types. In this scenario, the age property can be mapped automatically, but the fullName the property requires a custom mapping rule.</p><p>Here’s how we can define a custom mapping rule using Model Mapper:</p><pre>ModelMapper modelMapper = new ModelMapper();<br>TypeMap&lt;Person, PersonDTO&gt; typeMap = modelMapper.createTypeMap(Person.class, PersonDTO.class);<br>typeMap.addMappings(mapper -&gt; {<br>    mapper.map(src -&gt; src.getFirstName() + &quot; &quot; + src.getLastName(), PersonDTO::setFullName);<br>});</pre><p>In the code above, we first create an instance of the ModelMapper class. Then we create a TypeMap using the createTypeMap method, passing in the Person and PersonDTO classes as arguments. Finally, we use the addMappings method to specify a custom mapping rule.</p><p>The custom mapping rule uses a lambda expression to concatenate the firstName and lastName properties of the Person object and set the resulting value to the fullName property of the PersonDTO object.</p><p>With the custom mapping rule in place, we can now map a Person object to a PersonDTO object:</p><pre>Person person = new Person();<br>person.setFirstName(&quot;John&quot;);<br>person.setLastName(&quot;Doe&quot;);<br>person.setAge(30);<br><br>PersonDTO personDTO = modelMapper.map(person, PersonDTO.class);</pre><p>After mapping, the personDTO object would have the following values:</p><pre>fullName = &quot;John Doe&quot;<br>age = 30</pre><p>In conclusion, custom mapping rules in Model Mapper provide a way to specify how properties from one model should be mapped to properties in another model. This is especially useful when the default conventions don’t suffice.</p><p><strong><em>Thats it for this article, if you liked this article, don’t forget to clap your hands 👏 as many times as you can to show your support, leave your comments and share it with your friends.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a494e316840" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Brief  Introduction to Flutter Version Management]]></title>
            <link>https://medium.com/embrace-it/a-brief-introduction-to-flutter-version-management-ff240dafdbf6?source=rss-88dd94cb5b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff240dafdbf6</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[fvm]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[version-management]]></category>
            <dc:creator><![CDATA[Zubair Rehman]]></dc:creator>
            <pubDate>Fri, 26 Mar 2021 06:10:13 GMT</pubDate>
            <atom:updated>2021-03-27T02:50:23.039Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Brief Introduction to Flutter Version Management</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1uUeLc6yZkSbTrHnJ0EjEQ.png" /></figure><h3>Introduction</h3><p>Flutter Version Management (or FVM) is a simple CLI to manage different Flutter versions on a per-project basis. This means that we can now define a specific Flutter version for each project.</p><h3>Why do you need FVM?</h3><p>When working on Flutter projects you may need to switch between different SDK versions to validate and test upcoming Flutter releases with your apps, which is very tedious and time-consuming. This is where FVM comes to the rescue.</p><p>FVM allows you to have multiple Flutter versions installed on your local machine to quickly test your app against the upcoming new Flutter releases without waiting for Flutter installation every time. It also allows you to manage multiple channels and releases, and caches these versions locally, so you don’t have to wait for a full setup every time you want to switch versions.</p><p>Not only that, but you can also grab versions by a specific release, i.e. v2.0.0 or v2.1.0–12.1.pre in case you have projects on different Flutter SDK versions that you do not want to upgrade.</p><h3>How to use</h3><p>Before we install/activate FVM make sure that Dart is installed on your local machine by typing in the following command:</p><pre>$ dart</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGnPY3ZGRSaRfzQ5nXyftQ.png" /></figure><p>Once we know that Dart is installed, the next step is to activate FVM. Open your terminal and type in the following command to activate FVM:</p><pre>$ pub global activate fvm</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RRwnG1UIDTACyDAL7e1zYg.png" /></figure><blockquote><em>⚠️ Do not activate FVM using </em><em>flutter pub global activate if you plan on using the </em><em>--global flag. Only activate FVM using </em><em>pub global activate fvm.</em></blockquote><h4>List Flutter Releases</h4><p>Before you download and install any Flutter release, you can list them all including the current version for dev, beta and stable channels by typing in the following command.</p><pre>$ fvm releases</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nSZu9Zay9JsuT0z9kKratw.png" /></figure><h4>Install an SDK Version</h4><p>FVM gives you the ability to install many Flutter releases or channels. Use stable to install the Stable channel and v2.0.3 or 1.17.0-dev.3.1 to install the release. --skip-setup will skip Flutter setup after install.</p><pre>$ fvm install stable <strong>or</strong> fvm install 2.0.3</pre><h4>Project Config SDK Version</h4><p>If you configured your project to use a specific version, run install without any arguments will install the proper version.</p><pre>$ fvm install</pre><h4>List Installed Versions</h4><p>You can also list all the installed versions on your machine by typing in the following command. This command will also output where FVM stores the SDK versions.</p><pre>$ fvm list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QO_1LgFz0NXq5x8vMpzOxg.png" /></figure><h4>Remove a SDK Version</h4><p>Using the remove command will uninstall the SDK version locally, this will impact any projects that depend on that version of the SDK.</p><pre>$ fvm remove &lt;version&gt;</pre><h4>Upgrade the current SDK Version</h4><p>To upgrade currently used Flutter SDK version (e.g. stable) you should call the Flutter SDK command as you would normally do in case of typical Flutter installation. See more in the section <a href="https://github.com/leoafarias/fvm#running-flutter-sdk-commands">Running Flutter SDK commands</a>.</p><pre>$ fvm flutter upgrade</pre><h3>Configure Your IDE</h3><p>In some situations you might have to restart your IDE and the Flutter debugger to make sure it uses the new version. Below are some details on how you can configure your IDE.</p><h4>Android Studio</h4><p>Copy the absolute path of FVM symbolic link in your root project directory.</p><pre>Example: /absolute/path-to-your-project/.fvm/flutter_sdk</pre><p>In the Android Studio menu open Languages &amp; Frameworks -&gt; Flutter or search for Flutter and change Flutter SDK path. Apply the changes. You now can Run and Debug with the selected versions of Flutter. Restart Android Studio to see the new settings applied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BbH-yaGfBhTThVNs3rTILA.png" /></figure><h4>VSCode</h4><p>Add the following to your settings.json. This will list all Flutter SDKs installed when using Flutter: Change SDK. Use fvm list to show you the path to the versions.</p><h4>List all versions installed by FVM</h4><p>You can see all the versions installed by FVM in VS Code by just providing path to versions directory:</p><pre>{<br>  &quot;dart.flutterSdkPaths&quot;: [&quot;/Users/usr/fvm/versions&quot;]<br>}</pre><p>Alternatively, you can specify only selected versions. The following snippet will cause VS Code to show only stable and dev versions of Flutter.</p><pre>{<br>  &quot;dart.flutterSdkPaths&quot;: [<br>    &quot;/Users/usr/fvm/versions/stable&quot;,<br>    &quot;/Users/usr/fvm/versions/dev&quot;<br>  ]<br>}</pre><p>To change current Flutter version open a project and select Flutter: Change SDK in the command palette. You should see all the versions as depicted in the following screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*czbZRaHX_dKbPYYnwiIx-w.png" /><figcaption><a href="https://github.com/leoafarias/fvm/blob/master/docs/vs_code_versions.png?raw=true">https://github.com/leoafarias/fvm/blob/master/docs/vs_code_versions.png</a></figcaption></figure><h4>You can also add the version symlink for dynamic switch</h4><pre>{<br>  &quot;dart.flutterSdkPaths&quot;: [&quot;.fvm/flutter_sdk&quot;]<br>}</pre><h4>Remove the flutter sdk from search to make things easier</h4><pre>{<br>  &quot;search.exclude&quot;: {<br>    &quot;**/.fvm&quot;: true<br>  },<br>}</pre><h3>Useful Resources:</h3><p>You should check the <a href="https://github.com/leoafarias/fvm">examples</a> provided by the FVM package on their github page. Also, their new app with GUI which you can find <a href="https://github.com/leoafarias/sidekick">here</a>.</p><p><strong><em>That’s it for this article, if you liked this article, don’t forget to clap your hands 👏 as many times as you can to show your support, leave your comments and share it with your friends.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff240dafdbf6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/embrace-it/a-brief-introduction-to-flutter-version-management-ff240dafdbf6">A Brief  Introduction to Flutter Version Management</a> was originally published in <a href="https://medium.com/embrace-it">Embrace-It</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Use Custom Fonts & Images in Flutter Package]]></title>
            <link>https://zubairehman.medium.com/how-to-use-custom-fonts-images-in-flutter-package-c2d9d4bfd47a?source=rss-88dd94cb5b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2d9d4bfd47a</guid>
            <category><![CDATA[flutter-plugin]]></category>
            <category><![CDATA[custom-fonts]]></category>
            <category><![CDATA[flutter-image]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-package]]></category>
            <dc:creator><![CDATA[Zubair Rehman]]></dc:creator>
            <pubDate>Thu, 28 Nov 2019 09:04:09 GMT</pubDate>
            <atom:updated>2019-11-28T09:04:09.798Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zp2T13nsqXTUxXUKde58hw.png" /><figcaption>source: <a href="https://willowtreeapps.com/">https://willowtreeapps.com/</a></figcaption></figure><p>Flutter apps can include both code and <em>assets</em> (sometimes called resources). An asset is a file that is bundled and deployed with your app, and is accessible at runtime. Common types of assets include static data (for example, JSON files), configuration files, icons, and images (JPEG, WebP, GIF, animated WebP/GIF, PNG, BMP, and WBMP).</p><h3>Introduction</h3><p>In this article we will learn how to use custom fonts &amp; images in flutter packages. When working with flutter packages that might contain their own set of assets, Flutter does not make it very intuitive to manage those assets.</p><p>For example, in a normal Flutter application, you would usually include your assets in an assets folder, and then those assets would be registered in the pubspec.yaml, either by adding the full path of the asset, or by adding a relative path that will include all the assets under that directory. This is not true when working with packages.</p><h3>Adding Assets &amp; Images to a Package</h3><p>Flutter uses the <a href="https://dart.dev/tools/pub/pubspec">pubspec.yaml</a> file, located at the root of your project, to identify assets required by an app. Your app can access its assets through an <a href="https://api.flutter.dev/flutter/services/AssetBundle-class.html">AssetBundle</a> object.</p><p>The two main methods of an asset bundle allow you to load a string/text asset (loadString()) or an image/binary asset (load()) out of the bundle, given a logical key. The logical key maps to the path to the asset specified in the pubspec.yaml file at build time.</p><h4>Specifying Assets</h4><p>When working with packages you need to add assets under thelib directory, as shown in a screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WZFvNXsLh2lJqa3PXCdT3Q.png" /></figure><p>and then register them as:</p><pre><em># To add assets to your application, add an assets section, like this:<br></em>assets:<br>- packages/receipt_widget/assets/icons/ic_appicon.png</pre><p>in your pubspec.yaml file.</p><blockquote><em>where </em><em>receipt_widget is the name of the package and </em><em>ic_appicon.png represents the name of an image.</em></blockquote><h4>Loading Assets</h4><p>To load assets used by package itself, the package argument must be provided to <a href="https://api.flutter.dev/flutter/painting/AssetImage-class.html">AssetImage</a>.</p><pre>AssetImage(&#39;assets/icons/ic_appicon.png&#39;, package: &#39;receipt_widget&#39;)</pre><h4>Bundling of Package Assets</h4><p>If the desired asset is specified in the pubspec.yaml file of the package, it’s bundled automatically with the application. In particular, assets used by the package itself must be specified in its pubspec.yaml.</p><p>A package can also choose to have assets in its lib/ folder that are not specified in its pubspec.yaml file. In this case, for those images to be bundled, the application has to specify which ones to include in its pubspec.yaml. For instance, a package named receipt_widget could have the following files:</p><pre>.../lib/assets/images/background1.png<br>.../lib/assets/images/background2.png<br>.../lib/assets/images/background3.png</pre><p>To include, say, the first image, the pubspec.yaml of the application should specify it in the assets section:</p><pre>flutter:<br>  assets:<br>  - packages/receipt_widget/assets/images/background1.png</pre><p>The lib/ is implied, so it should not be included in the asset path.</p><h3>Adding Custom Fonts to a Package</h3><p>When working with flutter packages you have to place font files directly in the lib folder or in a subdirectory, such as lib/assets/fonts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*en8UR2jYOs0LmNnjjFrK4w.png" /></figure><p>and then register them as:</p><pre>fonts:<br>- family: ProductSans<br>  fonts:<br>    - asset: packages/receipt_widget/fonts/Product-Sans-Regular.ttf<br>    - asset: packages/receipt_widget/fonts/Product-Sans-Italic.ttf<br>      style: italic<br>    - asset: packages/receipt_widget/fonts/Product-Sans-Bold.ttf<br>      weight: 700</pre><h4>Use the Font</h4><p>Use a <a href="https://api.flutter.dev/flutter/painting/TextStyle-class.html">TextStyle</a> to change the appearance of text. To use package fonts, declare which font you’d like to use and which package the font belongs to.</p><pre>Text(<br>  &#39;Using the ProductSans font from the receipt_widget&#39;,<br>  style: TextStyle(<br>    fontFamily: &#39;ProductSans&#39;,<br>    package: &#39;receipt_widget&#39;,<br>  ),<br>);</pre><h3>Restart Your App</h3><p>Finally, whenever you add a new asset in your pubspec.yaml file, don’t forget to run $ flutter packages get and restart your app.</p><h3>Useful resources</h3><ul><li><a href="https://flutter.dev/docs/cookbook/design/package-fonts">Export fonts from a package</a></li><li><a href="https://flutter.dev/docs/development/ui/assets-and-images#asset-images-in-package-dependencies">Adding assets and images</a></li></ul><p><strong><em>Thats it for this article, if you liked this article, don’t forget to clap your hands 👏 as many times as you can to show your support, leave your comments and share it with your friends.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2d9d4bfd47a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2: A Complete Guide For Building RESTful Applications Using Aqueduct]]></title>
            <link>https://itnext.io/part-2-a-complete-guide-for-building-restful-applications-using-aqueduct-c58688ab8b8e?source=rss-88dd94cb5b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/c58688ab8b8e</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[restful-service]]></category>
            <category><![CDATA[aqueduct]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Zubair Rehman]]></dc:creator>
            <pubDate>Thu, 05 Sep 2019 17:55:06 GMT</pubDate>
            <atom:updated>2019-09-06T06:43:03.852Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_d4epJ7VXxqwDGHZ2r65fA.png" /><figcaption>source: <a href="https://bs-uploads.toptal.io/blackfish-uploads/blog/article/content/cover_image_file/cover_image/14556/cover-code-sharing-angular-dart-flutter-bloc-fdde1ea49ed55f1ab00c61d9dabeb97c.png">https://bs-uploads.toptal.io</a></figcaption></figure><p>This article is the continuation of my first article on <a href="https://medium.com/@zubairehman.work/part-1-a-complete-guide-for-building-restful-applications-using-aqueduct-668b07f62ad5"><strong>A</strong> <strong>Complete Guide For Building RESTful Applications Using Aqueduct</strong></a><strong>. </strong>In the previous article we learned about aqueduct and its core concept. In this article we will learn how to configure and build our very first application using <strong><em>Aqueduct</em></strong>. By the end of this article, you will have created an Aqueduct application that serves fictional heroes.</p><p>Before we move on, if you’re unfamiliar with Aqueduct, i would encourage you to read my first article where i have given a brief introduction to Aqueduct and its core concepts.</p><h3>Introduction</h3><p>Aqueduct is a modern Dart HTTP server framework. The framework is composed of libraries for handling and routing HTTP requests, object-relational mapping (ORM), authentication and authorization (OAuth 2.0 provider) and documentation (OpenAPI). These libraries are used to build scalable REST APIs that run on the Dart VM.</p><h3>Getting Started</h3><p>To get started, make sure you have the following software installed:</p><ol><li>Dart (<a href="https://www.dartlang.org/install">Install Instructions</a>)</li><li>IntelliJ IDEA or any other Jetbrains IDE, including the free Community Edition (<a href="https://www.jetbrains.com/idea/download/">Install Instructions</a>)</li><li>The IntelliJ IDEA Dart Plugin (<a href="https://www.dartlang.org/tools/jetbrains-plugin">Install Instructions</a>)</li></ol><h4>Activating Aqueduct</h4><p>Activate <strong><em>Aqueduct</em></strong> by running pub global activate aqueduct on your terminal. This will download and install all the necessary dependencies required to work with Aqueduct<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8N_4jF8sqtIBeeUa1Ubreg.png" /></figure><h4>Creating a Project</h4><p>Create a new project by running aqueduct create heroes on your terminal. This will create a heroes project under the directory specified in your terminal. You can open the project directory in <a href="https://www.jetbrains.com/idea/download/">IntelliJ IDE</a>, <a href="https://atom.io/">Atom</a> or <a href="https://code.visualstudio.com/">Visual Studio Code</a>. All three IDEs have a Dart plugin available.</p><p>In the project view, locate the lib directory; this is where your project&#39;s code will go. This project has two source files - heroes.dart and channel.dart. Open the file heroes.dart. Click Enable Dart Support in the top right corner of the editor.</p><blockquote>Note: A project name must be snake_case</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z7g2X9ALmGvHMKTO25Kfkw.png" /></figure><p>There are other templates exist that contain foundational code for using <strong>Aqueduct’s </strong>ORM and OAuth 2.0 implementation. These templates can be listed:</p><pre>aqueduct create list-templates</pre><p>You may provide the name of a template when creating a project to use that template:</p><pre>aqueduct create -t db [my_project_name]</pre><h4>Running a Project</h4><p>Now that we have successfully created a project, its time to run our application by simply running aqueduct serve from our project directory. For running within an IDE, run bin/main.dart. By default, a configuration file named config.yaml will be used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ciz3_kCiv7lfLpeicCeOVg.png" /></figure><p>Enter the following URL in your browser (I am using port 8888. This port might be different from yours and is visible in the terminal after starting aqueduct server)</p><pre><a href="http://localhost:8888/example">http://localhost:8888/example</a></pre><p>You should be able to see the following output in your browser</p><pre>{&quot;key&quot;:&quot;value&quot;}</pre><p>Lets add some more code to our heroes project to get a list of heroes, and to get a single hero by its identifier. Those requests are:</p><ol><li>GET /heroes to get the list of heroes</li><li>GET /heroes/:id to get an individual hero</li></ol><p>But before we dive into implementation, lets have a quick look at how our requests are gonna handle.</p><h4>Controller Objects Handle Requests</h4><p>Requests are handled by <em>controller objects</em>. A controller object can respond to a request. It can also take other action and let another controller respond.</p><p>Our application will link two controllers:</p><ul><li>a Router that makes sure the request path is /heroes or /heroes/:id</li><li>a HeroesControllers that responds with hero objects</li></ul><p>Your application starts with a channel object called the application channel. You link the controllers in your application to this channel. Each application has a subclass of ApplicationChannel that you override methods in to set up your controllers. This type is already declared in lib/channel.dart - open this file and find ApplicationChannel.entryPoint:</p><pre>@override<br>  Controller get entryPoint {<br>    final router = Router();<br><br>    router<br>      .route(&#39;/example&#39;)<br>      .linkFunction((request) async {<br>        return Response.ok({&#39;key&#39;: &#39;value&#39;});<br>      });<br><br>    return router;<br>  }</pre><p>When your application gets a request, the entryPoint controller is the first to handle it. In our case, this is a Router - a subclass of Controller. We need to route the path /heroes to a controller of our own, so we can control what happens.</p><p>Let&#39;s create a HeroesController by creating a new file in lib/controller/heroes_controller.dart and add the following code (you will need to create the subdirectory lib/controller/):</p><pre>import &#39;package:aqueduct/aqueduct.dart&#39;;<br>import &#39;package:heroes/heroes.dart&#39;;<br><br>class HeroesController extends Controller {<br>  final _heroes = [<br>    {&#39;id&#39;: 11, &#39;name&#39;: &#39;Captain America&#39;},<br>    {&#39;id&#39;: 12, &#39;name&#39;: &#39;Ironman&#39;},<br>    {&#39;id&#39;: 13, &#39;name&#39;: &#39;Wonder Woman&#39;},<br>    {&#39;id&#39;: 14, &#39;name&#39;: &#39;Hulk&#39;},<br>    {&#39;id&#39;: 15, &#39;name&#39;: &#39;Black Widow&#39;},    <br>  ];</pre><pre>  @override<br>  Future&lt;RequestOrResponse&gt; handle(Request request) async {<br>    return Response.ok(_heroes);<br>  }<br>}</pre><p>Notice that HeroesController is a subclass of Controller it overrides handle method by returning a 200 OK status code, and a body containing a JSON-encoded list of heroes Response object.</p><p>Right now, our HeroesController isn&#39;t hooked up to the application channel. We need to link it to the router. First, import our new file at the top of channel.dart.</p><pre>import &#39;controller/heroes_controller.dart&#39;;</pre><p>Then link this HeroesController to the Router for the path /heroes:</p><pre>@override<br>Controller get entryPoint {<br>  final router = Router();</pre><pre>  router<br>    .route(&#39;/heroes&#39;)<br>    .link(() =&gt; HeroesController());</pre><pre>  router<br>    .route(&#39;/example&#39;)<br>    .linkFunction((request) async {<br>      return Response.ok({&#39;key&#39;: &#39;value&#39;});<br>    });</pre><pre>  return router;<br>}</pre><p>We now have an application that will return a list of heroes. Let’s stop our application using Ctrl+ c and restart by running the following command from the command-line:</p><pre>aqueduct serve</pre><p>Enter the following URL in your browser</p><pre><a href="http://localhost:8888/heroes">http://localhost:8888/heroes</a></pre><p>You should be able to see the following output in your browser</p><pre>[<br>  {&quot;id&quot;:11,&quot;name&quot;:&quot;Captain America&quot;},<br>  {&quot;id&quot;:12,&quot;name&quot;:&quot;Ironman&quot;},<br>  {&quot;id&quot;:13,&quot;name&quot;:&quot;Wonder Woman&quot;},<br>  {&quot;id&quot;:14,&quot;name&quot;:&quot;Hulk&quot;},<br>  {&quot;id&quot;:15,&quot;name&quot;:&quot;Black Widow&quot;}<br>]</pre><p>Congratulations, you are done setting up the first part which is getting a list of heroes. Now, let’s move on to the next part of retrieving a single hero by providing its :id.</p><h4>Advanced Routing</h4><p>Right now, our application handles GET /heroes requests. Now we would like to send a request to retrieve a single hero. Let’s modify the /heroes route in channel.dart and add the following code:</p><pre>router<br>  .route(&#39;/heroes/[:id]&#39;)<br>  .link(() =&gt; HeroesController());</pre><p>Anything within the square brackets is optional, in our case its the :id portion of our route. Let’s modify heroes_controller.dart to add support for handling single hero request.</p><pre>@override<br>Future&lt;RequestOrResponse&gt; handle(Request request) async {<br>  if (request.path.variables.containsKey(&#39;id&#39;)) {<br>    final id = int.parse(request.path.variables[&#39;id&#39;]);<br>    final hero = _heroes.firstWhere((hero) =&gt; hero[&#39;id&#39;] == id, orElse: () =&gt; null);<br>    if (hero == null) {<br>      return Response.notFound();<br>    }</pre><pre>    return Response.ok(hero);<br>  }</pre><pre>  return Response.ok(_heroes);<br>}</pre><p>Let’s restart our application and make single hero request by typing in the following URL in our browser:</p><pre>http://localhost:8888/heroes/11</pre><p>The output will be like this:</p><pre>{&quot;id&quot;:11,&quot;name&quot;:&quot;Captain America&quot;}</pre><blockquote>Note: You can also use the terminal to do request, for example: curl -X GET <a href="http://localhost:8888/heroes/11">http://localhost:8888/heroes/11</a>. You can also trigger a 404 Not Found response by getting a hero that doesn’t exist.</blockquote><p>Our HeroesController is OK right now, but it&#39;ll soon run into a problem: what happens when we want to create a new hero? Or update an existing hero&#39;s name? Our handle method will start to get unmanageable, quickly.</p><p>That’s where ResourceController comes in.</p><h4>ResourceControllers and Operation Methods</h4><p>A ResourceController allows you to create a distinct method for each operation that we can perform on our heroes.</p><p>In heroes_controller.dart, replace HeroesController with the following:</p><pre>class HeroesController extends ResourceController {<br>  final _heroes = [<br>    {&#39;id&#39;: 11, &#39;name&#39;: &#39;Captain America&#39;},<br>    {&#39;id&#39;: 12, &#39;name&#39;: &#39;Ironman&#39;},<br>    {&#39;id&#39;: 13, &#39;name&#39;: &#39;Wonder Woman&#39;},<br>    {&#39;id&#39;: 14, &#39;name&#39;: &#39;Hulk&#39;},<br>    {&#39;id&#39;: 15, &#39;name&#39;: &#39;Black Widow&#39;},<br>  ];</pre><pre>  @Operation.get()<br>  Future&lt;Response&gt; getAllHeroes() async {<br>    return Response.ok(_heroes);<br>  }</pre><pre>  @Operation.get(&#39;id&#39;)<br>  Future&lt;Response&gt; getHeroByID() async {<br>    final id = int.parse(request.path.variables[&#39;id&#39;]);<br>    final hero = _heroes.firstWhere((hero) =&gt; hero[&#39;id&#39;] == id, orElse: () =&gt; null);<br>    if (hero == null) {<br>      return Response.notFound();<br>    }</pre><pre>    return Response.ok(hero);<br>  }<br>}</pre><p>Notice that we didn’t have to override handle in ResourceController. A ResourceController implements this method to call one of our <em>operation methods</em>. An operation method - like getAllHeroes and getHeroByID - must have an Operation annotation. The named constructor Operation.get means these methods get called when the request&#39;s method is GET. An operation method must also return a Future&lt;Response&gt;.</p><p>getHeroByID&#39;s annotation also has an argument - the name of our path variable :id. If that path variable exists in the request&#39;s path, getHeroByID will be called. If it doesn&#39;t exist, getAllHeroes will be called.</p><h4>Request Binding</h4><p>An operation method can declare parameters and <em>bind</em> them to properties of the request. When our operation method gets called, it will be passed values from the request as arguments. Request bindings automatically parse values into the type of the parameter (and return a better error response if parsing fails). Change the method getHeroByID():</p><pre>@Operation.get(&#39;id&#39;)<br>Future&lt;Response&gt; getHeroByID(@Bind.path(&#39;id&#39;) int id) async {<br>  final hero = _heroes.firstWhere((hero) =&gt; hero[&#39;id&#39;] == id, orElse: () =&gt; null);</pre><pre>  if (hero == null) {<br>    return Response.notFound();<br>  }</pre><pre>  return Response.ok(hero);<br>}</pre><p>Congratulations, we have created an Aqueduct application that serves fictional heroes. Till this point we are hard coding arrays into our code. What we would like to do next is to store heroes into the database and perform CRUD operations.</p><p>Thank you for reading! Feel free to say hi or share your thoughts on LinkedIn <a href="https://www.linkedin.com/in/zubairehman/">@zubairehman</a> or in the responses below!</p><h3>Next articles</h3><p>The story does not finish yet, in the next article we learn how to configure and perform CRUD operations using PostgreSQL, so stay tuned :)</p><p>Other parts of this post:</p><ul><li><a href="https://medium.com/@zubairehman.work/part-1-a-complete-guide-for-building-restful-applications-using-aqueduct-668b07f62ad5">Part 1: A Complete Guide For Building RESTful Applications Using Aqueduct (Core Concepts)</a></li><li>Part 2: A Complete Guide For Building RESTful Applications Using Aqueduct (Application Development)</li><li>Part 3: A Complete Guide For Building RESTful Applications Using Aqueduct (DB Configuration, coming soon)</li></ul><h3>Useful resources</h3><p><a href="http://aqueduct.io/docs/">http://aqueduct.io/docs/</a></p><p><strong><em>Thats it for this article, if you liked this article, don’t forget to clap your hands 👏 as many times as you can to show your support, leave your comments and share it with your friends.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c58688ab8b8e" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/part-2-a-complete-guide-for-building-restful-applications-using-aqueduct-c58688ab8b8e">Part 2: A Complete Guide For Building RESTful Applications Using Aqueduct</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1: A Complete Guide For Building RESTful Applications Using Aqueduct]]></title>
            <link>https://itnext.io/part-1-a-complete-guide-for-building-restful-applications-using-aqueduct-668b07f62ad5?source=rss-88dd94cb5b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/668b07f62ad5</guid>
            <category><![CDATA[restful-api]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[aqueduct]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Zubair Rehman]]></dc:creator>
            <pubDate>Thu, 05 Sep 2019 17:53:42 GMT</pubDate>
            <atom:updated>2019-09-06T06:41:59.249Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WCyGl9yS90RTxvALoL3usQ.png" /><figcaption>source: <a href="https://stablekernel.com/wp-content/uploads/2017/07/aqueduct-1500x660.png">https://stablekernel.com/wp-content/uploads/2017/07/aqueduct-1500x660.png</a></figcaption></figure><p>This article is the first in the series of articles about building a RESTful application in Dart using Aqueduct.</p><p>If you’re unfamiliar with the Aqueduct and its core concepts, a brief introduction to these notions are given below. Feel free to skip ahead to the <a href="https://medium.com/@zubairehman.work/part-2-a-complete-guide-for-building-restful-applications-using-aqueduct-c58688ab8b8e">next part</a> if you’re already familiar with them (even though a quick refresh won’t hurt).</p><h3>What is Aqueduct?</h3><p>Aqueduct is an HTTP web server framework for building REST applications written in Dart. REST is short for Representational State Transfer and allows client-server interaction using HTTP protocol. Each url is called <strong><em>request</em></strong> while data sent back is call <strong><em>response</em></strong>.</p><p>A RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data.</p><h3>Core Concepts</h3><p>Before we move on to the implementation, lets quickly go-through the core concepts we will be using to build a RESTful application.</p><h4><strong>Resources</strong></h4><p>Resources are the things your application exposes through its HTTP API. For example, the GitHub API exposes organization, repository, issues and pull request resources; a social network API has profiles, posts, and user relationships. Resources are organized into collections (e.g., all of the posts), for which individual resources within that collection can be uniquely identified (e.g., a single post).</p><h4><strong>Routing</strong></h4><p>An application exposes <strong><em>routes</em></strong> for each resource it manages. A route is a string that matches the path of a request. Resources are identified by the path of an HTTP request. For example, the URL http://example.com/organizations identifies the collection of organization resources on the server http://example.com. The route /organizations/:id identifies a single organization and will match the paths /organizations/1, /organizations/2, and so on.</p><pre>// Matches /organizations and /organizations/:id<br>route(&quot;/organizations/[:id]&quot;)...;<br><br>// Matches /organizations/:organizationId/posts <br>// and /organizations/:organizationsId/posts/:postId<br>route(&quot;/organizations/:organizationsId/posts/[:postId]&quot;)...;<br><br>// Matches /organizations/:organizationsId/posts <br>// and /organizations/:organizationsId/notes/:noteId<br>route(&quot;/organizations/:organizationsId/notes/[:noteId]&quot;)...;</pre><h4><strong>Controllers</strong></h4><p>Controllers are objects that handle requests. For example, a controller might fetch rows from a database and send them to the client in the response body. Another controller might verify the username and password of a request. <em>For example</em>, a controller could return a 200 OK response with a JSON-encoded list of organization. A controller could also check a request to make sure it had the right credentials in its authorization header.</p><p>There are two flavors of controllers. An <em>e</em><strong><em>ndpoint controller</em></strong> and a <strong><em>middleware controller</em></strong>.</p><ul><li><strong>Endpoint Controller</strong></li></ul><p>An <strong><em>endpoint controller</em></strong> performs operations on a resource or resource collection, and always sends a response. Endpoint controller <em>fulfils</em> requests by returning the state of a resource or by changing the state of a resource. You write most of your application-specific logic using endpoint controllers.</p><ul><li><strong>Middleware Controller</strong></li></ul><p>A <strong><em>middleware controller</em></strong> takes an action for a request, but isn’t responsible for fulfilling the request. Middleware controllers can do many different things and are often reusable in many channels. Most often, a middleware controller validates something about a request before it reaches an endpoint controller or to send a response for a request, to prevent any other controller in that channel from handling the request.</p><blockquote>A channel must have exactly one endpoint controller. It can be preceded by zero or more middleware controllers. See the guides on <a href="http://aqueduct.io/docs/http/controller/">Controllers</a> and <a href="http://aqueduct.io/docs/http/resource_controller/">ResourceControllers</a> for usage details.</blockquote><pre>class Authorizer extends Controller {<br>  @override<br>  Future&lt;RequestOrResponse&gt; handle(Request request) async {<br>    if (isValid(request)) {<br>      return request;<br>    }<br><br>    return Response.unauthorized();<br>  }<br>}</pre><h4>Channels</h4><p>Controllers are linked together to form a series of actions to take for a request. These linked together controllers are called a <strong><em>channel</em></strong>. For example, a channel might verify the credentials of a request and then return a list of organizations by composing two controllers that take each of these actions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yv2cRhLMBUdg3RPXrzbg0A.png" /></figure><h4>The Application Channel</h4><p>The <strong><em>application channel</em></strong> is an object that contains all of the controllers in an application. It designates one controller as the first controller to receive every request called its <strong><em>entry point</em></strong>. Controllers are linked to the entry point (directly or transitively) to form the entire application channel. In nearly every application, the entry point is a router; this controller splits the channel into sub-channels for a given route.</p><p>The application channel is also responsible for initializing the application’s services, reading configuration files and other startup related tasks.</p><blockquote>See the guide on the <a href="http://aqueduct.io/docs/application/channel/">Application Channel</a> for more details.</blockquote><pre>class AppChannel extends ApplicationChannel {<br>  @override<br>  Controller get entryPoint {<br>    final router = new Router();<br><br>    router<br>      .route(&quot;/users&quot;)<br>      .link(() =&gt; Authorizer())<br>      .link(() =&gt; UserController());<br><br>    return router;<br>  }<br>}</pre><h4>Services</h4><p>A <strong><em>service</em></strong> is an object that encapsulates complex tasks or algorithms, external communication or tasks that will be reused across an application. The primary users of service objects are controllers. Controllers often need to get (or create) information from outside the application. The most common example is database access, another REST API, a connected device, etc.</p><p>A <strong><em>service object</em></strong> encapsulates the information and behaviour needed to work with an external system and injects into controller by passing them as arguments to the controller’s constructor. The controller keeps a reference to the service, so that it can use it when handling a request.</p><blockquote>For more details on injecting services, see the guide on the <a href="http://aqueduct.io/docs/application/channel/">Application Channel</a>.</blockquote><pre>class AppChannel extends ApplicationChannel {<br>  PostgreSQLConnection database;<br><br>  @override<br>  Future prepare() async {<br>    database = PostgreSQLConnection();<br>  }<br><br>  @override<br>  Controller get entryPoint {<br>    final router = new Router();<br><br>    router<br>      .route(&quot;/users&quot;)<br>      .link(() =&gt; new Authorizer())<br>      .link(() =&gt; new UserController(database));<br><br>    return router;<br>  }<br>}</pre><h4>Isolates</h4><p><strong><em>Isolates</em></strong> are memory-isolated threads; an object created on one isolate can’t be referenced by another isolate. When an application starts, one or more isolates containing replicas of your application code are spawned. This behaviour effectively ‘load balances’ your application across multiple threads.</p><p>A benefit to this structure is that each isolate has its own set of services, like database connections. This eliminates the need for techniques like ‘database connection pooling’, because the entire application is effectively ‘pooled’.</p><h4>Bindings</h4><p>A request might contain headers, query parameters, a body and path parameters that need to be parsed, validated and used in controller code. <strong><em>Bindings</em></strong> are annotations added to variables that perform this parsing and validation automatically. Appropriate error responses are sent when a bound value can’t be parsed into expected type or validation fails.</p><pre>// Path Variable<br>@Bind.path(pathVariableName)</pre><pre>// URL Query Parameter @Bind.query(queryParameterName)Header@Bind.header(headerName)</pre><pre>// Request Body<br>@Bind.body()</pre><h4>Queries and Data Models</h4><p>Writing database <strong><em>queries</em></strong> by hand is error-prone and doesn’t leverage static analysis tools. Aqueduct’s ORM (Object-Relational Mapping) provides statically-typed queries that are easy to write and test.</p><p>Your application’s data model is defined by creating Dart classes. Each class is mapped to a database table, and each property of that class is mapped to a column in that table. Aqueduct’s command-line tool generates database migration files that detect changes in your data model that can be applied to a live, versioned database. A data model can also be represented as a JSON object to build tools on top of your application.</p><blockquote>For more details, see the guide on <a href="http://aqueduct.io/docs/db/">Databases</a>.</blockquote><pre>// This is a table definition of an &#39;article&#39;<br>class _Article {<br>  @Column(primaryKey: true)<br>  int id;<br><br>  String contents;<br><br>  @Column(indexed: true)<br>  DateTime publishedDate;<br>}</pre><h4>Authorization</h4><p>OAuth 2.0 is a standardized authorization framework. Aqueduct contains a specification-compliant implementation of an OAuth 2.0 server that can be integrated directly into your application. This implementation is easily customizable — it can store authorization artifacts — like tokens and client identifiers — in different types of databases or use stateless authorization mechanisms like JWT. The default implementation leverages the Aqueduct ORM to store artifacts in PostgreSQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6-fWaL42hLKZXR5prlNx5g.png" /></figure><p>Thank you for reading! Feel free to say hi or share your thoughts on LinkedIn <a href="https://www.linkedin.com/in/zubairehman/">@zubairehman</a> or in the responses below!</p><h3>Next articles</h3><p>The story does not finish yet, in the next article we learn how to configure and build our first API using aqueduct, so stay tuned :)</p><p>Other parts of this post:</p><ul><li>Part 1: A Complete Guide For Building RESTful Applications Using Aqueduct (Core Concepts)</li><li><a href="https://medium.com/@zubairehman.work/part-2-a-complete-guide-for-building-restful-applications-using-aqueduct-c58688ab8b8e">Part 2: A Complete Guide For Building RESTful Applications Using Aqueduct (Application Development)</a></li><li>Part 3: A Complete Guide For Building RESTful Applications Using Aqueduct (DB Configuration, coming soon)</li></ul><h3>Useful resources</h3><p><a href="http://aqueduct.io/docs/">http://aqueduct.io/docs/</a></p><p><strong><em>Thats it for this article, if you liked this article, don’t forget to clap your hands 👏 as many times as you can to show your support, leave your comments and share it with your friends.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=668b07f62ad5" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/part-1-a-complete-guide-for-building-restful-applications-using-aqueduct-668b07f62ad5">Part 1: A Complete Guide For Building RESTful Applications Using Aqueduct</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter For Web: A Complete Guide to Deploy a Web Application]]></title>
            <link>https://itnext.io/flutter-for-web-a-complete-guide-to-deploy-a-web-application-3fa9463377a8?source=rss-88dd94cb5b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fa9463377a8</guid>
            <category><![CDATA[flutter-web]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[surge]]></category>
            <category><![CDATA[web-app-development]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Zubair Rehman]]></dc:creator>
            <pubDate>Wed, 14 Aug 2019 10:44:20 GMT</pubDate>
            <atom:updated>2019-12-31T04:44:24.323Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4WaQ9Xrw1HSNnisyFwR31A.png" /><figcaption>source: <a href="https://miro.medium.com/max/1838/1*E2oMUSXlTD8E2TjIE3ZCJg.png">https://miro.medium.com/max/1838/1*E2oMUSXlTD8E2TjIE3ZCJg.png</a></figcaption></figure><p>Flutter was first announced at Google I/O in May 2017 with an alpha toolkit and in 2018 at Google I/O, it finally hit version 1.0 with a future new product, called <em>HummingBird</em>. We were all excited and could not wait for its release date and on May 7th 2019 at Google IO 2019, Google finally announced the availability of the <strong>Flutter for Web</strong> preview version.</p><h3>Introduction</h3><p>This article is the continuation of my first article on <a href="https://medium.com/@zubairehman.work/flutter-for-web-c75011a41956"><strong>Flutter For Web: A Complete Guide to Create &amp; Run a Web Application</strong></a><strong>. </strong>In this article we will learn how to build and deploy flutter for web applications on <a href="https://surge.sh/"><strong>Surge</strong></a><strong>. Surge </strong>is a static web publishing tool for Front-End Developers. It is the best way for developers to publish static web applications into production.</p><blockquote><em>To learn more about surge, follow the link to get started: </em><a href="https://surge.sh/help/getting-started-with-surge"><strong><em>Getting started with Surge</em></strong></a></blockquote><h3>Build and Deploy</h3><p>So without any further delay, let’s get started.</p><p>Open your project in terminal by changing the current directory to the one your project is located at and execute the following command.</p><pre>$ webdev build</pre><blockquote><em>Note: if you have problems configuring </em><em>webdev to run directly, try:<br></em><em>flutter packages pub global run webdev [command].</em></blockquote><p>The expected output in the terminal, is something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*giVVb2v5Jc5urS2_2zi2gw.png" /></figure><p>After the command is executed, you will be able to see that in your project folder a new folder named <strong>build</strong> is created containing all the files necessary to deploy a web application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bdnRQdsjuGBNNW9H4AL0Kw.png" /></figure><p>Now, we are going to deploy this folder. There can be a lots of ways for deploying flutter web application, the method that I am going to use is S<strong>urge</strong>.</p><p>It comes as an <strong>npm</strong> package and helps to deploy static sites to a remote URL. It’s fast, easy and free. With Surge, you’ll easily have something online quickly.</p><p>First install the command line tool using <strong>npm</strong> and then run surge within any directory you wish to publish onto the web. All you need to get started is:</p><ol><li>First, ensure you have a recent version of <a href="http://nodejs.org/"><strong>Node.js</strong></a></li><li>Then, install Surge using <strong>npm</strong> by running the following command:</li></ol><pre>$ npm i -g surge</pre><p>This command will install surge globally on your system, and hence you can use it everywhere.</p><blockquote><em>You may need to preface this command with </em><em>sudo</em></blockquote><p>Now, run surge from within the <strong>build</strong> directory, to publish that directory onto the web. To change your directory to the <strong>build</strong> directory, first execute the following command:</p><pre>$ cd build</pre><p>then run surge to publish the <strong>build </strong>directory:</p><pre>$ surge</pre><p>The surge command will now run. On your first time running this command you will be asked to create an account. Enter your email and choose a password. This is a one time requirement. Surge will display an auto generated sub-domain name. Move your cursor to the domain name and type any name that you want. Once that is done, press enter, surge will now automatically upload and deploy the website, and map it to it’s CDN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHoCCcyzhCV_1kRNtvkrjw.png" /></figure><p>Congratulations! You have successfully created a website with Flutter and deployed it on the internet, for the world to see. You can browse your website by going to the remote URL provided by surge in the terminal output, in my case it’s this: <a href="http://zubair-portfolio.surge.sh/#/">http://zubair-portfolio.surge.sh/#/</a></p><p>If you don’t want your project’s url to have the surge.sh part, you can buy a custom domain and configure your project to use it. To learn more about adding a custom domain, follow the link: <a href="https://surge.sh/help/adding-a-custom-domain">https://surge.sh/help/adding-a-custom-domain</a></p><p>I can’t wait to see how this technology grows and flourishes over time.</p><h3>Useful resources</h3><ul><li><a href="https://github.com/zubairehman/Portfolio-Demo">zubairehman/Portfolio-Demo</a></li><li><a href="https://github.com/zubairehman/Portfolio-Demo-1">zubairehman/Portfolio-Demo-1</a></li><li><a href="https://github.com/flutter/flutter_web">flutter/flutter_web</a></li><li><a href="https://flutter.dev/web">Web support for Flutter</a></li></ul><p><strong><em>Thats it for this article, if you liked this article, don’t forget to clap your hands 👏 as many times as you can to show your support, leave your comments and share it with your friends.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fa9463377a8" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/flutter-for-web-a-complete-guide-to-deploy-a-web-application-3fa9463377a8">Flutter For Web: A Complete Guide to Deploy a Web Application</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dependency Injection In Flutter]]></title>
            <link>https://medium.com/flutter-community/dependency-injection-in-flutter-f19fb66a0740?source=rss-88dd94cb5b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/f19fb66a0740</guid>
            <category><![CDATA[provide]]></category>
            <category><![CDATA[inject]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[inversion-of-control]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[Zubair Rehman]]></dc:creator>
            <pubDate>Sun, 16 Jun 2019 05:37:17 GMT</pubDate>
            <atom:updated>2019-08-19T00:21:20.128Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*RPeeYLxo4bDcz3N-9BIccw.png" /><figcaption><a href="https://cdn-images-1.medium.com/max/1200/0*IQQcFoHRGzR6S5A7.png">https://cdn-images-1.medium.com/max/1200/0*IQQcFoHRGzR6S5A7.png</a></figcaption></figure><h3>Introduction</h3><p>Dependency Injection (DI) is a design pattern used to implement Inversion of Control. It allows the creation of dependent objects outside of a class and provides those objects to a class through different ways. Using DI, we move the creation and binding of the dependent objects outside of the class that depends on them. This brings a higher level of flexibility, decoupling, and easier testing.</p><p>In this article, we’ll learn how to use dependency injection in <a href="https://flutter.io/">Flutter</a> using <a href="https://github.com/google/inject.dart"><strong><em>Inject</em></strong></a> (<em>A Compile-time dependency injection for Dart and Flutter, similar to Dagger)</em> through simple examples.</p><h4>Why would you even need to use DI?</h4><p>I don’t intend to go in depth in the theory of the pattern but consider the following class:</p><pre>class Car {  <br>   private Wheel wheel = Wheel()    <br>   <br>   drive() {    <br>      wheel.spin()  <br>   }<br>}</pre><p>While there is nothing inherently wrong with the previous class it presents two main problems:</p><ul><li>It’s impossible to mock the wheel to test the Car class in isolation.</li><li>If you had a SteelWheel and a PlasticWheel it would not be possible to interchange them without changing the consumer.</li></ul><p>We can easily solve these issues by providing the Wheel so the car can make use of it instead, like so:</p><pre>class Car() { </pre><pre>   // database instance<br>   <strong>final </strong>Wheel _wheel;</pre><pre>   // Constructor<br>   Car(<strong>this</strong>._wheel);</pre><pre>   drive() {   <br>      wheel.spin() <br>   }<br>}</pre><p>It’s easy to see why class with many dependencies can get out of hand very fast following the first path.</p><h4>Dependency Injection in Flutter</h4><p>Dependency Injection is a simple pattern but often times libraries are used to abstract it away from the developer. Many of these libraries use reflection (mirrors in Dart). Flutter presents two issues, however:</p><ul><li><a href="https://flutter.io/docs/resources/faq#does-flutter-come-with-a-reflectionmirrors-system"><strong>Mirrors are disabled</strong></a> for performance reasons.</li><li>The nested nature of widgets makes it <strong>impractical to pass dependencies many levels down the tree</strong>.</li></ul><p>We will overcome these issues by using Inject library. Inject uses the following annotations:</p><ul><li>@Injector: A inversion of control container constructed from a builder or a set of modules</li><li>@Module and @Provides: define classes and methods which provide dependencies</li><li>@Component: enable selected modules and used for performing dependency injection</li></ul><h3>Installation</h3><p>As there’s no package in official repository, we have to install it manually. I prefer to do it as a git package, so I’m going to define its dependencies in pubspec.yaml file as shown below:</p><pre>dependencies:<br> inject:<br> git:<br> url: <a href="https://github.com/google/inject.dart.git">https://github.com/google/inject.dart.git</a><br> path: package/inject</pre><pre>dev_dependencies:<br> build_runner: ^1.3.0</pre><pre>inject_generator:<br> git:<br> url: <a href="https://github.com/google/inject.dart.git">https://github.com/google/inject.dart.git</a><br> path: package/inject_generator</pre><h4>Usage</h4><p>What functionality do we usually expect from a DI library? Let’s go through some common use cases:</p><h4>Concrete class injection</h4><p>It can be as simple as this:</p><pre>import ‘package:inject/inject.dart’;</pre><pre><a href="http://twitter.com/provide">@provide</a><br>class StepService {<br>   // implementation<br>}</pre><p>We can use it e.g. with Flutter widgets like this:</p><pre><a href="http://twitter.com/provide">@provide</a><br>class SomeWidget extends StatelessWidget {<br>   final StepService _service;</pre><pre>   SomeWidget(this._service);<br>}</pre><h4>Interface injection</h4><p>First of all we need to define an abstract class with some implementation class, e.g.:</p><pre>abstract class UserRepository {<br>  Future&lt;List&lt;User&gt;&gt; allUsers();<br>}</pre><pre>class FirestoreUserRepository implements UserRepository {<br>   <a href="http://twitter.com/override">@override</a><br>   Future&lt;List&lt;User&gt;&gt; allUsers() {<br>   // implementation<br>   }<br>}</pre><p>And now we can provide dependencies in our module:</p><pre>import ‘package:inject/inject.dart’;</pre><pre><a href="http://twitter.com/module">@module</a><br>class UsersServices {<br>   <a href="http://twitter.com/provide">@provide</a><br>   UserRepository userRepository() =&gt; FirestoreUserRepository();<br>}</pre><h4>Providers</h4><p>What to do if we need not an instance of some class to be injected, but rather a provider, that will give us a new instance of this class each time? Or if we need to resolve the dependency lazily instead of getting concrete instance in the constructor? I found it neither in documentation (well, because there’s no documentation at all) nor in provided examples, but it actually works this way that you can request a function returning the required instance and it will be injected properly.</p><p>We can even define a helper type like this:</p><pre>typedef Provider&lt;T&gt; = T Function();</pre><p>and use it in our classes:</p><pre><a href="http://twitter.com/provide">@provide</a><br>class SomeWidget extends StatelessWidget {<br>   final Provider&lt;StepService&gt; _service;</pre><pre>SomeWidget(this._service);</pre><pre>void _someFunction() {<br>   final service = _service();<br>   // use service<br>   }<br>}</pre><h4>Assisted injection</h4><p>There’s no built-in functionality to inject objects that require arguments known at runtime only, so we can use the common pattern with factories in this case: create a factory class that takes all the compile-time dependencies in constructor and inject it, and provide a factory method with runtime argument that will create a required instance.</p><h4>Singletons, qualifiers and asynchronous injection</h4><p>Yes, the library supports all of this. There’s actually a good explanation in the official example.</p><h4>Wiring it up</h4><p>The final step in order to make everything work is to create an injector (aka component from Dagger), e.g. like this:</p><pre>import ‘main.inject.dart’ as g;</pre><pre><a href="http://twitter.com/Injector">@Injector</a>(const [UsersServices, DateResultsServices])<br>abstract class Main {<br>   <a href="http://twitter.com/provide">@provide</a><br>   MyApp get app;<br>   static Future&lt;Main&gt; create(<br>     UsersServices usersModule,<br>     DateResultsServices dateResultsModule,<br>   ) async {<br>     return await g.Main$Injector.create(<br>       usersModule,<br>       dateResultsModule,<br>     );<br>   }<br>}</pre><p>Here UserService and DateResultsServices are previously defined modules, MyApp is the root widget of our application, and main.inject.dart is an auto-generated file (more on this later).</p><p>Now we can define our main function like this:</p><pre>void main() async {<br>   var container = await Main.create(<br>      UsersServices(),<br>      DateResultsServices(),<br>   );<br>   runApp(container.app);<br>}</pre><h4>Running</h4><p>As inject works with code generation, we need to use build runner to generate the required code. We can use this command:</p><pre>flutter packages pub run build_runner build</pre><p>or watch command in order to keep the source code synced automatically:</p><pre>flutter packages pub run build_runner watch</pre><p>But there’s one important moment here: by default, the code will be generated into the cache folder and Flutter don’t currently support this (though there’s a work in progress in order to solve this problem). So we need to add the file inject_generator.build.yaml with the following content:</p><pre>builders:<br> inject_generator:<br> target: “:inject_generator”<br> import: “package:inject_generator/inject_generator.dart”<br> builder_factories:<br> — “summarizeBuilder”<br> — “generateBuilder”<br> build_extensions:<br> “.dart”:<br> — “.inject.summary”<br> — “.inject.dart”<br> auto_apply: dependents<br> build_to: source</pre><p>It’s actually the same content as in file inject.dart/package/inject_generator/build.yaml except for one line: build_to: cache has been replaced with `build_to: source`.</p><p>Now we can run the build_runner, it will generate the required code (and provide error messages if some dependencies cannot be resolved) and after that, we can run Flutter build as usual.</p><h4>Useful Resources:</h4><p>You should check the <a href="https://github.com/google/inject.dart">examples</a> provided with the library itself, and if you have some experience with Dagger library, inject will be really very familiar to you.</p><p>You should also check the <a href="https://github.com/zubairehman/flutter-boilerplate-project">boilerplate</a> project implemented using inject the library</p><p><strong><em>That&#39;s it for this article, if you liked this article, don’t forget to clap your hands 👏 as many times as you can to show your support, leave your comments and share it with your friends.</em></strong></p><p><a href="https://www.twitter.com/FlutterComm">JavaScript is not available.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f19fb66a0740" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/dependency-injection-in-flutter-f19fb66a0740">Dependency Injection 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[Flutter For Web]]></title>
            <link>https://itnext.io/flutter-for-web-c75011a41956?source=rss-88dd94cb5b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/c75011a41956</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-web]]></category>
            <category><![CDATA[hummingbird]]></category>
            <category><![CDATA[android-studio]]></category>
            <dc:creator><![CDATA[Zubair Rehman]]></dc:creator>
            <pubDate>Fri, 17 May 2019 09:11:13 GMT</pubDate>
            <atom:updated>2019-08-14T16:04:42.945Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter For Web: A Complete Guide to Create &amp; Run a Web Application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OlrI9IphckWpiNEzS9ielg.png" /><figcaption>Source: <a href="https://cdn-images-1.medium.com/max/1600/0*gD64Y8ECWBBuSZrx">https://cdn-images-1.medium.com/max/1600/0*gD64Y8ECWBBuSZrx</a></figcaption></figure><p>At Google I/O 2019 developer conference, Google launched version 1.5 of Flutter, its open source mobile UI framework that helps developers build native interfaces for Android and iOS. But that’s no longer true: The mobile framework is now a multi-platform UI framework, supporting the web, desktop, mobile, and even embedded devices. Flutter’s mission has expanded to building “the best framework for developing beautiful experiences for any screen.”</p><h3>Introduction</h3><p>Flutter was first announced at Google I/O in May 2017 with an alpha toolkit and in 2018 at Google I/O, it finally hit version 1.0 with a future new product, called <em>HummingBird</em>. We were all excited and could not wait for its release date and on May 7th 2019 at Google IO 2019, Google finally announced the availability of the <strong>Flutter for Web</strong> preview version.</p><p>Flutter has been created to give developers a fast development framework, and to users, a great engaging and fast experience. Flutter for web is a code-compatible implementation of Flutter that is rendered using standards-based web technologies: HTML, CSS and JavaScript. With Flutter for web, you can compile existing Flutter code written in Dart into a client experience that can be embedded in the browser and deployed to any web server. You can use all the features of Flutter, and you don’t need a browser plug-in.</p><h3>How to install</h3><p>In-order to develop for web you need flutter 1.5 and above, it enable support for targeting the web with Flutter, including Dart compilation to JavaScript. To use the Flutter SDK with the flutter_web preview make sure you have upgraded Flutter to at least v1.5.4 by running flutter upgrade from your machine.</p><pre>$ flutter upgrade</pre><p>To install the webdev package, which provides the build tools for <strong>Flutter for web</strong>, run the following:</p><pre>$ flutter packages pub global activate webdev</pre><p>Ensure that the $HOME/.pub-cache/bin directory is in your path, and then you may use the webdev command directly from your terminal.</p><p>In-order to add$HOME/.pub-cache/bin to your path, open path file by running below mentioned command from your terminal.</p><pre>$ touch ~/.bash_profile; open ~/.bash_profile</pre><p>It will open the file with TextEdit, make sure to have a reference to all components in your PATH and save it. If you open it again you’ll find your edits.</p><pre><strong>flutter sdk:</strong> <br>export PATH=$PATH:[Path to your flutter directory]/flutter/bin</pre><pre><strong>dart sdk:</strong> <br>export PATH=$PATH:[Path to your flutter directory]/flutter/bin/cache/dart-sdk/bin</pre><pre><strong>webdev:<br>mac:</strong> export PATH=$PATH:$HOME/.pub-cache/bin<br><strong>windows:</strong> %USERPROFILE%\AppData\Roaming\Pub\Cache\bin<br><strong>linux: </strong>$HOME/flutter/.pub-cache/bin</pre><blockquote>Note: if you have problems configuring webdev to run directly, try:<br>flutter packages pub global run webdev [command].</blockquote><p>Now that we are done setting up our development environment, let’s move forward to the next step of creating a web project.</p><h3>Tools support for Flutter web development</h3><p>Once the environment setup is done, you are gonna be needing an IDE to start developing for web. Choose your favourite IDE and follow the step by step instructions available below:</p><h4>Visual Studio Code</h4><p>Visual Studio Code supports Flutter web development with the v3.0 release of the <a href="https://dartcode.org/">Flutter extension</a>.</p><ul><li><a href="https://flutter.dev/docs/get-started/install">install</a> the Flutter SDK</li><li><a href="https://flutter.dev/docs/get-started/editor?tab=vscode">set up</a> VS Code</li><li>configure VS Code to point to your local Flutter SDK</li><li>run the Flutter: New Web Project command from VS Code</li><li>after the project is created, run your app by pressing F5 or “Debug -&gt; Start Debugging”</li><li>VS Code will use the webdev command-line tool to build and run your app; a new Chrome window should open, showing your running app</li></ul><h4>Using from IntelliJ</h4><ul><li><a href="https://flutter.dev/docs/get-started/install">install</a> the Flutter SDK</li><li><a href="https://flutter.dev/docs/get-started/editor">set up</a> your copy of IntelliJ or Android Studio</li><li>configure IntelliJ or Android Studio to point to your local Flutter SDK</li><li>create a new Dart project; note, for a Flutter for web app, you want to start from the Dart project wizard, not the Flutter project wizard</li><li>from the Dart project wizard, select the ‘Flutter for web’ option for the application template</li><li>create the project; pub get will be run automatically</li><li>once the project is created, hit the run button on the main toolbar</li><li>IntelliJ will use the webdev command-line tool to build and run your app; a new Chrome window should open, showing your running app</li></ul><h4><strong>Using Android Studio</strong></h4><p>In Android Studio there is no direct plug-in or template to create a web project, instead you can use <strong>Stagehand</strong> package that helps you get your web project set up. Stagehand is basically a Dart project scaffolding generator, inspired by tools like Web Starter Kit and Yeoman. In-order to create a web project with <strong>Stagehand, </strong>you need to<strong> </strong>follow the instructions below:</p><ul><li><a href="https://flutter.dev/docs/get-started/install">install</a> the Flutter SDK</li><li><a href="https://flutter.dev/docs/get-started/editor">set up</a> your copy of Android Studio</li><li>configure Android Studio to point to your local Flutter SDK</li><li>now run the following command from your terminal to install Stagehand $ pub global activate stagehand</li><li>once Stagehand is installed, you can use it to generate a project skeleton into the desired directory. As an example, here is how you create a simple web project with Stagehand:</li></ul><pre>$ mkdir flutter_web_project<br>$ cd flutter_web_project<br>$ stagehand web-simple</pre><p>And to list all of the project templates:</p><pre>$ stagehand</pre><ul><li>once the project is created, open that project in Android Studio and add the following dependencies in your pubspec.yaml file</li></ul><pre>dependencies:<br>  flutter_web: any<br>  flutter_web_ui: any<br><br>dev_dependencies:<br>  # Enables the `pub run build_runner` command<br>  build_runner: ^1.1.2<br>  # Includes the JavaScript compilers<br>  build_web_compilers: ^1.0.0<br><br># flutter_web packages are not published to pub.dartlang.org<br># These overrides tell the package tools to get them from GitHub<br>dependency_overrides:<br>  flutter_web:<br>    git:<br>      url: https://github.com/flutter/flutter_web<br>      path: packages/flutter_web<br>  flutter_web_ui:<br>    git:<br>      url: https://github.com/flutter/flutter_web<br>      path: packages/flutter_web_ui</pre><ul><li>run pub get from your terminal, this will download all the necessary packages</li><li>once done; create a lib folder in the root directory of your project</li><li>now create amain.dart file in the lib folder and paste the following code in it:</li></ul><pre>import &#39;package:flutter_web/material.dart&#39;;<br><br>void main() =&gt; runApp(Text(&#39;Hello World&#39;, textDirection: TextDirection.ltr));</pre><ul><li>once you are done; open the main.dart file present in web folder and paste the following code in it:</li></ul><pre>import &#39;package:fancy_proj/main.dart&#39; as app;<br>import &#39;package:flutter_web_ui/ui.dart&#39; as ui;<br><br>main() async {<br>  await ui.webOnlyInitializePlatform();<br>  app.main();<br>}</pre><ul><li>once everything is done, you are ready to test your web project. Run your app by typing the following command in your terminal:</li></ul><pre>$ webdev serve</pre><pre>[INFO] Generating build script completed, took 331ms<br>...<br>[INFO] Building new asset graph completed, took 1.4s<br>...<br>[INFO] Running build completed, took 27.9s<br>...<br>[INFO] Succeeded after 28.1s with 618 outputs (3233 actions)<br>Serving `web` on http://localhost:8080</pre><p>Open <a href="http://localhost:8080/">http://localhost:8080</a> in Chrome and you should see Hello World in red text in the upper-left corner.</p><h4>Getting (stateless) hot-reload with webdev</h4><p>To use webdev with hot-reload, run the following within your project directory:</p><pre>$ webdev serve --auto restart</pre><p>You’ll notice a similar output to flutter packages pub run build_runner serve but now changes to your application code should cause a quick refresh of the application on save.</p><blockquote>Note: the <em>--hot-reload</em> option is not perfect. If you notice unexpected behaviour, you may want to manually refresh the page.</blockquote><blockquote>Note: the <em>--hot-reload</em> option is currently &quot;stateless&quot;. Application state will be lost on reload. We do hope to offer &quot;stateful&quot; hot-reload on the web – we&#39;re actively working on it!</blockquote><h4>Stagehand templates</h4><p>There are many different templates available for Stagehand, a list all project templates are listed below:</p><ul><li>console-full - A command-line application sample.</li><li>package-simple - A starting point for Dart libraries or applications.</li><li>server-shelf - A web server built using the shelf package.</li><li>web-angular - A web app with material design components.</li><li>web-simple - A web app that uses only core Dart libraries.</li><li>web-stagexl - A starting point for 2D animation and games.</li></ul><h3>Useful resources</h3><ul><li><a href="https://github.com/flutter/flutter_web">flutter/flutter_web</a></li><li><a href="https://flutter.dev/web">Web support for Flutter</a></li></ul><p><strong><em>Thats it for this article, if you liked this article, don’t forget to clap your hands 👏 as many times as you can to show your support, leave your comments and share it with your friends.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c75011a41956" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/flutter-for-web-c75011a41956">Flutter For Web</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging in Flutter]]></title>
            <link>https://medium.com/flutter-community/logging-in-flutter-a583b3668228?source=rss-88dd94cb5b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/a583b3668228</guid>
            <category><![CDATA[logger]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[dart-package]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Zubair Rehman]]></dc:creator>
            <pubDate>Sun, 05 May 2019 17:26:27 GMT</pubDate>
            <atom:updated>2019-09-06T19:48:10.607Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SlPb_dFAE3NMVDz0rKWUIw.png" /></figure><p>I am sure that every developer out there has heard this phrase <em>‘Check the logs’</em> at least once in their career and checking the logs have saved us several times in many different situations. But what exactly a log message is and what are the advantages and disadvantages of logging? Let’s try to find out!</p><h3>What is logging?</h3><blockquote>Logging is the process of printing or saving information about what exactly your code is doing and what is the current data it works with.</blockquote><p>While developing mobile applications we, as developers, tend to put a lot of different logging priorities into our code. The reason why we do this is that we want to analyze certain activity in our apps. E.G. logic flows, stack-trace of methods execution, network requests, etc. This helps us to quickly identify and fix the issues that are hard to debug and reproduce.</p><h3>Pros &amp; cons of logging</h3><p>If used properly, logging can be a life-saving mechanism for discovering bugs, performance issues and other problems. But if done poorly, it can make your life miserable… We all know that feeling of going through thousands and thousands of lines of log messages without any useful info at all.</p><h3>Logging options in Flutter</h3><p>In Flutter there are different sets of options available for logging, one of which is <a href="https://pub.dartlang.org/packages/f_logs">FLog</a>. FLog is an advanced logging framework that provides a quick &amp; simple logging solution.</p><p>FLog is written in Dart and provides many of the advanced features needed for logging. Logs are saved in a database, which can then be exported as a zip file, which can then be uploaded to a server or to use locally to identify and debug issues. The logs can be filtered and sorted easily based on many useful filters available.</p><p>There are also several different types of log messages, which can be used in different situations:</p><ul><li>FLog.error — used for logging messages of type ERROR. This type is usually used inside of catch statements. It notifies us that something bad happened.</li><li>FLog.warning — used for logging messages of type WARN (warning). A common use-case for this type is when something strange happened, but it is not necessarily an error.</li><li>FLog.info — used for logging messages of type INFO. It’s perfect when we want to log some useful info like connecting to a server, successfully finishing a process, successfully receiving info from another universe, etc.</li><li>FLog.severe — It looks like FLog.error, but it’s way more severe. It’s to be used in these strange cases, which should never happen but… they do from time to time.</li></ul><h3>How to use</h3><p>To add FLogs to your flutter project, just paste in the below line in to pubspec.yaml file and get the dependencies.</p><pre>dependencies:   <br>   <strong>f_logs: ^1.1.1</strong></pre><h4>Runtime Permissions:</h4><p>Log files are exported to a storage directory, so it’s very important to add storage permission to your project:</p><p><strong>Android</strong>:</p><pre>&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;<br>&lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot;/&gt;</pre><p><strong>iOS</strong>:</p><pre>&lt;key&gt;NSPhotoLibraryAddUsageDescription&lt;/key&gt;<br>&lt;string&gt;FLogs would like to save photos from the app to your gallery&lt;/string&gt;<br>&lt;key&gt;NSPhotoLibraryUsageDescription&lt;/key&gt;<br>&lt;string&gt;FLogs would like to access your photo gallery for uploading images to the app&lt;/string&gt;</pre><h4><strong>Configuration</strong></h4><p>In-order to use logs, you can either provide your own configuration or use the one provided by FLogs. The default configuration can be requested by calling FLog.getDefaultConfigurations() method, which you can then override by providing your own set of values against each variable. Logs can be disabled by simply setting <strong><em>isLogsEnabled = false</em></strong>.</p><p>A complete list of configurable variables is available <a href="https://github.com/zubairehman/Flogs/wiki/Setup">here</a>.</p><pre>LogsConfig config = FLog.getDefaultConfigurations()<br>  ..isLogsEnabled = true<br>  ..timestampFormat = TimestampFormat.TIME_FORMAT_FULL_2;<br><br>FLog.applyConfigurations(config);</pre><h4>Available Methods</h4><p>To save logs, simply call any of the convenient methods mentioned below:</p><p><strong>1. Simple Info Log</strong></p><pre>FLog.info(<br>      className: &quot;HomePage&quot;,<br>      methodName: &quot;_buildRow1&quot;,<br>      text: &quot;My log text&quot;);</pre><p><strong>2. Simple Warning Log</strong></p><pre>FLog.warning(<br>      className: &quot;HomePage&quot;,<br>      methodName: &quot;_buildRow1&quot;,<br>      text: &quot;My log text&quot;;</pre><p><strong>3. Error Log</strong></p><pre>FLog.error(<br>      className: &quot;HomePage&quot;,<br>      methodName: &quot;_buildRow1&quot;,<br>      text: &quot;My log text&quot;);</pre><p><strong>4. Severe Log</strong></p><pre>FLog.severe(<br>      className: &quot;HomePage&quot;,<br>      methodName: &quot;_buildRow1&quot;,<br>      text: &quot;My log text&quot;);</pre><p><strong>5. Exception Log</strong></p><pre>FLog.logThis(<br>      className: &quot;HomePage&quot;,<br>      methodName: &quot;_buildRow1&quot;,<br>      text: &quot;My log text&quot;,<br>      type: LogLevel.SEVERE, <br>      exception: Exception(&quot;This is an Exception!&quot;));</pre><p><strong>6. Data Log</strong></p><pre>FLog.logThis(<br>      className: &quot;HomePage&quot;,<br>      methodName: &quot;_buildRow1&quot;,<br>      text: &quot;My log text&quot;,<br>      type: LogLevel.INFO,<br>      dataLogType: DataLogType.DEVICE.toString());</pre><blockquote>In above methods className and methodName are optional and, if not provided, will automatically be taken by getting calling class/method</blockquote><p><strong>7. printLogs</strong></p><pre>static printLogs() async {}</pre><p><strong>8. getAllLogsByCustomFilter</strong></p><pre>List&lt;Filter&gt; filters = [Filter.greaterThan(&#39;[FieldName]&#39;, &#39;[Value]&#39;)]<br><br>static Future&lt;List&lt;Log&gt;&gt; getAllLogsByCustomFilter(<br>    {List&lt;Filter&gt; filters}) async {}</pre><p><strong>9. getAllLogsByFilter</strong></p><pre>static Future&lt;List&lt;Log&gt;&gt; getAllLogsByFilter(<br>    {List&lt;String&gt; dataLogsType,<br>    List&lt;String&gt; logLevels,<br>    int startTimeInMillis,<br>    int endTimeInMillis,<br>    FilterType filterType}}) async {}</pre><p><strong>10. clearLogs</strong></p><pre>static clearLogs() {}</pre><p><strong>11. applyConfigurations</strong></p><pre>static applyConfigurations(LogsConfig config) {}</pre><p>A detail list of all the methods is available <a href="https://github.com/zubairehman/Flogs">here</a></p><h3>Resources</h3><ul><li><a href="https://pub.dartlang.org/packages/f_logs">f_logs | Flutter Package</a></li><li><a href="https://github.com/zubairehman/Flogs">zubairehman/Flogs</a></li></ul><p><strong><em>That&#39;s it for this article! If you liked it then don’t forget to clap, comment and share with friends!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a583b3668228" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/logging-in-flutter-a583b3668228">Logging 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[A Brief Introduction to Flutter]]></title>
            <link>https://zubairehman.medium.com/a-brief-introduction-to-flutter-ec189c7fb742?source=rss-88dd94cb5b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec189c7fb742</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[hybrid-apps]]></category>
            <category><![CDATA[hybrid-app-development]]></category>
            <dc:creator><![CDATA[Zubair Rehman]]></dc:creator>
            <pubDate>Sat, 06 Oct 2018 14:26:26 GMT</pubDate>
            <atom:updated>2018-10-06T14:43:12.139Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*6XmB8_gUBtHkt0twV6CgZA.png" /></figure><p>Now is an incredible time to be a mobile developer. Smartphones, tablets, and smart watches have become an important part of our lives, and Android and iOS keep getting better and adding new features at each new release. Great new frameworks help developers build apps faster and more reliably, and Flutter is, of course, one of those frameworks. Flutter is Google’s new mobile app toolkit for crafting beautiful native interfaces on iOS and Android in record time.</p><h3>Why Flutter?</h3><p>We could write hundreds of pages on the different ways to develop for mobile platforms. To make it really brief and simplifying a great deal, we have three major ways to develop for mobile, native, hybrid, and web.</p><h4>Native</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9vkeb_wfNlxq4MTTTYg4Cg.png" /></figure><p>Native means that we use the native official tools, and today, that means Android Studio with Java or Kotlin coding for Android and XCode with Swift or Objective-C for iOS. Android Studio and XCode with their supported languages are both great tools, tried and tested. They get new features as soon as they are available. They build fast and efficient apps using all the device capabilities natively, but they share one major disadvantage. If you want to build an app for both iOS and Android, you need to create and maintain two apps, one for each platform, and you need to know at least two languages.</p><h4>Web Apps</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XnQvioOrgrQLSefvWpFwoQ.png" /></figure><p>At the other end of the spectrum, we have web apps. We can access them from a browser and web apps lets us share the same code for both mobile and web development. This is great for developers who use HTML, CSS, and JavaScript. Only one code for any system, easy to use, easy to implement with one major flow. You cannot reach the device more advanced features and the user may feel your app isn’t really an app. It’s just a website really in the form of an app. Even if there are tools to overcome some, but not all of the limitations right now.</p><h4>Hybrid</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rhbnB3FCN94YSgKQK_qheg.png" /></figure><p>And there’s a third way. Tools like Xamarin, Cordova, Ionic, Reactive Native, just to name a few, those are called hybrid. Each of them has some advantages and disadvantages, but all these frameworks lets us build our apps with a single code base for mobile. They generally use some form of JavaScript, except for Xamarin that uses C#. The problem with most of them is they need a bridge between code and the mobile operating system and some of them have performances that are well below the level of native apps. Not only that, but in some cases, the complexity of using several third-party libraries and components with their compatibility issues can make the developer life a nightmare. Believe me when I say that I’ve been there.</p><h3>Where does Flutter fall then?</h3><p>In the hybrid category with a couple off features that Google believes can make the difference. The first one is that Flutter compiles to native for excellent performance. Actually, Flutter has two different compilation models. Just-in-time compilation where code is recompiled in real time allowing hard reload. This means that when we develop, we see the changes in real time with no need to recompile. You write the code and you see the results immediately on your device or emulator. Then we have ahead of time compilation. Code is compiled to native arm code for great performance on any device.</p><p>Flutter has been created to give developers a fast development framework, and to users, a great engaging and fast experience. And of course, you’ll have a single code base for both iOS and Android. Another difference from other hybrid frameworks is that with Flutter you don’t have bridges between your code and the device and this is another feature that can make Flutter stand out from some of its competitors. Actually, Flutter is a very young framework. It was announced at Google I/O in May 2017 with an alpha toolkit and at Google I/O 2018, the third beta was announced. So now, according to Google, Flutter is ready for production apps. Even if it’s production ready, there may be some major changes in the future.</p><h3>Dart as a programming language</h3><p>When we develop for Flutter, we use a language called Dart. It’s a strongly-typed object-oriented programming language developed by Google. If you don’t know Dart, don’t worry. If you are familiar with C#, Java, Swift, TypeScript, or even JavaScript, you’ll have no problems at all with Dart. You’ll see that it’s intuitive and easy to learn.</p><h3>Pre-requisites</h3><p>So what do you need to know before starting? Well you need to know any object-oriented programming language. If you understand variables, control flow, inheritance, classes, and objects, you’re good to go.</p><p>And what do you need to have? You can use a Windows PC, a Mac, or a Linux box with your favorite text editor (I personally prefer android studio). You’ll also need an Android device or emulator and if you are on a Mac, you can also use an iOS device or a simulator.</p><p>That’s all for now. I hope this article gave you good introduction about Flutter.</p><h3>Useful Links</h3><ul><li>Dart language: <a href="https://www.dartlang.org/guides/language/language-tour">https://www.dartlang.org/guides/language/language-tour</a></li><li>Dart packages: <a href="https://pub.dartlang.org/">https://pub.dartlang.org/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec189c7fb742" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>