<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shivansh Agrawal</title>
    <description>The latest articles on DEV Community by Shivansh Agrawal (@shivansh22agra).</description>
    <link>https://dev.to/shivansh22agra</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1135247%2F5edd6d67-1013-4040-814f-a4f4ccb08d4d.jpeg</url>
      <title>DEV Community: Shivansh Agrawal</title>
      <link>https://dev.to/shivansh22agra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shivansh22agra"/>
    <language>en</language>
    <item>
      <title>Use props and also fetch Data from an API in Next.js with Typescript</title>
      <dc:creator>Shivansh Agrawal</dc:creator>
      <pubDate>Sun, 03 Sep 2023 16:35:24 +0000</pubDate>
      <link>https://dev.to/shivansh22agra/use-props-and-also-fetch-data-from-an-api-in-nextjs-with-typescript-17a7</link>
      <guid>https://dev.to/shivansh22agra/use-props-and-also-fetch-data-from-an-api-in-nextjs-with-typescript-17a7</guid>
      <description>&lt;p&gt;First, we will create a Next.js app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LP7cHRph--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3h03tnkr1qheqy3vil4e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LP7cHRph--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3h03tnkr1qheqy3vil4e.png" alt="Image description" width="800" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see the response of the API by browsing &lt;a href="https://www.thecocktaildb.com/api/json/v1/1/filter.php?c=Cocktail"&gt;https://www.thecocktaildb.com/api/json/v1/1/filter.php?c=Cocktail&lt;/a&gt; this link in the browser. Since we can use get request apis in the browser. to view JSON beautifully we can use JSON Viewer Pro extension.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YWuIncvs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9wtiu1q54pl39cs6nd5c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YWuIncvs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9wtiu1q54pl39cs6nd5c.png" alt="Image description" width="800" height="696"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In app/Page.tsx which displays as the First screen with path name ‘/’&lt;/p&gt;

&lt;p&gt;To get Data from an API we will use the fetchdetails() function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchdetails() {
  const response = await fetch(
    "https://www.thecocktaildb.com/api/json/v1/1/filter.php?c=Cocktail"
  );
  if (response.ok) {
    const responseBody = await response.json();
    // console.log(`data ${data}`);
    // setData(responseBody);
    console.log(`data ${responseBody}`);
    return responseBody;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This fetch details will return response.json() if the response.ok.&lt;/p&gt;

&lt;p&gt;Then in the primary function of Page.tsx we will call this function like this :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const data = await fetchdetails();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Props are basically used to pass data from one function to another function.&lt;/p&gt;

&lt;p&gt;To use Props with type script. First, make an interface of data that has to pass. In my case, the interface looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Props {
    key: String;
    strDrink: String;
    strDrinkThumb: String;
    idDrink: String;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To display data. We will create a container with an image and text to display the image and the name of the cocktail coming from the API.&lt;/p&gt;

&lt;p&gt;Create a Components Folder in your dir and make a CocktailContainer.tsx file inside it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// import Link from "next/link";
import Image from "next/image";
interface Props {
  strDrink: String;
  strDrinkThumb: String;
  idDrink: String;
}

export default function CocktailContainer({
  strDrink,
  strDrinkThumb,
  idDrink,
}: Props) {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;{strDrink}&amp;lt;/h1&amp;gt;
      &amp;lt;Image src={strDrinkThumb + ""} alt="" width={150} height={150} /&amp;gt;
      {/* &amp;lt;Link href={`/asd`}&amp;gt;&amp;lt;/Link&amp;gt; */}
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now coming back to page.tsx file we pass data from the api to the above function to display the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
    &amp;lt;main className="font-poppins mx-10"&amp;gt;
      &amp;lt;div className="grid gap-10 grid-cols-fluid"&amp;gt;&amp;lt;/div&amp;gt;
      {data.drinks.map(function (item: Props) {
        return (
          &amp;lt;CocktailContainer
            key={item.idDrink.toString()}
            strDrink={item.strDrink}
            strDrinkThumb={item.strDrinkThumb}
            idDrink={item.idDrink}
          &amp;gt;&amp;lt;/CocktailContainer&amp;gt;
        );
      })}
    &amp;lt;/main&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code uses the map to pass or display any Object or list.&lt;br&gt;
The Whole code page.tsx will look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Image from "next/image";
import CocktailContainer from "@/components/cocktailContainer";
async function fetchdetails() {
  const response = await fetch(
    "https://www.thecocktaildb.com/api/json/v1/1/filter.php?c=Cocktail"
  );
  if (response.ok) {
    const responseBody = await response.json();
    // console.log(`data ${data}`);
    // setData(responseBody);
    console.log(`data ${responseBody}`);
    return responseBody;
  }
}
// eslint-disable-next-line @next/next/no-async-client-component
export default async function Home() {
  const data = await fetchdetails();

  interface Props {
    key: String;
    strDrink: String;
    strDrinkThumb: String;
    idDrink: String;
  }

  return (
    &amp;lt;main className="font-poppins mx-10"&amp;gt;
      &amp;lt;div className=""&amp;gt;&amp;lt;/div&amp;gt;
      {data.drinks.map(function (item: Props) {
        return (
          &amp;lt;CocktailContainer
            key={item.idDrink.toString()}
            strDrink={item.strDrink}
            strDrinkThumb={item.strDrinkThumb}
            idDrink={item.idDrink}
          &amp;gt;&amp;lt;/CocktailContainer&amp;gt;
        );
      })}
    &amp;lt;/main&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since to use external image domains, we first configure them.&lt;/p&gt;

&lt;p&gt;So, to do so replace this code in your next.config.js file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  images: {
    domains: ["www.thecocktaildb.com"],
  },
};

module.exports = nextConfig;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now after running your app, you would be seeing a list of cocktails.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dtOhr8Mi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2bziqh6s0109o81r7elp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dtOhr8Mi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2bziqh6s0109o81r7elp.png" alt="Image description" width="800" height="710"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Live Location Tracking in Google Maps Flutter using Geolocator in 2023</title>
      <dc:creator>Shivansh Agrawal</dc:creator>
      <pubDate>Sun, 03 Sep 2023 05:36:00 +0000</pubDate>
      <link>https://dev.to/shivansh22agra/live-location-tracking-in-google-maps-flutter-using-geolocator-in-2023-2mo7</link>
      <guid>https://dev.to/shivansh22agra/live-location-tracking-in-google-maps-flutter-using-geolocator-in-2023-2mo7</guid>
      <description>&lt;p&gt;The packages we need this feature are&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://pub.dev/packages/google_maps_flutter" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://res.cloudinary.com/practicaldev/image/fetch/s--gTOEYkW1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://pub.dev/static/hash-lqvmd91d/img/pub-dev-icon-cover-image.png" height="400" class="m-0" width="800"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://pub.dev/packages/google_maps_flutter" rel="noopener noreferrer" class="c-link"&gt;
          google_maps_flutter | Flutter Package
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;p class="truncate-at-3"&gt;
          A Flutter plugin for integrating Google Maps in iOS and Android applications.
        &lt;/p&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://res.cloudinary.com/practicaldev/image/fetch/s--A-KSduNl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://pub.dev/static/hash-lqvmd91d/img/flutter-logo-32x32.png" width="32" height="32"&gt;
        pub.dev
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://pub.dev/packages/geolocator" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://res.cloudinary.com/practicaldev/image/fetch/s--gTOEYkW1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://pub.dev/static/hash-lqvmd91d/img/pub-dev-icon-cover-image.png" height="400" class="m-0" width="800"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://pub.dev/packages/geolocator" rel="noopener noreferrer" class="c-link"&gt;
          geolocator | Flutter Package
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;p class="truncate-at-3"&gt;
          Geolocation plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API for generic location (GPS etc.) functions.
        &lt;/p&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://res.cloudinary.com/practicaldev/image/fetch/s--A-KSduNl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://pub.dev/static/hash-lqvmd91d/img/flutter-logo-32x32.png" width="32" height="32"&gt;
        pub.dev
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;For configuring Google Maps in Flutter we first need to set this property&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; android {
     defaultConfig {
         minSdkVersion 20
     }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;&amp;lt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;manifest ...
  &amp;lt;application ...
    &amp;lt;meta-data android:name="com.google.android.geo.API_KEY"
               android:value="YOUR KEY HERE"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get an API key at &lt;a href="https://cloud.google.com/maps-platform/"&gt;https://cloud.google.com/maps-platform/&lt;/a&gt;.&lt;br&gt;
Now the real feature implementation start&lt;/p&gt;

&lt;p&gt;First, initialize a variable of LatLng type like and a Googlemap controller to animate camera position as location changes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LatLng? location;
 GoogleMapController? mapController;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then To get the User’s current live location continuously We will use the geolocator package&lt;/p&gt;

&lt;p&gt;Add a foreground permission for location in android/app/src/main/AndroidManifest.xml:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;uses-permission android:name="android.permission.FOREGROUND_SERVICE" /&amp;gt;
&amp;lt;uses-permission
    android:name="android.permission.ACCESS_FINE_LOCATION" /&amp;gt;
&amp;lt;uses-permission android:name="android.permission.WAKE_LOCK"/&amp;gt;
&amp;lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;StreamSubscription? positionStream;
  void getUserLocation() async {
    LocationPermission permission;
    LocationSettings locationSettings;
    await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high)
        .then((Position position) async {
      location = LatLng(position.latitude, position.longitude);

      setState(() {});
    });

    permission = await Geolocator.requestPermission();
    if (defaultTargetPlatform == TargetPlatform.android) {
      locationSettings = AndroidSettings(
        accuracy: LocationAccuracy.high,
        forceLocationManager: true,
      );
    } else if (defaultTargetPlatform == TargetPlatform.iOS ||
        defaultTargetPlatform == TargetPlatform.macOS) {
      locationSettings = AppleSettings(
        accuracy: LocationAccuracy.high,
        activityType: ActivityType.fitness,
        distanceFilter: 100,
        pauseLocationUpdatesAutomatically: true,
        // Only set to true if our app will be started up in the background.
        showBackgroundLocationIndicator: false,
      );
    } else {
      locationSettings = const LocationSettings(
        accuracy: LocationAccuracy.high,
        distanceFilter: 100,
      );
    }

    positionStream =
        Geolocator.getPositionStream(locationSettings: locationSettings)
            .listen((Position? position) {
      location = LatLng(position!.latitude, position.longitude);
      mapController!.animateCamera(
        CameraUpdate.newCameraPosition(
          CameraPosition(
            target: LatLng(position.latitude, position.longitude),
            zoom: 14.0,
          ),
        ),
      );
      setState(() {});

    });
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Call this function in the intstate of your widget class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@override
  void initState() {
    super.initState();
    getUserLocation();
    // _getCurrentLocation();
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and in dispose call cancel this live tracking&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@override
  void dispose() {
    positionStream!.cancel();

    // TODO: implement dispose
    super.dispose();
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A marker will indicate user live location in Google Map like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GoogleMap(
          markers: {
            Marker(
                markerId: const MarkerId('Live Location'),
                position: location ?? const LatLng(0, 0))
          },
       initialCameraPosition:  const CameraPosition(target: LatLng(0.0, 0.0)),
          // myLocationEnabled: true,
          // myLocationButtonEnabled: false,
          // mapType: MapType.normal,
          // zoomGesturesEnabled: true,
          // zoomControlsEnabled: false,
          // polylines: Set&amp;lt;Polyline&amp;gt;.of(polylines.values),
          onMapCreated: (GoogleMapController controller) {
            mapController = controller;
          },
        ),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For testing, I use the Lockito app from the Play Store&lt;/p&gt;

&lt;p&gt;App should work like this in the video&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtube.com/shorts/RocbFph9QEg?feature=share"&gt;https://youtube.com/shorts/RocbFph9QEg?feature=share&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>googlema</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Modify Status Bar in Flutter Apps in 2023</title>
      <dc:creator>Shivansh Agrawal</dc:creator>
      <pubDate>Mon, 21 Aug 2023 17:08:07 +0000</pubDate>
      <link>https://dev.to/shivansh22agra/modify-status-bar-in-flutter-apps-in-2023-5dkc</link>
      <guid>https://dev.to/shivansh22agra/modify-status-bar-in-flutter-apps-in-2023-5dkc</guid>
      <description>&lt;p&gt;If u want to have your Status bar look like this&lt;br&gt;
Add this in your Scaffold&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wVtAU59A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2f431knp074mhyw5fbds.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wVtAU59A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2f431knp074mhyw5fbds.png" alt="Image description" width="401" height="48"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;appBar: AppBar(
          systemOverlayStyle: SystemUiOverlayStyle(
            systemStatusBarContrastEnforced: false,
            statusBarColor:
                Colors.transparent ,
            statusBarIconBrightness: Brightness.dark,
            statusBarBrightness: Brightness.light,
          ),
          elevation: 0,
          toolbarHeight: 0,
        ),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can modify this as per your needs&lt;/p&gt;

&lt;p&gt;You will notice that you have to swipe the status Bar once to see your changes.&lt;/p&gt;

&lt;p&gt;To prevent this Add this Code in your First screen initState&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
        overlays: SystemUiOverlay.values);

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

&lt;/div&gt;



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