<?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: David Adewoyin</title>
    <description>The latest articles on DEV Community by David Adewoyin (@davidadewoyin).</description>
    <link>https://dev.to/davidadewoyin</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%2F678235%2Fd8b07946-b6c1-4685-b1fb-8268b29b6c65.jpg</url>
      <title>DEV Community: David Adewoyin</title>
      <link>https://dev.to/davidadewoyin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davidadewoyin"/>
    <language>en</language>
    <item>
      <title>How to Build a Flutter App with GraphQL</title>
      <dc:creator>David Adewoyin</dc:creator>
      <pubDate>Fri, 19 Nov 2021 08:53:14 +0000</pubDate>
      <link>https://dev.to/davidadewoyin/how-to-build-a-flutter-app-with-graphql-5f3j</link>
      <guid>https://dev.to/davidadewoyin/how-to-build-a-flutter-app-with-graphql-5f3j</guid>
      <description>&lt;h2&gt;
  
  
  What are we building?
&lt;/h2&gt;

&lt;p&gt;We will be building a flutter app that fetches a list of countries using the  &lt;a href="https://countries.trevorblades.com/" rel="noopener noreferrer"&gt;Countries GraphQL API &lt;/a&gt; and displays brief information about the country.&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%2Fv1637274214623%2FV8I4Y2H8W.gif" 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%2Fv1637274214623%2FV8I4Y2H8W.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite.
&lt;/h2&gt;

&lt;p&gt;This article assumes the user is familiar with Flutter and have a basic understanding of GraphQL.&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Countries GraphQL API
&lt;/h2&gt;

&lt;p&gt;The Countries GraphQL API is a public GraphQL API for getting information about countries, continents, and languages. To understand how a given GraphQL API works, It is best to first interact with the endpoint using a test playground which enables you to run test queries, for this tutorial a playground for interacting with countries api  can be found  &lt;a href="https://countries.trevorblades.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example of a running a query in the playground.&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1637263707045%2F6PsliJbqO.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%2Fv1637263707045%2F6PsliJbqO.png" alt="Screenshot from 2021-11-18 19-52-12-1000x500.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to use GraphQL with flutter
&lt;/h2&gt;

&lt;p&gt;To use GraphQL with flutter, we use the  &lt;a href="https://pub.dev/packages/graphql" rel="noopener noreferrer"&gt;graphql&lt;/a&gt; package, which provides the most popular GraphQL client for dart.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the country directory app
&lt;/h2&gt;

&lt;p&gt;We create a new flutter project called country_directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter create country_directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and add the graphql package as a dependency in the pubspec.yaml file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
  graphql: ^5.0.0

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Basic Usage
&lt;/h3&gt;

&lt;p&gt;To connect to a GraphQL Server, we first need to create a &lt;strong&gt;GraphQLClient&lt;/strong&gt;. A GraphQLClient requires both a cache and a link to be initialized.&lt;/p&gt;

&lt;p&gt;Creating a file called** api.dart** to define our apis, we add the following lines of code which set the URL of the GraphQL endpoint and create an instance of the GraphQLClient needed to interact with the endpoint. HttpLink is used to customize the network access such as adding access token for authentication but since the countries apis is free authentication is not needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:graphql/client.dart';


const baseURL = "https://countries.trevorblades.com/";

final _httpLink = HttpLink(
  baseURL,
);

final GraphQLClient client = GraphQLClient(
  link: _httpLink,
  cache: GraphQLCache(),
);

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing Query with the Playground
&lt;/h2&gt;

&lt;p&gt;Our application consists of initially making a request to the endpoint in other to fetch a list of country name and their country code from the API and providing a dropdown that enables the user to choose a country in which another query will be sent to the endpoint in other to fetch details of the country.&lt;br&gt;
The initial query sent to the endpoint is shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {
  countries {
    code
    name
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the endpoint returns a response which contains a list of countries with the country code and name which part is shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"data": {
    "countries": [
      {
        "code": "AD",
        "name": "Andorra"
      },
      {
        "code": "AE",
        "name": "United Arab Emirates"
      },
      {
        "code": "AF",
        "name": "Afghanistan"
      },

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

&lt;/div&gt;



&lt;p&gt;The next step is to make a query request to the endpoint for retrieving the data of a particular country. The  example below shows querying the endpoint for data about Nigeria with the country code of &lt;em&gt;"NG"&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query {
  country(code:"NG"){
     name
    capital
    code
    native
    currency
    phone
    emoji
    }
}

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

&lt;/div&gt;



&lt;p&gt;Response returned from the GraphQL endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
  "data": {
    "country": {
      "name": "Nigeria",
      "capital": "Abuja",
      "code": "NG",
      "native": "Nigeria",
      "currency": "NGN",
      "phone": "234",
      "emoji": "🇳🇬"
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Examining the responses from the two queries.We create a new file model.dart and create a class in the file called Country with the following content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Country {
  String code;
  String name;
  String? capital;
  String? currency;
  String? native;
  String? phone;
  String? emoji;

  Country.fromJson(Map&amp;lt;String, dynamic&amp;gt; json)
      : code = json["code"],
        name = json["name"],
        capital = json["capital"],
        currency = json["currency"],
        native = json["native"],
        phone = json["phone"],
        emoji = json["emoji"];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice apart from the &lt;em&gt;code&lt;/em&gt; and &lt;em&gt;name&lt;/em&gt; field in the country class all other fields are nullable since the first request to the endpoint only returns the country code and name which is needed to create a country instance.We also create a factory method for easily creating an instance of the country from the json response.&lt;/p&gt;

&lt;p&gt;In the &lt;strong&gt;api.dart&lt;/strong&gt; file we create two constant that represent the two queries string to be sent to the GraphQL  endpoint.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const _getAllCountries = r'''
query {
  countries{
    code
    name
    }
  }
''';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;// parameters to be supplied to the query is firstly defined in the query head with the datatype, since we need to supply the country code in other to fetch details of a particular country we add the code parameter with the ID datatype as shown below&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const _getCountry = r'''
query getCountry($code:ID!){
  country(code:$code){
    name
    capital
    code
    native
    currency
    phone
    emoji

  }
}

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Fetching the list of countries
&lt;/h3&gt;

&lt;p&gt;import the country model we earlier created as we will be using it to store the details of the country we get as the responses from the api&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;``&lt;code&gt;import 'package:country_directory/model.dart';&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
We create a function getAllCountries which returns a list of countries as shown below:&lt;br&gt;
//returns a list of countries names with the country code&lt;/p&gt;

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

Future&amp;lt;List&amp;lt;Country&amp;gt;&amp;gt; getAllCountries() async {
  var result = await client.query(
    QueryOptions(
//gql is used to parse the _getAllCountries string constant we previously created into a format or document that the GraphQL client understand. 
      document: gql(_getAllCountries),
    ),
  );

  var json = result.data!["countries"];
  List&amp;lt;Country&amp;gt; countries = [];
  for (var res in json) {
    var country = Country.fromJson(res);
    countries.add(country);
  }
  return countries;
}


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

&lt;/div&gt;

&lt;p&gt;We also create a second function for returning  the data associated with a particular country. The function takes in a a country code and use that to fetch the country data.&lt;/p&gt;

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

// returns a country with the given country code
Future&amp;lt;Country&amp;gt; getCountry(String code) async {
  var result = await client.query(
    QueryOptions(
      document: gql(_getCountry),
      variables: {
        "code": code,
      },
    ),
  );

  var json = result.data!["country"];


  var country = Country.fromJson(json);
  return country;
}


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Creating the view
&lt;/h2&gt;

&lt;p&gt;Importing the the two files we created in the main.dart&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import 'package:country_directory/api.dart';
import 'package:country_directory/model.dart';


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

&lt;/div&gt;

&lt;p&gt;we create a stateful widget called &lt;strong&gt;HomePage&lt;/strong&gt; in the main.dart file which we  contains the view of our program&lt;br&gt;
We add the following lines of code to our main.dart.&lt;/p&gt;

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


class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State&amp;lt;HomePage&amp;gt; createState() =&amp;gt; _HomePageState();
}

class _HomePageState extends State&amp;lt;HomePage&amp;gt; {
  List&amp;lt;Country&amp;gt; countries = [];
  Country? selectedCountry;
// the future is set to getAllCountries since we need to initially get the list of all countries first.
  Future&amp;lt;List&amp;lt;Country&amp;gt;&amp;gt; future = getAllCountries();

}



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

&lt;/div&gt;

&lt;p&gt;Since we will be using a dropdown to select a country, we create a function for building the items of the dropdown&lt;/p&gt;

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

List&amp;lt;DropdownMenuItem&amp;lt;Country&amp;gt;&amp;gt; buildDropDownItem(List&amp;lt;Country&amp;gt; countries) {
    return countries
        .map((country) =&amp;gt; DropdownMenuItem&amp;lt;Country&amp;gt;(
              child: Text(country.name),
              value: country,
            ))
        .toList();
  }


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

&lt;/div&gt;

&lt;p&gt;We also create a pickCountriesWidget function for picking a particular country from the list of country&lt;/p&gt;

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


  Widget pickCountriesWidget(
      BuildContext context, AsyncSnapshot&amp;lt;List&amp;lt;Country&amp;gt;&amp;gt; snapshot) {
    var countries = snapshot.data;

    if (snapshot.connectionState == ConnectionState.done) {
      return Container(
        padding: const EdgeInsets.symmetric(horizontal: 10),
        child: DropdownButtonFormField(
          decoration: const InputDecoration(
            labelText: "Choose Country",
            border: OutlineInputBorder(),
          ),
          items: buildDropDownItem(countries!),
          value: selectedCountry,
          onChanged: (Country? country) {
            setState(() {
              selectedCountry = country;
            });
          },
        ),
      );
    }
    return const Center(
      child: CircularProgressIndicator(),
    );


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

&lt;/div&gt;

&lt;p&gt;When a country is selected from the dropdown we make sent a query to the api for fetching the details of the country.&lt;/p&gt;

&lt;p&gt;The following lines create a widget for displaying the details of the country.&lt;/p&gt;

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

Widget countryDetailsWidget(BuildContext context, AsyncSnapshot snapshot) {
    if (snapshot.connectionState == ConnectionState.waiting) {
      return const Padding(
        padding: EdgeInsets.only(top: 20),
        child: Center(
          child: CircularProgressIndicator(),
        ),
      );
    }
    if (snapshot.hasError) {
      return const Center(
        child: Text("Unable to fetch country data"),
      );
    }
    Country country = snapshot.data;

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const Padding(
          padding: EdgeInsets.symmetric(horizontal: 10),
          child: Text(
            "Country Info",
            style: TextStyle(fontWeight: FontWeight.bold),
          ),
        ),
        const SizedBox(height: 10),
        Card(
          color: Colors.grey.shade50,
          child: Padding(
            padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
            child: Row(
              children: [
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: const [
                    Text("Name"),
                    Text("Capital"),
                    Text("Country code"),
                    Text("Native"),
                    Text("Currency"),
                    Text("Phone Code"),
                    Text("Emoji"),
                  ],
                ),
                const Spacer(flex: 3),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(": ${country.name}",
                        style: const TextStyle(fontWeight: FontWeight.bold)),
                    Text(": ${country.capital}",
                        style: const TextStyle(fontWeight: FontWeight.bold)),
                    Text(": ${country.code}",
                        style: const TextStyle(fontWeight: FontWeight.bold)),
                    Text(": ${country.native}",
                        style: const TextStyle(fontWeight: FontWeight.bold)),
                    Text(": ${country.currency}",
                        style: const TextStyle(fontWeight: FontWeight.bold)),
                    Text(": ${country.phone!}",
                        style: const TextStyle(fontWeight: FontWeight.bold)),
                    Text(": ${country.emoji}",
                        style: const TextStyle(
                          fontWeight: FontWeight.bold,
                        )),
                  ],
                ),
                const Spacer(),
              ],
            ),
          ),
        ),
      ],
    );
  }


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

&lt;/div&gt;

&lt;p&gt;Putting everything together in the build method&lt;/p&gt;

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

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Colors.black,
        title: const Text("Country Directory"),
      ),
      body: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 15),
        child: ListView(
          children: [
            const SizedBox(height: 50),
            FutureBuilder&amp;lt;List&amp;lt;Country&amp;gt;&amp;gt;(
              future: future,
              builder: (context, snapshot) {
                return pickCountriesWidget(context, snapshot);
              },
            ),
            const SizedBox(height: 20),
            if (selectedCountry != null)
              FutureBuilder&amp;lt;Country&amp;gt;(
                future: getCountry(selectedCountry!.code),
                builder: (context, snapshot) {
                  return countryDetailsWidget(context, snapshot);
                },
              ),
          ],
        ),
      ),
    );
  }


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

&lt;/div&gt;



&lt;p&gt;The link to the application  is at  &lt;a href="https://github.com/david-adewoyin/country_directory" rel="noopener noreferrer"&gt;github&lt;/a&gt; . The article shows how to integrate GraphQL with flutter.Further articles will shows how to do mutations and subscriptions but the fundamentals of operation is the same.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>graphql</category>
      <category>mobile</category>
      <category>android</category>
    </item>
    <item>
      <title>Top 10 Rust Cargo Commands </title>
      <dc:creator>David Adewoyin</dc:creator>
      <pubDate>Mon, 15 Nov 2021 20:57:35 +0000</pubDate>
      <link>https://dev.to/davidadewoyin/top-rust-cargo-commands-2b70</link>
      <guid>https://dev.to/davidadewoyin/top-rust-cargo-commands-2b70</guid>
      <description>&lt;p&gt;Cargo is the Rust package manager, and is a powerful tool that can make programming in Rust quite a delight.It provides various commands that can be used in your daily programming. The list of commands that Cargo supports can be extended through Rust crates written by the community.&lt;/p&gt;

&lt;p&gt;The array of commands makes Cargo a versatile tool worth knowing for any Rust developer. &lt;/p&gt;

&lt;p&gt;This article provides a list of helpful Cargo commands worth knowing and using.&lt;/p&gt;

&lt;h2&gt;
  
  
  Top Cargo Commands to Know
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;code&gt;cargo install [options] crate...&lt;/code&gt; :
&lt;/h3&gt;

&lt;p&gt;cargo install is used for building and installing a Rust binary. There are multiple sources from which a crate can be installed. The default location is crates.io but the &lt;code&gt;--git&lt;/code&gt; , &lt;code&gt;--path&lt;/code&gt;, and &lt;code&gt;--registry&lt;/code&gt; flags can be set to change the source.&lt;br&gt;
Example of using cargo install is &lt;code&gt;cargo install sqlx&lt;/code&gt; which install the sqlx crate from crates.io.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. &lt;code&gt;cargo uninstall [options] [spec...]&lt;/code&gt;:
&lt;/h3&gt;

&lt;p&gt;As the name suggest this command removes a package installed with cargo-install.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. &lt;code&gt;cargo tree [options]&lt;/code&gt;:
&lt;/h3&gt;

&lt;p&gt;cargo tree will display a tree of dependencies to the terminal. An example of a simple project that depends on the "rand" package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myproject v0.1.0 (/myproject)
└── rand v0.7.3
    ├── getrandom v0.1.14
    │   ├── cfg-if v0.1.10
    │   └── libc v0.2.68
    ├── libc v0.2.68 (*)
    ├── rand_chacha v0.2.2
    │   ├── ppv-lite86 v0.2.6
    │   └── rand_core v0.5.1
    │       └── getrandom v0.1.14 (*)
    └── rand_core v0.5.1 (*)
[build-dependencies]
└── cc v1.0.50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. &lt;code&gt;cargo search [options] [query...]&lt;/code&gt;:
&lt;/h3&gt;

&lt;p&gt;This performs a textual search for crates on &lt;a href="https://crates.io" rel="noopener noreferrer"&gt;crates.io&lt;/a&gt;. The matching crates will be displayed along with their description in TOML format suitable for copying into a Cargo.toml manifest.&lt;br&gt;
Example of using cargo search is : &lt;code&gt;cargo search serde&lt;/code&gt; which returns a list of crate with textual search marching serde and a description which include their version number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;serde = "1.0.130"                         # A generic serialization/deserialization framework
discord_typed_interactions = "0.1.0"      # suppose you're working with discord slash commands and you want statically typed requ…
serde_json_experimental = "1.0.29-rc1"    # A JSON serialization file format
alt_serde_json = "1.0.61"                 # A JSON serialization file format
serde_json = "1.0.70"                     # A JSON serialization file format
serde_partiql = "1.1.65"                  # A PartiQL data model serialization file format
cargo-geiger = "0.11.1"                   # Detects usage of unsafe Rust in a Rust crate and its dependencies.
serde-encrypt = "0.6.0"                   # Encrypts all the Serialize
serde-encrypt-core = "0.6.0"              # Encrypts all the Serialize
typescript-definitions = "0.1.10"         # serde support for exporting Typescript definitions
... and 2787 crates more (use --limit N to see more)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. &lt;code&gt;cargo edit&lt;/code&gt; :
&lt;/h3&gt;

&lt;p&gt;This tool extends Cargo to allow you to add, remove, and upgrade dependencies by modifying your Cargo.toml file from the command line.&lt;/p&gt;

&lt;p&gt;Currently available sub-command includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cargo add&lt;/li&gt;
&lt;li&gt;cargo rm&lt;/li&gt;
&lt;li&gt;cargo upgrade&lt;/li&gt;
&lt;li&gt;cargo set-version&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To use cargo-edit, you will need to install it first through &lt;code&gt;cargo install cargo-edit&lt;/code&gt; as it's a cargo extension.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. &lt;code&gt;cargo +nightly udeps&lt;/code&gt; :
&lt;/h3&gt;

&lt;p&gt;cargo-udeps is used to find unused dependencies in Cargo.toml.&lt;br&gt;
While compilation of this tool also works on Rust stable, it needs Rust nightly to actually run. &lt;code&gt;cargo-udeps&lt;/code&gt; is a cargo extension so you have to install it first before it can be used.&lt;br&gt;
It can be installed through &lt;code&gt;cargo install cargo-udeps --locked&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  7. &lt;code&gt;cargo expand&lt;/code&gt; :
&lt;/h3&gt;

&lt;p&gt;Once installed, &lt;code&gt;cargo expand&lt;/code&gt; prints out the result of macro expansion and &lt;code&gt;#[derive]&lt;/code&gt; expansion applied to the current crate.It is a wrapper around the more verbose compiler command:&lt;code&gt;cargo rustc --profile=check -- -Zunpretty=expanded&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Install with &lt;code&gt;cargo install cargo-expand&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Example of using cargo-expand
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; #[derive(Debug)]
struct S;

fn main() {
    println!("{:?}", S);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;&lt;code&gt;cargo expand&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
struct S;
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for S {
    fn fmt(&amp;amp;self, f: &amp;amp;mut ::core::fmt::Formatter) -&amp;gt; ::core::fmt::Result {
        match *self {
            S =&amp;gt; {
                let mut debug_trait_builder = f.debug_tuple("S");
                debug_trait_builder.finish()
            }
        }
    }
}
fn main() {
    {
        ::std::io::_print(::core::fmt::Arguments::new_v1(
            &amp;amp;["", "\n"],
            &amp;amp;match (&amp;amp;S,) {
                (arg0,) =&amp;gt; [::core::fmt::ArgumentV1::new(arg0, ::core::fmt::Debug::fmt)],
            },
        ));
    };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  8. &lt;code&gt;cargo tarpaulin&lt;/code&gt; :
&lt;/h3&gt;

&lt;p&gt;Tarpaulin is a code coverage reporting tool for the Cargo build system.&lt;/p&gt;

&lt;p&gt;It's installed with &lt;code&gt;cargo install cargo-tarpaulin&lt;/code&gt;. Currently tarpaulin only works on x86_64 CPU architectures running Linux.Use &lt;code&gt;cargo tarpaulin --ignore-tests&lt;/code&gt; to compute code coverage for your application while ignoring test functions.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. &lt;code&gt;cargo audit&lt;/code&gt; :
&lt;/h3&gt;

&lt;p&gt;cargo audit can be installed through &lt;code&gt;cargo install cargo-audit&lt;/code&gt; and is used to audit Cargo.lock files for crates with security vulnerabilities reported to the &lt;a href="https://github.com/RustSec/advisory-db/" rel="noopener noreferrer"&gt;RustSec Advisory Database&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. &lt;code&gt;cargo deny&lt;/code&gt;:
&lt;/h3&gt;

&lt;p&gt;cargo-deny is a cargo plugin that lets you lint your project's dependency graph to ensure all your dependencies conform to your expectations and requirements.&lt;br&gt;
It's used to  audit Cargo.lock files for crates with security vulnerabilities, limit the usage of particular dependencies, their licenses, sources to download from, detect multiple versions of same packages in the dependency tree and more.&lt;br&gt;
use &lt;code&gt;cargo install --locked cargo-deny &amp;amp;&amp;amp; cargo deny init &amp;amp;&amp;amp; cargo deny check&lt;/code&gt; to installs cargo-deny, initializes your project with a default configuration, then runs all of the checks against your project.&lt;br&gt;
Example of a check is the licenses check that is used to verify that every crate you use has license terms you find acceptable .&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cargo deny check licenses&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwi587yusrjnv82gx4td.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwi587yusrjnv82gx4td.png" alt="License check of rust crate through cargo-deny"&gt;&lt;/a&gt;&lt;br&gt;
To learn more on how to use &lt;code&gt;cargo-deny&lt;/code&gt; check the &lt;a href="https://embarkstudios.github.io/cargo-deny/" rel="noopener noreferrer"&gt;cargo deny book&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The list of Cargo commands is vast and this article provides a small sample of them that you can use and hopefully learn how powerful Cargo is.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Structure a Flutter Project </title>
      <dc:creator>David Adewoyin</dc:creator>
      <pubDate>Sun, 14 Nov 2021 21:30:33 +0000</pubDate>
      <link>https://dev.to/davidadewoyin/structuring-flutter-project-26ob</link>
      <guid>https://dev.to/davidadewoyin/structuring-flutter-project-26ob</guid>
      <description>&lt;p&gt;A common problem faced by most beginners when attempting to write a program or an app beyond the simple hello world or TODO app is how to properly structure their code in other to accommodate ease of development and evolvement.&lt;/p&gt;

&lt;p&gt;Another factor that comes into play when designing how to properly structure your project is the architectural style you use, An application built using &lt;strong&gt;bloc&lt;/strong&gt; or &lt;strong&gt;provider&lt;/strong&gt; tends to have different project structure.&lt;/p&gt;

&lt;p&gt;Though there is no one size fit all,  the best approach i have found is to sample a wide array of common project structure and to evolve to the one that best suit your need.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Structure A Flutter Project
&lt;/h2&gt;

&lt;p&gt;In this article we will be covering how to structure our flutter application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffz66yecxwtyu2f2auauy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffz66yecxwtyu2f2auauy.png" alt="Flutter Project Directory "&gt;&lt;/a&gt;&lt;br&gt;
The Project structure consist of four major sub-folders containing different kind of files.  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Models&lt;/li&gt;
&lt;li&gt;Views&lt;/li&gt;
&lt;li&gt;Services&lt;/li&gt;
&lt;li&gt;Commands&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Additional folders include components which contains components which are widgets such as buttons, toasts that are share between pages and screens. &lt;/p&gt;
&lt;h3&gt;
  
  
  Models
&lt;/h3&gt;

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

&lt;p&gt;The Models folder contains the models of the application each in it own dart file.Some models extends ChangeNotifier and are use to propagate changes down the app such as to add the user name to the screen if the user log in. Example of a user model is shown below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class User {
  String? id;
  String? firstname;
  String? lastname;
  String? mobile;
  String? email;

  User(
      {this.id,
      this.firstname,
      this.lastname,
     });
  User.fromJson(Map&amp;lt;String, dynamic&amp;gt; json)
      : id = json["id"],
        firstname = json["firstname"],
        email = json["email"],
        mobile = json["phone"],
        lastname = json["lastname"],

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

&lt;/div&gt;



&lt;p&gt;An app model class is also created which is used with provider in other to provide change notification to various listeners in the application as the app state changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class AppModel extends ChangeNotifier {
  String? _accessToken;
  bool _isFreshInstall = true;
  User? _user;

  String? get accessToken =&amp;gt; _accessToken;
  bool get isFreshInstall =&amp;gt; _isFreshInstall;
  User? get user =&amp;gt; _user;

  set setUser(User user) {
    _user = user;
    notifyListeners();
  }

  set isFreshInstall(bool fresh) {
    _isFreshInstall = fresh;
    notifyListeners();
  }

  set accessToken(String? token) {
    _accessToken = token;
    notifyListeners();
  }

  @override
  void notifyListeners() {
    super.notifyListeners();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Views
&lt;/h3&gt;

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

&lt;p&gt;Views contains the various pages or screens of your application. The Views can also contain sub-folders that contains related views together.&lt;/p&gt;

&lt;h3&gt;
  
  
  Services
&lt;/h3&gt;

&lt;p&gt;The third folder is the Services which contains files that makes Apis calls or interact with external network such as HTTP or background location services.Files in this folder are strictly concerned with making requests.&lt;/p&gt;

&lt;p&gt;Here is how a service look like&lt;br&gt;
&lt;/p&gt;

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

User getUser() async {
// Makes http calls here
}

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Commands
&lt;/h3&gt;

&lt;p&gt;Commands is how you primarily interact with the Services.The Views invoke a command which in turn can call upon a service to fulfill a task. A base command is created in which other command class simply extends which makes it easy to share common models and services between various commands.&lt;/p&gt;

&lt;p&gt;Here is how the &lt;strong&gt;BaseCommand&lt;/strong&gt; class looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BuildContext? _mainContext;
BuildContext get mainContext =&amp;gt; _mainContext!;
bool get hasContext =&amp;gt; _mainContext != null;

void setContext(BuildContext c) {
  _mainContext = c;
}

class BaseAppCommand {
  UserService get userService =&amp;gt; getProvided();
  AppService get appService =&amp;gt; getProvided();

  AppModel get appModel =&amp;gt; getProvided();

  T getProvided&amp;lt;T&amp;gt;() {
    assert(_mainContext != null,
        "You must call setcontext(buildcontext before call commands");
    return _mainContext!.read&amp;lt;T&amp;gt;();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A bootstrap command is also used in other to configure or check app requirement such as is the user logged or initiate state or app configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class BootStrapCommand extends BaseAppCommand {
  Future&amp;lt;void&amp;gt; run(BuildContext context) async {
    if (Commands.hasContext == false) {
      Commands.setContext(context);
    }
    print("Bootstrapping app....");
    await appService.init();
    appModel.accessToken = await appService.accessToken() ?? null;
    var futures = await Future.wait&amp;lt;dynamic&amp;gt;([
      appService.accessToken(),
      appService.init(),
    ]);
    appModel.accessToken = futures.first as String? ?? null;

    if (appModel.accessToken != null) {
      appService.setAccessToken(appModel.accessToken!);
    }
    appModel.isFreshInstall = appService.isAppFreshInstall;
    appModel.setUser = appService.user();
  }
}

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

&lt;/div&gt;



&lt;p&gt;In this article i have tried to distill down how to structure a flutter application.&lt;/p&gt;

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