<?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: Shan</title>
    <description>The latest articles on DEV Community by Shan (@shanshaji).</description>
    <link>https://dev.to/shanshaji</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F297775%2Fa57b631b-6022-4626-9b1e-d3ba332ae9c4.png</url>
      <title>DEV Community: Shan</title>
      <link>https://dev.to/shanshaji</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shanshaji"/>
    <language>en</language>
    <item>
      <title>Create Flavors for Flutter App - iOS</title>
      <dc:creator>Shan</dc:creator>
      <pubDate>Sat, 13 Apr 2024 20:33:03 +0000</pubDate>
      <link>https://dev.to/shanshaji/create-flavors-for-flutter-app-ios-fnl</link>
      <guid>https://dev.to/shanshaji/create-flavors-for-flutter-app-ios-fnl</guid>
      <description>&lt;p&gt;Note: If you're new to Flutter and find it tricky to sift through many resources on setting up flavors, this article is for you. Experienced Flutter developers might already be familiar with this so please feel free to skip this. If you just want to have a quick refresh then you can go through the videos 😁.&lt;/p&gt;

&lt;p&gt;Note: It's better to save this for later reference. &lt;/p&gt;

&lt;p&gt;Have you ever wanted to manage different versions of your Flutter app for different needs? 'Flavors' in Flutter help you do just that. They're similar to 'build configurations' in iOS. Using flavors, you can create a production version of your app for real users, a staging version for debugging, and a preview version for QA testing — all from the same code base.&lt;/p&gt;

&lt;p&gt;To know more about 'Flavors' please go through the official documentation &lt;a href="https://docs.flutter.dev/deployment/flavors#launching-your-app-flavors" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Environment set up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Prerequisites:

&lt;ul&gt;
&lt;li&gt;Xcode installed&lt;/li&gt;
&lt;li&gt;An existing Flutter project&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Creating flavors in iOS
&lt;/h2&gt;

&lt;p&gt;Open your project in Xcode by going to the iOS folder and double-clicking on the &lt;code&gt;Runner.xcworkspace&lt;/code&gt; file. This action will launch Xcode for your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fonsqxgik2nafj3gp73ks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fonsqxgik2nafj3gp73ks.png" alt="iOS Folder" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2
&lt;/h3&gt;

&lt;p&gt;The second step would be to define schemes. Select Product &amp;gt; Scheme &amp;gt; New Scheme from the menu to add a new Scheme.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A scheme describes how Xcode runs different actions. In this article we will define two schemes &lt;code&gt;staging&lt;/code&gt; and &lt;code&gt;production&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/WEASQLPvrKs" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/sFOrRQmp3GU" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 3
&lt;/h3&gt;

&lt;p&gt;Let's duplicate the existing build configurations to create separate configurations for different flavors. This process involves replicating the default configurations and appending "staging" and "production"  as a suffix.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/6BQCr3RXGFE" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/6FO1ejkfuPY" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 4
&lt;/h3&gt;

&lt;p&gt;Let's now edit the &lt;code&gt;staging&lt;/code&gt; and &lt;code&gt;production&lt;/code&gt; schemes to align with the newly created build configurations. Similarly, map the newly created build configurations to the &lt;code&gt;production&lt;/code&gt; scheme.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/N8VsUrd-bmA" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 5
&lt;/h3&gt;

&lt;p&gt;Now that we've got our &lt;code&gt;staging&lt;/code&gt; and &lt;code&gt;production&lt;/code&gt; flavors ready, we can assign different bundle identifiers for each. &lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/amiPEh_WCQU" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Give it a shot—assign the bundle identifier for the production flavor yourself! 😁&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 6
&lt;/h3&gt;

&lt;p&gt;In the Build Settings, set the Product Name value to match each flavor. For example, add Todo Staging. For those unfamiliar, the product name in Xcode refers to the name of the app as it appears in the App Store and on devices once it's installed. Also we will be using this product name in the next step.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/BUhhEKrtMVo" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Oops! no video for production😌. Please try to do it yourself!&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 7
&lt;/h3&gt;

&lt;p&gt;Add the display name to &lt;code&gt;Info.plist&lt;/code&gt;. Update the Bundle Display Name value to &lt;code&gt;$(PRODUCT_NAME)&lt;/code&gt;. When we set the Bundle Display Name to &lt;code&gt;$(PRODUCT_NAME)&lt;/code&gt;, Xcode dynamically replaces it with the actual product name of our app during the build process.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/8Cm05iyUhXM" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 8
&lt;/h3&gt;

&lt;p&gt;Now it's time to setup our app icon for our &lt;code&gt;staging&lt;/code&gt; flavor. When we create your project from a template, it automatically includes a default asset catalog (Assets.xcassets) that contains the AppIcon. &lt;/p&gt;

&lt;p&gt;If we don’t have a default asset catalog or existing AppIcon or we want to add another, we can add an app icon to an asset catalog manually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the Project navigator, select an asset catalog.&lt;/li&gt;
&lt;li&gt;Click the Add button (+) at the bottom of the outline view.&lt;/li&gt;
&lt;li&gt;In the pop-up menu, choose OS variant &amp;gt; OS variant App Icon. Xcode creates a new app icon set or image stack with the name AppIcon.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/oIUDuWo-_bs" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 9
&lt;/h3&gt;

&lt;p&gt;Now that we've created the asset catalog, it's time to add the icons. To ensure compatibility with all the sizes specified in Xcode, we'll need to generate icons for each size. I typically use an app icon generator like &lt;a href="https://www.appicon.co/" rel="noopener noreferrer"&gt;appicon.co&lt;/a&gt; for this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fbvb7m8y4nrzn00zrad2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fbvb7m8y4nrzn00zrad2z.png" alt=" " width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you've generated the icons, simply download them and then either drag and drop them directly into the new staging asset catalog in Xcode or into the designated folder, following the steps outlined in the video.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/Yv2ceg8dt-A" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Next, we'll need to associate the build configuration with the newly created app icon set name.&lt;/p&gt;

&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/KnA0gQcSKCg" width="710" height="399"&gt;
  &lt;/iframe&gt;
 &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please follow the same steps for &lt;code&gt;production&lt;/code&gt; as well. &lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Step 10
&lt;/h3&gt;

&lt;p&gt;"Hurray 🎉! We're almost done. Now it's time to test the changes we've made so far.&lt;/p&gt;

&lt;p&gt;In Android Studio, add flavor configurations for both staging and production, as shown in the screenshot below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F2bk7qsaxyujbqdu81y9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F2bk7qsaxyujbqdu81y9k.png" alt=" " width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's try running the staging app. If everything works fine, you should see the app installed on your emulator, similar to the screenshot below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fxvg2mtdilzycrwv228s0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fxvg2mtdilzycrwv228s0.png" alt="Simulator Screenshot" width="800" height="1734"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>beginners</category>
      <category>ios</category>
    </item>
    <item>
      <title>The Art of Inferring with Large Language Models</title>
      <dc:creator>Shan</dc:creator>
      <pubDate>Tue, 23 May 2023 20:03:16 +0000</pubDate>
      <link>https://dev.to/shanshaji/the-art-of-inferring-with-large-language-models-243m</link>
      <guid>https://dev.to/shanshaji/the-art-of-inferring-with-large-language-models-243m</guid>
      <description>&lt;p&gt;Note: This is a documented version of ChatGPT Prompt Engineering for Developers course. You can find the course &lt;a href="https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/1/introduction" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Inferring is a powerful tool that can be used to extract meaning from text. It can be used to understand customer feedback, to identify trends in social media.&lt;/p&gt;

&lt;p&gt;Here are some examples of how inferring can be used in prompt engineering: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sentiment analysis&lt;/strong&gt;: Inferring can be used to identify the sentiment of a piece of text, such as whether it is positive, negative, or neutral. This can be used to understand customer feedback, identify trends in social media, and generate new ideas. &lt;/p&gt;

&lt;p&gt;Eg: We can use sentiment analysis to categorize playstore reviews into positive, negative, or neutral reviews. This will help us to prioritise the issues mentioned in the reviews and identify the issues that need to be addressed. This will allow the customer support team to quickly identify and resolve issues, and the engineers to focus on fixing high priority bugs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Topic modeling&lt;/strong&gt;: Inferring can be used to identify the topics of a piece of text. This can be used to understand the content of a document, identify patterns in data, and generate new ideas.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Named entity recognition&lt;/strong&gt;: Inferring can be used to identify named entities in a piece of text, such as people, places, and organizations. This can be used to understand the context of a document, identify potential customers, and generate new ideas.&lt;/p&gt;

&lt;p&gt;For example, if you are running an e-commerce website and you have received reviews from consumers who have purchased from your website, you can use a large language model (LLM) to analyse the reviews and identify named entities, such as the shop name and product name. This information can then be used to improve the customer experience, such as by recommending similar products or providing customer support.&lt;/p&gt;

&lt;p&gt;Section from the course starts here: &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;In this article we will infer sentiment and topics from product reviews and news articles. *&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;lamp_review = """
Needed a nice lamp for my bedroom, and this one had \
additional storage and not too high of a price point. \
Got it fast.  The string to our lamp broke during the \
transit and the company happily sent over a new one. \
Came within a few days as well. It was easy to put \
together.  I had a missing part, so I contacted their \
support and they very quickly got me the missing piece! \
Lumina seems to me to be a great company that cares \
about their customers and products!!
"""


What is the sentiment of the following product review, 
which is delimited with triple single quotes?

Review text: '''{lamp_review}'''

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

&lt;/div&gt;



&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fqgjcs9coufh7nxgxmpzh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fqgjcs9coufh7nxgxmpzh.png" alt="Review sentiment analysis" width="800" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see from the screenshot it's a long output. We can  ask the LLM to either output positive / negative as keywords.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"""
What is the sentiment of the following product review, 
which is delimited with triple single quotes?

Give your answer as a single word, either "positive" \
or "negative".

Review text: '''{lamp_review}'''
"""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F4wckdg0t3qbmohgyavnb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F4wckdg0t3qbmohgyavnb.png" alt=" " width="800" height="97"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we can ask an LLM to identify the emotions that the writer of a review is expressing. We can also ask the LLM if the writer is expressing any anger in their review. Additionally, we can ask the LLM to identify the company name and product name from the review. All of these tasks can be performed in a single prompt.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"""
Identify the following items from the review text: 
- Sentiment (positive or negative)
- List all the emotions expressed in the review not more than 5
- Is the reviewer expressing anger? (true or false)
- Item purchased by reviewer
- Company that made the item

The review is delimited with triple backticks. \
Format your response as a JSON object with \
"Sentiment", "Anger", Emotions, "Item" and "Brand" as the keys.
If the information isn't present, use "unknown" \
as the value.
Make your response as short as possible.
Format the Anger value as a boolean.

Review text: '''{lamp_review}'''
"""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2F3fyq9loyps3xep7sm2uf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3fyq9loyps3xep7sm2uf.png" alt="Analyse contents from text" width="800" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next topic in the course topic analysis 🙃.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Inferring can be used to identify the topics of a piece of long text.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;story = """
In a recent survey conducted by the government, 
public sector employees were asked to rate their level 
of satisfaction with the department they work at. 
The results revealed that NASA was the most popular 
department with a satisfaction rating of 95%.

One NASA employee, John Smith, commented on the findings, 
stating, "I'm not surprised that NASA came out on top. 
It's a great place to work with amazing people and 
incredible opportunities. I'm proud to be a part of 
such an innovative organization."

The results were also welcomed by NASA's management team, 
with Director Tom Johnson stating, "We are thrilled to 
hear that our employees are satisfied with their work at NASA. 
We have a talented and dedicated team who work tirelessly 
to achieve our goals, and it's fantastic to see that their 
hard work is paying off."

The survey also revealed that the 
Social Security Administration had the lowest satisfaction 
rating, with only 45% of employees indicating they were 
satisfied with their job. The government has pledged to 
address the concerns raised by employees in the survey and 
work towards improving job satisfaction across all departments.
"""

Determine five topics that are being discussed in the \
following text, which is delimited by triple backticks.

Make each item one or two words long. 

Format your response as a list of items separated by commas.

Text sample: '''{story}'''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see from the output we got different topics in the article that we gave to the LLM. This information can be used to recommend articles to users who are interested in those topics. &lt;/p&gt;

&lt;p&gt;For example, Suppose if a user is subscribed to the topics "java, javascript, and AI," and the user wants to only receive article suggestions based on his/her subscription the LLM can be used to identify the topic and we could create a service that will send notifications when a new article on any of those topic comes.&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fz10brdq3n1xrc11o7g2y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fz10brdq3n1xrc11o7g2y.png" alt=" " width="800" height="96"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>ai</category>
      <category>chatgpt</category>
    </item>
    <item>
      <title>Iterative Prompt Development: Iteratively analyse and refine your prompts</title>
      <dc:creator>Shan</dc:creator>
      <pubDate>Sun, 21 May 2023 13:07:43 +0000</pubDate>
      <link>https://dev.to/shanshaji/iterative-prompt-development-iteratively-analyse-and-refine-your-prompts-3ibl</link>
      <guid>https://dev.to/shanshaji/iterative-prompt-development-iteratively-analyse-and-refine-your-prompts-3ibl</guid>
      <description>&lt;p&gt;Note: This is a documented version of ChatGPT Prompt Engineering for Developers course. You can find the course &lt;a href="https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/1/introduction" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note: This article is pretty boring. I have added a general summary here for all those who don't have time to read this. &lt;/p&gt;

&lt;p&gt;In this article, we will see how to iteratively analyse and refine prompts to generate marketing copy from a product fact sheet. We will start with a simple prompt that generated a long, rambling text. We then iteratively will refine the prompt to limit the number of words, focus on the relevant details, and include the product IDs. Finally, we will add a table of dimensions. By following this iterative approach, we will be able to generate a concise and polished output that meets the needs of the marketing team. This is based on the example that is mentioned in the course.&lt;/p&gt;

&lt;p&gt;Note: Before reading this please try to read two another articles which is part of this course. It will give you a general guidelines on how to interact with LLM in a better way.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/shanshaji/writing-effective-prompts-for-large-language-models-two-prompting-principles-and-their-related-tactics-151a"&gt;Writing Effective Prompts for Large Language Models: Two Prompting Principles and Their Related Tactics.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/shanshaji/principle-2-of-writing-effective-prompts-for-large-language-models-give-them-time-to-think-25j3"&gt;Principle 2 of Writing Effective Prompts for Large Language Models: Give Them Time to Think&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: In this Article, you'll learn how to iteratively analyse and refine prompts. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;We will iteratively analyse and refine our prompts to generate marketing copy from a product fact sheet.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fact_sheet_chair = """
OVERVIEW
- Part of a beautiful family of mid-century inspired office furniture, 
including filing cabinets, desks, bookcases, meeting tables, and more.
- Several options of shell color and base finishes.
- Available with plastic back and front upholstery (SWC-100) 
or full upholstery (SWC-110) in 10 fabric and 6 leather options.
- Base finish options are: stainless steel, matte black, 
gloss white, or chrome.
- Chair is available with or without armrests.
- Suitable for home or business settings.
- Qualified for contract use.

CONSTRUCTION
- 5-wheel plastic coated aluminum base.
- Pneumatic chair adjust for easy raise/lower action.

DIMENSIONS
- WIDTH 53 CM | 20.87”
- DEPTH 51 CM | 20.08”
- HEIGHT 80 CM | 31.50”
- SEAT HEIGHT 44 CM | 17.32”
- SEAT DEPTH 41 CM | 16.14”

OPTIONS
- Soft or hard-floor caster options.
- Two choices of seat foam densities: 
 medium (1.8 lb/ft3) or high (2.8 lb/ft3)
- Armless or 8 position PU armrests 

MATERIALS
SHELL BASE GLIDER
- Cast Aluminum with modified nylon PA6/PA66 coating.
- Shell thickness: 10 mm.
SEAT
- HD36 foam

COUNTRY OF ORIGIN
- Italy
"""

Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple hyphen.

Technical specifications: ---{fact_sheet_chair}---
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As the prompt is bit big. When I unleashed this on GPT-3, it erupted with a whopping 369 words!😁. I won't be sharing the output here as it's a long text. To limit the number of words to certain limit we can tell GPT to generate at most x amount of words.&lt;/p&gt;

&lt;p&gt;The new prompt will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple hyphen.

Use at most 50 words.

Technical specifications: ---{fact_sheet_chair}---
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this prompt we are mentioning the number of words to GPT to limit the output.&lt;/p&gt;

&lt;p&gt;Issue 2 of the generated output:  Text focuses on the wrong details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple hyphen.

The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.

Use at most 50 words.

Technical specifications: ---{fact_sheet_chair}---

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

&lt;/div&gt;



&lt;p&gt;Here in this prompt we are asking the model to focus on the aspects that are relevant to the intended audience. Here we need to generate the description for furniture retailers.&lt;/p&gt;

&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fdmr80bt78590avh9y1hj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fdmr80bt78590avh9y1hj.png" alt="Limit Words Generated" width="800" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can further improve this prompt to attach the product ids in the description. The updated prompt will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple hyphen.

The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.

At the end of the description, include every 7-character 
Product ID in the technical specification.

Use at most 50 words.

Technical specifications: ---{fact_sheet_chair}---
"""

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

&lt;/div&gt;



&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F9kv1yu4ui2z4rwc0rq8w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9kv1yu4ui2z4rwc0rq8w.png" alt="Output with product id" width="800" height="175"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Issue 3 - Description needs a table of dimensions&lt;/p&gt;

&lt;p&gt;We can ask the model to generate a table for us along with the description. Here we will be generating a table of dimensions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.

Write a product description based on the information 
provided in the technical specifications delimited by 
triple hyphen.

The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.

At the end of the description, include every 7-character 
Product ID in the technical specification.

After the description, include a table that gives the 
product's dimensions. The table should have two columns.
In the first column include the name of the dimension. 
In the second column include the measurements in inches only.

Give the table the title 'Product Dimensions'.

Format everything as HTML that can be used in a website. 
Place the description in a &amp;lt;div&amp;gt; element.

Technical specifications: ---{fact_sheet_chair}---
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output generated is in HTML. I am not going to add the screenshot here as the output is a bit long. You can copy and paste this prompt to know how the output will look like. &lt;/p&gt;

&lt;p&gt;Here is another example of how the iterative approach can be used to improve the quality of generated outputs. Let's say you want to write a poem about a flower. Your first prompt might be something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Write a poem about a flower.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prompt is too general and will likely result in a poem that is not very specific or creative. To improve the prompt, you could add more details about the flower, such as its colour, shape, or smell. You could also specify the tone of the poem, such as whether you want it to be happy, sad, or reflective.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Write a happy poem about a red lily.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prompt is more likely to result in a poem that is both specific and creative. Once you have written the poem, you can then evaluate it and see if it meets your needs. If not, you can iterate on the prompt and try again until the desired output is achieved.&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>ai</category>
      <category>beginners</category>
      <category>prompts</category>
    </item>
    <item>
      <title>Principle 2 of Writing Effective Prompts for Large Language Models: Give Them Time to Think</title>
      <dc:creator>Shan</dc:creator>
      <pubDate>Sat, 20 May 2023 05:42:14 +0000</pubDate>
      <link>https://dev.to/shanshaji/principle-2-of-writing-effective-prompts-for-large-language-models-give-them-time-to-think-25j3</link>
      <guid>https://dev.to/shanshaji/principle-2-of-writing-effective-prompts-for-large-language-models-give-them-time-to-think-25j3</guid>
      <description>&lt;p&gt;Note: This is a documented version of ChatGPT Prompt Engineering for Developers course. You can find the course &lt;a href="https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/1/introduction" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note: In this Article, you'll practice one prompting principle and it's related tactics in order to write effective prompts for large language models. You can view my previous article &lt;a href="https://dev.to/shanshaji/writing-effective-prompts-for-large-language-models-two-prompting-principles-and-their-related-tactics-151a"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Principle 2&lt;/strong&gt;: Give the model time to “think”.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Large language models can make reasoning errors by rushing to an incorrect conclusion. This can happen if the model is given a task that is too complex or if it is not given enough time to consider all of the evidence. To prevent this, you can reframe the query to request a chain or series of relevant reasoning. This will help the model to slow down and consider all of the evidence before drawing a conclusion. Just like humans, large language models can make mistakes if they are rushed or given too much to do. Instructing the model to think longer about a problem can help to improve its accuracy.&lt;/p&gt;

&lt;p&gt;Here are some tips for reframing a query to request a chain or series of relevant reasoning:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the word "explain" or "justify" in your query.&lt;/li&gt;
&lt;li&gt;Ask the model to provide evidence to support its conclusion.&lt;/li&gt;
&lt;li&gt;Ask the model to consider all of the relevant information.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the outputs that were generated for the same question asked in different ways.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Frloqjwz612bs19v91kaa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Frloqjwz612bs19v91kaa.png" alt="Give Them Time to Think" width="800" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F73179uloinlgq3rioij4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F73179uloinlgq3rioij4.png" alt="Give Them Time to Think" width="799" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tactic 1&lt;/strong&gt;: Specify the steps required to complete a task&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;text = """
In a charming village, siblings Jack and Jill set out on \ 
a quest to fetch water from a hilltop \ 
well. As they climbed, singing joyfully, misfortune \ 
struck—Jack tripped on a stone and tumbled \ 
down the hill, with Jill following suit. \ 
Though slightly battered, the pair returned home to \ 
comforting embraces. Despite the mishap, \ 
their adventurous spirits remained undimmed, and they \ 
continued exploring with delight.
"""

prompt_1 = """
Perform the following actions: 
1 - Summarise the following text delimited by triple \
hyphen with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the following \
keys: french_summary, num_names.

Separate your answers with line breaks.

Text:
---{text}---
"""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this prompt we are specifying all the steps that should be performed by the model before arriving at a conclusion. &lt;br&gt;
As seen from the screenshot, the model provided a clear and concise answer for our query.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Frwr4vyahbt7whqzfh7z4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Frwr4vyahbt7whqzfh7z4.png" alt=" " width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us try to give another prompt that will give us a more structured output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;text = """
In a charming village, siblings Jack and Jill set out on \ 
a quest to fetch water from a hilltop \ 
well. As they climbed, singing joyfully, misfortune \ 
struck—Jack tripped on a stone and tumbled \ 
down the hill, with Jill following suit. \ 
Though slightly battered, the pair returned home to \ 
comforting embraces. Despite the mishap, \ 
their adventurous spirits remained undimmed, and they \ 
continued exploring with delight.
"""

Your task is to perform the following actions: 
1 - Summarise the following text delimited by 
  &amp;lt;&amp;gt; with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the 
  following keys: french_summary, num_names.

Use the following format:

Summary: summary
Translation: summary translation
Names: list of names in Italian summary
Output JSON: json with summary and num_names

Text: &amp;lt;{text}&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;As seen from the screenshot the output is now more structured and follows a format.&lt;/p&gt;

&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F4a31grlzw7ca1otvjpbc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F4a31grlzw7ca1otvjpbc.png" alt="Structured Response" width="800" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tactic 2&lt;/strong&gt;: Instruct the model to work out its own solution before rushing to a conclusion&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Determine if the student's solution is correct or not.

Question:
I'm building a solar power installation and I need \
 help working out the financials. 
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \ 
me a flat $100k per year, and an additional $10 / square \
foot

What is the total cost for the first year of operations 
as a function of the number of square feet.

Student's Solution:

Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prompt will give the output as the student's answer is correct but the answer is wrong because the calculation "100,000 + 100x" is wrong it should be "100,000 + 10x". So the answer should be "360x + 100,000". &lt;/p&gt;

&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F7hea656y0p6ucivrrpzx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F7hea656y0p6ucivrrpzx.png" alt=" " width="799" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get the correct output we need to ask the model to first generate it's own answer and then compare the answer with the student's answer. Here we asking the model to do it's own analysis on the question and generate an answer for us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;To solve the problem do the following:
- First, work out your own solution to the problem. 
- Then compare your solution to the student's solution 
and evaluate if the student's solution is correct or not. 
Don't decide if the student's solution is correct until 
you have done the problem yourself.

Use the following format:
Question:
----
question here
----

Student's solution:
----
student's solution here
----

Actual solution:
----
steps to work out the solution and your solution here
----

Is the student's solution the same as actual solution \
just calculated:
---
yes or no
---

Student grade:
---
correct or incorrect
----

Question:
""""
I'm building a solar power installation and I need help \
working out the financials. 
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \
me a flat $100k per year, and an additional $10 / square \
foot
What is the total cost for the first year of operations \
as a function of the number of square feet.
""""
Student's solution:
""""
Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
""""
Actual solution:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fjbsfuo3tlktt8rf3pdlm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjbsfuo3tlktt8rf3pdlm.png" alt=" " width="800" height="781"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is an example of how asking the model to do a calculation itself and breaking down the task into steps to give the model more time to think can help you &lt;br&gt;
get more accurate responses. Here i am using hyphen and triple double quotes as delimiters. You can use any delimiters as you like. &lt;/p&gt;

&lt;p&gt;To improve the accuracy and quality of the responses from large language models, it is important to give them time to "think". This can be done by reframing your query to request a chain or series of relevant reasoning, or by instructing the model to work out its own solution before rushing to a conclusion. Additionally, it is important to be as specific as possible in your queries, use natural language, use keywords, and be patient when waiting for a response.&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>promptengineering</category>
      <category>beginners</category>
      <category>ai</category>
    </item>
    <item>
      <title>Writing Effective Prompts for Large Language Models: Two Prompting Principles and Their Related Tactics</title>
      <dc:creator>Shan</dc:creator>
      <pubDate>Fri, 19 May 2023 18:42:11 +0000</pubDate>
      <link>https://dev.to/shanshaji/writing-effective-prompts-for-large-language-models-two-prompting-principles-and-their-related-tactics-151a</link>
      <guid>https://dev.to/shanshaji/writing-effective-prompts-for-large-language-models-two-prompting-principles-and-their-related-tactics-151a</guid>
      <description>&lt;p&gt;Note: This is a documented version of ChatGPT Prompt Engineering for Developers course. You can find the course &lt;a href="https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/1/introduction" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Note: In this Article, you'll practice one prompting principle and it's related tactics in order to write effective prompts for large language models. I will create another article on principle 2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prompting Principles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Principle 1: Write clear and specific instructions.&lt;/li&gt;
&lt;li&gt;Principle 2: Give the model time to “think”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tactic 1&lt;/strong&gt;: Use delimiters to clearly indicate distinct parts of the input.&lt;/p&gt;

&lt;p&gt;Delimiters can be anything like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Triple Quotes: ''' '''&lt;/li&gt;
&lt;li&gt;Triple Backticks:```&lt;/li&gt;
&lt;li&gt;Triple Dashes: --- ---&lt;/li&gt;
&lt;li&gt;Angle Brackets: &amp;lt;&amp;gt;&lt;/li&gt;
&lt;li&gt;Xml Tags: &amp;lt;tag&amp;gt; &amp;lt;/tag&amp;gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
text = """
You should express what you want a model to do by \ 
providing instructions that are as clear and \ 
specific as you can possibly make them. \ 
This will guide the model towards the desired output, \ 
and reduce the chances of receiving irrelevant \ 
or incorrect responses. Don't confuse writing a \ 
clear prompt with writing a short prompt. \ 
In many cases, longer prompts provide more clarity \ 
and context for the model, which can lead to \ 
more detailed and relevant outputs.
"""

prompt = """
Summarise the text delimited by angle brackets\ 
into a single sentence.
&amp;lt;text&amp;gt;
"""

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

&lt;/div&gt;



&lt;p&gt;Output that i got after giving this prompt to chat GPT.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F8e8sj2text6gcv31mgcw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8e8sj2text6gcv31mgcw.png" alt="Delimiter GPT prompt output " width="800" height="221"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tactic 2&lt;/strong&gt;: Ask for a structured output&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JSON, HTML
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"""
Generate a list of three made-up book titles along \ 
with their authors and genres. 
Provide them in JSON format with the following keys: 
book_id, title, author, genre.
"""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prompt will generate the output in json format. If we change the value JSON to HTML then the output will be in HTML format.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JSON&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"books"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"book_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"The Secret Garden"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Emily Greenfield"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"genre"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Children's Fiction"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"book_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Midnight Shadows"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Jacob Nightfall"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"genre"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Thriller"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For those who don't know what is JSON and HTML it is fine. HTML is a markup language used for structuring and presenting web content, while JSON is a data interchange format used for storing and exchanging structured data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tactic 3&lt;/strong&gt;: Ask the model to check whether conditions are satisfied&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;text_1 = """
Making a cup of tea is easy! First, you need to get some \ 
water boiling. While that's happening, \ 
grab a cup and put a tea bag in it. Once the water is \ 
hot enough, just pour it over the tea bag. \ 
Let it sit for a bit so the tea can steep. After a \ 
few minutes, take out the tea bag. If you \ 
like, you can add some sugar or milk to taste. \ 
And that's it! You've got yourself a delicious \ 
cup of tea to enjoy.
"""
prompt = """
You will be provided with text delimited by triple quotes. 
If it contains a sequence of instructions, \ 
re-write those instructions in the following format:

Step 1 - ...
Step 2 - …
…
Step N - …

If the text does not contain a sequence of instructions, \ 
then simply write \"No steps provided.\"

\"\"\"{text_1}\"\"\"
"""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fs8rcfn1bori34uqn2wic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fs8rcfn1bori34uqn2wic.png" alt="Ask the model to check whether conditions are satisfied" width="799" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An effective use case for this tactic involves providing a code snippet that encompasses essential business logic, and subsequently leveraging AI to verify the comprehensive handling of all conditions within the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;text_2 = """
The sun is shining brightly today, and the birds are \
singing. It's a beautiful day to go for a \ 
walk in the park. The flowers are blooming, and the \ 
trees are swaying gently in the breeze. People \ 
are out and about, enjoying the lovely weather. \ 
Some are having picnics, while others are playing \ 
games or simply relaxing on the grass. It's a \ 
perfect day to spend time outdoors and appreciate the \ 
beauty of nature.
"""
prompt = """
You will be provided with text delimited by triple quotes. 
If it contains a sequence of instructions, \ 
re-write those instructions in the following format:

Step 1 - ...
Step 2 - …
…
Step N - …

If the text does not contain a sequence of instructions, \ 
then simply write \"No steps provided.\"

\"\"\"{text_2}\"\"\"
"""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example you can clearly see there are not tasks mentioned in the text. Since there are not steps we need to get "No steps provided." as the output.&lt;/p&gt;

&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fvozodh287kk1wtnzpypk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fvozodh287kk1wtnzpypk.png" alt="Ask the model to check whether conditions are satisfied" width="800" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tactic 4&lt;/strong&gt;: "Few-shot" prompting&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prompt = """
Your task is to answer in a consistent style.

&amp;lt;child&amp;gt;: Teach me about patience.

&amp;lt;grandparent&amp;gt;: The river that carves the deepest \ 
valley flows from a modest spring; the \ 
grandest symphony originates from a single note; \ 
the most intricate tapestry begins with a solitary thread.

&amp;lt;child&amp;gt;: Teach me about resilience.
"""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tactic involves training the model with successful examples of tasks and subsequently requesting the model to perform a specific task based on the provided examples.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fpb7yw77o50j48i0a2ioj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fpb7yw77o50j48i0a2ioj.png" alt="" width="800" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In conclusion, Principle 1 emphasizes the significance of providing clear and specific instructions to ChatGPT in order to achieve desired outputs. By expressing instructions in a precise manner, we guide the model towards the intended outcome and minimize the risk of irrelevant or incorrect responses. This principle emphasizes that clarity should not be compromised for the sake of brevity, as longer prompts can provide additional context and enhance the quality of the model's responses. When crafting prompts, it is essential to focus on writing instructions that are as explicit as possible, leaving no room for ambiguity. Following Principle 1 ensures that we harness the full potential of ChatGPT and obtain detailed and relevant outputs that align with our expectations.&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>prompt</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Boost Your Productivity: How to Create and Use Custom Snippets in VS Code</title>
      <dc:creator>Shan</dc:creator>
      <pubDate>Sat, 01 Apr 2023 04:25:36 +0000</pubDate>
      <link>https://dev.to/shanshaji/boost-your-productivity-how-to-create-and-use-custom-snippets-in-vs-code-5bbo</link>
      <guid>https://dev.to/shanshaji/boost-your-productivity-how-to-create-and-use-custom-snippets-in-vs-code-5bbo</guid>
      <description>&lt;p&gt;As a developer, you might find yourself frequently using the same code patterns or syntax. Repeatedly typing out the same code can be tedious and can slow down your workflow. This is where snippets come in handy.&lt;/p&gt;

&lt;p&gt;Visual Studio Code (VS Code) provides a built-in feature for defining and using snippets. Snippets are predefined templates of code that you can insert into your code file using a simple keyboard shortcut. In this article, we’ll explore how to create and use snippets in VS Code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defining Snippets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;VS Code provides an easy way to create and define your own snippets. You can define snippets either for a specific language or for all languages. To create or edit your own snippets, go to the Command Palette by pressing Ctrl+Shift+P (Windows, Linux) or Cmd+Shift+P (macOS), and then search for "Configure User Snippets". Selecting this option will bring up a dropdown menu that allows you to choose a language-specific snippets file or a global snippets file.&lt;/p&gt;

&lt;p&gt;Snippets files are written in JSON format, which supports C-style comments, and can define an unlimited number of snippets. Snippets support most TextMate syntax for dynamic behavior and can intelligently format whitespace based on the insertion context.&lt;/p&gt;

&lt;p&gt;Let’s look at an example of defining a snippet for a JavaScript for loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;// &lt;span class="k"&gt;in &lt;/span&gt;file &lt;span class="s1"&gt;'Code/User/snippets/javascript.json'&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"For Loop"&lt;/span&gt;: &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"prefix"&lt;/span&gt;: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"for"&lt;/span&gt;, &lt;span class="s2"&gt;"for-const"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;,
    &lt;span class="s2"&gt;"body"&lt;/span&gt;: &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"for (const &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;2&lt;/span&gt;:element&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; of &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;1&lt;/span&gt;:array&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;) {"&lt;/span&gt;, &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="nv"&gt;$0&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;, &lt;span class="s2"&gt;"}"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;,
    &lt;span class="s2"&gt;"description"&lt;/span&gt;: &lt;span class="s2"&gt;"A for loop."&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;For Loop&lt;/code&gt; is the name of the snippet. It will be displayed via IntelliSense if no description is provided. The &lt;code&gt;prefix&lt;/code&gt; property defines one or more trigger words that display the snippet in IntelliSense. Substring matching is performed on prefixes, so in this case, &lt;code&gt;fc&lt;/code&gt; could match &lt;code&gt;for-const&lt;/code&gt;. The &lt;code&gt;body&lt;/code&gt; property is one or more lines of content, which will be joined as multiple lines upon insertion. Newlines and embedded tabs will be formatted according to the context in which the snippet is inserted. Finally, the &lt;code&gt;description&lt;/code&gt; property is an optional description of the snippet displayed by IntelliSense.&lt;/p&gt;

&lt;p&gt;Additionally, the body of the example above has three placeholders (listed in order of traversal): ${1:array}, ${2:element}, and $0. You can quickly jump to the next placeholder with Tab, at which point you may edit the placeholder or jump to the next one. The string after the colon : (if any) is the default text, for example element in ${2:element}. Placeholder traversal order is ascending by number, starting from one; zero is an optional special case that always comes last and exits snippet mode with the cursor at the specified position.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Snippets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you’ve defined your snippets, you can start using them in your code. To insert a snippet, simply type the prefix in your code file and press Tab. The snippet will then be inserted into your code with the cursor placed at the first placeholder. You can then use Tab to jump to the next placeholder or use Shift+Tab to jump to the previous one.&lt;/p&gt;

&lt;p&gt;For example, if we had the "For Loop" snippet defined as above, we could use it in our JavaScript file by typing for and then pressing Tab. The snippet would be inserted into the code, and we could then fill in the placeholders as needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;More Detailed Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're interested in using the 'Freezed' package in Flutter, I've created a handy VS Code extension that provides code snippets to speed up your development process. You can find the extension on GitHub at &lt;a href="https://github.com/ArkrootHQ/freezed-snippets" rel="noopener noreferrer"&gt;https://github.com/ArkrootHQ/freezed-snippets&lt;/a&gt;, and it's completely free to use. If you have any suggestions or ideas for improving the extension, feel free to contribute to the project. Your contributions are always welcome and greatly appreciated!&lt;/p&gt;

&lt;p&gt;Here's a quick overview of the snippets currently included in the extension.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "Part statement": {
    "prefix": "pts",
    "body": ["part '${TM_FILENAME_BASE}.g.dart';"],
    "description": "Creates a filled-in part statement"
  },
  "Part 'Freezed' statement": {
    "prefix": "ptf",
    "body": ["part '${TM_FILENAME_BASE}.freezed.dart';"],
    "description": "Creates a filled-in freezed part statement"
  },
  "Freezed Data Class": {
    "prefix": ["fdataclass", "fdc"],
    "body": [
      "@freezed",
      "class ${1:DataClass} with _$${1:DataClass}{",
      "  const factory ${1:DataClass}(${2}) = _${1:DataClass};",
      "}",
      "factory ${1:DataClass}.fromJson(Map&amp;lt;String, dynamic&amp;gt; json)",
      "=&amp;gt; _$${1:DataClass}FromJson(json);"
    ],
    "description": "Freezed Data Class"
  },
  "Freezed Union": {
    "prefix": "funion",
    "body": [
      "@freezed",
      "class ${1:Union} with _$${1:Union}{",
      "  const factory ${1:Union}.${2}(${4}) = ${3};",
      "}"
    ],
    "description": "Freezed Union"
  },
  "Freezed Union Case": {
    "prefix": "funioncase",
    "body": ["const factory ${1:Union}.${2}(${4}) = ${3};"],
    "description": "Freezed Union Case"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is an explanation of each snippet:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Part statement": inserts a filled-in "part" statement for the current file.&lt;/li&gt;
&lt;li&gt;"Part 'Freezed' statement": inserts a filled-in "part" statement for the generated Freezed file.&lt;/li&gt;
&lt;li&gt;"Freezed Data Class": creates a new Freezed data class with a constructor and a "fromJson" factory method.&lt;/li&gt;
&lt;li&gt;"Freezed Union": creates a new Freezed union with a specified number of cases.&lt;/li&gt;
&lt;li&gt;"Freezed Union Case": inserts a new case into an existing Freezed union.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Snippets are a powerful feature in VS Code that can greatly increase your productivity as a developer. By defining your own snippets, you can save time&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What are pre-commit hooks and How to use in flutter projects?</title>
      <dc:creator>Shan</dc:creator>
      <pubDate>Sat, 11 Mar 2023 07:42:02 +0000</pubDate>
      <link>https://dev.to/shanshaji/what-are-pre-commit-hooks-and-how-to-use-in-flutter-projects-4c0m</link>
      <guid>https://dev.to/shanshaji/what-are-pre-commit-hooks-and-how-to-use-in-flutter-projects-4c0m</guid>
      <description>&lt;p&gt;Version control systems (VCS) like Git are essential tools for software development, allowing developers to track changes to their code and collaborate with others. One important feature of Git is the ability to use pre-commit hooks, which are scripts or programs that are run automatically before a commit is made. Pre-commit hooks can be used to perform various checks and validations on the code changes being committed, ensuring that they meet certain standards or requirements.&lt;/p&gt;

&lt;p&gt;In this article, we'll discuss what pre-commit hooks are, why they're useful, and how to configure them in a Flutter project. We'll also discuss some examples of pre-commit hooks you can use in your projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Pre-Commit Hook?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A pre-commit hook is a script or program that is executed automatically before a commit is made to a VCS. A pre-commit hook aims to check the changes being committed to ensure they meet certain standards or requirements. For example, a pre-commit hook might be used to enforce code style guidelines, prevent certain files from being committed, or check for syntax errors and other issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use Pre-Commit Hooks?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Pre-commit hooks offer several benefits to software development teams:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consistency: Pre-commit hooks can enforce consistent coding standards and practices across the entire team, ensuring that all code adheres to the same guidelines.&lt;/li&gt;
&lt;li&gt;Error prevention: By running automated checks before commits are made, pre-commit hooks can catch errors and other issues early in the development process, preventing them from being introduced into the codebase.&lt;/li&gt;
&lt;li&gt;Time savings: Pre-commit hooks can automate time-consuming tasks such as linting and code formatting, freeing up developers to focus on more important tasks.&lt;/li&gt;
&lt;li&gt;Collaboration: Pre-commit hooks can help ensure that all team members are aware of code changes and are able to review them before they are committed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Configuring Pre-Commit Hooks in a Flutter Project:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Configuring a pre-commit hook in a Flutter project involves creating a script that will be executed before a commit is made, and then configuring Git to run that script automatically. Here are the steps to configure a pre-commit hook in a Flutter project:&lt;/p&gt;

&lt;p&gt;Step 1: Create a Pre-Commit Hook Script&lt;/p&gt;

&lt;p&gt;The first step is to create a pre-commit hook script that will be run automatically before each commit. This script can be written in any scripting language, but in this article, we'll be using Bash.&lt;/p&gt;

&lt;p&gt;Create a file named pre-commit (without any file extension since we are using bash) in the .git/hooks/ directory of your project. If the .git/hooks/ directory does not exist, create it.&lt;/p&gt;

&lt;p&gt;Here's an example pre-commit hook script that runs &lt;code&gt;flutter analyze&lt;/code&gt; and &lt;code&gt;dart analyze&lt;/code&gt; to check for errors in the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;

&lt;span class="c"&gt;# Run Flutter analyze and check for errors&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;flutter analyze&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"COMMIT REJECTED: Flutter analyze found the following errors:"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$output&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="c"&gt;# Run Dart analyze and check for errors&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;dart analyze&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"COMMIT REJECTED: Dart analyze found the following errors:"&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$output&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="nb"&gt;exit &lt;/span&gt;1
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="c"&gt;# If we made it this far, the commit is allowed&lt;/span&gt;
&lt;span class="nb"&gt;exit &lt;/span&gt;0

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

&lt;/div&gt;



&lt;p&gt;This script runs &lt;code&gt;flutter analyze&lt;/code&gt; and &lt;code&gt;dart analyz&lt;/code&gt;e to check for errors in the code. If either command detects an error, the commit will be rejected.&lt;/p&gt;

&lt;p&gt;Step 2: Make the Script Executable&lt;/p&gt;

&lt;p&gt;Next, you'll need to make the script executable. To do this, open a terminal and navigate to your Flutter project directory. Then, run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x pre-commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command gives the &lt;code&gt;pre-commit&lt;/code&gt; script executable permissions.&lt;/p&gt;

&lt;p&gt;Step 3: Configure Git to Run the Script&lt;/p&gt;

&lt;p&gt;The final step is to configure Git to run the pre-commit hook script automatically before each commit. To do this, navigate to your Flutter project directory in a terminal and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; .git/hooks
&lt;span class="nb"&gt;ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; ../../pre-commit pre-commit

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

&lt;/div&gt;



&lt;p&gt;This command creates a symbolic link to the pre-commit script in the .git/hooks directory, which Git will use to run the script automatically before each commit.&lt;/p&gt;

&lt;p&gt;If you have successfully configured a pre-commit hook in your Flutter project and if your codebase has analyzer problems, then you will get an error message indicating that the commit has been rejected.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F3rs4beb336mhwsa6e722.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F3rs4beb336mhwsa6e722.png" alt=" " width="796" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! You've now configured a pre-commit hook in your Flutter project.&lt;/p&gt;

&lt;p&gt;Pre-commit hooks are a powerful tool for ensuring code quality and consistency in your Flutter projects. They can be used to enforce coding standards, catch errors and security vulnerabilities, and automate time-consuming tasks. By following the steps outlined in this article, you can easily configure pre-commit hooks in your own projects and improve your development workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus
&lt;/h2&gt;

&lt;p&gt;You can find an easy to use pre-commit hook &lt;a href="https://github.com/shan-shaji/flutter-pre-commit-hook-script" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>flutter</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Equatable package in dart</title>
      <dc:creator>Shan</dc:creator>
      <pubDate>Fri, 03 Feb 2023 16:21:26 +0000</pubDate>
      <link>https://dev.to/shanshaji/equatable-package-in-dart-3f7l</link>
      <guid>https://dev.to/shanshaji/equatable-package-in-dart-3f7l</guid>
      <description>&lt;p&gt;The equatable package in Flutter is a powerful tool for comparing objects. It allows developers to easily determine if two objects have the same properties and values, which can be especially useful when working with complex data structures or implementing value types in their Flutter apps.&lt;/p&gt;

&lt;p&gt;The equatable package provides a base Equatable class that we can extend to create our own custom value types. To use the package, we need to import it in our dart file and extend the Equatable class.&lt;/p&gt;

&lt;p&gt;Here is an example of how to use equatable to create a custom value type called Person:&lt;/p&gt;

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

class Person extends Equatable {
  final String name;
  final int age;

  Person({required this.name, required this.age});

  @override
  List&amp;lt;Object&amp;gt; get props =&amp;gt; [name, age];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example, the Person class extends Equatable and implements the props getter. The props getter is used to specify which properties of the object should be used to determine equality. In this case, the name and age properties of two Person objects are being compared.&lt;/p&gt;

&lt;p&gt;Once you have defined your custom value type, you can use the == operator to compare two instances of that type:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final person1 = Person(name: 'John', age: 30);
final person2 = Person(name: 'John', age: 30);

print(person1 == person2); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Alternatively, you can use the isEquals method to compare two instances of your custom value type:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final person1 = Person(name: 'John', age: 30);
final person2 = Person(name: 'John', age: 30);

print(Equatable.is(person1, person2)); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can also use equatable package to compare a list of objects.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final people1 = [
  Person(name: 'John', age: 30),
  Person(name: 'Mike', age: 25),
];

final people2 = [
  Person(name: 'John', age: 30),
  Person(name: 'Mike', age: 25),
];

print(Equatable.listEquals(people1, people2)); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The equatable package uses the == operator and the hashCode method to determine equality between objects. When the == operator is called on two objects, equatable compares the values of the properties specified in the props getter to determine if they are equal. If the props getter is not implemented or is empty, equatable will use the hashCode method to compare the objects.&lt;/p&gt;

&lt;p&gt;It’s important to note that equatable only compares the properties that you specify in the props getter. If you need to compare other properties or custom logic, you should implement the == operator and hashCode in your custom class.&lt;/p&gt;

&lt;p&gt;Using equatable package can make your code more robust and maintainable, as it allows you to easily compare complex data structures and value types. It can be especially useful when working with large and complex data structures, as it provides an easy and consistent way to determine equality between objects.&lt;/p&gt;

&lt;p&gt;Another important feature of the equatable package is that it can help to improve the performance of your app. When you use the == operator to compare two objects, the equatable package will only compare the properties specified in the props getter, rather than comparing all properties of the object. This can greatly reduce the amount of computation required to determine equality, especially when comparing large data structures or collections of objects.&lt;/p&gt;

&lt;p&gt;Additionally, the equatable package can be used in conjunction with other popular Flutter packages, such as provider and bloc, to help manage and compare the state of your app. For example, you can use the equatable package to compare the state of a provider or bloc before and after an update, and only rebuild the parts of your app that have changed.&lt;/p&gt;

&lt;p&gt;In summary, the equatable package is a powerful tool for comparing objects in Flutter. It provides a simple and consistent way to determine equality between objects, and can greatly improve the performance of your app when working with complex data structures or collections of objects. Whether you are working on a simple app or a large and complex project, the equatable package is a valuable tool to have in your toolbox.&lt;/p&gt;

</description>
      <category>crypto</category>
      <category>ethereum</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>What are contexts in flutter?</title>
      <dc:creator>Shan</dc:creator>
      <pubDate>Thu, 02 Feb 2023 09:21:07 +0000</pubDate>
      <link>https://dev.to/shanshaji/what-are-contexts-in-flutter-5735</link>
      <guid>https://dev.to/shanshaji/what-are-contexts-in-flutter-5735</guid>
      <description>&lt;p&gt;In Flutter, the context refers to the location of a widget in the widget tree. It provides information about the surrounding environment and services that the widget might need.&lt;/p&gt;

&lt;p&gt;For example, the context can contain information such as the theme of the app, the locale, the screen size, and more. By accessing the context, a widget can make decisions about how to display itself based on the context.&lt;/p&gt;

&lt;p&gt;In Flutter, the context is passed down the widget tree from parent to child, allowing child widgets to access the context of their parent and ancestors. This makes it possible for widgets to use information from higher up in the tree, without having to pass it down as an argument to every widget along the way.&lt;/p&gt;

&lt;p&gt;There are different ways to access the context in Flutter, but the most common one is by using the BuildContext argument in the build method of a widget. You can also access the context from event handlers, such as onPressed, by using the context argument in the callback.&lt;/p&gt;

&lt;p&gt;By using the context, you can create reusable widgets that can adapt to the environment and services they are used in, making it easier to create complex and flexible user interfaces.&lt;br&gt;
In more simple way we can think of context in Flutter like a backpack that you wear everywhere you go. The backpack contains things that you need to know about where you are and what you're doing. &lt;/p&gt;

&lt;p&gt;For example, it might have information about the place you're at, what time it is, and what your favorite color is.&lt;/p&gt;

&lt;p&gt;When you're building a toy with Flutter, you want your toy to know some of the things that are in your backpack. For example, you might want your toy to know what the color of your backpack is, so it can be painted that color. The context is like a way to pass information from your backpack to your toy.&lt;/p&gt;

&lt;p&gt;Just like how you can pass your backpack to your friends, the context gets passed from one Flutter widget to another. This way, your toy can have access to all the information it needs, without having to ask you for it every time it needs to know something.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;If&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;understood&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Still couldn't understand? continue your reading.&lt;/p&gt;

&lt;p&gt;Imagine you're building a toy house. You want your toy house to know the theme of the room it's in, so it can be decorated accordingly. The theme might be "beach house," for example, so the toy house will be decorated with seashells, sand, and other beach-related items.&lt;/p&gt;

&lt;p&gt;To provide the theme information to the toy house, you could pass it down as an argument every time you create a new widget. However, this quickly becomes unwieldy and hard to maintain, especially as your toy house becomes more complex and has more parts.&lt;/p&gt;

&lt;p&gt;With contexts in Flutter, you can define the theme information once, at the root of the widget tree, and have it be automatically available to all the widgets further down the tree. The widgets can access the context without having to know anything about the widgets higher up in the tree.&lt;/p&gt;

&lt;p&gt;In this way, contexts make it easier to manage the flow of information in your Flutter app, and to create reusable and flexible widgets that can adapt to their environment and the services they need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ThemeChanger&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StatefulWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;child&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;ThemeChanger&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nd"&gt;@required&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;child&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nd"&gt;@required&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;_ThemeChangerState&lt;/span&gt; &lt;span class="n"&gt;createState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_ThemeChangerState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;_ThemeChangerState&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;State&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ThemeChanger&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;_currentTheme&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;initState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;_currentTheme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;widget&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;initState&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="n"&gt;changeTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="n"&gt;newTheme&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;_currentTheme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newTheme&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Theme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;data:&lt;/span&gt; &lt;span class="n"&gt;_currentTheme&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"green"&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;ThemeData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;primarySwatch:&lt;/span&gt; &lt;span class="n"&gt;Colors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;green&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ThemeData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;primarySwatch:&lt;/span&gt; &lt;span class="n"&gt;Colors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;widget&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;child&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyHomePage&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;StatelessWidget&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nd"&gt;@override&lt;/span&gt;
  &lt;span class="n"&gt;Widget&lt;/span&gt; &lt;span class="n"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BuildContext&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Scaffold&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;appBar:&lt;/span&gt; &lt;span class="n"&gt;AppBar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;title:&lt;/span&gt; &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Context Example"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="nl"&gt;actions:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="n"&gt;IconButton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nl"&gt;icon:&lt;/span&gt; &lt;span class="n"&gt;Icon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Icons&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;refresh&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nl"&gt;onPressed:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;themeChanger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
                  &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;ancestorWidgetOfExactType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ThemeChanger&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
              &lt;span class="n"&gt;themeChanger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;changeTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;themeChanger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;_currentTheme&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"green"&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s"&gt;"blue"&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"green"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
          &lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="nl"&gt;body:&lt;/span&gt; &lt;span class="n"&gt;Center&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;Column&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nl"&gt;mainAxisAlignment:&lt;/span&gt; &lt;span class="n"&gt;MainAxisAlignment&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;center&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;children:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="n"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The theme can be changed dynamically"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
          &lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;runApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;ThemeChanger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nl"&gt;theme:&lt;/span&gt; &lt;span class="s"&gt;"green"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;MaterialApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nl"&gt;home:&lt;/span&gt; &lt;span class="n"&gt;MyHomePage&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
      &lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this version, the MyHomePage widget has an action in the app bar that allows the user to change the theme. When the user taps the refresh icon, the theme is changed from green to blue or vice versa.&lt;/p&gt;

&lt;p&gt;The MyHomePage widget uses the ancestorWidgetOfExactType method to access the ThemeChanger widget, which is the parent widget that holds the current theme. It then calls the changeTheme method on the ThemeChanger widget to change the theme dynamically.&lt;/p&gt;

&lt;p&gt;This demonstrates how contexts can be used to make it easy to change the theme dynamically, without having to pass the theme information as arguments down the widget tree.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is ancestorWidgetOfExactType?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ancestorWidgetOfExactType&lt;/code&gt; is a method in Flutter's BuildContext class that returns the nearest ancestor widget of a specified type. It takes a single argument, which is the type of the ancestor widget that you want to find.&lt;br&gt;
This method is useful when you want to access a widget that is higher up in the widget tree, but you don't want to pass it down as an argument to all of the intermediate widgets. Instead, you can use &lt;code&gt;ancestorWidgetOfExactType&lt;/code&gt; to find the nearest ancestor of a specific type and then use that widget to access the data or call methods on it.&lt;/p&gt;

&lt;p&gt;In the previous example we are using this to find &lt;code&gt;ThemeChanger&lt;/code&gt; widget.&lt;/p&gt;

</description>
      <category>crypto</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>How to use get_it package in flutter</title>
      <dc:creator>Shan</dc:creator>
      <pubDate>Tue, 31 Jan 2023 13:52:49 +0000</pubDate>
      <link>https://dev.to/shanshaji/how-to-use-getit-package-al3</link>
      <guid>https://dev.to/shanshaji/how-to-use-getit-package-al3</guid>
      <description>&lt;p&gt;The get_it package is a service locator for Dart and Flutter applications. It allows you to register and retrieve objects (services) throughout your app, making it easy to manage dependencies and decouple different parts of your code.&lt;/p&gt;

&lt;p&gt;Here's an example of how to use get_it in a Flutter app:&lt;br&gt;
First, add the get_it package to your pubspec.yaml file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="nl"&gt;dependencies:&lt;/span&gt;
  &lt;span class="nl"&gt;get_it:&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mf"&gt;7.2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, import get_it in the file where you'll be using it:&lt;/p&gt;

&lt;p&gt;Create a new file called locator.dart. In this you can register all your dependencies and we can call &lt;code&gt;setupLocator&lt;/code&gt; inside the main.dart.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="s"&gt;'package:get_it/get_it.dart'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="n"&gt;locator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;GetIt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;I&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setupLocator&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;locator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;registerSingleton&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reason why i named it as &lt;code&gt;locator&lt;/code&gt; is because it provides a centralized location (or "locator") for managing service locators and dependency injection in a Flutter application.&lt;/p&gt;

&lt;p&gt;In main.dart call &lt;code&gt;setupLocator&lt;/code&gt;. This will register the services with get_it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;setupLocator&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="n"&gt;runApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MyApp&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To register a service, use the registerSingleton() or registerLazySingleton() method on the GetIt instance. For example, to register a UserService:&lt;/p&gt;

&lt;p&gt;Import locator.dart file and you can access the get_it instance to register the services.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;locator&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;registerSingleton&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(()&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To retrieve a service, use the get() method on the GetIt instance. For example, to get the UserService:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;UserService&lt;/span&gt; &lt;span class="n"&gt;userService&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;locator&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;UserService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: In case of Lazy Singleton, the service will not be instantiated until it is requested for the first time, which is useful for services that are expensive to construct.&lt;/p&gt;

&lt;p&gt;That's a basic example of how to use get_it in a Flutter app. You can also use the package to register and retrieve factory functions, non-singleton objects, and more. For more advanced usage, refer to the package's documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are singletons?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A singleton is a design pattern that ensures that a class has only one instance, while providing a global access point to that instance. This means that any time the singleton class is called, the same instance of the class is returned.&lt;/p&gt;

&lt;p&gt;The singleton pattern is often used when a single instance of a class needs to coordinate actions across the system. For example, a logging service, or a configuration manager, would be good candidates for the singleton pattern.&lt;/p&gt;

&lt;p&gt;In Dart and Flutter, you can implement a singleton by making the constructor private, and exposing a static instance getter method. However, the get_it package provides a more convenient way to implement singletons by registering and retrieving singletons via its API.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are factory instances?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A factory instance is a way to create an object in a consistent way, without specifying the exact type of the object that will be created. This is done by defining a factory method, which is a function that creates and returns an object, typically based on some input.&lt;/p&gt;

&lt;p&gt;A factory method is different from a constructor in that it doesn't have to create a new instance of the class every time it's called. Instead, it can return the same instance multiple times, or return a new instance based on some logic.&lt;/p&gt;

&lt;p&gt;In Dart and Flutter, you can create factory instances by defining a static factory method on a class or by using get_it package's registerFactory method.&lt;/p&gt;

&lt;p&gt;Here's an example of how to create factory instance using get_it package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;getIt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;registerFactory&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;MyService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;MyService&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this factory, every time you call getIt.get() it will call the factory function and return a new instance of MyService.&lt;/p&gt;

&lt;p&gt;Factory instances can be useful in cases where you want to return a new instance of a class based on some condition, or where you want to return a different implementation of an interface depending on the context.&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>programming</category>
      <category>dart</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
