<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mubeen Ur Rehman Jazib</title>
    <description>The latest articles on DEV Community by Mubeen Ur Rehman Jazib (@mubeenmurj).</description>
    <link>https://dev.to/mubeenmurj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F939249%2F69823038-46d1-4edc-be55-0642b962982e.jpeg</url>
      <title>DEV Community: Mubeen Ur Rehman Jazib</title>
      <link>https://dev.to/mubeenmurj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mubeenmurj"/>
    <language>en</language>
    <item>
      <title>Flutter Web Deployment on Netlify — Manual &amp; Automated (continuous)</title>
      <dc:creator>Mubeen Ur Rehman Jazib</dc:creator>
      <pubDate>Tue, 11 Oct 2022 18:59:56 +0000</pubDate>
      <link>https://dev.to/mubeenmurj/flutter-web-deployment-on-netlify-manual-automated-continuous-2cbl</link>
      <guid>https://dev.to/mubeenmurj/flutter-web-deployment-on-netlify-manual-automated-continuous-2cbl</guid>
      <description>&lt;p&gt;Out of several platforms supported by Flutter, the web has the easiest deployment process. Just one command away and then place the output code on the server. That’s all!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.netlify.com/" rel="noopener noreferrer"&gt;Netlify&lt;/a&gt; is a modern, high-performance platform to host websites, e-commerce stores, and web apps (as well as many other functionalities). We can also host Flutter web on Netlify.&lt;/p&gt;

&lt;p&gt;There are two ways to host Flutter web on Netlify:&lt;/p&gt;

&lt;h2&gt;
  
  
  1: Manual Deployment
&lt;/h2&gt;

&lt;p&gt;This is a relatively easy process. First of all, we build the web app for release using a simple command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

flutter build web


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This command will build the web app located at /build/web. This folder contains all the assets, and files related to the app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsjqa2uqfl670tg95j0xm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsjqa2uqfl670tg95j0xm.png" alt="Output folder containing web app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, you need to drag and drop the web folder or browse the folder in the Netlify project “deploys” tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgos48jbfhm11s1of8n3y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgos48jbfhm11s1of8n3y.png" alt="drag and drop section in netlify"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After some time taken by the deployment process, the site will be deployed.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F02luaz2f20n0tggs263a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F02luaz2f20n0tggs263a.png" alt="Site deployed using manual process"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Manual deployment is straightforward but must be done repeatedly after the app changes or updates. So let’s make it automated, the right way.&lt;/p&gt;

&lt;h2&gt;
  
  
  2: Automated Deployment (recommended)
&lt;/h2&gt;

&lt;p&gt;To make the deployment automated, you need to follow these simple steps.&lt;/p&gt;

&lt;p&gt;1: Connect the git repo to your Netlify site. (If your site already exists, then go to Site settings -&amp;gt; Build &amp;amp; deploy -&amp;gt; Continuous Deployment.)&lt;/p&gt;

&lt;p&gt;2: Select the git provider.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6lw8653trj7le8z075g0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6lw8653trj7le8z075g0.png" alt="picking the git provider"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3: Then select the repository.&lt;/p&gt;

&lt;p&gt;4: Set up the deployment settings. Fill up the fields with these values: Publish directory: &lt;code&gt;build/web&lt;/code&gt; and build command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

if [ -d "flutter" ]; then cd flutter &amp;amp;&amp;amp; git pull &amp;amp;&amp;amp; cd ..; else git clone https://github.com/flutter/flutter.git; fi; flutter/bin/flutter build web


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnrtv3m0fecqbpcdbowy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnrtv3m0fecqbpcdbowy.png" alt="Setting deployment settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5: Click the deploy site button and your site will be deployed. Congrats!!!  &lt;/p&gt;

&lt;h3&gt;
  
  
  Thinking about the build command given in step 4? 🤔
&lt;/h3&gt;

&lt;p&gt;Whenever the repo is updated, Netlify will start the deployment, and the build command will be executed.&lt;/p&gt;

&lt;p&gt;The command to build the web is really small, so why other complex commands? The answer is that we need Flutter SDK to build the web.&lt;/p&gt;

&lt;p&gt;We will fetch the Flutter SDK directly from GitHub by cloning it into our project git clone &lt;code&gt;https://github.com/flutter/flutter.git&lt;/code&gt;. A new folder “flutter” will be created on the root directory, which is why we need to get into it, then the bin folder, and at last execute our command &lt;code&gt;flutter/bin/flutter build web&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After the first deployment, the deployment will run into an error because the flutter will have been already cloned and can’t be cloned again. To dodge this problem, we need to place the git code into the conditional statement. If the flutter folder exists, then it will be updated to the latest version, else flutter will be cloned.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

if [ -d "flutter" ]; then cd flutter &amp;amp;&amp;amp; git pull &amp;amp;&amp;amp; cd ..; else git clone https://github.com/flutter/flutter.git; fi;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;On every deployment, the latest version of flutter will be pulled. But what if you wish to stay on a specific version of flutter?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Try this command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

if ! [[ -d "flutter" ]]; then git clone --single-branch --branch &amp;lt;BRANCH_NAME&amp;gt; https://github.com/flutter/flutter.git; fi; flutter/bin/flutter build web


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The site I uploaded is &lt;a href="https://ngflutter.netlify.app/" rel="noopener noreferrer"&gt;https://ngflutter.netlify.app/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>netlify</category>
    </item>
  </channel>
</rss>
