<?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: Afolayan Ademola Segun</title>
    <description>The latest articles on DEV Community by Afolayan Ademola Segun (@har4lionkest).</description>
    <link>https://dev.to/har4lionkest</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%2F306830%2F4a91aed6-8a15-483f-bcae-f6e8e514041f.png</url>
      <title>DEV Community: Afolayan Ademola Segun</title>
      <link>https://dev.to/har4lionkest</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/har4lionkest"/>
    <language>en</language>
    <item>
      <title>Drowdown Button In Flutter</title>
      <dc:creator>Afolayan Ademola Segun</dc:creator>
      <pubDate>Wed, 26 Oct 2022 17:40:01 +0000</pubDate>
      <link>https://dev.to/har4lionkest/drowdown-button-in-flutter-18al</link>
      <guid>https://dev.to/har4lionkest/drowdown-button-in-flutter-18al</guid>
      <description>&lt;p&gt;Hey Guys, &lt;/p&gt;

&lt;p&gt;Have you ever been stuck and you dont know exact thing to do anymore, trust me,    there are some bugs that won't just let you kill them (if you like use Bagon😂)...&lt;/p&gt;

&lt;p&gt;Well I came across this bug 🐞 , yeah and I checked through Flutter documentation, Stack Overflow and the likes, couldn't get my solution. &lt;/p&gt;

&lt;p&gt;I was able to figure it out after couple of hours and I will like to share my solution. Also I will be sharing some other solutions I came across just in case my solution doesnt fit. You can get all soluton in one stop, yah.&lt;/p&gt;

&lt;p&gt;In this article you will be learning how to use DropDownButton and learn various properties of it in flutter and also get the solution to common bugs associated with this widget.&lt;/p&gt;

&lt;p&gt;Lets dive in...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Dropdown Button 💁🏽‍♂️?&lt;/strong&gt;&lt;br&gt;
Dropdown Button is a Material Design button for selecting from a list of items.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DropdownButton&amp;lt;String&amp;gt;(
  value: dropdownValue,
  icon: const Icon(Icons.arrow_downward),
  elevation: 16,
  style: const TextStyle(color: Colors.deepPurple),
  underline: Container(
    height: 2,
    color: Colors.deepPurpleAccent,
  ),
  onChanged: (String? value) {
    // This is called when the user selects an item.
    setState(() {
      dropdownValue = value!;
    });
  },
  items: list.map&amp;lt;DropdownMenuItem&amp;lt;String&amp;gt;&amp;gt;((String value) 
  {
    return DropdownMenuItem&amp;lt;String&amp;gt;(
      value: value,
      child: Text(value),
    );
  }).toList(),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The Dropdown Button has some properties and methods, To use this widget, you need to have a list of items that you will use in your dropdown. For the above example here is the list that was used&lt;/p&gt;

&lt;p&gt;&lt;em&gt;const List list = ['One', 'Two', 'Three'];&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;and when you run this in your flutter project, you will get something like this: 👇🏼👇🏼👇🏼👇🏼👇🏼👇🏼&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jH4D8NbB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4g9xvpomv8uotaf4gfe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jH4D8NbB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q4g9xvpomv8uotaf4gfe.png" alt="This image shows the result of above codes" width="880" height="821"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There you go!!!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dropdown Button has a major?&lt;/strong&gt;&lt;br&gt;
You have to use this widget right, and if not, you get stuck. This is the major issue with using a Drondown Button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Error meesage:&lt;/strong&gt;&lt;br&gt;
_Drop down Either or 2 more dropdown were detected with the same value???? _&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Lets take this example as our point of focus.&lt;/em&gt;&lt;/p&gt;

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

  final List&amp;lt;String&amp;gt; nameList = &amp;lt;String&amp;gt;[
   "Name1",
    "Name2",
    "Name3",
    "Name4",
    "Name5",
    "Name6",
    "Name7",
    "Name8"
   ];

   @override
  Widget build(BuildContext context) {
    return Scaffold(
     appBar: AppBar(
     elevation: 2.0,
     title: Text('Hello'),
     ),
    body:  ListView(
        children: &amp;lt;Widget&amp;gt;[
          Row(
            children: &amp;lt;Widget&amp;gt;[
              Text('Name: '),
              Center(
                child: DropdownButton(
                  value: _value1,
                  onChanged: (value) {
                    setState(() {
                      _value1 = value;
                    });
                  },
                  items: nameList.map(
                    (item) {
                      return DropdownMenuItem(
                        value: item,
                        child: new Text(item),
                      );
                    },
                  ).toList(),
                ),
              ),
            ],
          ),
          Row(
            children: &amp;lt;Widget&amp;gt;[
              Text('Name: '),
              Center(
                child: DropdownButton(
                  value: _value2,
                  onChanged: (value) {
                    setState(() {
                      _value2 = value;
                    });
                  },
                  items: nameList.map(
                    (item) {
                      return DropdownMenuItem(
                        value: item,
                        child: new Text(item),
                      );
                    },
                  ).toList(),
                ),
              ),
            ],
          ),
        ],
      ),
    backgroundColor: Colors.grey[200],
   );
  }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;One:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Always make sure the value of the property "value" is not empty.  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         DropdownButton(
          // Initial Value
          _**value: dropdownvalue,**_

          // Down Arrow Icon
          icon: const Icon(Icons.keyboard_arrow_down),   

          // Array list of items
          items: items.map((String items) {
            return DropdownMenuItem(
              value: items,
              child: Text(items),
            );
          }).toList(),
          // After selecting the desired option,it will
          // change button value to selected value
          onChanged: (String? newValue) {
            setState(() {
              dropdownvalue = newValue!;
            });
          },
        ),
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Two:&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;
If the value is going to be promised, that is at a later time the property will get its value, then. check if the value is empty first, if it is empty replaced with a default value.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; DropdownButton(
   value: _value1.isNotEmpty ? _value1 : null, // guard it 
     with null if empty
    items: nameList.map((item) {
       return DropdownMenuItem(
          value: item,
          child: new Text(item),
        );
      }).toList(), 
    );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Three:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
If you are getting your list from the database, make sure the function you call in not in your build context, it should be called once. And the reson why that is so is because when call your api that will get the list within your build context, its get called multipble times as you are using setstate to update the selected value. Here is a complete example code  ------ &lt;br&gt;
 See here. 👇🏼👇🏼👇🏼👇🏼👇🏼👇🏼👇🏼&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  class _ParentBankState extends 
  State&amp;lt;ParentCategory&amp;gt; {
  final _formKey = GlobalKey&amp;lt;FormState&amp;gt;();

   String? _selectedBankCategory;
    // List category = [];
   final List&amp;lt;String&amp;gt; _parentCategory = [
    "Select Category",
   ];

   _//Make sure you do your calls here_

  @override
  void initState() {
    //do your calls to get the list from your database 
   //here so that it will be called once...

  final category = context.read&amp;lt;AddMoneyCubit&amp;gt;. 
  ().loadBankList();
   super.initState();
  }

@override
 Widget build(BuildContext context) {

 //Do not call your api here, why?
 //because buildcontext get build multiple times and that 
 //will make your dropdwon throw that error, because it is 
 //seeing the value beeing used repeatedly...

  var businessBankDropDown =
    BlocBuilder&amp;lt;AddMoneyCubit, AddMoneyState&amp;gt;(
  builder: (context, state) {
    return Form(
      key: _formKey,
      child: ButtonTheme(
        alignedDropdown: true,
        child: DropdownButtonHideUnderline(
          child: DropdownButton&amp;lt;String&amp;gt;(
            menuMaxHeight: 300,
            isExpanded: true,
            value: _selectedParentCategory,
            hint: const Text(
              "Parent Category",
              style: TextStyle(fontSize: 14),
            ),
            items: state is LoadBankList
                ? state.categoryListModel.map((e) {
                    return DropdownMenuItem&amp;lt;String&amp;gt;(
                        value: e.text,
                        child: Row(
                          children: [
                            Text(
                              e.text,
                              style: const TextStyle(
                                  fontSize: 14.0, color: 
              IposColors.black),
                            ),
                          ],
                        ));
                  }).toList()
                : _parentBank.map((String value) {
                    return DropdownMenuItem&amp;lt;String&amp;gt;(
                        value: value,
                        child: Row(
                          children: [
                            Text(
                              value,
                              style: const TextStyle(
                                  fontSize: 14.0, color: 
                    IposColors.black),
                            ),
                          ],
                        ));
                  }).toList(),

            onChanged: (value) {
              setState(() {
                print(value);
           _selectedBankCategory = value;
              });
            },
            style: const TextStyle(fontSize: 30),
           ),
           ),
          ),
         );
         },
        );

    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height / 16.4,
       decoration: BoxDecoration(
       color: Colors.white,
       borderRadius: BorderRadius.circular(10),
       border: Border.all(
        color: Colors.grey,
       ),
     ),
     child: businessBankDropDown);
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This was my Solution.&lt;/p&gt;

&lt;p&gt;Thank you for taking your time to go through this.&lt;/p&gt;

&lt;p&gt;I hope you have learned to use this awesome widget and this helps you resolve your bugs 🐞🪲  issues...&lt;/p&gt;

&lt;p&gt;If you would like to discuss this or any related issueChat Me. Follow me on &lt;a href="https://twitter.com/Har4lionkest"&gt;Twitter&lt;/a&gt; for More...&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>dropdown</category>
    </item>
    <item>
      <title>How To Display A SnackBar In Flutter</title>
      <dc:creator>Afolayan Ademola Segun</dc:creator>
      <pubDate>Mon, 21 Feb 2022 13:29:27 +0000</pubDate>
      <link>https://dev.to/har4lionkest/how-to-display-a-snackbar-in-flutter-cgn</link>
      <guid>https://dev.to/har4lionkest/how-to-display-a-snackbar-in-flutter-cgn</guid>
      <description>&lt;p&gt;Hi, It's &lt;a href="http://afolayanademola.com.ng/"&gt;Kest&lt;/a&gt; &lt;a href="https://hashnode.com/@kest"&gt;Again&lt;/a&gt; And I am about to show &lt;em&gt;you how to display a snackbar in Flutter&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What's a SnackBar anyway?&lt;/em&gt;&lt;/strong&gt; 🤔🤔🤔&lt;br&gt;
A SnackBar can be useful to briefly inform your users when certain actions take place. For example, when a user swipes away a message in a list, you might want to inform them that the message has been deleted. You might even want to give them an option to undo the action.&lt;/p&gt;

&lt;p&gt;You will be able to display a Snackbar in three easy steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a Scaffold.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Display a SnackBar.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Provide an optional action.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Create a Scaffold&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Creating a Scaffold is one of the easiest things to do in Flutter, as a piece of general knowledge, &amp;gt; everything in Flutter is a widget, And Fortunately, it's the same for Scaffold.&lt;br&gt;
The Scaffold widget, from the material library, creates this visual structure and ensures that important widgets don’t overlap.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    return MaterialApp(
      title: 'SnackBar Demo',
      home: Scaffold(
          appBar: AppBar(
          title: const Text('SnackBar Demo'),
          ),
         body: const SnackBarPage(),
        ),
      );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;2. Display A SnackBar&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;With the Scaffold in place, Its time to Display a Snackbar, you can do that with the code snippets below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const snackBar = SnackBar(
        content: Text('Yay! A SnackBar!'),
       );

     // Find the ScaffoldMessenger in the widget tree
     // and use it to show a SnackBar.
     ScaffoldMessenger.of(context).showSnackBar(snackBar);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Yay!! that's it. It's as easy as that. However if you would like your snackBar to perform more functions other than displaying messages about users actions. You can add other properties to the widget.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Provide an optional action&lt;/strong&gt;&lt;br&gt;
You might want to provide an action to the user when the SnackBar is displayed. For example, if the user accidentally deletes a message, they might use an optional action in the SnackBar to recover the message.&lt;/p&gt;

&lt;p&gt;Here’s an example of providing an additional action to the SnackBar widget:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     final snackBar = SnackBar(
         content: const Text('Yay! A SnackBar!'),
         action: SnackBarAction(
         label: 'Undo',
         onPressed: () {
          // Some code to undo the change.
          },
         ),
        );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And that's a wrap. &lt;em&gt;Shikena&lt;/em&gt;🤗 (that's all). I hope this article has been able to enlighten you and make building awesome, beautiful, and useful apps.&lt;/p&gt;

&lt;p&gt;If you would like to discuss this or any related issue&lt;a href="https://wa.me/message/OEGQ4YVXBSFWL1"&gt;Chat Me&lt;/a&gt;. Follow me on &lt;a href="https://twitter.com/Har4lionkest"&gt;Twitter&lt;/a&gt; for More...&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>snackbar</category>
    </item>
    <item>
      <title>How TO DELETE DATA OVER THE INTERNET IN FLUTTER</title>
      <dc:creator>Afolayan Ademola Segun</dc:creator>
      <pubDate>Tue, 16 Nov 2021 14:48:17 +0000</pubDate>
      <link>https://dev.to/har4lionkest/how-to-delete-data-over-the-internet-in-flutter-25nj</link>
      <guid>https://dev.to/har4lionkest/how-to-delete-data-over-the-internet-in-flutter-25nj</guid>
      <description>&lt;p&gt;Hi, I am  &lt;a href="https://kest.hashnode.dev/"&gt;Kest&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;If you have been following my  &lt;a href="https://kest.hashnode.dev/"&gt;CRUD&lt;/a&gt; operation tutorial series you will already know without the title that this is the last part of the series on CRUD operation.&lt;/p&gt;

&lt;p&gt;Users are used to this feature (ability to delete input fields) that are now available in almost every application that involves inputting fields. They do not only want to be able to edit their input, they also want to be able to delete it.  &lt;/p&gt;

&lt;p&gt;This tutorial which is the last of the four CRUD operation, is the simplest of them all, so grab a chair 🪑 and a drink 🍹🥤 let's go over it.&lt;/p&gt;

&lt;p&gt;In just three simple steps, you will be able to implement the Delete operation in flutter your application, here are the steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Add the Http Package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delete data on the server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update the screen.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;😯😯😯 is that it?  Yes, it's as simple as that. Let go deep into the steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Add the Http Package.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;As usual to install the http package, add it to the dependencies section of the pubspec.yaml file. You can find the latest version of the http package on pub.dev.&lt;br&gt;
That famous pubspec.yaml file is pronounced(pubspec dot yamul or yamil depending on where you coding from... 😂😂😂).&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2.Delete data on the server.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Using  the JSONPlaceholder as a case study, we want to delete a particular album. we will make use of the http.delete() method.&lt;br&gt;
 Note that this requires the id of the album that you want to delete. For this example, use something you already know, for example id = 1.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Future&amp;lt;http.Response&amp;gt; deleteAlbum(String id) async {
       final http.Response response = await http.delete(        
       Uri.parse
     ('https://jsonplaceholder.typicode.com/albums/$id'),
        headers: &amp;lt;String, String&amp;gt;{
       'Content-Type': 'application/json; charset=UTF-8',
         },
       );
       return response;
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The http.delete() method returns a Future that contains a Response.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Future is a core Dart class for working with async operations. A Future object represents a potential value or error that will be available at some time in the future.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The http.Response class contains the data received from a successful http call.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The deleteAlbum() method takes an id argument that is needed to identify the data to be deleted from the server.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3.Update the screen.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In order to check whether the data has been deleted or not. First, fetch the data from the JSONPlaceholder using the http.get() method, and display it on the screen. (See my tutorial on how to fetch Data from the internet  &lt;a href="https://kest.hashnode.dev/how-to-fetch-live-data-from-the-internet-in-flutter"&gt;here&lt;/a&gt; for a complete example). You should now have a Delete Data button that, when pressed, calls the deleteAlbum() method.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: &amp;lt;Widget&amp;gt;[
        Text(snapshot.data?.title ?? 'Deleted'),
        ElevatedButton(
           child: const Text('Delete Data'),
           onPressed: () {
              setState(() {
              _futureAlbum =
              deleteAlbum(snapshot.data!.id.toString());
            });
         },
       ),
      ],
     );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, when you click on the Delete Data button, the deleteAlbum() method is called and the id you are passing is the id of the data that you retrieved from the internet. This means you are going to delete the same data that you fetched from the internet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Returning a response from the deleteAlbum() method&lt;/strong&gt;&lt;br&gt;
Once the delete request has been made, you can return a response from the deleteAlbum() method to notify our screen that the data has been deleted.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Future&amp;lt;Album&amp;gt; deleteAlbum(String id) async {
        final http.Response response = await http.delete(
          Uri.parse('https://jsonplaceholder.typicode.com/albums/$id'),
        headers: &amp;lt;String, String&amp;gt;{
       'Content-Type': 'application/json; charset=UTF-8',
           },
          );
        if (response.statusCode == 200) {
       // If the server did return a 200 OK response,
      // then parse the JSON. After deleting,
      // you'll get an empty JSON `{}` response.
      // Don't return `null`, otherwise `snapshot.hasData`
      // will always return false on `FutureBuilder`.
      return Album.fromJson(jsonDecode(response.body));
      } else {
      // If the server did not return a "200 OK response",
      // then throw an exception.
      throw Exception('Failed to delete album.');
        }  
       }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;FutureBuilder() now rebuilds when it receives a response. Since the response won’t have any data in its body if the request was successful, the Album.fromJson() method creates an instance of the Album object with a default value (null in our case). This behavior can be altered in any way you wish.&lt;/p&gt;

&lt;p&gt;Yeah 🕺🕺🕺🕺🕺&lt;/p&gt;

&lt;p&gt;That’s all! Now you’ve got a function that deletes the data from the internet.&lt;/p&gt;

&lt;p&gt;Congratulations. If you have been following you should be able to perform the CRUD operations in flutter now. &lt;/p&gt;

&lt;p&gt;kindly follow me on &lt;a href="https://twitter.com/Har4lionkest?s=09"&gt;Twitter&lt;/a&gt;  for More...  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>How To Send Data To The Internet In Flutter!</title>
      <dc:creator>Afolayan Ademola Segun</dc:creator>
      <pubDate>Wed, 27 Oct 2021 14:03:48 +0000</pubDate>
      <link>https://dev.to/har4lionkest/how-to-send-data-to-the-internet-in-flutter-2fp0</link>
      <guid>https://dev.to/har4lionkest/how-to-send-data-to-the-internet-in-flutter-2fp0</guid>
      <description>&lt;p&gt;Hey Guys, &lt;/p&gt;

&lt;p&gt;In  &lt;a href="https://kest.hashnode.dev/how-to-fetch-live-data-from-the-internet-in-flutter" rel="noopener noreferrer"&gt;My Last Article&lt;/a&gt;, we learned how to Fetch Data from the internet using the http package.&lt;br&gt;
 &lt;br&gt;
Now what about &lt;strong&gt;Sending Data&lt;/strong&gt; to the Internet 🤔, yeah it so easy also...&lt;/p&gt;

&lt;p&gt;Sending data to the Internet is necessary for most apps. The http package has got that covered, too.&lt;/p&gt;

&lt;p&gt;These few steps below show us how we can achieve this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Add the http package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Send data to a server using the http package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Convert the response into a custom Dart object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get a title from user input.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Display the response on the Screen.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So we will go through these steps together,&lt;/p&gt;

&lt;h3&gt;
  
  
  Add the http package
&lt;/h3&gt;

&lt;p&gt;To install the http package, add it to the dependencies section of the popular pubspec.yaml file (pronounced pubspec dot yamul or yaamu file 😂). &lt;br&gt;
You can find the latest version of the http package on pub.dev.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1631623405717%2FjEkrTrlPw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1631623405717%2FjEkrTrlPw.png" alt="article1.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;-Sending data to Server&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We will be using the instance of sending an Album to the Server and we can do that by sending an Album title to JSONplaceholder using the &lt;strong&gt;http.post()&lt;/strong&gt; method.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Future&amp;lt;http.Response&amp;gt; createAlbum(String title) {  
    return http.post( Uri.parse(
    'https://jsonplaceholder.typicode.com/albums'
      ), 
    headers: &amp;lt;String, String&amp;gt;{ 
     'Content-Type': 'application/json; charset=UTF-8', 
     }, 
  body: jsonEncode(&amp;lt;String, String&amp;gt;{
   'title': title,
    }),
   );
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The http.post() method returns a Future that contains a Response.&lt;br&gt;
Just like we have learned previously:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Future is a core Dart class for working with asynchronous operations. A Future object &lt;br&gt;
represents a potential value or error that will be available at some time in the future.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The http.Response class contains the data received from a successful http call.&lt;br&gt;
The createAlbum() method takes an argument title that is sent to the server to create &lt;br&gt;
an Album.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Convert the http.Response  to a custom Dart object&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To make your life easier, it is better to convert raw data into Dart objects. &lt;br&gt;
How do we convert our Data into Dart object? &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create an Album Class&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Convert the http.Response to an Album&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But I don't know how to create an album class, and I can't even converts http.Response to an Album!!!  Dont worry mate. I gat you covered! 🤝&lt;br&gt;
Just follow this instance of a class.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Album {
  final int id;
  final String title; 
 Album({required this.id, required this.title}); 
   factory Album.fromJson(Map&amp;lt;String, dynamic&amp;gt; json) { 
  return Album( 
      id: json['id'], title: json['title'], 
       );
   }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Converting http.Response to an album, very easy:&lt;/em&gt;&lt;br&gt;
  Use the following steps to update the createAlbum() function to return &lt;br&gt;
  a Future:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Convert the response body into a JSON Map with the dart:convert package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the server returns a CREATED response with a status code of 201, then convert the JSON Map into an Album using the fromJson() factory method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the server doesn’t return a CREATED response with a status code of 201, then throw an exception. (Even in the case of a “404 Not Found” server response, throw an  exception. Do not return null. This is important when examining the data in snapshot, &lt;br&gt;
as shown below.)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope this is not too difficult to do, check this code snippet below to have a better understanding...&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;Album&amp;gt; createAlbum(String title) async {  
   final response = await http.post( 
   Uri.parse(
    'https://jsonplaceholder.typicode.com/albums'), headers: &amp;lt;String, String&amp;gt;{ 
     'Content-Type': 'application/json; charset=UTF-8', 
       }, 
  body: jsonEncode(&amp;lt;String, String&amp;gt;{
   'title': title,
    }), 
    ); 
  if (response.statusCode == 201) { 
      // If the server did return a 201 CREATED response,\
     // then parse the JSON. 
   return Album.fromJson(jsonDecode(response.body)); 
 } else { 
  // If the server did not return a 201 CREATED response, 
 // then throw an exception.
 throw Exception('Failed to create album.'); 
   }
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;YES!!!&lt;/strong&gt; Now you’ve got a function that sends the title to a server to create an album.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;-Get a title from user input&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Next, create a TextField to enter a title and an ElevatedButton to send data to the Server. Also, define a TextEditingController to read the user input from a TextField.&lt;/p&gt;

&lt;p&gt;When the ElevatedButton is pressed, the _futureAlbum is set to the value returned by createAlbum() method.&lt;br&gt;
Something Like this: 👇👇👇👇👇👇👇👇👇👇👇👇👇&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Column( 
   mainAxisAlignment: MainAxisAlignment.center, 
   children: &amp;lt;Widget&amp;gt;[ 
     TextField( controller: _controller, decoration: const InputDecoration(
        hintText:  'Enter Title'
      ), ), 
     ElevatedButton( onPressed: () { 
      setState(() { 
          _futureAlbum = 
         createAlbum(_controller.text); 
     }); 
    },
  child: const Text('Create Data'), 
   ),
   ], 
  )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;On pressing the &lt;strong&gt;Create Data button&lt;/strong&gt;, make the network request, which sends the data in the TextField to the server as a POST request. The Future, _futureAlbum, is used in the next step.&lt;/p&gt;

&lt;p&gt;From Here its as simple as saying ABC ✌️&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;- Display the Response on the Screen &lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To display the data on the screen, use the FutureBuilder widget. The FutureBuilder widget comes with Flutter and makes it easy to work with asynchronous data sources. You must provide two parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The Future you want to work with. In this case, the future returned from &lt;br&gt;
the createAlbum() function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A builder function that tells Flutter what to render, depending on the state of &lt;br&gt;
the Future: loading, success, or error.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/strong&gt; The snapshot.hasData only returns true when the snapshot contains a non-null data value. This is why the createAlbum() function should throw an exception even in the case of a “404 Not Found” server response. If createAlbum() returns null, then CircularProgressIndicator displays indefinitely.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FutureBuilder&amp;lt;Album&amp;gt;(  
     future: _futureAlbum, builder: (context, snapshot) {
      if (snapshot.hasData) { 
          return Text(snapshot.data!.title); 
       } else if (snapshot.hasError) {
         return Text('${snapshot.error}'); 
         } 
      return const CircularProgressIndicator(); 
     },)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;Done! *&lt;/em&gt; You have successfully, sent Data to a server on the Internet!!! what you can't do doesn't exist  😉. congratulations&lt;/p&gt;

&lt;p&gt;if you would like to discuss this or any related issue  &lt;a href="https://wa.me/message/OEGQ4YVXBSFWL1" rel="noopener noreferrer"&gt;Chat Me.&lt;/a&gt; &lt;br&gt;
Follow me on  &lt;a href="https://twitter.com/Har4lionkest?s=09" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;  for More...&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How To Update Data Over The Internet -- Flutter</title>
      <dc:creator>Afolayan Ademola Segun</dc:creator>
      <pubDate>Wed, 27 Oct 2021 13:56:42 +0000</pubDate>
      <link>https://dev.to/har4lionkest/how-to-update-data-over-the-internet-flutter-71</link>
      <guid>https://dev.to/har4lionkest/how-to-update-data-over-the-internet-flutter-71</guid>
      <description>&lt;p&gt;Hi guys, It's &lt;em&gt;&lt;a href="https://kest.hashnode.dev/"&gt; Kest &lt;/a&gt;&lt;/em&gt; again.  I have taken the time to explain how you can &lt;a href="https://kest.hashnode.dev/how-to-fetch-live-data-from-the-internet-in-flutter-ckslzjtu10ptw2xs1be6c81ag"&gt; &lt;em&gt;Read&lt;/em&gt;&lt;/a&gt;  and  &lt;a href="https://kest.hashnode.dev/how-to-send-data-to-the-internet-in-flutter-cktk3lcln02jxzds1d02vebn6"&gt;&lt;em&gt;Create&lt;/em&gt; &lt;/a&gt;   &lt;strong&gt;DATA&lt;/strong&gt; over the internet using the HTTP package in Flutter. &lt;/p&gt;

&lt;p&gt;what if I tried to post and I make a mistake? you know there is a cliche about making mistakes, it says &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"no one is above mistakes".&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You wonder how it was possible for you to edit your Posts and Comments on some of your social media applications. Wonder no more 😉😉&lt;/p&gt;

&lt;p&gt;Updating data over the internet is necessary for most apps. The http package has got that covered! &lt;/p&gt;

&lt;p&gt;The following are  the steps to take when updating Data over the internet in Flutter&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the http package. &lt;/li&gt;
&lt;li&gt;Update data over the internet using the http package.&lt;/li&gt;
&lt;li&gt;Convert the response into a custom Dart object.&lt;/li&gt;
&lt;li&gt;Get the data from the internet.&lt;/li&gt;
&lt;li&gt;Update the existing title from user input, update and display the response on the screen.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Add the HTTP package :&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The first step always is to add your package to the popular pubspec.yaml as a dependency. Go to pub.dev to get HTTP package.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qowxrBCj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1633620277357/Doz1g4gjk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qowxrBCj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1633620277357/Doz1g4gjk.png" alt="arti3.png" width="880" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Updating data over the internet using the HTTP package.&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Using the JSONPLACEHOLDER as our API, this is how to update Data over the internet.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Future&amp;lt;http.Response&amp;gt; updateAlbum(String title) {
    return http.put(
      Uri.parse('https://jsonplaceholder.typicode.com/albums/1'),
       headers: &amp;lt;String, String&amp;gt;{
       'Content-Type': 'application/json; charset=UTF-8',
        },
       body: jsonEncode(&amp;lt;String, String&amp;gt;{
      'title': title,
    }),
   );
 }  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  *&lt;em&gt;3. Convert the http.Response to a custom Dart object. *&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;While it’s easy to make a network request, working with a raw Future isn’t very convenient 😤. To make your life easier, convert the http.Response into a Dart object 😊😊&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Create an Album Class *&lt;/em&gt;&lt;br&gt;
First, create an Album class that contains the data from the network request. It includes a factory constructor that creates an Album from JSON.&lt;/p&gt;

&lt;p&gt;This is how to create a class:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  class Album {
    final int id;
    final String title;
    Album({required this.id, required this.title});
     factory Album.fromJson(Map&amp;lt;String, dynamic&amp;gt; json) {
       return Album(
         id: json['id'],
         title: json['title'],
       );
    }
   }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Then Convert the http.Response to an Album&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Now, use the following steps to update the updateAlbum() function to return a Future:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Convert the response body into a JSON Map with the dart:convert package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the server returns an UPDATED response with a status code of 200, then convert the JSON Map into an Album using the fromJson() factory method.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the server doesn’t return an UPDATED response with a status code of 200, then throw an exception. (Even in the case of a “404 Not Found” server response, throw an exception. Do not return null. This is important when examining the data in snapshot, as shown below.)&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;Album&amp;gt; updateAlbum(String title) async {
  final response = await http.put(
   Uri.parse('https://jsonplaceholder.typicode.com/albums/1'),
   headers: &amp;lt;String, String&amp;gt;{
   'Content-Type': 'application/json; charset=UTF-8',
    },
   body: jsonEncode(&amp;lt;String, String&amp;gt;{
   'title': title,
  }),
 );
if (response.statusCode == 200) {
 // If the server did return a 200 OK response,
 // then parse the JSON.
  return Album.fromJson(jsonDecode(response.body));
 } else {
  // If the server did not return a 200 OK response,
  // then throw an exception.
 throw Exception('Failed to update album.');
  }
 }
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hooray! Now you’ve got a function that updates the title of an album.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Get the Data from the Internet.&lt;/strong&gt;&lt;br&gt;
Get the data from the internet before you can update it. For a complete example, see the Fetch data recipe on flutter.dev. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Future&amp;lt;Album&amp;gt; fetchAlbum() async {
      final response = await http.get(
       Uri.parse('https://jsonplaceholder.typicode.com/albums/1'),
   );
    if (response.statusCode == 200) {
      // If the server did return a 200 OK response,
      // then parse the JSON.
        return Album.fromJson(jsonDecode(response.body));
      } else {
       // If the server did not return a 200 OK response,
       // then throw an exception.
       throw Exception('Failed to load album');
       }  
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Ideally, you will use this method to set _futureAlbum during initState to fetch the data from the internet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Update the existing title from user input.&lt;/strong&gt;&lt;br&gt;
Create a TextField to enter a title and a ElevatedButton to update the data on server. Also define a TextEditingController to read the user input from a TextField.&lt;/p&gt;

&lt;p&gt;When the ElevatedButton is pressed, the _futureAlbum is set to the value returned by updateAlbum() method.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   Column(
    mainAxisAlignment: MainAxisAlignment.center,
     children: &amp;lt;Widget&amp;gt;[
      Padding(
      padding: const EdgeInsets.all(8.0),
       child: TextField(
       controller: _controller,
        decoration: const InputDecoration(hintText: 'Enter Title'),
       ),  
       ),
     ElevatedButton(
     onPressed: () {
       setState(() {
       _futureAlbum = updateAlbum(_controller.text);
        });
       },
       child: const Text('Update Data'),
         ),
        ],
      );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;On pressing the Update Data button, a network request sends the data in the TextField to the server as a POST request. The _futureAlbum variable is used in the next step.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;5. Display the response on screen. *&lt;/em&gt;&lt;br&gt;
To display the data on screen, use the FutureBuilder widget. The FutureBuilder widget comes with Flutter and makes it easy to work with async data sources. You must provide two parameters:&lt;/p&gt;

&lt;p&gt;The Future you want to work with. In this case, the future returned from the updateAlbum() function.&lt;br&gt;
A builder function that tells Flutter what to render, depending on the state of the Future: loading, success, or error.&lt;br&gt;
Note that snapshot.hasData only returns true when the snapshot contains a non-null data value. This is why the updateAlbum function should throw an exception even in the case of a “404 Not Found” server response. If updateAlbum returns null then CircularProgressIndicator will display indefinitely.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FutureBuilder&amp;lt;Album&amp;gt;(
  future: _futureAlbum,
  builder: (context, snapshot) {
   if (snapshot.hasData) {
   return Text(snapshot.data!.title);
    }  else if (snapshot.hasError) {
    return Text('${snapshot.error}');
    }
     return const CircularProgressIndicator();
    },
   );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That it 🤔? Yes, that is it!!!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can choose where to updated the changes its sample codes are just for guidance on how you can effect an update. &lt;/p&gt;

&lt;p&gt;If you would like to discuss this or any related issue  &lt;a href="https://wa.me/message/OEGQ4YVXBSFWL1"&gt;Chat Me&lt;/a&gt; . Follow me on  &lt;a href="https://twitter.com/Har4lionkest?s=09"&gt;Twitter&lt;/a&gt;  for More...&lt;/p&gt;

</description>
    </item>
    <item>
      <title>HOW TO FETCH LIVE DATA FROM THE INTERNET IN FLUTTER
</title>
      <dc:creator>Afolayan Ademola Segun</dc:creator>
      <pubDate>Fri, 06 Aug 2021 11:37:37 +0000</pubDate>
      <link>https://dev.to/har4lionkest/how-to-fetch-live-data-from-the-internet-in-flutter-4bo7</link>
      <guid>https://dev.to/har4lionkest/how-to-fetch-live-data-from-the-internet-in-flutter-4bo7</guid>
      <description>&lt;p&gt;HOW TO FETCH LIVE DATA FROM THE INTERNET IN FLUTTER&lt;/p&gt;

&lt;p&gt;In computer programming, create, read, update, and delete (CRUD) are the four basic operations of persistent storage. CRUD is sometimes used to describe user interface conventions that facilitate viewing, searching, and changing information using computer-based forms and report.&lt;/p&gt;

&lt;p&gt;To READ or Fecthing data from the internet is necessary for most apps. Luckily, Dart and Flutter provide tools, such as the http package, for this type of work.&lt;/p&gt;

&lt;p&gt;In this tutorial I will be taking you through how to perform these operations in flutter.&lt;br&gt;
This process uses the following steps:&lt;br&gt;
      1.Add the http package.&lt;br&gt;
      2.Make a network request using the http package.&lt;br&gt;
      3.Convert the response into a custom Dart object.&lt;br&gt;
      4.Fetch and&lt;br&gt;
      5. Display the data with Flutter. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the http package&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The http package provides the simplest way to fetch data from the internet.&lt;/p&gt;

&lt;p&gt;To install the http package, add it to the dependencies section of the pubspec.yaml file. You can find the latest version of the http package the pub.dev. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pOdk3FrM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2c4rurb4ulniaiu6tb07.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pOdk3FrM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2c4rurb4ulniaiu6tb07.png" alt="import file"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image above shows how to add file to the pubspec,yaml file and also how to import the http package.  The third step in the image is showing how to add internet persmission to your app.&lt;/p&gt;

&lt;p&gt;The line of code should be added to the AndroidManifest.xml file found in tha Android/app/src/main.&lt;/p&gt;

&lt;p&gt;This is all with step one.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make a network request&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Using an album sample from the API from the JSONPlaceholder , we will make a request to read the contet of the album using the http.get() method.&lt;br&gt;
           Future fetchAlbum() {&lt;br&gt;&lt;br&gt;
                      return &lt;br&gt;
http.get(Uri.parse('&lt;a href="https://jsonplaceholder.typicode.com/albums/1')"&gt;https://jsonplaceholder.typicode.com/albums/1')&lt;/a&gt;); &lt;br&gt;
     }&lt;/p&gt;

&lt;p&gt;The http.get() method returns a Future that contains a Response.&lt;br&gt;
Future is a core Dart class for working with async operations. A Future object represents a potential value or error that will be available at some time in the future.&lt;br&gt;
The http.Response class contains the data received from a successful http call.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Convert the response into a custom Dart object&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While it’s easy to make a network request, working with a raw Future  is not going to be easy, for convenience it is better to convert the raw files into JSON. To make your life easier, convert the http.Response into a Dart object.&lt;/p&gt;

&lt;p&gt;Create an Album class&lt;br&gt;
First, create an Album class that contains the data from the network request. It includes a factory constructor that creates an Album from JSON.&lt;/p&gt;

&lt;p&gt;This is an example of how the class should look like &lt;br&gt;
        class Album {&lt;br&gt;
               final int userId;&lt;br&gt;
               final int id;&lt;br&gt;
               final String title;&lt;br&gt;
        Album({&lt;br&gt;
               required this.userId,&lt;br&gt;
               required this.id,&lt;br&gt;
               required this.title,&lt;br&gt;
             });&lt;br&gt;
        factory Album.fromJson(Map json) {&lt;br&gt;
               return Album(&lt;br&gt;
               userId: json['userId'],&lt;br&gt;
               id: json['id'],&lt;br&gt;
               title: json['title'],&lt;br&gt;
             );&lt;br&gt;
            }&lt;br&gt;
           }&lt;/p&gt;

&lt;p&gt;Convert the http.Response to an Album&lt;/p&gt;

&lt;p&gt;Now, use the following steps to update the fetchAlbum() function to return a Future:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; 1. Convert the response body into a JSON Map with the dart:convert package.

 2. If the server does return an OK response with a status code of 200, then convert the JSON Map into an Album using the fromJson() factory method.

 3. If the server does not return an OK response with a status code of 200, then throw an exception. (Even in the case of a “404 Not Found” server response, throw an exception. Do not return null. This is important when examining the data in snapshot, as shown below.)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D3ZUcqcp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hltz9un7mb4ku7hxsbuz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D3ZUcqcp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hltz9un7mb4ku7hxsbuz.png" alt="future"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once again using the flutter Future keyword specifying the object 'album' and creating a fucntion that is async we can and will be able to get our data from the request call and then convert after the if condition is paased which is to test the status of our call, if the satus shows successf  which is what the 'if (statusCode ==200) means the we cna convert from Json to dart object.  If the condition is not true then it will throw an exception (an error message).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fetch the data
Call the fetchAlbum() method in either the initState()&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;class _MyAppState extends State {&lt;br&gt;
    late Future futureAlbum; @override void&lt;br&gt;&lt;br&gt;
    initState() { super.initState(); futureAlbum = &lt;br&gt;
    fetchAlbum(); } // ···&lt;br&gt;
      }&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Display the data&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To display the data on screen, use the FutureBuilder widget. The FutureBuilder widget comes with Flutter and makes it easy to work with asynchronous data sources.&lt;br&gt;
You must provide two parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The Future you want to work with. In this case, the future returned from the fetchAlbum() function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A builder function that tells Flutter what to render, depending on the state of the Future: loading, success, or error.&lt;/p&gt;

&lt;p&gt;FutureBuilder(&lt;br&gt;
      future: futureAlbum,&lt;br&gt;
      builder: (context, snapshot) {&lt;br&gt;
     if (snapshot.hasData) {&lt;br&gt;
        return Text(snapshot.data!.title);&lt;br&gt;
     } else if (snapshot.hasError) {&lt;br&gt;
        return Text('${snapshot.error}');&lt;br&gt;
        }&lt;br&gt;
    // By default, show a loading spinner.&lt;br&gt;
        return const CircularProgressIndicator();&lt;br&gt;
            },&lt;br&gt;
      )&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hurray!!! You have been able to succesfully read a live data from the internet into your Flutter app.  &lt;/p&gt;

&lt;p&gt;Congratulations. For More tutorial follow me on Twitter. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Why MongoDB???</title>
      <dc:creator>Afolayan Ademola Segun</dc:creator>
      <pubDate>Mon, 02 Aug 2021 16:25:40 +0000</pubDate>
      <link>https://dev.to/har4lionkest/why-mongodb-173n</link>
      <guid>https://dev.to/har4lionkest/why-mongodb-173n</guid>
      <description>&lt;p&gt;MongoDB is a Document database with the scalability and flexibility that you want&lt;br&gt;
with the querying indexing that you need.&lt;br&gt;
Scalability is the capacity to be changed in size or scale while&lt;br&gt;
Flexibility is the quality of being modified easily without being broken.&lt;/p&gt;

&lt;p&gt;Key MongoDB Features&lt;br&gt;
Document Based: MongoDB stores data in documents (field-value pair data structures, No-SQL) instead of rows and column styles in traditional database in No-SQL pronounced (NO Sequel Data abase)&lt;br&gt;
Scalability: It is very easy to distribute data across multiple machines as your users and amount of data grows. so whatever you do MongoDb gives you the room for you to grow.&lt;/p&gt;

&lt;p&gt;Flexibility: There is no need to define a documents data schema before filling it with data meaning each documents can have a different number and types of field, and we can also change this fields all the time. And all this is really inline with some real life business situation and therefore it proves really useful]&lt;/p&gt;

&lt;p&gt;Performance: Thanks to embedded data models. indexing, shading(divining a larger part into smaller unit), flexible documents, native duplication&lt;br&gt;
MongoDB has proven to be a very performance database.&lt;/p&gt;

&lt;p&gt;Open Source: MongoDB is a Free and open source database published under the SSPL license MongoDB is probably the most used Database with Node.js&lt;/p&gt;

&lt;p&gt;BSON : It is the data format for MongoDB, it is used for data storage. like JSON but typed. So MongoDB document are typed. In relational Each field is called a column. It is arrange in table structures.&lt;br&gt;
Another interesting feature in MongoDB is the concept of Embedded Documents. which is again something not present in relational database.&lt;br&gt;
It is also called De-normalizing. Including related data into a single document. This allows for quicker access and easier data models (its not always the best solution though)&lt;br&gt;
The advantage is that it allow us to read all the data at once&lt;br&gt;
In Relational Database it is not possible to embed data, so you have to create a whole new table for the data and then link with some unique key from the field.&lt;/p&gt;

&lt;p&gt;Finally the Maximum size for each Document in BSON is 60mb but this might increase in the future. and then each Documents have a unique ID once which act as a primary key to the document. It is automatically generated once you create a BSON documents. and so we don't have to worry about it.&lt;br&gt;
With this understanding that you have of MongoDB, I believe you will start finding interesting to work with it and if you are SQL fan, yoop It doesn't take anything away to try different stuffs. Try MongoDB; you will love it!!!&lt;/p&gt;

&lt;p&gt;MongoDB Document structure in picture.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yh22Y_jK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmqpiukqhmf9jdc2mij1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yh22Y_jK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmqpiukqhmf9jdc2mij1.jpg" alt="JSON"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>node</category>
      <category>mongoose</category>
      <category>n0sql</category>
    </item>
    <item>
      <title>Nodejs, Blocking Vs Non_Blocking</title>
      <dc:creator>Afolayan Ademola Segun</dc:creator>
      <pubDate>Thu, 28 Jan 2021 08:16:18 +0000</pubDate>
      <link>https://dev.to/har4lionkest/nodejs-blocking-vs-nonblocking-20a5</link>
      <guid>https://dev.to/har4lionkest/nodejs-blocking-vs-nonblocking-20a5</guid>
      <description>&lt;p&gt;Blocking refers to operations that block further execution until that operation finishes while non-blocking refers to code that doesn't block execution. Or as Node. js docs puts it, blocking is when the execution of additional JavaScript in the Node. js process must wait until a non-JavaScript operation completes&lt;/p&gt;

&lt;p&gt;Synchronous vs Asynchronous&lt;br&gt;
Synchronous (or sync) execution usually refers to code executing in sequence. In sync programming, the program is executed line by line, one line at a time. Each time a function is called, the program execution waits until that function returns before continuing to the next line of code.&lt;/p&gt;

&lt;p&gt;Asynchronous (or async) execution refers to execution that doesn’t run in the sequence it appears in the code. In async programming the program doesn’t wait for the task to complete and can move on to the next task.&lt;/p&gt;

&lt;p&gt;I will give this simple illustration so that you will understand this two subject so well. Imagine you visit a restaurant and you order a black coffee, the now the waiter represent the server, he will get your orders but since black coffee isn't yet available, it will just be prepared, the waiter wont wait until they chef finish making your black coffee, he will move to another customer to accept his request or order, keeping in and that you made a request for black coffee and you haven't gotten any yet. &lt;/p&gt;

&lt;p&gt;That is how it works. there is a reminder called call back function in Node, that tells the waiter/server that the coffee is finally ready and the customer which is you can finally get your coffee. This is how it works. All of  this process is what is called Asynchronous.  but when other customer have to wait until your request is being handled completely before they can be serve that is what is called synchronous.&lt;/p&gt;

&lt;p&gt;Relating it to node, the waiter is the sever, the customers are the clients/users making requests. and Node.js gives avenue to serve asynchronously without blocking, that is what is called non-blocking. Thank you for ordering our coffee, I hope you enjoyed your coffee...&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>blocking</category>
      <category>nonblocking</category>
    </item>
    <item>
      <title>React Native</title>
      <dc:creator>Afolayan Ademola Segun</dc:creator>
      <pubDate>Thu, 02 Jan 2020 23:32:30 +0000</pubDate>
      <link>https://dev.to/har4lionkest/react-native-22ih</link>
      <guid>https://dev.to/har4lionkest/react-native-22ih</guid>
      <description>&lt;p&gt;Hey i am kest.  Just want to share my personal experience with react native.  I aint introducing anything.  What do i know? I just want to encourage you out there if you just started. Its not going to be easy but you need to continue learning... You need more than the "i just want to learn".  You need the desire and passion to react... 😆. So i was introduced to react by my siwes supervisor who hardly had time for me. But i really want to learn, hence my relentless effort.  Glory to God i am trying bit by bit.  You can too. &lt;br&gt;
Its interesting.  Its captivating and it joy unspeakable when you actually see the result of your work on that device, on that emulator.  So sweet. &lt;br&gt;
So dont stop please. &lt;br&gt;
Dont. &lt;br&gt;
Well, have you heard of npm...? &lt;br&gt;
Its gonna piss you off trust me.  But you need that piece to react.  Keep running npm no matter what! Its an advice from/for a senior dev, they say!&lt;br&gt;
This is for my colleague; beginners.&lt;/p&gt;

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