<?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 Ashna Nizam on Medium]]></title>
        <description><![CDATA[Stories by Ashna Nizam on Medium]]></description>
        <link>https://medium.com/@ashnizaster?source=rss-a80870f2b002------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*A6bc25ZRYawl2QkjCIi0LA.png</url>
            <title>Stories by Ashna Nizam on Medium</title>
            <link>https://medium.com/@ashnizaster?source=rss-a80870f2b002------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 02:33:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashnizaster/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[Live Streaming App using Flutter and ZEGOCLOUD]]></title>
            <link>https://ashnizaster.medium.com/live-streaming-app-using-flutter-and-zegocloud-46e046cbc0e1?source=rss-a80870f2b002------2</link>
            <guid isPermaLink="false">https://medium.com/p/46e046cbc0e1</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[zegocloud]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[live-streaming]]></category>
            <dc:creator><![CDATA[Ashna Nizam]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 05:42:56 GMT</pubDate>
            <atom:updated>2023-03-20T05:42:56.497Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*EMzE4CmseK-fJy2xmLj6KQ.png" /></figure><p>Hey guys, welcome back. So today we will be learning how to create a simple livestreaming app using Flutter and ZEGOCLOUD. Before we dive in lets get familiar with what is <a href="https://www.zegocloud.com/">ZEGOCLOUD</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/0*Bdo0kT3Jz2b65BQN.jpeg" /></figure><h3>What is ZEGOCLOUD?</h3><p>ZEGOCLOUD is a professional audio and video global cloud service provider dedicated to providing quality real-time audio and video services. These services include video calls, video conferencing, audio calls and even live streaming. It uses <a href="https://www.zegocloud.com/product/video-call">Express Video SDK</a> that is a fully featured and Robust SDK. It provides high quality videos with low latency (low network bandwidth). Apart from that it is easy to integrate and beginner friendly for developers. ZEGOCLOUD provides 10,000 free minutes for developers to build powerful communication applications.</p><p>It even provides <a href="https://www.zegocloud.com/uikits">UIKits</a> and SDK’s to build customized UI. Today we will be mainly focusing on building a livestreaming app using UI kits.</p><h3>Pre-requisites</h3><ol><li><strong>Flutter version &gt; 1.12</strong></li><li><strong>ZEGOCLOUD account</strong></li><li><strong>Basic knowledge about Flutter</strong></li></ol><h3>Video tutorial</h3><p>I have also uploaded a video tutorial in YouTube. Make sure to check it out and hit the like and subscribe button if you guys found it useful.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FHOmE4lzpycw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DHOmE4lzpycw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FHOmE4lzpycw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/96239105359e62acf54966e9c0bb12e7/href">https://medium.com/media/96239105359e62acf54966e9c0bb12e7/href</a></iframe><h3>Let’s get started</h3><p>Open Android Studio and create a new Flutter Project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/0*z4hmLxzojLeOc80Z.png" /></figure><p>After that provide a name to your project. Note that the name should only have lower case letters and underscores. Then check the flutter SDK path and click finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*4uuceHWiZWrYi8dRLJaH3Q.png" /></figure><p>Once the project is created, in main.dart clear the starting code and inside runApp() call the MaterialApp() widget. Here we will be adding all the code. So first we will have to import the dependency for creating material UI.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><p>Next we will change the theme to a deep purple color as the primary swatch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*mBc06lMJf3iwmSz3gPqBsg.png" /></figure><p>Next we will create the home screen. For this we will be implementing the <a href="https://api.flutter.dev/flutter/widgets/StatelessWidget-class.html">stateless widget</a>. And we will call this HomeScreen() inside the MaterialApp().</p><pre>void main() {<br>  runApp(<br>    MaterialApp(<br>      home: HomeScreen(),<br>      debugShowCheckedModeBanner: false,<br>      theme: ThemeData(<br>        primarySwatch: Colors.deepPurple,<br>      ),<br>    ),<br>  );<br>}</pre><p>Next we will create the HomeScreen() which will have 2 buttons — <strong>Start live</strong> and <strong>Join live</strong> buttons. The code is as given below.</p><pre>class HomeScreen extends StatelessWidget {<br>  const HomeScreen({Key? key}) : super(key: key);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return SafeArea(<br>      child: Scaffold(<br>        appBar: AppBar(<br>          title: Text(&quot;Livestream Demo&quot;),<br>          centerTitle: true,<br>        ),<br>        body: Center(<br>          child: Column(<br>            mainAxisAlignment: MainAxisAlignment.center,<br>            children: [<br>              ElevatedButton(<br>                  onPressed: () {<br>                    String user = Random().nextInt(1000).toString();<br>                    Navigator.push(<br>                      context,<br>                      MaterialPageRoute(<br>                        builder: (context) =&gt; LiveStreamingScreen(<br>                          user: user,<br>                          isHost: true,<br>                        ),<br>                      ),<br>                    );<br>                  },<br>                  child: Text(&quot;Start Live&quot;)),<br>              ElevatedButton(<br>                  onPressed: () {<br>                    String user = Random().nextInt(1000).toString();<br>                    Navigator.push(<br>                      context,<br>                      MaterialPageRoute(<br>                        builder: (context) =&gt; LiveStreamingScreen(<br>                          user: user,<br>                          isHost: false,<br>                        ),<br>                      ),<br>                    );<br>                  },<br>                  child: Text(&quot;Join Live&quot;)),<br>            ],<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>The above code provides an AppBar() to display the app title. Apart from that it contains the <strong>Start Live</strong> and <strong>Join Live</strong> buttons arranged centrally in a column fashion.</p><p>The custom <strong>isHost</strong> property determines if the user joining is the host or the audience of the livestream. The <strong>user</strong> value is given a random number from 1–1000 and the value is converted to a string. This value represents the different users who are part of the livestream. In order to integrate the random number generator we should add the dart:math library</p><pre>import &#39;dart:math&#39;;</pre><p>Next we will be moving to the livestream section of the app. For this first we will import the zego_uikit_prebuilt_live_streaming dependency. For this run the following command.</p><p>flutter pub add zego_uikit_prebuilt_live_streaming</p><p>This will add the latest zego_uikit_prebuilt_live_streaming dependency. Next we will import the package in our main.dart</p><pre>import &#39;package:zego_uikit_prebuilt_live_streaming/zego_uikit_prebuilt_live_streaming.dart&#39;;</pre><p>Next we create the LiveStreamingScreen() using <a href="https://api.flutter.dev/flutter/widgets/StatelessWidget-class.html">stateless widget</a>. We do this by adding the ZegoUIKitPrebuiltLiveStreaming() widget which is part of the zego_uikit_prebuilt_live_streaming.dart file. The code is as below.</p><pre>class LiveStreamingScreen extends StatelessWidget {<br>  final String user;<br>  final bool isHost;<br>  const LiveStreamingScreen({<br>    Key? key,<br>    required this.user,<br>    required this.isHost,<br>  }) : super(key: key);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return SafeArea(<br>      child: ZegoUIKitPrebuiltLiveStreaming(<br>        appID: &quot;YOUR APP ID&quot;,<br>        appSign:<br>            &quot;YOUR APP SIGN&quot;,<br>        userID: user,<br>        userName: user,<br>        liveID: &quot;liveID&quot;,<br>        config: isHost<br>            ? ZegoUIKitPrebuiltLiveStreamingConfig.host()<br>            : ZegoUIKitPrebuiltLiveStreamingConfig.audience(),<br>      ),<br>    );<br>  }<br>}</pre><p>In the above code, the userName and userID properties are given the same value for convenience. To scale up the app, you can map custom <strong>userID</strong>’s to <strong>userNames</strong>. The liveID property holds the id for the livestream. You can give a value from a TextField() to make it custom instead of static value. This value determines which livestream the user will be joining. The config property has the custom UI configurations for the host and audience. This can be set as ZegoUIKitPrebuiltLiveStreamingConfig.host() or ZegoUIKitPrebuiltLiveStreamingConfig.audience() which is given based on the custom isHost property.</p><p>In order to get appID and appSign values we will need to create a project in the ZEGOCLOUD project dashboard. To access the project dashboard <a href="https://console.zegocloud.com/"><strong>click here</strong></a>.</p><p>In the console you will be prompted to the window as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*zkqrIHxZtMbjiJlt.png" /></figure><p>If you already have an account directly login else sign up by filling in the details to create one.</p><p>Once you have your account created, click on create new project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/0*sv-Wkd2W9lZmszff.png" /></figure><p>Next choose the use case of our project. For our purpose we will be using the <strong>Live Streaming </strong>use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*st71zOPUKNj6LtOz64UtYQ.png" /></figure><p>After that give your project a suitable name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*OHGTwBoz1Y7ajyMF.png" /></figure><p>Then for our purpose we will <strong><em>start with UI kits</em></strong> as shown below. In that the code used for each platform is also given so we as developers can better understand it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*GuJE4yfJc4FjEyMtLZpkyQ.png" /></figure><p>Once our project is successfully build we will see a button with a text saying <strong><em>start building your app</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*iD_P7nl2AeI2jauRk9RyGQ.png" /></figure><p>Click the button and then we will be prompted to select the framework for our project. Choose Flutter as the Framework for the project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*ymMtH_Ff1qDz_hYM.png" /></figure><p>This will take us to the UI configuration page as shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EEbS6jV0vsOhtk191Mc_NQ.png" /></figure><p>As we scroll down press the <strong>Save &amp; Start to integrate</strong> button to access the app id and app sign of the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fBSwd7fybnzigVWYpTHgrA.png" /></figure><p>Once that is done you will be taken to the project configuration page where you will get your app id and app sign.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9OE4uromWG-YE16FceNc6Q.png" /></figure><p>Add these values to the appID and appSign properties</p><pre>ZegoUIKitPrebuiltLiveStreaming(<br>        appID: &quot;YOUR APP ID&quot;,<br>        appSign:<br>            &quot;YOUR APP SIGN&quot;,<br>        userID: user,<br>        userName: user,<br>        liveID: &quot;liveID&quot;,<br>        config: isHost<br>            ? ZegoUIKitPrebuiltLiveStreamingConfig.host()<br>            : ZegoUIKitPrebuiltLiveStreamingConfig.audience(),<br>      ),</pre><p>Next we need to add the android and iOS configurations.</p><h4>Android configurations</h4><p>First open the android/app/build.gradle file. Modify the compileSdkVersion under the android block to <strong>33</strong></p><pre>android {<br>    compileSdkVersion 33</pre><p>Next we have to add the permissions. For that open your android/app/src/main/AndroidManifest.xml file and add the following lines of code inside the &lt;manifest&gt; tag before the &lt;application&gt; tag.</p><pre>&lt;uses-permission android:name=”android.permission.ACCESS_WIFI_STATE” /&gt;<br>&lt;uses-permission android:name=”android.permission.RECORD_AUDIO” /&gt; <br>&lt;uses-permission android:name=”android.permission.INTERNET” /&gt; <br>&lt;uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” /&gt; <br>&lt;uses-permission android:name=”android.permission.CAMERA” /&gt; <br>&lt;uses-permission android:name=”android.permission.BLUETOOTH” /&gt; <br>&lt;uses-permission android:name=”android.permission.MODIFY_AUDIO_SETTINGS” /&gt; <br>&lt;uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” /&gt; <br>&lt;uses-permission android:name=”android.permission.READ_PHONE_STATE” /&gt; <br>&lt;uses-permission android:name=”android.permission.WAKE_LOCK” /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*S6p-6HcJIodlUoqe.png" /></figure><p>After that create a file proguard-rules.pro inside android/app folder. This is done to prevent obfuscation of the SDK public class names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/0*8zYv3czBWt0l_DRX.png" /></figure><p>In proguard-rules.pro add the following lines of code.</p><pre>-keep class **.zego.** { *; }</pre><p>Now we will add the following config code to the release part of android/app/build.gradle</p><pre>proguardFiles getDefaultProguardFile(&#39;proguard-android.txt&#39;), &#39;proguard-rules.pro&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*VxblllzsY7C-M1_v.png" /></figure><p>Once that is done we are done with the android configurations. Moving on we will be implementing the iOS configurations.</p><h3>iOS Configurations</h3><p>For iOS we need to add the app permissions. For that add the following lines of code in ios/Runner/Info.plist</p><pre>&lt;key&gt;NSCameraUsageDescription&lt;/key&gt;<br>&lt;string&gt;We require camera access to connect to a video conference&lt;/string&gt;<br>&lt;key&gt;NSMicrophoneUsageDescription&lt;/key&gt;<br>&lt;string&gt;We require microphone access to connect to a video conference&lt;/string&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/0*-4dhVnA7TZPIVmUx.png" /></figure><p>That’s it!😀 Now run the app and try it out with your friends. If you like this story make sure to leave a clap and comment your feedbacks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46e046cbc0e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Video Call App using Flutter and ZEGOCLOUD]]></title>
            <link>https://ashnizaster.medium.com/video-call-app-using-flutter-and-zegocloud-638fcb876af1?source=rss-a80870f2b002------2</link>
            <guid isPermaLink="false">https://medium.com/p/638fcb876af1</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[video-conferencing]]></category>
            <category><![CDATA[zegocloud]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[video-chat]]></category>
            <dc:creator><![CDATA[Ashna Nizam]]></dc:creator>
            <pubDate>Fri, 17 Feb 2023 16:36:39 GMT</pubDate>
            <atom:updated>2023-02-17T16:36:39.736Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*QPShRrFNQrpSsn6TCC1F6Q.png" /></figure><p>Hey guys, welcome back. So today we will be learning how to create a simple video calling app using Flutter and ZEGOCLOUD. Before we dive in lets get familiar with what is <a href="https://www.zegocloud.com/">ZEGOCLOUD</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*N0anLeM3Ik1XcbHc4HJsrg.jpeg" /></figure><h3>What is ZEGOCLOUD?</h3><p>ZEGOCLOUD is a professional audio and video global cloud service provider dedicated to providing quality real-time audio and video services. These services include video calls, video conferencing, audio calls and even live streaming. It uses <a href="https://www.zegocloud.com/product/video-call">Express Video SDK</a> that is a fully featured and Robust SDK. It provides high quality videos with low latency (low network bandwidth). Apart from that it is easy to integrate and beginner friendly for developers. ZEGOCLOUD provides 10,000 free minutes for developers to build powerful communication applications.</p><p>It even provides <a href="https://www.zegocloud.com/uikits">UIKits</a> and SDK’s to build customized UI. Today we will be mainly focusing on building a video chat app using UI kits.</p><h4>Pre-requisites</h4><ol><li><strong>Flutter version &gt; 1.12</strong></li><li><strong>ZEGOCLOUD account</strong></li><li><strong>Basic knowledge about Flutter</strong></li></ol><h4>Video tutorial</h4><p>I have also uploaded a video tutorial in YouTube. Make sure to check it out and hit the like and subscribe button if you guys found it useful.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FjcmKX54cgu4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DjcmKX54cgu4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjcmKX54cgu4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/662224e6a44eae2bf00a3d8ef7ec7f07/href">https://medium.com/media/662224e6a44eae2bf00a3d8ef7ec7f07/href</a></iframe><h3>Let’s get started</h3><p>Open Android Studio and create a new Flutter Project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*Kc8MY5SoBJlXHDxKm2y_SQ.png" /><figcaption>Select NEW FLUTTER PROJECT to begin</figcaption></figure><p>After that provide a name to your project. Note that the name should only have lower case letters and underscores. Then check the flutter SDK path and click finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*FZBBgPEUSwyJj5O7ZONDUA.png" /></figure><p>Once the project is created, in main.dart clear the starting code and inside runApp() call the MaterialApp() widget. After that, inside the lib folder we will add 2 more files — homescreen.dart and vidchat_screen.dart</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/309/1*Dqs06cIETEB9Tj4LKlYK6w.png" /></figure><p>Here as the names suggest we will be creating the Home Screen or Landing Screen in homescreen.dart and the Video Call Screen will be in the vidchat_screen.dart . In main.dart we will call the Landing Screen. The code is as given below.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;homescreen.dart&#39;;<br><br>void main() {<br>  runApp(<br>    MaterialApp(<br>      home: LandingScreen(),<br>      debugShowCheckedModeBanner: false,<br>      theme: ThemeData(<br>        primarySwatch: Colors.deepOrange,<br>      ),<br>    ),<br>  );<br>}</pre><p>Here we have imported the homescreen.dart file and also used a custom theme with deep orange color as the primary color.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*sYTtZ21zgrAlWM4jD00HiA.png" /></figure><p>Next we will implement the landing screen UI. Here we will be doing a simple UI with an AppBar() and a button. The button will take us to a video call room. We will be using a Stateless widget for this.</p><p>First things first, we will import the flutter material.dart and the vidchat_screen.dart . Apart from that we will be also importing the dart math library as well. This is done so that we can generate a random number to each user joining the <a href="https://www.zegocloud.com/blog/video-chat-rooms">video chat room</a>.</p><pre>import &#39;dart:math&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br>import &#39;vidchat_screen.dart&#39;;</pre><p>Next we will create the Landing Screen by extending the Stateless widget. Below is the code for the UI.</p><pre>class LandingScreen extends StatelessWidget {<br>  const LandingScreen({Key? key}) : super(key: key);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    String conferenceId = &quot;conference_id&quot;;<br>    String userId = Random().nextInt(1000).toString();<br>    return SafeArea(<br>      child: Scaffold(<br>        appBar: AppBar(<br>          title: Text(&quot;Video Chat Demo&quot;),<br>          centerTitle: true,<br>        ),<br>        body: Center(<br>          child: ElevatedButton(<br>            onPressed: () {<br>              Navigator.push(<br>                context,<br>                MaterialPageRoute(<br>                  builder: (context) {<br>                    return VideoChatScreen(<br>                      conference_id: conferenceId,<br>                      user_id: userId,<br>                    );<br>                  },<br>                ),<br>              );<br>            },<br>            child: Text(&quot;Join Video chat&quot;),<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Here a String value conference_id is given. This is basically the video chat room id with which users can join. It can be also given as a value accepted from a TextFormField() . By doing so a user can join different video chat rooms with different values. But here since we will be using a single meeting room only, we will be giving the conference_id value as a constant string value. The userId will be storing the random numbers generated to indicate the different users joining the meeting.</p><p>These values will be passed over to the Meeting Room, when the Elevated button in the center is pressed along with navigating to that screen. Next we will be diving deep into the Video Chat Room Screen where we will be making use of ZEGOCLOUD SDK.</p><p>In vidchat_screen.dart also, we will be using a Stateless widget. Here we will be implementing the UI using the prebuilt UI kits of ZEGOCLOUD. In order to do that first we have to import the prebuilt video conferencing ui kit into our app. For this in terminal, run the command</p><p>flutter pub add zego_uikit_prebuilt_video_conference</p><p>This will add the zego_uikit_prebuilt_video_conference package into our app and can be seen in the dependencies section of pubspec.yaml as shown below</p><pre>dependencies:<br>  flutter:<br>    sdk: flutter<br>  cupertino_icons: ^1.0.2<br>  zego_uikit_prebuilt_video_conference: ^1.1.12</pre><p>After this is done, in vidchat_screen.dart import the package to use the Video Conference UI kit along with flutter material.dart.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:zego_uikit_prebuilt_video_conference/zego_uikit_prebuilt_video_conference.dart&#39;;</pre><p>Next create a Stateless widget and recieve the values passed from Landing Screen. Afterwards use the ZEGOCLOUD prebuilt UI kit to create the UI in the build method as given below.</p><pre>class VideoChatScreen extends StatelessWidget {<br>  final String conference_id;<br>  final String user_id;<br>  const VideoChatScreen(<br>      {Key? key, required this.conference_id, required this.user_id})<br>      : super(key: key);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return ZegoUIKitPrebuiltVideoConference(<br>      appID: &quot;YOUR APP ID&quot;,<br>      appSign:<br>          &quot;YOUR APP SIGN&quot;,<br>      conferenceID: conference_id,<br>      userID: user_id,<br>      userName: &quot;user $user_id&quot;,<br>      config: ZegoUIKitPrebuiltVideoConferenceConfig(<br>        turnOnMicrophoneWhenJoining: false,<br>      ),<br>    );<br>  }<br>}</pre><p>In the above code, to get appID and appSign values we will need to create a project in the ZEGOCLOUD project dashboard. To access the project dashboard <a href="https://console.zegocloud.com/"><strong>click here</strong></a>.</p><p>In the console you will be prompted to the window as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLZhpBZoUaUvCOKXm8peWw.png" /></figure><p>If you already have an account directly login else sign up by filling in the details to create one.</p><p>Once you have your account created, click on create new project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*k2j3MCbFZKrWbh5P7-oOpw.png" /></figure><p>Next choose the use case of our project. For our purpose we will be using the <strong>Voice &amp; Video Calls</strong> use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8-6SX8uJAcZKdZBGosdFKg.png" /></figure><p>After that give your project a suitable name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*8_1GXXw4u__oZPQ1JoytXQ.png" /></figure><p>Then for our purpose we will <strong><em>start with UI kits</em></strong> as shown below. In that the code used for each platform is also given so we as developers can better understand it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*SkBgKFdRpo-uWHK0kE4K5Q.png" /></figure><p>Once our project is successfully build we will see a button with a text saying <strong><em>start building your app</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DdeuS2DyB6YbgJ7F3yqx4g.png" /></figure><p>Click the button and then we will be prompted to select the framework for our project. Choose Flutter as the Framework for the project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*XsIDzct6fPiMWeFF3sDYMA.png" /></figure><p>Afterwards in the UI configuration make sure it is in 1-on-1 call. In case you want to create a project with group video chat then select the group call.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GV380qC5OlVA0jeg81vpRQ.png" /></figure><p>Once that is done go back to your <strong>Overview</strong> tab. There we will see the project that we have created just now. Click on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*ZyguOvfjQjW57jgPz7a_Rg.png" /></figure><p>Once the project is opened copy the AppID and AppSign and paste it into your code in vidchat_screen.dart</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*B9g5HWHkvo1XH-cCHSavGQ.png" /></figure><p>Instead of “YOUR APP ID” paste your AppID. AppID is not a String so it is pasted as it is. For AppSign it needs a String value. So paste the AppSign instead of “YOUR APP SIGN”.</p><pre>ZegoUIKitPrebuiltVideoConference(<br>      appID: &quot;YOUR APP ID&quot;,<br>      appSign:<br>          &quot;YOUR APP SIGN&quot;,<br>      conferenceID: conference_id,<br>      userID: user_id,<br>      userName: &quot;user $user_id&quot;,<br>      config: ZegoUIKitPrebuiltVideoConferenceConfig(<br>        turnOnMicrophoneWhenJoining: false,<br>      ),<br>    );</pre><p>The remaining properties are assigned based on the values passed vid constructor. The config property takes a ZegoUIKitPrebuiltVideoConferenceConfig() , and the video call configurations such as turning on the mic or camera when user joins, what to do when user leaves the video chat room, usage of speakers when joining etc. which are part of it, can be configured.</p><p>Now before we run our app we have some more configurations to be done. Let’s dive into that</p><h4>Android Configurations</h4><p>First open the android/app/build.gradle file. Modify the compileSdkVersion under the android block to <strong>33</strong></p><pre>android {<br>    compileSdkVersion 33</pre><p>Next we have to add the permissions. For that open your android/app/src/main/AndroidManifest.xml file and add the following lines of code inside the &lt;manifest&gt; tag before the &lt;application&gt; tag.</p><pre>&lt;uses-permission android:name=”android.permission.ACCESS_WIFI_STATE” /&gt;<br>&lt;uses-permission android:name=”android.permission.RECORD_AUDIO” /&gt; <br>&lt;uses-permission android:name=”android.permission.INTERNET” /&gt; <br>&lt;uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” /&gt; <br>&lt;uses-permission android:name=”android.permission.CAMERA” /&gt; <br>&lt;uses-permission android:name=”android.permission.BLUETOOTH” /&gt; <br>&lt;uses-permission android:name=”android.permission.MODIFY_AUDIO_SETTINGS” /&gt; <br>&lt;uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” /&gt; <br>&lt;uses-permission android:name=”android.permission.READ_PHONE_STATE” /&gt; <br>&lt;uses-permission android:name=”android.permission.WAKE_LOCK” /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bt5XOT1Je-eS_VbZ6z0Bwg.png" /></figure><p>After that create a file proguard-rules.pro inside android/app folder. This is done to prevent obfuscation of the SDK public class names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*QBgmeyCq1bcwSVC5frvlRw.png" /></figure><p>In proguard-rules.pro add the following lines of code.</p><pre>-keep class **.zego.** { *; }</pre><p>Now we will add the following config code to the release part of android/app/build.gradle</p><pre>proguardFiles getDefaultProguardFile(&#39;proguard-android.txt&#39;), &#39;proguard-rules.pro&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NzhfDhYRNnJmjoQbSqS_xQ.png" /></figure><p>Once that is done we are done with the android configurations. Moving on we will be implementing the iOS configurations.</p><h4>iOS Configurations</h4><p>For iOS we need to add the app permissions. For that add the following lines of code in ios/Runner/Info.plist</p><pre>&lt;key&gt;NSCameraUsageDescription&lt;/key&gt;<br>&lt;string&gt;We require camera access to connect to a video conference&lt;/string&gt;<br>&lt;key&gt;NSMicrophoneUsageDescription&lt;/key&gt;<br>&lt;string&gt;We require microphone access to connect to a video conference&lt;/string&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*wvnb7-93NXw_o7TTqmqVww.png" /></figure><p>That’s it!😀 Now run the app and try it out with your friends. If you like this story make sure to leave a clap and comment your feedbacks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=638fcb876af1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Weather app using API integration in Flutter]]></title>
            <link>https://ashnizaster.medium.com/weather-app-using-api-integration-in-flutter-d69f69e6bed7?source=rss-a80870f2b002------2</link>
            <guid isPermaLink="false">https://medium.com/p/d69f69e6bed7</guid>
            <category><![CDATA[weather]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[openweathermap]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Ashna Nizam]]></dc:creator>
            <pubDate>Thu, 04 Aug 2022 13:06:02 GMT</pubDate>
            <atom:updated>2022-08-10T07:52:28.452Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e7HoY8ROLXuN1TQxpK-3yw.png" /></figure><p>Ever wanted to create a real life mobile application. Here’s your chance. Today we will be creating a complete application from scratch which enables us to observe the weather conditions using OpenWeatherMap API and Flutter.</p><p>Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, desktop, and embedded devices from a single codebase. OpenWeatherMap is an online service, owned by OpenWeather Ltd, that provides global weather data via API, including current weather data, forecasts, nowcasts and historical weather data for any geographical location.</p><p>Now that we have a brief idea about Flutter and OpenWeatherMap, let’s dive right in.</p><h4>Video Tutorial</h4><p>I have also uploaded a video tutorial in YouTube. Make sure to check it out and hit the like and subscribe button if you guys found it useful.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F66MPx99S4Jg&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D66MPx99S4Jg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/01a3ad90e02a2543e70234b237be8d2f/href">https://medium.com/media/01a3ad90e02a2543e70234b237be8d2f/href</a></iframe><h4><strong>Creating a New Flutter Project</strong></h4><p>Open up android studio(or visual studio) to create a new flutter project(If you don’t have flutter installed then follow steps in <a href="https://youtu.be/nqJ_gEmEdzE">this video</a> and proceed). Choose Start a new flutter project option</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*gvq8FyYkHrnvJOw6jaLqFg.png" /></figure><p>Then a new pop up window comes where we will select flutter application and hit the next button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*is5ib3v5EJpId1cDSQ0HWg.png" /></figure><p>Next give your application a name and then again hit next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*p3bLPbKtRD64Njl505A1kA.png" /></figure><p>Once the above steps are done, the package name comes up. This is the unique id by which the application will be known once published. Then hit on finish to create your flutter project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8CTPV1aNgToLcI-db8HFAA.png" /></figure><p>Once that is done we will have our main.dart file loaded, along with the necessary files, with the default flutter start project, which is a counter app.</p><h4><strong>Fetching the packages</strong></h4><p>Flutter provides various packages for simplifying the app building process. Here, we make use of a few packages like <a href="https://pub.dev/packages/http"><strong>http</strong></a> and <a href="https://pub.dev/packages/geolocator"><strong>geolocator</strong></a>. The http package aids in establishing a connection between our Flutter app with the internet and the geocoding package aids in obtaining the location data. We can incorporate the packages into our app by providing the package name with version in the pubspec.yaml in our flutter project, that is the configuration file.</p><pre>dependencies:<br>  geolocator:<br>  http:</pre><p>Here I have not specified the version number of the packages. This enables to obtain the latest compatible versions of the dependencies on running pub get command. In order to see the exact version obtained you can refer the pubspec.lock file. For this project I have used version 8.0.5 of geolocator package and version 0.13.3 of http package.</p><p>We will be implementing the code as functions. So our aim is to display the current location weather conditions on opening the app and then to get the current weather conditions of any other locations or city.</p><p>In order to achieve this initially we will have to get the current location’s latitude and longitude. We can achieve this with the help of geolocator package. However in order to use the package there are certain configurations for android as well as iOS platforms which can be referred in the <a href="https://pub.dev/packages/geolocator"><strong>readme</strong></a> section of geolocator package.</p><p>Once the configurations are done we can proceed to get the current location latitude and longitude.</p><h4>Building the App</h4><p>In the default main.dart file we will be removing the unnecessary code and keep the necessary code only. Here we will be working with <em>MaterialApp</em> instead of <em>MyApp</em>. Therefore we delete the <em>MyApp</em> references in <em>main.dart</em> and <strong>delete</strong> the <strong>test file</strong> under projects section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*icGafjSKwZnQ9RqkD1TUKw.png" /></figure><p>Once the MyApp references are deleted and replaced with MaterialApp() as the root widget, the main.dart looks like below</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><pre>void main() {<br>  runApp(<br>    MaterialApp(),<br>  );<br>}</pre><p>Now create a new dart file by right clicking on <strong>lib &gt;New&gt;Dart File</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*GIuWVA5oI-EnCUCA6pAKNQ.png" /></figure><p>Inside this dart file import the material.dart package. We will now create a <a href="https://api.flutter.dev/flutter/widgets/StatefulWidget-class.html">Stateful widget</a> to build our app. The shortcut to create one is to simply type <strong><em>stful</em></strong> and we will get a skeletal code of the Stateful widget. Replace the YourWidgetName with your own custom names.</p><pre>class YourWidgetName extends StatefulWidget {<br>  @override<br>  _YourWidgetNameState createState() =&gt; _YourWidgetNameState();<br>}<br><br>class _YourWidgetNameState extends State&lt;YourWidgetName&gt; {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Container();<br>  }<br>}</pre><p>Now once that is done, import this dart file in main.dart and set the home property of MaterialApp() to the name given for the Stateful widget created. The home property is used to display the starting screen in an app when the app involves only a single screen. Here I have given the name as HomeScreen() and the dart file name as homescreen.dart.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;homescreen.dart&#39;;<br><br>void main() {<br>  runApp(<br>    MaterialApp(<br>      debugShowCheckedModeBanner: false,<br>      home: HomeScreen(),<br>      theme: ThemeData(<br>        primaryColor: Colors.white,<br>        accentColor: Colors.white,<br>      ),<br>    ),<br>  );<br>}</pre><p>Apart from the home property of MaterialApp we will also be specifying the debugShowCheckedModeBanner property to false so the debug banner won’t be visible and also setting the primary and accent theme colors to white using the theme property.</p><h4>Step 1: Getting Current location co-ordinates</h4><p>It is inside the homescreen.dart we will be obtaining the current location latitude and longitude. The latitude and longitude is not displayed in the final version of the app so we will just try to print the values in terminal.</p><p>For this first we have to import the geolocator package in homescreen.dart.</p><pre>import &#39;package:geolocator/geolocator.dart&#39;;</pre><p>Then we add a asynchronous function as given below</p><pre>getCurrentLocation() async {<br>    var p = await Geolocator.getCurrentPosition(<br>      desiredAccuracy: LocationAccuracy.low,<br>      forceAndroidLocationManager: true,<br>    );<br>    if (p != null) {<br>      print(&#39;Lat:${p.latitude}, Long:${p.longitude}&#39;);<br>      <br>    } else {<br>      print(&#39;Data unavailable&#39;);<br>    }<br>  }</pre><p>When the getCurrentLocation() method of Geolocator package is called it returns a Position value(comprising of latitude, longitude, accuracy, altitude, heading etc) is returned. Since the time in obtaining the Position value is not known and can be obtained at any point in the future we use await keyword. This means the function works asynchronously from the remaining executions.</p><p>The accuracy of the position can set by the desiredAccuracy property and the location manager of android can be set by the forceAndroidLocationManager property. The returned Position value consists of the details of the current location details of the device. To obtain the latitude and longitude, the corresponding parameters of the Position value is called and printed accordingly.</p><p>This function is then called in the initState() method of the Stateful() widget as shown</p><pre>@override<br>void initState() {<br>  // TODO: implement initState<br>  super.initState();<br>  getCurrentLocation();<br>}</pre><p>The build method is returned with a simple Scaffold() wrapped in SafeArea() as shown.</p><pre>Widget build(BuildContext context) {<br>  return SafeArea(<br>    child: Scaffold(),<br>  );<br>}</pre><p>With this run the application and we will obtain the latitude and longitude of the current location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*aji_J9TCnD5RaTz3p82KXQ.png" /></figure><p>Note: Here the latitude and longitude are that of the emulator’s which is set as default.</p><h4>STEP 2: Getting API key from OpenWeatherMap</h4><p>For getting the real-time weather data we will be making use of <a href="https://openweathermap.org/"><strong>OpenWeatherMap</strong></a> API. To access the API data we require an API key. In order to do that, choose the Pricing section from the top menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*MX7oW-8RQ9F1UcWk3N1Ebg.png" /></figure><p>Then scroll down till you see the various plans for current weather. Choose the Free plan and click on the Get API key option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*pVNWCo7eWqykQXw0U5MlKw.png" /></figure><p>Once that is done, a new window comes up where you have to create an account. Provide the necessary information and create your account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*WoqMmTjxMy1F7kuRKtDFqg.png" /></figure><p>Once the account is created, a pop-up will come up asking about the purpose for which we intend to use our API key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*iruK3Xs3ZemMH-JXpoN6_Q.png" /></figure><p>Here specifying the company is optional while specifying the purpose is mandatory. If you don’t know which purpose to choose you can go with Education/Science. Then click save.</p><p>Now in your dashboard go to the API keys section. Here you will find all your API keys under the Key section. Note that the API key here is unique to you and you shouldn’t share it with anyone else.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*MQlTa8UKhG1ghlARWwyF7w.png" /></figure><p>Once you get your API key you can proceed to call the API to get the weather data. There are various formats of calling the API and how the response will be, all of which can be referred <a href="https://openweathermap.org/current">here</a>. For our purpose we will be calling the API via the latitude longitude format and the city name format as given below</p><pre><strong>API call by latitude longitude format<br></strong>https://api.openweathermap.org/data/2.5/weather?lat={lat}&amp;lon={lon}&amp;appid={API key}</pre><pre><strong>API call by city name format</strong><br>https://api.openweathermap.org/data/2.5/weather?q={city name}&amp;appid={API key}</pre><p>As both API calls have same API key and domain, we will store those values in a new dart file named constants under lib folder. For creating the file refer the Building App section above. In the created constants.dart file add the following lines of code.</p><pre>const String domain = &quot;https://api.openweathermap.org/data/2.5/weather?&quot;;<br>const String apiKey = &quot;PASTE YOUR API KEY HERE&quot;;</pre><p>Now we will try obtaining the weather data which will be a JSON response.</p><h4>STEP 3: Getting weather data of Current location</h4><p>After successfully completing the above steps, we will try obtaining the weather data. For this inside the homescreen.dart we will write a function to first connect our app to the internet and then obtain weather data. This is where we will be implementing http package. So first we import the package as http so it becomes easier to access the different fields in the package</p><pre>import &#39;package:http/http.dart&#39; as http;<br>import &#39;constants.dart&#39; as k;<br>import &#39;dart:convert&#39;;</pre><p>Similarly we also import the constants.dart where we copied the API key and domain link. Along with it as we are dealing with getting a single JSON response for each call, we use the convert library of dart for decoding the JSON response we obtain.</p><pre><strong>API call by latitude longitude format<br></strong>https://api.openweathermap.org/data/2.5/weather?lat={lat}&amp;lon={lon}&amp;appid={API key}</pre><p>Next we will write the function to connect our app to internet. This function will also be asynchronous as it is returning a future. Here we first create a Client object so we don’t have to open and close ports every time we call the get method. Then we provide our URI (A URI is a character sequence that helps identify a logical or physical resource connected to the internet) address which is the API call format providing the necessary fields.</p><pre>getCurrentCityWeather(Position position) async {<br>  var client = http.Client();<br>  var uri =<br>      &#39;${k.domain}lat=${position.latitude}&amp;lon=${position.longitude}&amp;appid=${k.apiKey}&#39;;<br>  var url = Uri.parse(uri);<br>  var response = await client.get(url);<br>  if (response.statusCode == 200) {<br>    var data = response.body;<br>    print(data);<br>   } else {<br>    print(response.statusCode);<br>  }<br>}</pre><p>After that the URI is converted into URL address(It is the location of the URI in the internet). Then using the client field, the get method which fetches the data from the URL is called. This value is then stored in the response variable. The status code of the response determines the result of the data fetching process. If the code is 200, it means that the data is fetched successfully. The JSON data can be obtained from the body of response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*GB6kO3rWHxJX8cGUKZIL3Q.png" /></figure><p>The above code when made to run will print the weather data we receive from the API call. In the body we can see various parameters like temperature, pressure, humidity, visibility, wind speed etc.</p><h4>STEP 4: Getting weather data of various cities</h4><p>Similar to STEP 3 we will implement getting the weather data of a particular city based on the city name. Here the only difference is instead of providing latitude and longitude in the API call we provide the city name.</p><pre><strong>API call by city name format</strong><br>https://api.openweathermap.org/data/2.5/weather?q={city name}&amp;appid={API key}</pre><p>So the same function with modification in function name, parameter and uri is provided to obtain the weather data.</p><pre>getCityWeather(String cityname) async {<br>    var client = http.Client();<br>    var uri = &#39;${k.domain}q=$cityname&amp;appid=${k.apiKey}&#39;;<br>    var url = Uri.parse(uri);<br>    var response = await client.get(url);<br>    if (response.statusCode == 200) {<br>      var data = response.body;<br>      var decodeData = json.decode(data);<br>      print(data);<br>      <br>    } else {<br>      print(response.statusCode);<br>    }<br>  }</pre><p>The above code also yields a similar result as in STEP 3 but with the location (city) we have specified.</p><h4>STEP 5: Completing the Build</h4><p>Now that we have obtained the weather data and location data, we will now proceed to building the UI of the app. So here we will be using cards on a gradient background to display weather conditions.</p><p>For that we first provide the body of the Scaffold() which is a Container() covering the entire screen and which has a gradient filling. Here I have used gradients from <a href="https://cssgradient.io/gradient-backgrounds/"><em>Gradient Backgrounds</em></a> which has an immense collection of background gradients along with the corresponding colour codes. The following is the gradient I have chosen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*AfJZ8-ueVM4ULF3Iwv9szg.png" /></figure><p>The code for obtaining complete background gradient is as shown below. Here we will set the resizeToAvoidBottomInset property of Scaffold() widget to false so that resizing of the widgets when the keyboard pops up is avoided.</p><pre>SafeArea(<br>  child: Scaffold(<br>    resizeToAvoidBottomInset: false,<br>    body: Container(<br>      width: double.infinity,<br>      height: double.infinity,<br>      padding: EdgeInsets.all(20),<br>      decoration: BoxDecoration(<br>        gradient: LinearGradient(<br>          colors: [<br>            Color(0xffFA8BFF),<br>            Color(0xff2BD2FF),<br>            Color(0xff2BFF88),<br>          ],<br>          begin: Alignment.bottomLeft,<br>          end: Alignment.topRight,<br>        ),<br>      ),<br>    ),<br>  ),<br>);</pre><p>Then we will provide a few variables to store values of temperature, pressure, humidity, cloud cover, city name and the state of the data that is whether the data is fetched and ready to be used by the app. These variables are declared inside the Stateful widget before the initState method.</p><pre>bool isLoaded = false;<br>num temp;<br>num press;<br>num hum;<br>num cover;<br>String cityname = &#39;&#39;;</pre><p>Next we will add a Visibility widget as the child of the Container widget. So only when there is data will the weather data is displayed else it shows a loading indicator. For this the value of isLoaded is dynamically changed in the functions using setState method. The code is as given below.</p><pre>Container(<br>  child: Visibility(<br>     visible: isLoaded,<br>     child: Column(),<br>     replacement: Center(<br>       child: CircularProgressIndicator(),<br>      ),<br>    ),<br>  ),</pre><p>Now to store the weather data into the variables we will provide another function to update the variables. This function will have the decoded JSON data as the parameter and based on the value of it, the parameter values are set.</p><pre>updateUI(var decodedData) {<br>  setState(() {<br>    if (decodedData == null) {<br>      temp = 0;<br>      press = 0;<br>      hum = 0;<br>      cover = 0;<br>      cityname = &#39;Not available&#39;;<br>    } else {<br>      temp = decodedData[&#39;main&#39;][&#39;temp&#39;] - 273;<br>      press = decodedData[&#39;main&#39;][&#39;pressure&#39;];<br>      hum = decodedData[&#39;main&#39;][&#39;humidity&#39;];<br>      cover = decodedData[&#39;clouds&#39;][&#39;all&#39;];<br>      cityname = decodedData[&#39;name&#39;];<br>    }<br>  });<br>}</pre><p>This function will be called in both the API calling functions if the status code of received data is 200</p><pre>getCurrentCityWeather(Position position) async {<br>  //Networking code<br>  if (response.statusCode == 200) {<br>    var data = response.body;<br>   <strong> var decodeData = json.decode(data);<br>    updateUI(decodeData);<br>    setState(() {<br>      isLoaded = true;<br>    });</strong><br>  } else {<br>    print(response.statusCode);<br>  }<br>}</pre><p>The code highlighted in bold is added to the function. It basically decodes the JSON data and calls the updateUI method which sets the value of the variables to the corresponding weather data. Along with that, the varibles representing the state of data obtained is also updated throughout the build with the help of setState method. Similarly for the function using API call with city name, the same code is added.</p><pre>getCityWeather(String cityname) async {<br>    //Networking code<br>    if (response.statusCode == 200) {<br>      var data = response.body;<br>      <strong>var decodeData = json.decode(data);<br>      updateUI(decodeData);<br>      setState(() {<br>        isLoaded = true;<br>      });</strong><br>    } else {<br>      print(response.statusCode);<br>    }<br>  }</pre><p>Inside the column of Visibilty widget we will add a TextFormField as the first child. For the controller of this TextFormField a controller is also provided, which is declared along with the variables.</p><pre>TextEditingController controller = TextEditingController();</pre><p>The code of the TextFormField is as given below. Note that we have set the value of isLoaded to false once the city name is entered. This provides a loading indicator to the user while fetching the data, so the user will know there is some process going on.</p><pre>child: Column(<br>  children: [<br>    Container(<br>      width: MediaQuery.of(context).size.width * 0.85,<br>      height: MediaQuery.of(context).size.height * 0.09,<br>      padding: EdgeInsets.symmetric(<br>        horizontal: 10,<br>      ),<br>      decoration: BoxDecoration(<br>        color: Colors.black.withOpacity(0.3),<br>        borderRadius: BorderRadius.all(<br>          Radius.circular(<br>            20,<br>          ),<br>        ),<br>      ),<br>      child: Center(<br>        child: TextFormField(<br>          onFieldSubmitted: (String s) {<br>            setState(() {<br>              cityname = s;<br>              getCityWeather(s);<br>              isLoaded = false;<br>              controller.clear();<br>            });<br>          },<br>          controller: controller,<br>          cursorColor: Colors.white,<br>          style: TextStyle(<br>              fontSize: 20,<br>              fontWeight: FontWeight.w600,<br>              color: Colors.white),<br>          decoration: InputDecoration(<br>            hintText: &#39;Search city&#39;,<br>            hintStyle: TextStyle(<br>              fontSize: 18,<br>              color: Colors.white.withOpacity(0.7),<br>              fontWeight: FontWeight.w600,<br>            ),<br>            prefixIcon: Icon(<br>              Icons.search_rounded,<br>              size: 25,<br>              color: Colors.white.withOpacity(0.7),<br>            ),<br>            border: InputBorder.none,<br>          ),<br>        ),<br>      ),<br>    ),<br>  ],<br>),</pre><p>As the width cannot be specified in a TextFormField, it is wrapped inside a container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*JX6F9Pdmf8H9Fh1V-VZ8eQ.png" /></figure><p>Afterwards in order for minimum memory usage, we will dispose the controller in the dispose method of Stateful widget as shown below.</p><pre>@override<br>void dispose() {<br>  // TODO: implement dispose<br>  controller.dispose();<br>  super.dispose();<br>}</pre><p>Next we will add the next child of the Column() which is a SizedBox widget for adding necessary space between the components.</p><pre>SizedBox(<br>  height: 30,<br>),</pre><p>This is followed by the City name data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*iFoH-4yB72wdOmotwh9hlg.png" /></figure><p>It is implemented by use of a Row() widget wrapped with a Padding widget. It comprises of an Icon and a Text and the code is as given below</p><pre>Padding(<br>  padding: const EdgeInsets.all(8.0),<br>  child: Row(<br>    crossAxisAlignment: CrossAxisAlignment.end,<br>    children: [<br>      Icon(<br>        Icons.pin_drop,<br>        color: Colors.red,<br>        size: 40,<br>      ),<br>      Text(<br>        cityname,<br>        overflow: TextOverflow.ellipsis,<br>        style: TextStyle(<br>          fontSize: 28,<br>          fontWeight: FontWeight.bold,<br>        ),<br>      )<br>    ],<br>  ),<br>),</pre><p>This is again followed by a SizedBox widget</p><pre>SizedBox(<br>  height: 20,<br>),</pre><p>Next comes the weather data section displayed as cards. Here I have used Container for creating custom cards. For the data I have used Image and Text widgets.</p><p>Note that the images used here are from the project file itself. So in order to do that we will have to configure those images. For this first create a new directory in the project folder under project_name&gt;New&gt;Directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*JCblKe8KR3lwJ7y9YfKzWg.png" /></figure><p>Name the new directory as images. Then once the directory is created add the necessary images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*X_1y4cwY-gTrG86mZv6E2w.png" /></figure><p>Afterwards, go to your pubspec.yaml file. Scroll down to the asset section where images are incorporated. Uncomment the lines and make sure the spacing is correct as shown below. The below code includes all the files under images directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*yTW-OCZD3QMzGDpD3sY3gw.png" /></figure><p>Then run pub get command at the top right corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*hlfxSoJIjaPLmzNGK2qtHg.png" /></figure><p>Once that is done, the images will be configured in the app. Now in homescreen.dart we will add the code for creating the card display.</p><pre>Container(<br>  width: double.infinity,<br>  height: MediaQuery.of(context).size.height * 0.12,<br>  margin: EdgeInsets.symmetric(<br>    vertical: 10,<br>  ),<br>  decoration: BoxDecoration(<br>    borderRadius: BorderRadius.all(<br>      Radius.circular(15),<br>    ),<br>    color: Colors.white,<br>    boxShadow: [<br>      BoxShadow(<br>        color: Colors.grey.shade900,<br>        offset: Offset(1, 2),<br>        blurRadius: 3,<br>        spreadRadius: 1,<br>      )<br>    ],<br>  ),<br>  child: Row(<br>    children: [<br>      Image(<br>        image: AssetImage(&#39;images/thermometer.png&#39;),<br>        width: MediaQuery.of(context).size.width * 0.09,<br>      ),<br>      SizedBox(<br>        width: 10,<br>      ),<br>      Text(<br>        &#39;Temperature: ${temp?.toInt()} ºC&#39;,<br>        style: TextStyle(<br>            fontSize: 20, fontWeight: FontWeight.w600),<br>      )<br>    ],<br>  ),<br>),</pre><p>Once the above code is added stop and cold start the app for the configuration changes to be included. When the app is loaded we will get a card display as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*GbcGPBtAQq8_Ra17l3AI6w.png" /></figure><p>Again 3 more cards are added by replacing the image and text for the respective weather parameters. For the next 3 card displays, the images are wrapped with a padding on all sides.</p><pre>Padding(<br>  padding: const EdgeInsets.all(8.0),<br>  child: Image(<br>    image: AssetImage(&#39;images/barometer.png&#39;),<br>    width: MediaQuery.of(context).size.width * 0.09,<br>  ),<br>),</pre><p>Once that is done we will get an output as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*ryzDP2xOfdzOQyQCWrHVbQ.png" /></figure><p>The final working demo of the app is as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*i5BRUwE-Ij2fvlvpmr2gKA.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d69f69e6bed7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A simple Calculator using Flutter]]></title>
            <link>https://ashnizaster.medium.com/a-simple-calculator-using-flutter-8ef52c9980d3?source=rss-a80870f2b002------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ef52c9980d3</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[calculator]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[Ashna Nizam]]></dc:creator>
            <pubDate>Sat, 19 Mar 2022 17:55:34 GMT</pubDate>
            <atom:updated>2022-03-28T15:31:55.539Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wanted to create your own apps? Application development is a rising popularity field that helps in developing coding skills. Mobile app development is becoming easier with flutter framework provided by google. To kick start your app development skills, we will learn to build a simple calculator app using flutter. Let’s get started.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FOtlrK1qLbjc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DOtlrK1qLbjc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FOtlrK1qLbjc%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d05d8a412e981264be5cd5472ed72f05/href">https://medium.com/media/d05d8a412e981264be5cd5472ed72f05/href</a></iframe><h4>Creating a new flutter project</h4><p>Open up android studio(or visual studio) to create a new flutter project(If you don’t have flutter installed then follow steps in <a href="https://youtu.be/nqJ_gEmEdzE">this video</a> and proceed). Choose Start a new flutter project option</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gvq8FyYkHrnvJOw6jaLqFg.png" /><figcaption>Start a new flutter project</figcaption></figure><p>Then a new pop up window comes where we will select flutter application and hit the next button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*is5ib3v5EJpId1cDSQ0HWg.png" /></figure><p>Next give your application a name and then again hit next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*p3bLPbKtRD64Njl505A1kA.png" /></figure><p>Once the above steps are done, the package name comes up. This is the unique id by which the application will be known once published. Then hit on finish to create your flutter project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*-M0u-ywrsEddfcdfYhC8jg.png" /></figure><p>Once that is done we will have our main.dart file loaded, along with the necessary files, with the default flutter start project, which is a counter app.</p><h4>Fetching the dependencies</h4><p>Flutter provides various packages for simplifying the app building process. Here, we make use of such a package. We will be using <a href="https://pub.dev/packages/math_expressions"><em>math_expressions</em></a> flutter package. This package helps in solving mathematical expressions in flutter. We can incorporate the package into our app by providing the package name with version in the pubspec.yaml in our flutter project, that is the configuration file.</p><p>In order to do that write down the following code in pubspec.yaml and then run pub get command</p><pre>dependencies:<br>  math_expression:^2.3.0</pre><p>The version number need not be necessarily specified. If it is not specified the latest compatible version is fetched.</p><p>Next import the package into required dart file</p><pre><strong>import</strong> &#39;package:math_expressions/math_expressions.dart&#39;;</pre><p>On successfully importing the package we can proceed with our build.</p><h4>Building the app</h4><p>In the default main.dart file we will be removing the unnecessary code and keep the necessary code only. Here we will be using a Material App() widget as the root widget under the runApp of the main function as shown</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:simple_calc/simple_calc_ui.dart&#39;;<br><br>void main() {<br>  runApp(<br>    MaterialApp(<br>      home: SimpleCalc(),//YourWidgetName<br>      debugShowCheckedModeBanner: false,<br>    ),<br>  );<br>}</pre><p>Now we will create a new dart file for creating our app from File&gt;New&gt;Dart File</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*48x7oZSQoMOEUpoRPhUrJA.png" /></figure><p>We will now create a <a href="https://api.flutter.dev/flutter/widgets/StatefulWidget-class.html">Stateful widget</a> to build our app. The shortcut to create one is to simply type <strong><em>stful</em></strong> and we will get a skeletal code of the Stateful widget. Replace the YourWidgetName with your own custom names.</p><pre>class YourWidgetName extends StatefulWidget {<br>  @override<br>  _YourWidgetNameState createState() =&gt; _YourWidgetNameState();<br>}<br><br>class _YourWidgetNameState extends State&lt;YourWidgetName&gt; {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Container();<br>  }<br>}</pre><p>The UI is quite simple with an app bar and a white and teal theme. First we will make the app bar. In order to do this, we create a<strong> Scaffold()</strong> widget wrapped in a <strong>SafeArea()</strong> widget.</p><pre>Widget build(BuildContext context) {<br>  return SafeArea(<br>    child: Scaffold(),<br>  );<br>}</pre><p>The Scaffold() widget has properties like appBar, body, floating action button etc. So here we will be making use of the appBar and body properties. The appBar property is where we provide the title and other actions in our app. The app bar is quite simple with a background colour and a text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pc2pvNAY_Fldyk5iLu82cQ.png" /><figcaption>App Bar</figcaption></figure><p>In AppBar() widget we provide the background color, title and center title properties as below</p><pre>Scaffold(<br>  appBar: AppBar(<br>   backgroundColor: Colors.teal,<br>  title: Text(<br>    &quot;Simple Calculator&quot;,<br>    style: TextStyle(<br>      color: Colors.white,<br>    ),<br>  ),<br>  centerTitle: true,<br>)<br>),</pre><p>Apart from the appBar and body property we will be using the resizeToAvoidBottomInset property of Scaffold() as well. This is to ensure that the components we build in our app does not resize and cause errors when the keyboard pops up.</p><pre>Scaffold(<br>  resizeToAvoidBottomInset: false,<br>),</pre><p>Next we come to the body property of Scaffold(). The body consists of 3 text input fields where we input the numbers and operation to do, 2 buttons to calculate and clear the result and finally an area to display the answer.</p><p>We will be arranging elements in a Column fashion so we will be using Column() widget with equal spaced children widgets</p><pre>Scaffold(<br>  body:Column(<br>    mainAxisAlignment: MainAxisAlignment.spaceEvenly,<br>    children: [<br>      <br>    ],<br>  ) ,<br>),</pre><p>Inside the children property we will give a list of widgets. The first widget we will give is a row of text input fields as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*VusskkxbwKjDpKG1817Vfg.png" /><figcaption>Number and operator input field</figcaption></figure><p>In order for controlling the state of the text input fields we will be providing controllers for each field (In this case 3 controller). Apart from that we will be also assigning a variable to store the results. In addition we will be making the UI responsive by means of <a href="https://medium.com/tagmalogic/widgets-sizes-relative-to-screen-size-in-flutter-using-mediaquery-3f283afc64d6">MediaQuery</a> class.</p><pre>class _SimpleCalcState extends State&lt;SimpleCalc&gt; {<br>  TextEditingController num1 = TextEditingController();<br>  TextEditingController num2 = TextEditingController();<br>  TextEditingController operator = TextEditingController();<br>  String ans = &#39;&#39;;<br><br>  @override<br>  Widget build(BuildContext context) {<br>    double w = MediaQuery.of(context).size.width;<br>    double h = MediaQuery.of(context).size.height;<br>    double txt = MediaQuery.textScaleFactorOf(context);<br>    return SafeArea(<br>            );</pre><p>We create the text input fields within containers to provide definite width. The 1st and 2nd number input fields are similar and differ only in the hint text property. The operator input field is also similar and differs in the hint text and keyboard type values.</p><pre><strong>//1st child of Column() widget</strong><br>Row(<br>  mainAxisAlignment: MainAxisAlignment.center,<br>  children: [</pre><pre><strong>//1st number</strong><br>    Container(<br>      padding: EdgeInsets.all(10 * txt),<br>      width: w * 0.35,<br>      child: TextFormField(<br>        cursorColor: Colors.teal,<br>        controller: num1,<br>        onChanged: (val) {<br>          setState(() {<br>            num1.text = val;<br>            num1.selection = TextSelection.fromPosition(<br>              TextPosition(offset: num1.text.length),<br>            );<br>          });<br>        },<br>        keyboardType: TextInputType.number,<br>        decoration: InputDecoration(<br>          hintText: &#39;1st number&#39;,<br>          hintStyle: TextStyle(<br>            color: Colors.grey.shade400,<br>          ),<br>        ),<br>      ),<br>    ),</pre><pre><strong>//Operator</strong><br>    Container(<br>      padding: EdgeInsets.all(10 * txt),<br>      width: w * 0.25,<br>      child: TextFormField(<br>        textAlign: TextAlign.center,<br>        cursorColor: Colors.teal,<br>        controller: operator,<br>        onChanged: (val) {<br>          setState(() {<br>            operator.text = val;<br>            operator.selection = TextSelection.fromPosition(<br>              TextPosition(offset: operator.text.length),<br>            );<br>          });<br>        },<br>        decoration: InputDecoration(<br>          hintText: &#39;(+,-, etc)&#39;,<br>          hintStyle: TextStyle(<br>            color: Colors.grey.shade400,<br>          ),<br>        ),<br>      ),<br>    ),</pre><pre><strong>//2nd number</strong><br>    Container(<br>      padding: EdgeInsets.all(10 * txt),<br>      width: w * 0.35,<br>      child: TextFormField(<br>        cursorColor: Colors.teal,<br>        controller: num2,<br>        keyboardType: TextInputType.number,<br>        onChanged: (val) {<br>          setState(() {<br>            num2.text = val;<br>            num2.selection = TextSelection.fromPosition(<br>              TextPosition(offset: num2.text.length),<br>            );<br>          });<br>        },<br>        decoration: InputDecoration(<br>            hintText: &#39;2nd number&#39;,<br>            hintStyle: TextStyle(<br>              color: Colors.grey.shade400,<br>            )),<br>      ),<br>    ),<br>  ],<br>),</pre><p>The onChange property that takes in a function is where the value of the text input field changes. It takes in a new value every time the user changes the current value. Here inside onChange property we call the predefined setState function of Stateful widget, which rebuilds the UI with the new values. Here we update the values of the controller with the new values, so it is easier to frame the equations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*UWPxKH00Ebt0KYJmEvLOxA.png" /><figcaption>Area to display the result</figcaption></figure><p>Next we provide an area for displaying the calculated result. For this we will be using Container() widget as the second child of Column() widget.</p><pre><strong>//2nd child of Column() widget</strong><br>Container(<br>  width: double.infinity,<br>  height: h * 0.4,<br>  child: Center(<br>    child: Text(<br>      ans == &#39;&#39; ? &#39;Your Answer will be displayed here&#39; : ans,<br>      style: TextStyle(<br>        fontSize: ans == &#39;&#39; ? 16 * txt : 25 * txt,<br>        color: ans == &#39;&#39; ? Colors.grey.shade400 : Colors.teal,<br>      ),<br>    ),<br>  ),<br>),</pre><p>Finally we have the calculate and clear buttons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*Ny3Yu0A8SlEFWpoQMhs8pA.png" /></figure><p>As the names suggest these buttons are for calculating the result and clearing the text input fields along with the result. Both the buttons are arranged in a Row fashion. So, the final child of the Column() widget will be a Row() widget.</p><pre><strong>//3rd child of Column() widget</strong><br>Row(<br>  mainAxisAlignment: MainAxisAlignment.spaceEvenly,<br>  children: [</pre><pre><strong>//Calculate button</strong><br>    Container(<br>      width: w * 0.4,<br>      height: h * 0.08,<br>      child: ElevatedButton(<br>        style: ElevatedButton.styleFrom(<br>          primary: Colors.teal,<br>        ),<br>        onPressed: () {<br>          ans = calc();<br>          setState(() {});<br>        },<br>        child: Text(<br>          &#39;CALCULATE&#39;,<br>        ),<br>      ),<br>    ),</pre><pre><strong>//Clear button</strong><br>    Container(<br>      width: w * 0.4,<br>      height: h * 0.08,<br>      child: ElevatedButton(<br>        style: ElevatedButton.styleFrom(<br>          primary: Colors.teal,<br>        ),<br>        onPressed: () {<br>          num1.clear();<br>          operator.clear();<br>          num2.clear();<br>          ans = &#39;&#39;;<br>          setState(() {});<br>        },<br>        child: Text(<br>          &#39;CLEAR&#39;,<br>        ),<br>      ),<br>    ),<br>  ],<br>)</pre><p>The clear button basically clears the values in the text fields. This is made easy by using the predefined clear function of the text editing controllers and then calling setState() thereby rebuilding the UI with the new set of values.</p><p>The answer or result value is stored in the “ans” variable. The result is computed with help of a function</p><pre>String calc() {<br>  Parser p = Parser();<br>  Expression e = p.parse(&#39;${num1.text + operator.text + num2.text}&#39;);<br>  ContextModel cm = ContextModel();<br>  num ans = e.evaluate(EvaluationType.REAL, cm);<br>  return ans.toString().length &gt; 10<br>      ? ans.toStringAsPrecision(3)<br>      : ans.toString();<br>}</pre><p>In the function we create an instance of the Parser class to convert the string values to the desired numerical datatype. Next the expression is formed using the data in the text editing controllers. An instance of the context model is also created which keeps track of all the known variables and functions. With the help of these values the result is calculated using predefined evaluate function of Expression object. The final value is then returned as a String for ease of displaying.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*Zl0OEFF6AVHC0ijlm6AvTw.png" /></figure><p>And that’s all. We have completed building our simple calculator. The built app can do basic computations like addition, subtraction, multiplication, division etc. With the help of math_expressions package we can also do more complex calculations like finding solutions of higher order equations, trignometric equations etc. Make sure you give it a try and share your results in the comments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*6oRBaeuiALloJ1epQkF7mg.png" /></figure><p>P.S. You can obtain the complete code from my github profile and a complete tutorial video on youtube. Make sure to check it out as well :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ef52c9980d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your own custom shapes and designs using CustomPaint() in Flutter]]></title>
            <link>https://ashnizaster.medium.com/make-your-own-custom-shapes-and-designs-using-custompaint-in-c8f97577f5e4?source=rss-a80870f2b002------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8f97577f5e4</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[curvesdesign]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[custom-paint]]></category>
            <dc:creator><![CDATA[Ashna Nizam]]></dc:creator>
            <pubDate>Sat, 19 Jun 2021 12:45:40 GMT</pubDate>
            <atom:updated>2022-03-28T15:33:52.420Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FfDS1FlS1GBs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DfDS1FlS1GBs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FfDS1FlS1GBs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/657a71eec68bf55384aa1d24ef859f2c/href">https://medium.com/media/657a71eec68bf55384aa1d24ef859f2c/href</a></iframe><p>Hey guys, welcome back to yet another tutorial. Today we will be making custom shapes which includes curves, lines and all sorts of shapes and designs you can think of. So let’s dive right in.</p><p>Before we do that we have to know some basics. Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, desktop, and embedded devices from a single codebase. We use widgets which are similar to building blocks for building our UI. Each widget has a set of properties by which we can customize it. And the order in which we put all the widgets in place is what we get as a completed app.</p><p>For our purpose we will be making use of the following components</p><p>i. <a href="https://api.flutter.dev/flutter/widgets/CustomPaint-class.html">CustomPaint()</a></p><p>ii. <a href="https://api.flutter.dev/flutter/dart-ui/Paint-class.html">Paint()</a></p><p>iii. <a href="https://api.flutter.dev/flutter/dart-ui/Path-class.html">Path()</a></p><p>So first thing is we need to create a flutter project and connect emulator to our editor.</p><p>Then we need to import required material.dart package of flutter.</p><pre>import &#39;package:flutter/material.dart&#39;;</pre><p>Next we need to create a stateless class and return a Scaffold() where we will be building our shapes. Scaffold allows us to use a lot of features like bottom navigation bars, app bars, snack bars etc.</p><pre>class MyApp extends StatelessWidget {<br>  // This widget is the root of your application.<br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold();<br>  }<br>}</pre><p>Read more about Scaffold in the link given below</p><p><a href="https://api.flutter.dev/flutter/material/Scaffold-class.html">Scaffold()</a></p><p>Next we add an appbar similar to a title bar, which is a property of Scaffold(). You can customize <a href="https://api.flutter.dev/flutter/material/AppBar-class.html">AppBar()</a> by changing it’s default property values. This is not necessary as we won’t be doing much in here and our main focus is on the body or content.</p><pre>Scaffold(<br>appBar: AppBar(<br>  title: Text(&#39;Custom Shape&#39;),<br> ),<br>);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CaB-dzK87WHlUVzA_3AjYw.png" /></figure><p>After this comes our body which is also a property of Scaffold(). It is here were we call our CustomPaint() class. CustomPaint() takes in two required properties — painter and child. These properties must be mentioned otherwise it will throw an error.</p><pre>body: CustomPaint(<br>  painter: MyShape(),<br>  child: Container(),<br>),</pre><p>Here, the painter takes in a CustomPainter widget and it is where we draw our shapes and patterns. The child property takes a Widget. This Widget is what is going to be displayed on top of our shapes and designs. Thus, it helps us build unique designs and shapes for our app.</p><p>We are using an empty container as we are not gonna build any content. You can use the child property to add your own custom data like text, images or even other CustomPaint(). To keep the code clean we are using a separate class which returns a CustomPainter widget.</p><p>Next we need to create MyShape() class which extends CustomPainter class. Along with it we need to add two required override functions as well — paint() and shouldRepaint().</p><pre>class MyShape extends CustomPainter {<br>  @override<br>  void paint(Canvas canvas, Size size) {<br>    // <em>TODO: implement paint<br>  </em>}<br><br>  @override<br>  bool shouldRepaint(covariant CustomPainter oldDelegate) {<br>    // <em>TODO: implement shouldRepaint<br>    </em>return true;<br>  }<br>}</pre><p>The paint() function is where all our design and shape making is done. The shouldRepaint() function returns a new instance of the CustomPainter ( and checks if it has any changes from old instance). It must always return true so as to show up the latest changes we make in paint() method.</p><p>Before we start drawing shapes we need to understand the co-ordinate system used in Canvas. The top left corner of the body is the origin or the point (0,0). Size is basically the area of the body and we can get the height and width from Size. The following figure shows the Co-ordinates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h82Ckl8mQhkD2BBoqtdlzA.png" /></figure><p>We will be using these coordinates to build a shape or pattern. So the basic way in which we draw shapes or designs is by drawing the shape using different colours, strokes etc.</p><p>For this we use path and paint variables. Each of them will be storing instances of Path() and Paint() classes respectively. Path allows to set the path or outline of our shape while Paint() defines the style of paint, fill or stroke we need to use.</p><pre>void paint(Canvas canvas, Size size) {<br>  // <em>TODO: implement paint<br>  </em>final paint = Paint();<br>  final path = Path();<br> }</pre><p>Next we define the paint properties. Here we will be implementing a simple fill type design. Feel free to use stroke type design and experiment with the property values to get cool designs.</p><figure><img alt="A simple bezier curve made in flutter" src="https://cdn-images-1.medium.com/max/1024/1*Xkuha6cp5_AzPu8SnoHCXw.png" /></figure><p>We are going to make the above curve. For that we need to determine the coordintes so we can draw the curve. Calculating the angle points is the hard part of making custom designs and shapes. Each curvature is obtained from 3 sets of points.</p><p>Assuming the maximum height (size.height) and maximum width (siz.width) as 1 and the minimum values of height and width as 0 we can obtain the following co-ordinates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*zOsmJsgvkImeecO8xbmp3A.png" /></figure><p>We use the paint function of Paint() class to obtain the style of paint, the colour to be used, the gradient to be used and many more cool stuff.</p><pre>void paint(Canvas canvas, Size size) {<br>  // <em>TODO: implement paint<br>  </em>final paint = Paint();<br>  final path = Path();<br>  paint.color = Colors.<em>lightGreen</em>;<br>  paint.style = PaintingStyle.stroke;<br>  paint.strokeWidth = 5;<br>  path.moveTo(0, size.height * 0.8);<br>  path.quadraticBezierTo(<br>    size.width * 0.1,<br>    size.height * 0.78,<br>    size.width * 0.3,<br>    size.height * 0.89,<br>  );<br>  path.quadraticBezierTo(<br>    size.width * 0.45,<br>    size.height * 0.95,<br>    size.width * 0.6,<br>    size.height * 0.85,<br>  );<br>  path.quadraticBezierTo(<br>    size.width * 0.75,<br>    size.height * 0.75,<br>    size.width * 0.85,<br>    size.height * 0.7,<br>  );<br>  path.quadraticBezierTo(<br>    size.width * 0.95,<br>    size.height * 0.65,<br>    size.width,<br>    size.height * 0.68,<br>  );<br>  path.lineTo(size.width, size.height);<br>  path.lineTo(0, size.height);<br>  path.lineTo(0, size.height * 0.8);<br><br>  canvas.drawPath(path, paint);<br>}</pre><p>The path is analogous to a pen or pencil. So first we use the move function to move the starting point to the point (0, size.height * 0.8). The size.height refers to the height of the canvas and the 0.8 refers to 80% of the height. Then we draw a curve using the quadraticBezierTo(x1,y1,x2,y2) function of path which adds a quadratic bezier segment that curves from the current point to the given point (x2,y2), using the control point (x1,y1). As we need 3 curve segments to make our curve we use 3 sets of the quadraticBezierTo function.</p><p>Then we use the lineTo function to obtain the straight lines for our completing our curve. It takes in two parameters (x,y) which defines the stop point. Finally we use the drawPath() of canvas to obtain the curve in our app.</p><p>We can experiment by changing paint style or paint colour.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JHXASFiDuRzJpjl2_E_sMQ.png" /></figure><p>You can add more than one paint and path objects to create different designs and style.</p><pre>void paint(Canvas canvas, Size size) {<br>  // <em>TODO: implement paint<br>  </em>final paint = Paint();<br>  final path = Path();<br>  paint.color = Colors.<em>blueAccent</em>;<br>  paint.style = PaintingStyle.stroke;<br>  paint.strokeWidth = 15;<br>  path.moveTo(0, size.height * 0.8);<br>  path.quadraticBezierTo(<br>    size.width * 0.1,<br>    size.height * 0.78,<br>    size.width * 0.3,<br>    size.height * 0.89,<br>  );<br>  path.quadraticBezierTo(<br>    size.width * 0.45,<br>    size.height * 0.95,<br>    size.width * 0.6,<br>    size.height * 0.85,<br>  );<br>  path.quadraticBezierTo(<br>    size.width * 0.75,<br>    size.height * 0.75,<br>    size.width * 0.85,<br>    size.height * 0.7,<br>  );<br>  path.quadraticBezierTo(<br>    size.width * 0.95,<br>    size.height * 0.65,<br>    size.width,<br>    size.height * 0.68,<br>  );<br>  path.lineTo(size.width, size.height);<br>  path.lineTo(0, size.height);<br>  path.lineTo(0, size.height * 0.8);<br><br>  canvas.drawPath(path, paint);<strong><br>  final paint1 = Paint();<br>  paint1.color = Colors.<em>yellow</em>;<br>  paint1.style = PaintingStyle.fill;<br>  canvas.drawPath(path, paint1);</strong><br>}</pre><p>We get the following output from the above code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KFT1_J_dPsCkxRMTrcycKw.png" /></figure><p>Hope you all had a great time building custom curves. If you liked this tutorial give a clap by clicking on the icon on the left of the screen. Do comment about your experience and share the new designs you made.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8f97577f5e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to send sensor data to firebase Firestore using google app script — Part 2]]></title>
            <link>https://ashnizaster.medium.com/how-to-send-sensor-data-to-firebase-firestore-using-google-app-script-part-2-432cb55f3f27?source=rss-a80870f2b002------2</link>
            <guid isPermaLink="false">https://medium.com/p/432cb55f3f27</guid>
            <category><![CDATA[google-sheets]]></category>
            <category><![CDATA[sensors]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[app-script]]></category>
            <category><![CDATA[firestore]]></category>
            <dc:creator><![CDATA[Ashna Nizam]]></dc:creator>
            <pubDate>Fri, 25 Dec 2020 06:54:51 GMT</pubDate>
            <atom:updated>2020-12-25T08:27:54.445Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to send sensor data to firebase Firestore using google app script — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u0acoDS9y6Opae4NimF1Ow.jpeg" /></figure><p>Welcome to part 2 of the step by step tutorial on how to send sensor data to Firestore using google app script. Check out the <a href="https://ashnizaster.medium.com/how-to-send-sensor-data-to-firebase-firestore-using-google-app-script-part-1-aea75ab6cbd6">part 1</a> of this two part tutorial to know how to send data from sensors to google sheets. In this tutorial I will be walking you through sending data dynamically from the google sheets to cloud Firestore as sensor data gets logged.</p><p><strong>STEP 4:</strong></p><p>After getting sensor data to google sheets we need to setup our cloud Firestore. For this, open google firebase. Sign in using the same google account in which you created the sheets. If you are already signed in then your google profile pic will be visible at the top right corner. After signing in click on ‘Go to console’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*S-Rt2ce2bCthBG5wJU6Ztw.png" /></figure><p><strong>STEP 4.1</strong>:</p><p>Create a new project. If you already have projects then click Add project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2yIP50VhECKgQMxoK1dz5A.png" /></figure><p><strong>STEP 4.2:</strong></p><p>Give a name for your project and click continue</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gBjQcFP4a6ZNlRMBq_Z8xw.png" /></figure><p>Then enable the google analytics for the project and press Continue</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kdouZcknz_OXfMhqt8vdOg.png" /></figure><p>Now choose google analytics account. If you don’t have one then choose the default account for firebase and click on Create project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*RB1zBP-H6CyiUGG64OZ_iQ.png" /></figure><p>Now your project will be created and you will be prompted to a window as shown below. Click Continue to go to your project dashboard</p><p><strong>STEP 4.3</strong>:</p><p>Choose Cloud Firestore from the dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a2dgwK9rWI2V3qNrZ77b6g.png" /></figure><p>Now click on create database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OtVpLT0bsY52vL3XaQbqwQ.png" /></figure><p>Here you will be prompted to choose the mode in which the database is going to be created. As this is for DIY project purpose we will be going with <strong>test mode</strong>. This can be later changed by changing the firebase rules. After choosing the mode click on Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IAf3fGxkHOnCDf8gemQ9cQ.png" /></figure><p>To set up the Firestore location check the region where you are from. This cannot be changed later and must be given correctly in order for the database to work properly especially when the data is timestamped. After choosing the location click on enable to finish setting up your database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lPBGGWqO85FPSjCwL6YiRg.png" /></figure><p>Now your database is ready to accept values</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nWnuzEpeRXEbd94-IojOMQ.png" /></figure><p><strong>STEP 5</strong>:</p><p>Now we need to get the project credentials for our firebase project. For this head over to <a href="https://console.cloud.google.com/">google console</a>. Now search the firebase project you have created and select that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RT7i89LnYI1aGeq6o0H5qA.png" /></figure><p>After selecting the project head over to API overview and choose credentials</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XWWIyXUOymiqiWhKta4rVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*_00RlUUALeZ69gmfgL7JAg.png" /></figure><p>Next choose the service account of the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AevZxRd9zcL9NcCGaYNVbw.png" /></figure><p>Now create a new key for enabling API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*cfZ802ejgnIpTKi_irGdxw.png" /></figure><p>Choose JSON format and click on create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*vh7n3dDoreqb7YdXN2TDoQ.png" /></figure><p>Now a JSON file would be downloaded with the private keys. From this note down the <strong>private_key</strong>, <strong>client_email</strong> and <strong>project_id</strong>.</p><p><strong>STEP 6</strong>:</p><p>The final step of this project is to add the corresponding app script code to send data received in google sheets to Firestore. For that first we need to install the Firestore library. To do so open script editor and go to <strong>Resources-&gt;Libraries</strong>. Copy the following code for Firestore library in the input box and click Add</p><p><em>1VUSl4b1r1eoNcRWotZM3e87ygkxvXltOgyDZhixqncz9lQ3MjfT1iKFw</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3K7d6KRwBr6qhN6v28bLEg.png" /></figure><p>Now select the latest version from the version drop down and enable the Development mode option. Then hit save and the Firestore library would be added to the script editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2AszrPY5XnRHWcMFR_wZzA.png" /></figure><p>Now copy the <a href="https://github.com/AshNiz24/How-to-send-sensor-data-to-firebase-Firestore-using-google-app-script/blob/main/AppScript2.gs">code</a> for sending data to Firestore. In the <a href="https://ashnizaster.medium.com/how-to-send-sensor-data-to-firebase-firestore-using-google-app-script-part-1-aea75ab6cbd6">part 1</a> of the code you might have noticed that I have commented out a statement ‘firestore()’ just before the returning the content service. Make sure to uncomment this line as this line is the one that connects the Firestore part of the code to the main code.</p><p>After copying the code you might have to authenticate your web app again as we have added some libraries. To know how to authenticate your web app check the <a href="https://ashnizaster.medium.com/how-to-send-sensor-data-to-firebase-firestore-using-google-app-script-part-1-aea75ab6cbd6">part 1</a> of this tutorial where I have explained it in detail. Also make sure to update the gas id in your Arduino code. Get the complete script editor code <a href="https://github.com/AshNiz24/How-to-send-sensor-data-to-firebase-Firestore-using-google-app-script/blob/main/Script%20Editor%20final.gs">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mNoKbsmdpPA1pIwRbBiRJQ.png" /></figure><p>If you did everything correctly and got the output like above, Congratulations! on getting your sensor data to firestore. If you haven’t then don’t worry everything takes some patience and it might be just a small careless mistake. Review what you have done and you would be able to rectify it and get the final result. Hope you have enjoyed my first tutorial. Feel free to ask your queries in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=432cb55f3f27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to send sensor data to firebase Firestore using google app script — Part 1]]></title>
            <link>https://ashnizaster.medium.com/how-to-send-sensor-data-to-firebase-firestore-using-google-app-script-part-1-aea75ab6cbd6?source=rss-a80870f2b002------2</link>
            <guid isPermaLink="false">https://medium.com/p/aea75ab6cbd6</guid>
            <category><![CDATA[app-script]]></category>
            <category><![CDATA[google-sheets]]></category>
            <category><![CDATA[firestore]]></category>
            <category><![CDATA[nodemcu]]></category>
            <category><![CDATA[sensors]]></category>
            <dc:creator><![CDATA[Ashna Nizam]]></dc:creator>
            <pubDate>Fri, 25 Dec 2020 06:41:51 GMT</pubDate>
            <atom:updated>2020-12-25T08:22:55.192Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to send sensor data to firebase Firestore using google app script — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TYmdykjxXn6R1Ydhif4oSw.jpeg" /></figure><p>Have you ever wondered how we can send sensor data to a database? Most of you might have come across on how to send sensor data to real time database of google firebase. But the problem? Almost all the data is just getting overwritten and not exactly stored. So how can we store data? Here is the part where google app script comes to play. It acts as a mediator between the database and the sensor circuits.</p><p>In the part 1 of the two part tutorial I will be showing you the step by step instructions on how to send sensor data to google sheets (which acts as the mediator here) using app script. Head over to <a href="https://ashnizaster.medium.com/how-to-send-sensor-data-to-firebase-firestore-using-google-app-script-part-2-432cb55f3f27">part 2</a> of this tutorial where I will be showing you how to send data from the google sheets to Firestore.</p><p>So before we jump into the project we should know what all are the different tools we use for achieving our goal.</p><p><strong>What is google firebase?</strong></p><p>According to the google firebase community Google firebase is a Google backend application development software that enables developers to develop iOS, Android and web applications. Firebase provides tools for tracking analytics, reporting and fixing app crashes and many more.</p><figure><img alt="Firebase cloud Firestore logo" src="https://cdn-images-1.medium.com/max/200/1*Iz9GcUr8wlgS-znAaA0okw.png" /></figure><p>Firebase provides 2 data types — Real time database and Cloud Firestore. Both are NoSQL databases. Real time database was the original database and cloud Firestore is the newest database of firebase. To know more about firebase databases <a href="https://firebase.google.com/docs/database/rtdb-vs-firestore">click here</a>.</p><p><strong>What is google app script?</strong></p><p>According to google developers community, Google Apps Script is a rapid application development platform that makes it fast and easy to create business applications that integrate with Google Workspace. It is based on JavaScript and provides built in libraries for google workspace applications.</p><p>It is used to add customized functions to google sheets, customized menus for google docs and forms, create stand alone web applications, interaction with other google services and much more. To know more head over to <a href="https://developers.google.com/apps-script/overview">google app script documentation</a>.</p><p>So for our purpose I am using a DHT22 temperature humidity sensor, a NodeMCU, and a bit of coding to achieve our goal.</p><p><strong>STEP 1</strong></p><p>Setup the connections of the sensor circuit as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*ixuZiHsPz6OyJl_IYw707Q.png" /></figure><p><em>Note 1</em>: The resistor need not be used if the dht22 module is used as it has inbuilt resistor.</p><p><strong>STEP 2.1</strong></p><p>Open Google Sheets and Create a new Spreadsheet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*Q1aoJij5SoboeBGrv4nouw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*4__jpTyrWeGPe9XvFmLemQ.png" /></figure><p><strong>STEP 2.2</strong></p><p>Double click and rename the spreadsheet document. Also rename the sheet name. Here I have named my spreadsheet as ‘Temperature Humidity log’ and sheet name as ‘log’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*RxFtfthbE1LcMmkyVJ0ORA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*ZiW4k7kbN0YYHP6GunqDXg.png" /></figure><p><em>Note 2</em>: Be sure to note down the spreadsheet id. We will need this later for setting up sheets using app script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*DzZTcyxVwNx9f27gm0F_IQ.png" /><figcaption>ID is the characters between ‘d/’ and ‘/edit’</figcaption></figure><p><strong>STEP 2.3</strong></p><p>Give the required headings for logging the values</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*goril9WZJtxbMm6Llcljjw.png" /></figure><p><strong>STEP 2.4</strong></p><p>Now open script editor from tools option and a window will be opened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*obPRCM8onL0qQctWCicfpg.png" /></figure><p>Now rename the script editor title with the same name as given for the spreadsheet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*u67ZInT0vze9AZVLrqhVzQ.png" /></figure><p>Now paste the code given <a href="https://github.com/AshNiz24/How-to-send-sensor-data-to-firebase-Firestore-using-google-app-script/blob/main/AppScript1.gs">here</a>.</p><p><strong>STEP 2.5</strong></p><p>Publish the script as a web app by following the steps below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-d61FB6MH6NE5UKhxVYXdQ.png" /></figure><p>Now you will get a window where you can set the visibility of the web app. Choose the visibility to ‘Anyone, even anonymous’ and click deploy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*0AQ62AYoQHIrbDDPSBTp2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*LLqzhEddpLnzU799Ge0QGQ.png" /></figure><p>Now you will be prompted to authenticate your web application. Click on review permissions and select your account</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*Lffhnd-Hg1vGoeR5D3hkng.png" /></figure><p>Then click the advanced option and select ‘Go To (Your spreadsheet name)’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*2ZdOC875yVi1NaVFHEwuyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*xabkRz6c-bqVkJawdrZzMA.png" /></figure><p>Then click allow and proceed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*PJ-DPPomE4Xmo44RAojWEA.png" /></figure><p>Now you will have a window with your web app link. Copy this link which is of the form https://script.google.com/macros/s/<strong>gas id</strong>/exec</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*pNFB412kmz-SpFGM-6DPMA.png" /></figure><p><strong>STEP 3:</strong></p><p>Install the required libraries for configuring ide with the DHT22 sensor and connecting NodeMCU to the web. Copy paste the code for Arduino IDE from <a href="https://github.com/AshNiz24/How-to-send-sensor-data-to-firebase-Firestore-using-google-app-script/blob/main/dht22_gs_firestore.ino">here</a>.</p><p>DHT Sensor Libraries</p><ul><li><a href="https://github.com/adafruit/DHT-sensor-library">adafruit/DHT-sensor-library</a></li><li><a href="https://github.com/adafruit/Adafruit_Sensor">adafruit/Adafruit_Sensor</a></li></ul><p><a href="https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html">Wi-Fi Libraries</a></p><p>Hope you enjoyed creating a new project which sends sensor data to the google sheets which acts as a mediator here. Follow the <a href="https://ashnizaster.medium.com/how-to-send-sensor-data-to-firebase-firestore-using-google-app-script-part-2-432cb55f3f27">part 2</a> of this tutorial to learn about sending the data from google sheets to Firestore.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aea75ab6cbd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>