<?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: OLayemii</title>
    <description>The latest articles on DEV Community by OLayemii (@olayemii).</description>
    <link>https://dev.to/olayemii</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%2F144649%2F76c1244c-2d7f-4d97-81e2-8c5a48766f85.jpg</url>
      <title>DEV Community: OLayemii</title>
      <link>https://dev.to/olayemii</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/olayemii"/>
    <language>en</language>
    <item>
      <title>Adding Route Paths (Polylines) Between two Points to Google Maps in Flutter</title>
      <dc:creator>OLayemii</dc:creator>
      <pubDate>Sat, 30 Jan 2021 17:08:24 +0000</pubDate>
      <link>https://dev.to/olayemii/adding-route-paths-polylines-between-two-points-to-google-maps-in-flutter-23o2</link>
      <guid>https://dev.to/olayemii/adding-route-paths-polylines-between-two-points-to-google-maps-in-flutter-23o2</guid>
      <description>&lt;p&gt;Recently, I was working on a flutter project which requires maps and route lines showing the path between two coordinates (the source and destination coordinates).&lt;/p&gt;

&lt;p&gt;In this tutorial, I will show you how I was able to achieve this  using this two packages from &lt;a href="https://pub.dev" rel="noopener noreferrer"&gt;pub.dev&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://pub.dev/packages/google_maps_flutter" rel="noopener noreferrer"&gt;google_maps_flutter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pub.dev/packages/flutter_polyline_points" rel="noopener noreferrer"&gt;flutter_polyline_points&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After installing this packages, we need to create a google project and get a Google Maps API key from the &lt;a href="https://console.cloud.google.com/google/maps-apis" rel="noopener noreferrer"&gt;Google Developer Console&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can also check this &lt;a href="https://developers.google.com/maps/documentation/maps-static/get-api-key" rel="noopener noreferrer"&gt;article&lt;/a&gt; on how to get an api key. &lt;/p&gt;

&lt;p&gt;We also need to activate the following services on the developer console for our Google project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Maps SDK for Android&lt;/li&gt;
&lt;li&gt;Maps SDK for iOS&lt;/li&gt;
&lt;li&gt;Directions API&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;small&gt;&lt;em&gt;This can be done by clicking on the search icon on the app bar of the developer console and searching for this services then activating them&lt;/em&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;Lastly, we need to setup billing for our project, the Directions API which does the route generation requires billing to work. Though you won't be charged without activating auto charge after your free trial.&lt;/p&gt;

&lt;p&gt;You can read this article on &lt;a href="https://support.google.com/googleapi/answer/6158867?hl=en" rel="noopener noreferrer"&gt;How to Setup Billing For Your Google Developer Account&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We now need to setup Google maps for our flutter project. &lt;/p&gt;

&lt;h4&gt;
  
  
  On Android
&lt;/h4&gt;

&lt;p&gt;Specify your API key in the application manifest &lt;code&gt;android/app/src/main/AndroidManifest.xml&lt;/code&gt;:&lt;/p&gt;

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

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;manifest&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;application&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;meta&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="nl"&gt;android:&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"com.google.android.geo.API_KEY"&lt;/span&gt; 
&lt;span class="nl"&gt;android:&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"YOUR KEY HERE"&lt;/span&gt;&lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;


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

&lt;/div&gt;
&lt;h4&gt;
  
  
  On iOS
&lt;/h4&gt;

&lt;p&gt;Specify your API key in the application delegate &lt;code&gt;ios/Runner/AppDelegate.m&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;

&lt;span class="cp"&gt;#include&lt;/span&gt; &lt;span class="cpf"&gt;"AppDelegate.h"&lt;/span&gt;&lt;span class="cp"&gt;
#include&lt;/span&gt; &lt;span class="cpf"&gt;"GeneratedPluginRegistrant.h"&lt;/span&gt;&lt;span class="cp"&gt;
#import "GoogleMaps/GoogleMaps.h"
&lt;/span&gt;
&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="n"&gt;implementation&lt;/span&gt; &lt;span class="n"&gt;AppDelegate&lt;/span&gt;

&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BOOL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;UIApplication&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;application&lt;/span&gt;
    &lt;span class="n"&gt;didFinishLaunchingWithOptions&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NSDictionary&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;launchOptions&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;GMSServices&lt;/span&gt; &lt;span class="n"&gt;provideAPIKey&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="s"&gt;"YOUR KEY HERE"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;GeneratedPluginRegistrant&lt;/span&gt; &lt;span class="n"&gt;registerWithRegistry&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;super&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;application&lt;/span&gt; &lt;span class="n"&gt;didFinishLaunchingWithOptions&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;launchOptions&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Or in your swift code, specify your API key in the application delegate &lt;code&gt;ios/Runner/AppDelegate.swift&lt;/code&gt;:&lt;/p&gt;

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


&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;UIKit&lt;/span&gt;
&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;Flutter&lt;/span&gt;
&lt;span class="kd"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;GoogleMaps&lt;/span&gt;

&lt;span class="kd"&gt;@UIApplicationMain&lt;/span&gt;
&lt;span class="kd"&gt;@objc&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kt"&gt;AppDelegate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;FlutterAppDelegate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="nv"&gt;application&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;UIApplication&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;didFinishLaunchingWithOptions&lt;/span&gt; &lt;span class="nv"&gt;launchOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;UIApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;LaunchOptionsKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]?&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;GMSServices&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;provideAPIKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"YOUR KEY HERE"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kt"&gt;GeneratedPluginRegistrant&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;application&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;didFinishLaunchingWithOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;launchOptions&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
&lt;h1&gt;
  
  
  Adding Google Maps to Our Flutter Application
&lt;/h1&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'dart:async'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:google_maps_flutter/google_maps_flutter.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:flutter/material.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;runApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MyApp&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyApp&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StatefulWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;_MyAppState&lt;/span&gt; &lt;span class="n"&gt;createState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_MyAppState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Starting point latitude&lt;/span&gt;
  &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;_originLatitude&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;6.5212402&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Starting point longitude&lt;/span&gt;
  &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;_originLongitude&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.3679965&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Destination latitude&lt;/span&gt;
  &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;_destLatitude&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;6.849660&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Destination Longitude&lt;/span&gt;
  &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;_destLongitude&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.648190&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Markers to show points on the map&lt;/span&gt;
  &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MarkerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Marker&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;markers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt; 

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;_MyAppState&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;State&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MyApp&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Google Maps controller&lt;/span&gt;
  &lt;span class="n"&gt;Completer&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;GoogleMapController&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Completer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="c1"&gt;// Configure map position and zoom&lt;/span&gt;
  &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;CameraPosition&lt;/span&gt; &lt;span class="n"&gt;_kGooglePlex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CameraPosition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nl"&gt;target:&lt;/span&gt; &lt;span class="n"&gt;LatLng&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_originLatitude&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_originLongitude&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nl"&gt;zoom:&lt;/span&gt; &lt;span class="mf"&gt;9.4746&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt; 

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;initState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;/// add origin marker origin marker&lt;/span&gt;
    &lt;span class="n"&gt;_addMarker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="n"&gt;LatLng&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_originLatitude&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_originLongitude&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="s"&gt;"origin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;BitmapDescriptor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;defaultMarker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Add destination marker&lt;/span&gt;
    &lt;span class="n"&gt;_addMarker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="n"&gt;LatLng&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_originLatitude&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_originLongitude&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="s"&gt;"destination"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;BitmapDescriptor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;defaultMarkerWithHue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;initState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;MaterialApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;title:&lt;/span&gt; &lt;span class="s"&gt;'Welcome to Flutter'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;home:&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;appBar:&lt;/span&gt; &lt;span class="n"&gt;AppBar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;title:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Welcome to Flutter'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;GoogleMap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nl"&gt;mapType:&lt;/span&gt; &lt;span class="n"&gt;MapType&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;normal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nl"&gt;initialCameraPosition:&lt;/span&gt; &lt;span class="n"&gt;_kGooglePlex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nl"&gt;myLocationEnabled:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nl"&gt;tiltGesturesEnabled:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nl"&gt;compassEnabled:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nl"&gt;scrollGesturesEnabled:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nl"&gt;zoomGesturesEnabled:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nl"&gt;markers:&lt;/span&gt; &lt;span class="kt"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Marker&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;markers&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;values&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nl"&gt;onMapCreated:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;GoogleMapController&lt;/span&gt; &lt;span class="n"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="n"&gt;_controller&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;complete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
       &lt;span class="p"&gt;),&lt;/span&gt; 
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// This method will add markers to the map based on the LatLng position&lt;/span&gt;
  &lt;span class="n"&gt;_addMarker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;LatLng&lt;/span&gt; &lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;BitmapDescriptor&lt;/span&gt; &lt;span class="n"&gt;descriptor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;MarkerId&lt;/span&gt; &lt;span class="n"&gt;markerId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;MarkerId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;Marker&lt;/span&gt; &lt;span class="n"&gt;marker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="n"&gt;Marker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;markerId:&lt;/span&gt; &lt;span class="n"&gt;markerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;icon:&lt;/span&gt; &lt;span class="n"&gt;descriptor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;position:&lt;/span&gt; &lt;span class="n"&gt;position&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;markers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;markerId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;marker&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;This should render google maps with two markers at the origin and destination coordinates.&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%2Fi%2Fssp8bbn4mrd0nlqkygve.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%2Fi%2Fssp8bbn4mrd0nlqkygve.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Adding Polylines Between the Locations on Our Map
&lt;/h1&gt;

&lt;p&gt;Now all we need to do is add the polylines to show the path between our point. To do this we make use of the &lt;code&gt;flutter_polyline_points&lt;/code&gt; package&lt;/p&gt;

&lt;p&gt;Add ```dart&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;import 'package:flutter_polyline_points/flutter_polyline_points.dart';{% raw %}&lt;code&gt;&lt;br&gt;
&lt;/code&gt;``&lt;br&gt;
to the imports at the top of the file.&lt;/p&gt;

&lt;p&gt;Next, we need to define a variable to store the polylines we will later query for, and create a PolylinePoints object too.&lt;/p&gt;

&lt;p&gt;Add this among other class properties we defined earlier&lt;/p&gt;

&lt;p&gt;&lt;code&gt;`dart&lt;br&gt;
  PolylinePoints polylinePoints = PolylinePoints();&lt;br&gt;
  Map&amp;lt;PolylineId, Polyline&amp;gt; polylines = {};&lt;br&gt;
`&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to write a method to help us query the directions API for the points of the polyline&lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;dart&lt;br&gt;
    void _getPolyline() async {&lt;br&gt;
    List polylineCoordinates = [];&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
  Constants.API_KEY,
  PointLatLng(_originLatitude, _originLongitude),
  PointLatLng(_destLatitude, _destLongitude),
  travelMode: TravelMode.driving,
);
if (result.points.isNotEmpty) {
  result.points.forEach((PointLatLng point) {
    polylineCoordinates.add(LatLng(point.latitude, point.longitude));
  });
} else {
  print(result.errorMessage);
}
_addPolyLine(polylineCoordinates);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
&lt;code&gt;&lt;/code&gt;`&lt;/p&gt;

&lt;p&gt;We referenced a &lt;code&gt;_addPolyLine&lt;/code&gt; function from the &lt;code&gt;_getPolyline&lt;/code&gt; function, the &lt;code&gt;_addPolyLine&lt;/code&gt; will help us populate the maps with the polyline points. Let's create this method too&lt;/p&gt;

&lt;p&gt;&lt;code&gt;`dart&lt;br&gt;
  _addPolyLine(List&amp;lt;LatLng&amp;gt; polylineCoordinates) {&lt;br&gt;
    PolylineId id = PolylineId("poly");&lt;br&gt;
    Polyline polyline = Polyline(&lt;br&gt;
      polylineId: id,&lt;br&gt;
      color: Constants.primaryColorSwatch,&lt;br&gt;
      points: polylineCoordinates,&lt;br&gt;
      width: 8,&lt;br&gt;
    );&lt;br&gt;
    polylines[id] = polyline;&lt;br&gt;
    setState(() {});&lt;br&gt;
  }&lt;br&gt;
`&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then we add the &lt;code&gt;polylines&lt;/code&gt; object to our &lt;code&gt;GoogleMap&lt;/code&gt; property&lt;/p&gt;

&lt;p&gt;&lt;code&gt;`dart&lt;br&gt;
   polylines: Set&amp;lt;Polyline&amp;gt;.of(polylines.values),&lt;br&gt;
`&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the final code &lt;/p&gt;

&lt;p&gt;`&lt;code&gt;&lt;/code&gt;dart&lt;br&gt;
import 'dart:async';&lt;/p&gt;

&lt;p&gt;import 'package:google_maps_flutter/google_maps_flutter.dart';&lt;br&gt;
import 'package:flutter/material.dart';&lt;/p&gt;

&lt;p&gt;void main() =&amp;gt; runApp(MyApp());&lt;/p&gt;

&lt;p&gt;class MyApp extends StatefulWidget {&lt;br&gt;
  &lt;a class="mentioned-user" href="https://dev.to/override"&gt;@override&lt;/a&gt;&lt;br&gt;
  _MyAppState createState() =&amp;gt; _MyAppState();&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;// Starting point latitude&lt;br&gt;
  double _originLatitude = 6.5212402;&lt;br&gt;
// Starting point longitude&lt;br&gt;
  double _originLongitude = 3.3679965;&lt;br&gt;
// Destination latitude&lt;br&gt;
  double _destLatitude = 6.849660;&lt;br&gt;
// Destination Longitude&lt;br&gt;
  double _destLongitude = 3.648190;&lt;br&gt;
// Markers to show points on the map&lt;br&gt;
  Map markers = {}; &lt;/p&gt;

&lt;p&gt;PolylinePoints polylinePoints = PolylinePoints();&lt;br&gt;
  Map polylines = {};&lt;/p&gt;

&lt;p&gt;class _MyAppState extends State {&lt;br&gt;
  // Google Maps controller&lt;br&gt;
  Completer _controller = Completer();&lt;br&gt;
  // Configure map position and zoom&lt;br&gt;
  static final CameraPosition _kGooglePlex = CameraPosition(&lt;br&gt;
    target: LatLng(_originLatitude, _originLongitude),&lt;br&gt;
    zoom: 9.4746,&lt;br&gt;
  ); &lt;/p&gt;

&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/override"&gt;@override&lt;/a&gt;&lt;br&gt;
  void initState() {&lt;br&gt;
    /// add origin marker origin marker&lt;br&gt;
    _addMarker(&lt;br&gt;
      LatLng(_originLatitude, _originLongitude),&lt;br&gt;
      "origin",&lt;br&gt;
      BitmapDescriptor.defaultMarker,&lt;br&gt;
    );&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Add destination marker
_addMarker(
  LatLng(_destLatitude, _destLongitude),
  "destination",
  BitmapDescriptor.defaultMarkerWithHue(90),
);

_getPolyline();

super.initState();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
  &lt;a class="mentioned-user" href="https://dev.to/override"&gt;@override&lt;/a&gt;&lt;br&gt;
  Widget build(BuildContext context) {&lt;br&gt;
    return MaterialApp(&lt;br&gt;
      title: 'Welcome to Flutter',&lt;br&gt;
      home: Scaffold(&lt;br&gt;
        appBar: AppBar(&lt;br&gt;
          title: Text('Welcome to Flutter'),&lt;br&gt;
        ),&lt;br&gt;
        body: GoogleMap(&lt;br&gt;
            mapType: MapType.normal,&lt;br&gt;
            initialCameraPosition: _kGooglePlex,&lt;br&gt;
            myLocationEnabled: true,&lt;br&gt;
            tiltGesturesEnabled: true,&lt;br&gt;
            compassEnabled: true,&lt;br&gt;
            scrollGesturesEnabled: true,&lt;br&gt;
            zoomGesturesEnabled: true,&lt;br&gt;
            polylines: Set.of(polylines.values),&lt;br&gt;
            markers: Set.of(markers.values),&lt;br&gt;
            onMapCreated: (GoogleMapController controller) {&lt;br&gt;
              _controller.complete(controller);&lt;br&gt;
            },&lt;br&gt;
       ), &lt;br&gt;
      ),&lt;br&gt;
    );&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;// This method will add markers to the map based on the LatLng position&lt;br&gt;
  _addMarker(LatLng position, String id, BitmapDescriptor descriptor) {&lt;br&gt;
    MarkerId markerId = MarkerId(id);&lt;br&gt;
    Marker marker =&lt;br&gt;
        Marker(markerId: markerId, icon: descriptor, position: position);&lt;br&gt;
    markers[markerId] = marker;&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;_addPolyLine(List polylineCoordinates) {&lt;br&gt;
    PolylineId id = PolylineId("poly");&lt;br&gt;
    Polyline polyline = Polyline(&lt;br&gt;
      polylineId: id,&lt;br&gt;
      points: polylineCoordinates,&lt;br&gt;
      width: 8,&lt;br&gt;
    );&lt;br&gt;
    polylines[id] = polyline;&lt;br&gt;
    setState(() {});&lt;br&gt;
  }&lt;/p&gt;

&lt;p&gt;void _getPolyline() async {&lt;br&gt;
    List polylineCoordinates = [];&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
  "YOUR API KEY HERE",
  PointLatLng(_originLatitude, _originLongitude),
  PointLatLng(_destLatitude, _destLongitude),
  travelMode: TravelMode.driving,
);
if (result.points.isNotEmpty) {
  result.points.forEach((PointLatLng point) {
    polylineCoordinates.add(LatLng(point.latitude, point.longitude));
  });
} else {
  print(result.errorMessage);
}
_addPolyLine(polylineCoordinates);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
}&lt;br&gt;
&lt;code&gt;&lt;/code&gt;`&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%2Fi%2Fpfv79g75lhysw7ehr1qf.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%2Fi%2Fpfv79g75lhysw7ehr1qf.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a &lt;a href="https://gist.github.com/OLayemii/43bbedc0716d3b66bbd7e8577bcc8580" rel="noopener noreferrer"&gt;link to a gist with complete code&lt;/a&gt; &lt;/p&gt;

</description>
      <category>flutter</category>
      <category>google</category>
      <category>maps</category>
      <category>polylines</category>
    </item>
    <item>
      <title>Cleaner React git commits</title>
      <dc:creator>OLayemii</dc:creator>
      <pubDate>Sat, 09 Jan 2021 17:12:40 +0000</pubDate>
      <link>https://dev.to/olayemii/cleaner-react-git-commits-9b3</link>
      <guid>https://dev.to/olayemii/cleaner-react-git-commits-9b3</guid>
      <description>&lt;p&gt;&lt;em&gt;In this article, we’re going to learn how we can improve the quality of codes we commit to git by beautifying and linting at the point of commit. We’ll walk through an example React app to see how with husky, we can configure githooks to trigger code linting and beautification before committing to git.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When we write softwares, we always want to keep our codebase to be clean, readable, free from unused fragments and consistent across files. However, this is a hectic task to handle manually.&lt;/p&gt;

&lt;p&gt;In this tutorial, I will be showing you how you can effortlessly make setups for automatic code linting and beautification before any commit to git.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;Since we’ll be using React for this tutorial, the first step is to create a new react application.&lt;br&gt;
I will be scaffolding a new React application with the CRA tool.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# scaffold new react application
npx create-react-app react-husky-setup

# navigate to the newly created application
cd react-husky-setup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, we will install all the tools we need as development dependencies.&lt;/p&gt;

&lt;p&gt;I have outlined every dependency we need to install before we unlock this super powers I have been talking about.&lt;/p&gt;

&lt;p&gt;[ ] Install PrettierJS&lt;br&gt;
[ ] Install EsLint and EsLint plugins&lt;br&gt;
[ ] Install Lint-staged&lt;br&gt;
[ ] Intall HuskyJS&lt;br&gt;
[ ] Unlock Awesomeness&lt;/p&gt;

&lt;h3&gt;
  
  
  Install PrettierJS
&lt;/h3&gt;

&lt;p&gt;According to the official website, &lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Prettier is an opinionated code formatter with support for: JavaScript, including ES2017 , JSX, Angular, Vue, Flow, TypeScript; CSS, Less, and SCSS, HTML, JSON, GraphQL, Markdown, including GFM and MDX and YAML.&lt;/p&gt;

&lt;p&gt;It removes all original styling* and ensures that all outputted code conforms to a consistent style..&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will be using prettier to format badly indented codes and perform code formatting before making commits. Let’s install prettier&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# install with yarn
yarn add prettier --dev --exact

# install with npm
npm install --save-dev --save-exact prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We then create a &lt;code&gt;.prettierrc&lt;/code&gt; file in our root directory, this will allow us configure prettier based on our standards.&lt;/p&gt;

&lt;p&gt;This is my preferred configuration:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "printWidth": 100,
  "tabWidth": 2,
  "useTabs": false,
  "semi": true,
  "singleQuote": false,
  "trailingComma": "none",
  "bracketSpacing": true,
  "jsxBracketSameLine": false,
  "jsxSingleQuote": false,
  "proseWrap": "always",
  "htmlWhitespaceSensitivity": "css",
  "quoteProps": "as-needed"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Install ES Lint and ES Lint plugins
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;ESLint is a  pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. ESLint helps you maintain your code quality with ease.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# install with yarn 
yarn add eslint babel-eslint eslint-config-prettier eslint-plugin-html eslint-plugin-prettier --dev

# install with npm

npm install --save-dev eslint babel-eslint eslint-config-prettier eslint-plugin-html eslint-plugin-prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We are installing eslint along with some eslint based plugins. The extra plugins and their uses are listed in the table below:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;babel-eslint&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This allows you to lint ALL valid Babel code including experimental features (such as new features).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;eslint-config-prettier&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This turns off all rules that are unnecessary or might conflict with Prettier.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;eslint-plugin-html&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This will allow eslint to lint inline scripts embeded within HTML&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;eslint-plugin-prettier&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This runs Prettier as an ESLint rule and reports differences as individual ESLint issues.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;We also need to create an &lt;code&gt;.eslintrc&lt;/code&gt; file in our root directory to configure eslint. This is my preferred configurations:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "env": {
    "browser": true,
    "es6": true
  },
  "extends": ["eslint:recommended", "react-app", "prettier"],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "plugins": ["react-hooks"],
  "rules": {
    "linebreak-style": ["error", "unix"],
    "quotes": ["error", "double"],
    "semi": ["error", "always"],
    "no-console": 2,
    "no-alert": 2,
    "no-func-assign": 1,
    "no-invalid-regexp": 1,
    "no-unreachable": 1,
    "default-case": 1,
    "react-hooks/rules-of-hooks": "error",
    "react-hooks/exhaustive-deps": "warn"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Install Lint-Staged
&lt;/h3&gt;

&lt;p&gt;Lint staged allows us to lint only staged code, this is because running a lint process on a whole project is slow and some linting results from an overall linting can be irrelevant. Therefore, lint staged helps us to confine our linting to only staged codes making the process faster and efficient (since we only need to lint codes we intend to commit anyway).&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# install with yarn
yarn add lint-staged --dev --exact

# install with npm
npm install --save-dev lint-staged
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We’ll then setup lint-stage by including a config object in our &lt;code&gt;package.json&lt;/code&gt; file&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#... Rest package.json
"lint-staged": {
  "**/*.+(js|ts|graphql|yml|yaml|vue)": [
    "eslint --fix",
    "prettier --write",
    "git add"
  ],
  "*/*.+(css|sass|less|scss|json|html)": [
    "prettier --write",
    "git add"
  ]
}


Here we are configuring lint-staged to run `eslint, prettier` then perform a new `git add` to staged codes for all `js,ts,graphql,yaml,vue` files and to only run `prettier` and a `git add` for `css, sass, less, scss, json, html` files.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Install HuskyJS
&lt;/h3&gt;

&lt;p&gt;When we use git, we automatically have access to use git hooks, git hooks allow us to hook into various hook events and perform functions before or after this events. We can see a list of available git hooks if we check &lt;code&gt;.git/hooks&lt;/code&gt; directory in our project.&lt;br&gt;
You can see also see the list of supported hooks from the documentation. However, for this tutorial we are only really concerned about the &lt;code&gt;pre-commit&lt;/code&gt; hook. This hook is executed before a git commit operation.&lt;br&gt;
The turn down of using git hooks is that you can only write them as bash scripts. But we dont want to go through the hazzle of learning a new language for this purpose, and that is where husky comes into play.&lt;/p&gt;

&lt;p&gt;Husky allows us write git hooks easily and makes it easier to share them across team members.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# install with yarn
yarn add husky --dev

# install with npm
npm install --save-dev husky
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To configure husky to use our custom &lt;code&gt;pre-commit&lt;/code&gt; hook, we need to include husky configuration to our package.json file&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#... Rest package.json
"husky": {
  "hooks": {
    "pre-commit": "lint-staged"
  }
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This tells husky to run the commands we defined for &lt;code&gt;lint-staged&lt;/code&gt; in our &lt;code&gt;package.json&lt;/code&gt; file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Unlock Awesomeness
&lt;/h3&gt;

&lt;p&gt;Finally we’ve gone through all installations and setups, from my &lt;code&gt;.eslintrc&lt;/code&gt; rules, I enabled and error flag for  &lt;code&gt;console&lt;/code&gt; statements in my codebase, so let’s try adding a &lt;code&gt;console.log&lt;/code&gt; statement to our &lt;code&gt;App.js&lt;/code&gt; file and try committing our code to git.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gjYXixm0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_8E84AE0AAA0112E34926EA17BE216A11A534A240D81D8A5317C615B571DE61C1_1592862844070_code.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gjYXixm0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_8E84AE0AAA0112E34926EA17BE216A11A534A240D81D8A5317C615B571DE61C1_1592862844070_code.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NlIs_gdq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_8E84AE0AAA0112E34926EA17BE216A11A534A240D81D8A5317C615B571DE61C1_1592862607119_Screenshot%2B2020-06-22%2Bat%2B22.47.26.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NlIs_gdq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://paper-attachments.dropbox.com/s_8E84AE0AAA0112E34926EA17BE216A11A534A240D81D8A5317C615B571DE61C1_1592862607119_Screenshot%2B2020-06-22%2Bat%2B22.47.26.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aha! Eslint flags the console statement so our intended commit is reverted and we get to see what line has errors.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
