<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Dammak Blog]]></title><description><![CDATA[Damola Adekoya Blog on mobile, web and desktop development]]></description><link>https://blog.dammak.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 02:51:54 GMT</lastBuildDate><atom:link href="https://blog.dammak.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Mastering the Singleton Pattern in Dart]]></title><description><![CDATA[Picture this: You're building a Flutter app for a food delivery service. Your app needs to track user analytics, manage configuration settings, handle API calls, and maintain a logging system. Without proper architecture, you might end up creating mu...]]></description><link>https://blog.dammak.dev/mastering-the-singleton-pattern-in-dart</link><guid isPermaLink="true">https://blog.dammak.dev/mastering-the-singleton-pattern-in-dart</guid><category><![CDATA[design patterns]]></category><category><![CDATA[Dart]]></category><category><![CDATA[Flutter]]></category><category><![CDATA[Software Engineering]]></category><dc:creator><![CDATA[Damola Adekoya]]></dc:creator><pubDate>Mon, 16 Jun 2025 06:29:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1750055324870/f83b1e47-1a09-42b1-b4ef-b1ed40fe48cb.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Picture this: You're building a Flutter app for a food delivery service. Your app needs to track user analytics, manage configuration settings, handle API calls, and maintain a logging system. Without proper architecture, you might end up creating multiple instances of these services throughout your app, leading to inconsistent data, memory waste, and debugging nightmares.</p>
<p>I learned this the hard way during my first major Flutter project. I had analytics data scattered across different instances, configuration settings that somehow got out of sync between screens, and log files that were being written to from multiple places simultaneously. The result? A buggy app with memory leaks and data inconsistencies that took weeks to untangle. This is where the Singleton design pattern becomes your best friend. It's like having a single, trusted manager for critical services in your app – ensuring there's only one instance of important classes and providing global access to them.</p>
<h2 id="heading-what-is-the-singleton-pattern">What is the Singleton Pattern?</h2>
<p>The Singleton pattern is one of the most well-known design patterns in software engineering. At its core, it's deceptively simple: ensure a class has only one instance and provide a global point of access to that instance. Think of it like having a single CEO in a company. No matter how many departments need to communicate with the CEO, there's only one person in that role. Similarly, a Singleton ensures that no matter how many parts of your app need access to a particular service, there's only one instance of that service running.</p>
<h3 id="heading-when-to-use-singleton-the-good-times">When to Use Singleton (The Good Times)</h3>
<p>The Singleton pattern shines in several specific scenarios:</p>
<ol>
<li><p>Shared Resources Management When you need to manage access to shared resources like files, network connections, or hardware devices, Singleton ensures coordinated access and prevents conflicts.</p>
</li>
<li><p>Configuration Management Application settings and configuration data typically need to be consistent across your entire app. A Singleton configuration manager ensures all parts of your app access the same settings.</p>
</li>
<li><p>Logging Services Centralized logging is crucial for debugging and monitoring. A Singleton logger ensures all log entries go through the same service, maintaining consistency and proper file handling.</p>
</li>
<li><p>Caching Systems Cache managers need to maintain a single source of truth for cached data. Multiple cache instances could lead to inconsistent data and memory waste.</p>
</li>
<li><p>Service Locators When implementing service locator patterns, you typically want a single registry that manages and provides access to various services.</p>
</li>
</ol>
<h3 id="heading-when-to-avoid-singleton-the-dark-side">When to Avoid Singleton (The Dark Side)</h3>
<p>Despite its usefulness, Singleton can become problematic when overused:</p>
<ol>
<li><p>Testing Difficulties Singletons create global state, making unit testing challenging. They can introduce dependencies between tests and make it difficult to isolate components.</p>
</li>
<li><p>Hidden Dependencies When classes use Singletons directly, it's not immediately obvious what dependencies they have, making the code harder to understand and maintain.</p>
</li>
<li><p>Tight Coupling Overuse of Singletons can lead to tightly coupled code where classes depend directly on specific implementations rather than abstractions.</p>
</li>
<li><p>Concurrent Access Issues In multi-threaded environments, Singletons can introduce race conditions and require careful synchronization.</p>
</li>
<li><p>Violating Single Responsibility Principle Singletons often end up doing too much, violating the single responsibility principle and becoming "god objects."</p>
</li>
</ol>
<h2 id="heading-implementing-singleton-in-dart-a-complete-example">Implementing Singleton in Dart: A Complete Example</h2>
<pre><code class="lang-dart"><span class="hljs-keyword">enum</span> LogLevel { debug, info, warning, error }

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Logger</span> </span>{
  <span class="hljs-comment">// Singleton instance</span>
  <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Logger _instance = Logger._internal();

  <span class="hljs-comment">// Private constructor</span>
  Logger._internal();

  <span class="hljs-comment">// Factory constructor returns the same instance every time</span>
  <span class="hljs-keyword">factory</span> Logger() =&gt; _instance;

  <span class="hljs-keyword">void</span> log(<span class="hljs-built_in">String</span> message, [LogLevel level = LogLevel.info]) {
    <span class="hljs-keyword">final</span> timestamp = <span class="hljs-built_in">DateTime</span>.now().toIso8601String();
    <span class="hljs-keyword">final</span> levelStr = level.toString().split(<span class="hljs-string">'.'</span>).last.toUpperCase();
    <span class="hljs-built_in">print</span>(<span class="hljs-string">'[<span class="hljs-subst">$timestamp</span>] [<span class="hljs-subst">$levelStr</span>] <span class="hljs-subst">$message</span>'</span>);
  }
}
</code></pre>
<h2 id="heading-understanding-the-implementation">Understanding the Implementation</h2>
<p>Let's break down the key components of our Singleton implementation:</p>
<p><strong>1. Private Constructor</strong> The <code>Logger._internal()</code> constructor is private, preventing external instantiation of the class. This is crucial for maintaining the singleton guarantee.</p>
<p><strong>2. Factory Constructor</strong> The <code>factory Logger()</code> constructor is the public interface for getting the singleton instance. It checks if an instance already exists and creates one only if necessary.</p>
<p><strong>3. Static Instance Variable</strong> The <code>_instance</code> variable holds the single instance of the class. It's nullable initially and gets initialized on first access.</p>
<p><strong>4. Thread Safety Considerations</strong> In Dart, the null-aware assignment operator (<code>??=</code>) provides basic thread safety for singleton creation. However, for more complex scenarios, you might need additional synchronization mechanisms.</p>
<h3 id="heading-alternative-singleton-implementations-in-dart">Alternative Singleton Implementations in Dart</h3>
<p><strong>1. Eager Initialization</strong></p>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EagerSingleton</span> </span>{
  <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> EagerSingleton _instance = EagerSingleton._internal();

  EagerSingleton._internal();

  <span class="hljs-keyword">factory</span> EagerSingleton() =&gt; _instance;
}
</code></pre>
<p><strong>2. Using Static Final</strong></p>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StaticSingleton</span> </span>{
  <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> StaticSingleton instance = StaticSingleton._internal();

  StaticSingleton._internal();
}
</code></pre>
<p><strong>3. With Async Initialization</strong></p>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncSingleton</span> </span>{
  <span class="hljs-keyword">static</span> AsyncSingleton? _instance;
  <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Completer&lt;AsyncSingleton&gt; _completer = Completer&lt;AsyncSingleton&gt;();

  AsyncSingleton._internal();

  <span class="hljs-keyword">static</span> Future&lt;AsyncSingleton&gt; getInstance() <span class="hljs-keyword">async</span> {
    <span class="hljs-keyword">if</span> (_instance == <span class="hljs-keyword">null</span>) {
      _instance = AsyncSingleton._internal();
      <span class="hljs-keyword">await</span> _instance!._initialize();
      _completer.complete(_instance);
    }
    <span class="hljs-keyword">return</span> _completer.future;
  }

  Future&lt;<span class="hljs-keyword">void</span>&gt; _initialize() <span class="hljs-keyword">async</span> {
    <span class="hljs-comment">// Perform async initialization</span>
    <span class="hljs-keyword">await</span> Future.delayed(<span class="hljs-built_in">Duration</span>(seconds: <span class="hljs-number">1</span>));
  }
}
</code></pre>
<h2 id="heading-common-misuse-patterns">Common Misuse Patterns</h2>
<h3 id="heading-1-the-everything-is-a-singleton-anti-pattern">1. The "Everything is a Singleton" Anti-pattern</h3>
<p>I've seen developers make every service class a Singleton, thinking it's always better to have one instance. This leads to tightly coupled, hard-to-test code.</p>
<p><strong>Bad Example:</strong></p>
<pre><code class="lang-dart"><span class="hljs-comment">// Don't do this!</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserService</span> </span>{
  <span class="hljs-keyword">static</span> UserService? _instance;
  UserService._internal();
  <span class="hljs-keyword">factory</span> UserService() =&gt; _instance ??= UserService._internal();
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ProductService</span> </span>{
  <span class="hljs-keyword">static</span> ProductService? _instance;
  ProductService._internal();
  <span class="hljs-keyword">factory</span> ProductService() =&gt; _instance ??= ProductService._internal();
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CartService</span> </span>{
  <span class="hljs-keyword">static</span> CartService? _instance;
  CartService._internal();
  <span class="hljs-keyword">factory</span> CartService() =&gt; _instance ??= CartService._internal();
}
</code></pre>
<h3 id="heading-2-singleton-as-a-glorified-global-variable">2. Singleton as a Glorified Global Variable</h3>
<p>Using Singleton just to avoid passing parameters is a code smell. If you're not truly ensuring single instance semantics, you're probably misusing the pattern.</p>
<h3 id="heading-3-mutable-singleton-state">3. Mutable Singleton State</h3>
<p>Making Singleton instances heavily mutable can lead to unexpected behavior and debugging nightmares.</p>
<h3 id="heading-4-ignoring-disposal-and-cleanup">4. Ignoring Disposal and Cleanup</h3>
<p>Not properly managing resources in Singletons can lead to memory leaks and resource exhaustion.</p>
<h2 id="heading-best-practices-for-singleton-in-dart">Best Practices for Singleton in Dart</h2>
<h3 id="heading-1-use-dependency-injection-when-possible">1. Use Dependency Injection When Possible</h3>
<p>Instead of accessing Singletons directly, consider using dependency injection frameworks like <code>get_it</code> or <code>provider</code>.</p>
<pre><code class="lang-dart"><span class="hljs-comment">// Using get_it for dependency injection</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:get_it/get_it.dart'</span>;

<span class="hljs-keyword">final</span> getIt = GetIt.instance;

<span class="hljs-keyword">void</span> setupDependencies() {
  getIt.registerSingleton&lt;Logger&gt;(Logger());
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OrderService</span> </span>{
  <span class="hljs-keyword">final</span> Logger logger;
  OrderService({<span class="hljs-keyword">required</span> <span class="hljs-keyword">this</span>.logger});
}
</code></pre>
<h3 id="heading-2-make-singletons-immutable-when-possible">2. Make Singletons Immutable When Possible</h3>
<p>If your Singleton doesn't need to change state, make it immutable.</p>
<h3 id="heading-3-provide-clear-disposal-methods">3. Provide Clear Disposal Methods</h3>
<p>Always provide ways to clean up resources:</p>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">DatabaseService</span> </span>{
  <span class="hljs-comment">// ... singleton implementation</span>

  Future&lt;<span class="hljs-keyword">void</span>&gt; dispose() <span class="hljs-keyword">async</span> {
    <span class="hljs-keyword">await</span> _connection?.close();
    _instance = <span class="hljs-keyword">null</span>;
  }
}
</code></pre>
<h3 id="heading-4-consider-using-abstract-interfaces">4. Consider Using Abstract Interfaces</h3>
<p>Make your Singletons implement interfaces to improve testability:</p>
<pre><code class="lang-dart"><span class="hljs-keyword">abstract</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ILogger</span> </span>{
  <span class="hljs-keyword">void</span> info(<span class="hljs-built_in">String</span> message);
  <span class="hljs-keyword">void</span> error(<span class="hljs-built_in">String</span> message);
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Logger</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">ILogger</span> </span>{
  <span class="hljs-comment">// ... singleton implementation</span>
}
</code></pre>
<h3 id="heading-5-document-singleton-behavior">5. Document Singleton Behavior</h3>
<p>Always document why a class is a Singleton and what guarantees it provides.</p>
<h2 id="heading-testing-strategies-for-singletons">Testing Strategies for Singletons</h2>
<h3 id="heading-1-reset-between-tests">1. Reset Between Tests</h3>
<pre><code class="lang-dart"><span class="hljs-keyword">void</span> main() {
  tearDown(() {
    <span class="hljs-comment">// Reset singleton state between tests</span>
    Logger.instance.clearLogs();
  });
}
</code></pre>
<h3 id="heading-2-use-dependency-injection-for-testing">2. Use Dependency Injection for Testing</h3>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TestableOrderService</span> </span>{
  <span class="hljs-keyword">final</span> ILogger logger;
  TestableOrderService(<span class="hljs-keyword">this</span>.logger);
}
</code></pre>
<h3 id="heading-3-mock-singletons">3. Mock Singletons</h3>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MockLogger</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">ILogger</span> </span>{
  <span class="hljs-keyword">final</span> <span class="hljs-built_in">List</span>&lt;<span class="hljs-built_in">String</span>&gt; logs = [];

  <span class="hljs-meta">@override</span>
  <span class="hljs-keyword">void</span> info(<span class="hljs-built_in">String</span> message) =&gt; logs.add(<span class="hljs-string">'INFO: <span class="hljs-subst">$message</span>'</span>);

  <span class="hljs-meta">@override</span>
  <span class="hljs-keyword">void</span> error(<span class="hljs-built_in">String</span> message) =&gt; logs.add(<span class="hljs-string">'ERROR: <span class="hljs-subst">$message</span>'</span>);
}
</code></pre>
<h2 id="heading-real-world-considerations">Real-world Considerations</h2>
<p>In production Flutter apps, I've found that Singleton works well for:</p>
<ul>
<li><p><strong>Analytics services</strong> - You want all events going through the same tracking instance</p>
</li>
<li><p><strong>Configuration managers</strong> - App settings should be consistent everywhere</p>
</li>
<li><p><strong>Cache managers</strong> - Shared cache state across the app</p>
</li>
<li><p><strong>Network clients</strong> - Reusing HTTP clients and connection pools</p>
</li>
</ul>
<p>However, I avoid Singleton for:</p>
<ul>
<li><p><strong>Business logic services</strong> - These should be injected dependencies</p>
</li>
<li><p><strong>UI state management</strong> - Use proper state management solutions</p>
</li>
<li><p><strong>Data repositories</strong> - These benefit from dependency injection for testing</p>
</li>
</ul>
<h2 id="heading-performance-considerations">Performance Considerations</h2>
<p>From my experience with Flutter apps, Singletons can improve performance by:</p>
<ul>
<li><p>Reducing object creation overhead</p>
</li>
<li><p>Sharing expensive resources like network connections</p>
</li>
<li><p>Maintaining cache state across the application</p>
</li>
</ul>
<p>However, they can hurt performance if:</p>
<ul>
<li><p>They hold onto large amounts of memory</p>
</li>
<li><p>They prevent garbage collection of unused resources</p>
</li>
<li><p>They create bottlenecks in multi-threaded scenarios</p>
</li>
</ul>
<h3 id="heading-conclusion">Conclusion</h3>
<p>The Singleton pattern is a powerful tool that, like any tool, can be both helpful and harmful depending on how it's used. In Dart and Flutter development, it's particularly useful for managing shared resources, configuration, and services that truly benefit from having a single instance. The key is restraint. Not every class needs to be a Singleton, and global state should be used judiciously. When you do use Singleton, implement it properly with consideration for testing, resource management, and long-term maintainability. Remember that modern dependency injection frameworks often provide better alternatives to direct Singleton usage, offering the benefits of single instances while maintaining testability and loose coupling. As with any design pattern, the goal isn't to use Singleton everywhere, but to recognize when it's the right tool for the job and implement it thoughtfully.</p>
<p><strong>Coming up next:</strong> In our next article, we'll explore the Factory design pattern in Dart. We'll see how Factory methods can help you create objects without specifying their exact classes, making your code more flexible and easier to extend. We'll build a practical example showing how to create different types of payment processors for our food delivery app, and discuss when Factory patterns shine compared to simple constructors. Stay tuned!</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Design Patterns: Why Dart Developers Should Care]]></title><description><![CDATA[Introduction
If you've ever built a moderately complex Flutter app, you've probably hit that moment where everything starts to feel... messy. Maybe your state management is tangled, your service classes are doing too much, or you're duplicating logic...]]></description><link>https://blog.dammak.dev/understanding-design-patterns-why-dart-developers-should-care</link><guid isPermaLink="true">https://blog.dammak.dev/understanding-design-patterns-why-dart-developers-should-care</guid><category><![CDATA[Beginner Developers]]></category><category><![CDATA[architecture]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[Dart]]></category><category><![CDATA[Flutter]]></category><category><![CDATA[Developer]]></category><category><![CDATA[software development]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[Blogging]]></category><dc:creator><![CDATA[Damola Adekoya]]></dc:creator><pubDate>Sat, 31 May 2025 19:37:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1748719608708/2f066e9e-7508-4d4d-be37-d38a2b997ac0.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>If you've ever built a moderately complex Flutter app, you've probably hit that moment where everything starts to feel... messy. Maybe your state management is tangled, your service classes are doing too much, or you're duplicating logic in multiple places. As the codebase grows, so does the pain.</p>
<p>These are signs of architectural drift — when a once-clear structure begins to dissolve under the weight of new features and rushed fixes. The good news? You're not alone, and there's a tried-and-true set of solutions to help: design patterns.</p>
<p>Design patterns aren’t magic wands or rigid blueprints. They're reusable solutions to common software design problems — kind of like best practices distilled into patterns. And yes, they absolutely apply to Dart and Flutter.</p>
<p>Let’s explore why design patterns are worth your time as a Dart developer, how they show up in real-world Flutter apps, and how they can make your architecture cleaner, leaner, and more maintainable.</p>
<h2 id="heading-what-are-design-patterns">What Are Design Patterns?</h2>
<p>In plain terms, design patterns are general solutions to recurring problems in software design. They’re not chunks of copy-pasteable code but more like conceptual guides or best practices you can implement in different contexts.</p>
<p>The idea gained popularity through the Gang of Four (Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides), who documented 23 classic patterns grouped into three categories:</p>
<p>Creational Patterns – Deal with object creation logic.</p>
<p>Structural Patterns – Deal with object composition and relationships.</p>
<p>Behavioral Patterns – Deal with communication between objects.</p>
<p>Design patterns are language-agnostic, but can and should be adapted idiomatically in Dart — especially with Flutter’s component-driven architecture and reactive programming style.</p>
<h2 id="heading-why-dart-developers-should-care">Why Dart Developers Should Care</h2>
<p>Flutter allows you to build rich UIs quickly, but without good structure, things can spiral fast. As your app grows, features become harder to isolate, test, and debug.</p>
<p>Here’s how design patterns help:</p>
<ul>
<li><p>Maintainability – Changes are easier when responsibilities are clearly separated.</p>
</li>
<li><p>Reusability – Patterns can be reused across different projects or parts of the app.</p>
</li>
<li><p>Scalability – Your codebase remains structured even as it grows.</p>
</li>
<li><p>Separation of Concerns – Business logic, data layers, and UI are decoupled.</p>
</li>
</ul>
<h3 id="heading-example-problem">Example Problem</h3>
<p>You might start by making network calls directly inside your widgets. Then, business logic spreads everywhere. When the backend changes or you need to cache data locally, your only option is a painful refactor. A Repository or Facade pattern would have saved the day.</p>
<p>Categories of Design Patterns (With Dart/Flutter Examples)</p>
<ul>
<li><strong>Creational Patterns</strong></li>
</ul>
<p>How objects are created in a flexible, scalable way.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Pattern</td><td>Description</td><td>Flutter Use Case</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Singleton</strong></td><td>Ensures a class has only one instance and provides a global point of access to it.</td><td>Services like logging, analytics, or <code>SharedPreferences</code> wrapper.</td></tr>
<tr>
<td><strong>Factory Method</strong></td><td>Creates objects without specifying the exact class of object that will be created.</td><td>Dynamic widget creation based on user type or feature flags.</td></tr>
<tr>
<td><strong>Builder</strong></td><td>Constructs a complex object step-by-step.</td><td>Building configurable dialogs or complex UI from simpler components.</td></tr>
<tr>
<td><strong>Abstract Factory</strong></td><td>Provides an interface for creating families of related objects.</td><td>Theme switching between light and dark UI widgets.</td></tr>
<tr>
<td><strong>Prototype</strong></td><td>Creates new objects by cloning an existing object.</td><td>Repeating configurations like custom button styles. <em>(less common in Dart)</em></td></tr>
</tbody>
</table>
</div><ul>
<li><strong>Structural Patterns</strong> How objects and classes are composed to form larger structures.</li>
</ul>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Pattern</td><td>Description</td><td>Flutter Use Case</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Facade</strong></td><td>Provides a simplified interface to a complex system.</td><td>Combining Firebase Auth, Google Sign-In, and database logic under one AuthService.</td></tr>
<tr>
<td><strong>Decorator</strong></td><td>Dynamically adds behavior to an object without changing its structure.</td><td>Enhancing widgets by wrapping them in <code>Padding</code>, <code>Container</code>, etc.</td></tr>
<tr>
<td><strong>Adapter</strong></td><td>Converts one interface into another that clients expect.</td><td>Adapting a REST API model to a local database model.</td></tr>
<tr>
<td><strong>Bridge</strong></td><td>Separates abstraction from implementation so they can vary independently.</td><td>Abstracting business logic from different data sources (e.g., remote vs local).</td></tr>
<tr>
<td><strong>Composite</strong></td><td>Treats individual objects and compositions uniformly.</td><td>Building nested menu structures or UI trees.</td></tr>
<tr>
<td><strong>Proxy</strong></td><td>Provides a surrogate or placeholder for another object to control access.</td><td>Caching images or controlling access to network calls.</td></tr>
</tbody>
</table>
</div><ul>
<li><strong>Behavioral Patterns</strong> How objects communicate and responsibilities are assigned.</li>
</ul>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Pattern</td><td>Description</td><td>Flutter Use Case</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Observer</strong></td><td>Allows an object to notify other objects when its state changes.</td><td><code>ValueNotifier</code>, <code>Stream</code>, <code>Bloc</code>, or <code>Provider</code> for state management.</td></tr>
<tr>
<td><strong>Strategy</strong></td><td>Defines a family of algorithms, encapsulates each one, and makes them interchangeable.</td><td>Switching sorting or filtering strategies in a product list.</td></tr>
<tr>
<td><strong>Command</strong></td><td>Encapsulates a request as an object.</td><td>Undo/redo operations in a form or drawing app.</td></tr>
<tr>
<td><strong>Mediator</strong></td><td>Encapsulates communication between objects to reduce dependencies.</td><td>Centralizing UI interaction logic in a controller or service.</td></tr>
<tr>
<td><strong>State</strong></td><td>Allows an object to alter its behavior when its internal state changes.</td><td>Managing page or tab view states in an onboarding flow.</td></tr>
<tr>
<td><strong>Iterator</strong></td><td>Provides a way to access elements of a collection sequentially.</td><td>Custom list views or carousel components.</td></tr>
<tr>
<td><strong>Chain of Responsibility</strong></td><td>Passes a request along a chain until it's handled.</td><td>Form field validation pipelines.</td></tr>
</tbody>
</table>
</div><h3 id="heading-real-world-use-cases-in-dartflutter">Real-world Use Cases in Dart/Flutter</h3>
<p>Let’s zoom into a few Dart-specific examples:</p>
<h3 id="heading-singleton-for-app-wide-services">Singleton for app-wide services</h3>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AuthService</span> </span>{
  <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> AuthService _instance = AuthService._internal();
  <span class="hljs-keyword">factory</span> AuthService() =&gt; _instance;
  AuthService._internal();

  User? _currentUser;
  <span class="hljs-built_in">bool</span> <span class="hljs-keyword">get</span> isAuthenticated =&gt; _currentUser != <span class="hljs-keyword">null</span>;

  Future&lt;<span class="hljs-keyword">void</span>&gt; login(<span class="hljs-built_in">String</span> email, <span class="hljs-built_in">String</span> password) {
    <span class="hljs-comment">// Login implementation</span>
  }
}
</code></pre>
<h3 id="heading-factory-for-widget-creation">Factory for widget creation</h3>
<pre><code class="lang-dart"><span class="hljs-keyword">abstract</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ButtonFactory</span> </span>{
  Widget createButton(ButtonType type, <span class="hljs-built_in">String</span> text, VoidCallback onPressed);
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MaterialButtonFactory</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">ButtonFactory</span> </span>{
  <span class="hljs-meta">@override</span>
  Widget createButton(ButtonType type, <span class="hljs-built_in">String</span> text, VoidCallback onPressed) {
    <span class="hljs-keyword">switch</span> (type) {
      <span class="hljs-keyword">case</span> ButtonType.primary:
        <span class="hljs-keyword">return</span> ElevatedButton(onPressed: onPressed, child: Text(text));
      <span class="hljs-keyword">case</span> ButtonType.secondary:
        <span class="hljs-keyword">return</span> OutlinedButton(onPressed: onPressed, child: Text(text));
      <span class="hljs-keyword">case</span> ButtonType.text:
        <span class="hljs-keyword">return</span> TextButton(onPressed: onPressed, child: Text(text));
    }
  }
}
</code></pre>
<h3 id="heading-observer-via-valuenotifier-or-stream">Observer via ValueNotifier or Stream</h3>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CounterNotifier</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">ValueNotifier</span>&lt;<span class="hljs-title">int</span>&gt; </span>{
  CounterNotifier() : <span class="hljs-keyword">super</span>(<span class="hljs-number">0</span>);

  <span class="hljs-keyword">void</span> increment() {
    value++;
  }

  <span class="hljs-keyword">void</span> decrement() {
    value--;
  }
}

<span class="hljs-comment">// Usage in widget</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CounterWidget</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  <span class="hljs-keyword">final</span> CounterNotifier counter;

  <span class="hljs-meta">@override</span>
  Widget build(BuildContext context) {
    <span class="hljs-keyword">return</span> ValueListenableBuilder&lt;<span class="hljs-built_in">int</span>&gt;(
      valueListenable: counter,
      builder: (context, count, child) {
        <span class="hljs-keyword">return</span> Text(<span class="hljs-string">'Count: <span class="hljs-subst">$count</span>'</span>);
      },
    );
  }
}
</code></pre>
<h3 id="heading-facade-to-simplify-complex-apis">Facade to simplify complex APIs</h3>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UserFacade</span> </span>{
  <span class="hljs-keyword">final</span> ApiService _apiService;
  <span class="hljs-keyword">final</span> DatabaseService _dbService;
  <span class="hljs-keyword">final</span> CacheService _cacheService;

  UserFacade(<span class="hljs-keyword">this</span>._apiService, <span class="hljs-keyword">this</span>._dbService, <span class="hljs-keyword">this</span>._cacheService);

  Future&lt;User&gt; getUser(<span class="hljs-built_in">String</span> id) <span class="hljs-keyword">async</span> {
    <span class="hljs-comment">// Try cache first</span>
    <span class="hljs-keyword">final</span> cachedUser = <span class="hljs-keyword">await</span> _cacheService.getUser(id);
    <span class="hljs-keyword">if</span> (cachedUser != <span class="hljs-keyword">null</span>) <span class="hljs-keyword">return</span> cachedUser;

    <span class="hljs-comment">// Try local database</span>
    <span class="hljs-keyword">final</span> dbUser = <span class="hljs-keyword">await</span> _dbService.getUser(id);
    <span class="hljs-keyword">if</span> (dbUser != <span class="hljs-keyword">null</span>) {
      <span class="hljs-keyword">await</span> _cacheService.setUser(dbUser);
      <span class="hljs-keyword">return</span> dbUser;
    }

    <span class="hljs-comment">// Fetch from API</span>
    <span class="hljs-keyword">final</span> apiUser = <span class="hljs-keyword">await</span> _apiService.fetchUser(id);
    <span class="hljs-keyword">await</span> _dbService.saveUser(apiUser);
    <span class="hljs-keyword">await</span> _cacheService.setUser(apiUser);
    <span class="hljs-keyword">return</span> apiUser;
  }
}
</code></pre>
<h3 id="heading-decorator-to-enhance-ui-widgets">Decorator to enhance UI widgets</h3>
<pre><code class="lang-dart"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">LoadingDecorator</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  <span class="hljs-keyword">final</span> Widget child;
  <span class="hljs-keyword">final</span> <span class="hljs-built_in">bool</span> isLoading;

  <span class="hljs-keyword">const</span> LoadingDecorator({
    <span class="hljs-keyword">required</span> <span class="hljs-keyword">this</span>.child,
    <span class="hljs-keyword">required</span> <span class="hljs-keyword">this</span>.isLoading,
  });

  <span class="hljs-meta">@override</span>
  Widget build(BuildContext context) {
    <span class="hljs-keyword">return</span> Stack(
      children: [
        child,
        <span class="hljs-keyword">if</span> (isLoading)
          Container(
            color: Colors.black26,
            child: Center(child: CircularProgressIndicator()),
          ),
      ],
    );
  }
}
</code></pre>
<h2 id="heading-design-patterns-and-clean-architecture">Design Patterns and Clean Architecture</h2>
<p>Clean Architecture emphasizes separation of concerns: UI, business logic, and data handling should live in distinct layers. Here’s how design patterns help:</p>
<p>Use Cases: Implemented using the Command or Strategy pattern to isolate logic.</p>
<p>Repositories: Abstract data sources using Factory, Facade, or Adapter patterns.</p>
<p>UI: Uses Observer or State patterns to react to changes.</p>
<p>The result? Code that’s easier to test, maintain, and expand.</p>
<h2 id="heading-misconceptions-and-anti-patterns">Misconceptions and Anti-patterns</h2>
<ol>
<li><p>“Design patterns are too heavy.” No, they’re lightweight guidelines when used correctly. Use what makes sense — and keep it simple.</p>
</li>
<li><p>Overusing Singleton Not everything should be globally available. Overuse leads to tight coupling and poor testability.</p>
</li>
<li><p>Forcing patterns unnecessarily Don’t use a pattern just because you can. Apply them where there’s a clear need.</p>
</li>
</ol>
<h2 id="heading-series-preview-whats-coming-next">Series Preview / What’s Coming Next</h2>
<p>This article kicks off a deep-dive series into Design Patterns in Dart/Flutter, where we’ll explore:</p>
<p>🔹 Creational Patterns – Singleton, Factory, Builder</p>
<p>🔹 Structural Patterns – Adapter, Facade, Decorator</p>
<p>🔹 Behavioral Patterns – Observer, Strategy, State</p>
<p>Each pattern will include:</p>
<ul>
<li><p>Real Dart/Flutter code</p>
</li>
<li><p>Practical use cases</p>
</li>
<li><p>When to use (and when not to)</p>
</li>
<li><p>Common mistakes</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Whether you're building a side project or leading a team on a production app, design patterns help you write cleaner, more scalable, and easier-to-understand Dart code.</p>
<p>They’re not academic fluff — they’re proven tools used by seasoned developers across industries.</p>
<p>💬 Now it’s your turn:</p>
<ul>
<li><p>Follow the series</p>
</li>
<li><p>Share your favorite pattern</p>
</li>
<li><p>Or suggest one you’d love to see covered next</p>
</li>
<li><p>Let’s build apps that don’t just work — but scale beautifully.</p>
</li>
</ul>
<p>See you in the next article! 💙</p>
]]></content:encoded></item><item><title><![CDATA[How to run your flutter app on multiple emulator devices using vscode]]></title><description><![CDATA[Flutter is a cross-platform mobile framework i.e its support for Android, iOS, macOS, Window, Linux e.t.c, developing flutter is so fascinating that you get to write once and run on all platforms. in this post, I will be showing how to run more than ...]]></description><link>https://blog.dammak.dev/how-to-run-your-flutter-app-on-multiple-emulator-devices-using-vscode</link><guid isPermaLink="true">https://blog.dammak.dev/how-to-run-your-flutter-app-on-multiple-emulator-devices-using-vscode</guid><category><![CDATA[Flutter]]></category><category><![CDATA[flutter]]></category><category><![CDATA[Visual Studio Code]]></category><category><![CDATA[Android]]></category><category><![CDATA[iOS]]></category><dc:creator><![CDATA[Damola Adekoya]]></dc:creator><pubDate>Fri, 28 Aug 2020 16:43:14 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1598632938133/ZLn4S_mYE.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Flutter is a cross-platform mobile framework i.e its support for Android, iOS, macOS, Window, Linux e.t.c, developing flutter is so fascinating that you get to write once and run on all platforms. in this post, I will be showing how to run more than one emulator concurrently using Visual studio code, by default you can only run a single emulator at a time on a project. Thanks to super-fast hot reload and restart feature of flutter which makes development experience faster and better. But it would have been better if you can be testing/debugging your application as you are developing on all platform's devices without you have to wait for one device.</p>
<h2 id="steps">Steps</h2>
<ul>
<li>Create different emulator devices you want to run your application on. e.g iOS devices, Android device</li>
</ul>
<p>NB: I won't be showing how to create emulator devices, follow below link on how to create the emulator</p>
<p> <a target="_blank" href="https://grinchik.com/blog/how-to-install-ios-simulator-and-android-emulator-on-mac/">How to create Android and iOS emulator device</a> .</p>
<ul>
<li><p>Make sure all the devices are launched.i.e all devices for iOS and Android.</p>
</li>
<li><p>Get ID for all your devices, to get the device id run <code>flutter devices</code> on your terminal to get your device id. [screenshot below]</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1589134834356/POTEo31RS.png" alt="Screenshot 2020-05-10 at 7.18.03 PM.png" /></p>
<ul>
<li>Create a launch configuration setting for your flutter project. [screenshot below]</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1589137863580/x-TAbnlk_.png" alt="Screenshot 2020-05-10 at 6.53.34 PM.png" /></p>
<ul>
<li>Create a device profile for each of the devices in the launch.json</li>
</ul>
<pre><code>{
      "<span class="hljs-attr">name</span>": <span class="hljs-string">"iPad Pro"</span>,
      "<span class="hljs-attr">request</span>": <span class="hljs-string">"launch"</span>,
      "<span class="hljs-attr">type</span>": <span class="hljs-string">"dart"</span>,
      "<span class="hljs-attr">deviceId</span>": <span class="hljs-string">"CE96E50B-A047-40D9-9921-1359CA2CF231"</span>

}
</code></pre><p>NB:
name is the profile name i.e device name although it can be any name. 
below is the sample configuration setting for my flutter app</p>
<pre><code>{
  <span class="hljs-comment">// Use IntelliSense to learn about possible attributes.</span>
  <span class="hljs-comment">// Hover to view descriptions of existing attributes.</span>
  <span class="hljs-comment">// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387</span>
  <span class="hljs-string">"version"</span>: <span class="hljs-string">"0.2.0"</span>,
  <span class="hljs-string">"configurations"</span>: [
    {
      <span class="hljs-string">"name"</span>: <span class="hljs-string">"Flutter"</span>,
      <span class="hljs-string">"request"</span>: <span class="hljs-string">"launch"</span>,
      <span class="hljs-string">"type"</span>: <span class="hljs-string">"dart"</span>
    },
    {
      <span class="hljs-string">"name"</span>: <span class="hljs-string">"Android"</span>,
      <span class="hljs-string">"request"</span>: <span class="hljs-string">"launch"</span>,
      <span class="hljs-string">"type"</span>: <span class="hljs-string">"dart"</span>,
      <span class="hljs-string">"deviceId"</span>: <span class="hljs-string">"emulator-5554"</span>
    },
    {
      <span class="hljs-string">"name"</span>: <span class="hljs-string">"iPhone"</span>,
      <span class="hljs-string">"request"</span>: <span class="hljs-string">"launch"</span>,
      <span class="hljs-string">"type"</span>: <span class="hljs-string">"dart"</span>,
      <span class="hljs-string">"deviceId"</span>: <span class="hljs-string">"iPhone"</span>
    },
    {
      <span class="hljs-string">"name"</span>: <span class="hljs-string">"iPad Pro"</span>,
      <span class="hljs-string">"request"</span>: <span class="hljs-string">"launch"</span>,
      <span class="hljs-string">"type"</span>: <span class="hljs-string">"dart"</span>,
      <span class="hljs-string">"deviceId"</span>: <span class="hljs-string">"CE96E50B-A047-40D9-9921-1359CA2CF231"</span>
    }
  ],
  <span class="hljs-string">"compounds"</span>: [
    {
      <span class="hljs-string">"name"</span>: <span class="hljs-string">"All Devices"</span>,
      <span class="hljs-string">"configurations"</span>: [<span class="hljs-string">"Android"</span>, <span class="hljs-string">"iPhone"</span>, <span class="hljs-string">"iPad Pro"</span>]
    }
  ]
}
</code></pre><ul>
<li><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1589135855993/Rhtru9sq2.png" alt="Screenshot 2020-05-10 at 7.36.17 PM.png" /></li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Top 10 Youtube channels for Flutter developers (2020)]]></title><description><![CDATA[It's 2020 and the rate in which Flutter is trending is increasing exponentially, and learning can be difficult if people are not been pointed to the right resources. With the below-curated list of the youtube channel, I believe it will help flutter d...]]></description><link>https://blog.dammak.dev/top-10-youtube-channels-for-flutter-developers-2020</link><guid isPermaLink="true">https://blog.dammak.dev/top-10-youtube-channels-for-flutter-developers-2020</guid><category><![CDATA[Flutter]]></category><category><![CDATA[iOS]]></category><category><![CDATA[Android]]></category><category><![CDATA[Mobile Development]]></category><category><![CDATA[flutter]]></category><dc:creator><![CDATA[Damola Adekoya]]></dc:creator><pubDate>Tue, 07 Jan 2020 16:31:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1578413331395/f8hXGxQj7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>It&#39;s 2020 and the rate in which Flutter is trending is increasing exponentially, and learning can be difficult if people are not been pointed to the right resources. With the below-curated list of the youtube channel, I believe it will help flutter developers to learn and master the Flutter.</p>
<h3 id="-official-flutter-youtube-channel-https-www-youtube-com-channel-ucwxdfgee9kyzlddr7tg9cmw-videos-"><a target='_blank' rel='noopener noreferrer'  href="https://www.youtube.com/channel/UCwXdFgeE9KYzlDdR7TG9cMw/videos">Official Flutter Youtube Channel</a></h3>
<p>Flutter Youtube channel is a goto place to learn things about flutter, the Flutter team has published various content on flutter. you will get to know things about different widgets, Google IO videos content on flutter, Flutter Interact and lot more.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://www.youtube.com/watch?v=b_sQ9bMltGU&list=PLjxrf2q8roU23XGwz3Km7sQZFTdB996iG" data-card-controls="0" data-card-theme="light">https://www.youtube.com/watch?v=b_sQ9bMltGU&list=PLjxrf2q8roU23XGwz3Km7sQZFTdB996iG</a></div>
<h3 id="-mtechviral-https-www-youtube-com-channel-ucftm1fgjzskospdzgtbp7ha-videos-"><a target='_blank' rel='noopener noreferrer'  href="https://www.youtube.com/channel/UCFTM1FGjZSkoSPDZgtbp7hA/videos">MTECHVIRAL</a></h3>
<p>MTECHVIRAL is a youtube channel created and managed by Pawan Kumar known as imthepk, Pawan Kumar is the first Google Developer Expert in Indian and he is also an expert for web, firebase e.t.c. He has spent the last 2 years creating a lot of awesome content on flutter.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://youtu.be/9UUtD_GR7zw" data-card-controls="0" data-card-theme="light">https://youtu.be/9UUtD_GR7zw</a></div>
<h3 id="-fireship-https-www-youtube-com-watch-v-hwbuu9cp4qi-list-pl0vfts4vzfniqytnn1tz6u0ec_vjcn9vy-"><a target='_blank' rel='noopener noreferrer'  href="https://www.youtube.com/watch?v=hwBUU9CP4qI&amp;list=PL0vfts4VzfNiQYtnn1TZ6U0Ec_vjCN9VY">Fireship</a></h3>
<p>Fireship has huge content that varies from the web, firebase, flutter e.t.c. Fireship is a goto place to learn various things as a flutter developer either beginner, intermediate or expert. Fireship was created and managed by Jeff Delaney. Jeff Delaney is a Google Developer Expert for firebase and he is passionate about creating content for the community. </p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://www.youtube.com/watch?v=vsyjMrZa5OU" data-card-controls="0" data-card-theme="light">https://www.youtube.com/watch?v=vsyjMrZa5OU</a></div>
<h3 id="-code-with-andrea-https-www-youtube-com-channel-ucrtnst4oyz53l0qgkqled5q-videos-"><a target='_blank' rel='noopener noreferrer'  href="https://www.youtube.com/channel/UCrTnsT4OYZ53l0QGKqLeD5Q/videos">Code With Andrea.</a></h3>
<p> Andrea Bizzotto is a Google Developer Expert in Flutter, Udemy instructor and the founder of CodeWithAdrea Youtube channel. Andrea created the channel to be a better flutter developer and he has published videos on flutter for the community.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://youtu.be/uckoKNHT24Q" data-card-controls="0" data-card-theme="light">https://youtu.be/uckoKNHT24Q</a></div>
<h3 id="-marcus-ng-https-www-youtube-com-channel-uc6dy0rq6zdnquhq1eeergua-videos-"><a target='_blank' rel='noopener noreferrer'  href="https://www.youtube.com/channel/UC6Dy0rQ6zDnQuHQ1EeErGUA/videos">Marcus Ng</a></h3>
<p>Marcus Ng is a mobile app developer specializing in building apps with Flutter and Swift. Marcus Ng is also an Udemy instructor and the founder of Marcus Ng youtube channel, he has published a lot of flutter content on his youtube channel. feel free to give his channel a shot.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://youtu.be/h-igXZCCrrc" data-card-controls="0" data-card-theme="light">https://youtu.be/h-igXZCCrrc</a></div>
<h3 id="-raja-yogan-https-www-youtube-com-channel-ucjbxam226xzvgrko-jyjjgq-videos-"><a target='_blank' rel='noopener noreferrer'  href="https://www.youtube.com/channel/UCjBxAm226XZvgrkO-JyjJgQ/videos">Raja Yogan</a></h3>
<p>Raja Yogan Youtube channel was created and managed by Raja Yogan himself. Raja Yogan is a Software Engineer, Consultant, and Architect in India, who is passionate about flutter, firebase, and mobile app development. Raja Yogan Youtube channel has a lot of flutter tutorials, tip, and trick you can learn as a flutter developer</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://youtu.be/NBjDMRDGbXY" data-card-controls="0" data-card-theme="light">https://youtu.be/NBjDMRDGbXY</a></div>
<h3 id="-reso-coder-https-www-youtube-com-channel-ucsivrn68cuk8cs8mbtbmbka-videos-"><a target='_blank' rel='noopener noreferrer'  href="https://www.youtube.com/channel/UCSIvrn68cUk8CS8MbtBmBkA/videos">Reso Coder</a></h3>
<p>Reso Coder is a Youtube channel that has a lot of content for beginner, intermediate and expert alike. Subscribe to the channel so you can catch up with the upcoming video</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://youtu.be/7mpNF9zWrMc" data-card-controls="0" data-card-theme="light">https://youtu.be/7mpNF9zWrMc</a></div>
<h3 id="-techie-blossom-https-www-youtube-com-channel-uc3wqikiaoupo6ejjocwh6_q-videos-"><a target='_blank' rel='noopener noreferrer'  href="https://www.youtube.com/channel/UC3wqIkiaOUpO6EjJoCwH6_Q/videos">Techie Blossom</a></h3>
<p>Techie Bossom is a youtube channel that has a lot of amazing content around flutter, firebase, and web. if you are a beginner flutter developer who wants to build apps to have the experience, Techie Blossom youtube channel is for you.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://www.youtube.com/watch?v=pAYGLroI1DI" data-card-controls="0" data-card-theme="light">https://www.youtube.com/watch?v=pAYGLroI1DI</a></div>
<h3 id="-filledstacks-https-www-youtube-com-channel-uc2d0bylqqcdf9ljfydl_02q-videos-"><a target='_blank' rel='noopener noreferrer'  href="https://www.youtube.com/channel/UC2d0BYlqQCdF9lJfydl_02Q/videos">FilledStacks</a></h3>
<p>Another Youtube channel to explore its content is FilledStack. FilledStack has content dedicated to flutter alone, there are a lot of flutter widgets, tricks and tips you need to add to what you already know. Filledstack also has a dev blog where you can read and learn thing around flutter  <a target='_blank' rel='noopener noreferrer'  href="https://www.filledstacks.com/">click here</a> </p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://youtu.be/NfvA-7-HzYk" data-card-controls="0" data-card-theme="light">https://youtu.be/NfvA-7-HzYk</a></div>
<h3 id="-the-net-ninja-https-www-youtube-com-playlist-list-pl4cuxegkcc9jlyyp2aoh6hcwuxfdx6pbj-"><a target='_blank' rel='noopener noreferrer'  href="https://www.youtube.com/playlist?list=PL4cUxeGkcC9jLYyp2Aoh6hcWuxFDX6PBJ">The Net Ninja</a></h3>
<p>The Net Ninja is a youtube channel that has a lot of amazing content not only flutter also various content across all areas on the web.  The Net Ninja channel was created and managed by Shaun. Shaun is a Udemy instructor who is obsessed with technology and loves creating content around it.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" data-card-width="600px" data-card-key="2e4d628b39a64b99917c73956a16b477" href="https://www.youtube.com/watch?v=1ukSR1GRtMU&t=2s" data-card-controls="0" data-card-theme="light">https://www.youtube.com/watch?v=1ukSR1GRtMU&t=2s</a></div>
<h1 id="conclusion">Conclusion</h1>
<p>I hope the above channels will help you to learn flutter faster and easier, if you have any other youtube channel that is not on the list please feel free to drop it in the comment box.</p>
]]></content:encoded></item><item><title><![CDATA[How to fix Android X error with firebase plugin in your flutter application]]></title><description><![CDATA[One of the current challenges as of the time I'm writing this article is using firebase in flutter application, using firebase in your flutter application at default return error. Firebase returns different errors base on the context of what you are ...]]></description><link>https://blog.dammak.dev/how-to-fix-android-x-error-with-firebase-plugin-in-your-flutter-application</link><guid isPermaLink="true">https://blog.dammak.dev/how-to-fix-android-x-error-with-firebase-plugin-in-your-flutter-application</guid><category><![CDATA[Flutter]]></category><category><![CDATA[android apps]]></category><category><![CDATA[Android Studio]]></category><category><![CDATA[Mobile Development]]></category><category><![CDATA[programming languages]]></category><dc:creator><![CDATA[Damola Adekoya]]></dc:creator><pubDate>Wed, 11 Dec 2019 10:06:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1576058762625/0K1NzGjMH.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>One of the current challenges as of the time I&#39;m writing this article is using firebase in flutter application, using firebase in your flutter application at default return error. Firebase returns different errors base on the context of what you are doing, but the fix for any kind of error you might encounter is to enable AndroidX into your flutter project.  In this article, I will be showing step by step process on how to fix this issue.</p>
<h1 id="steps-to-fix-firebase-plugin-error">Steps to fix firebase plugin error</h1>
<ul>
<li><p><strong> Enable multiDex in your defaultConfig build.gradle file.</strong></p>
</li>
</ul>
<p>To enable multiDex, navigate to your android project folder. Inside your app folder, open your build.gradle file at the app level then add google support service at the defaultConfig section</p>
<pre><code><span class="hljs-attribute">multiDexEnabled</span> <span class="hljs-literal">true</span>
</code></pre><p>overall default config should look like below</p>
<pre><code> defaultConfig {
        <span class="hljs-regexp">//</span> <span class="hljs-symbol">TODO:</span> Specify your own unique Application ID (<span class="hljs-symbol">https:</span>/<span class="hljs-regexp">/developer.android.com/studio</span><span class="hljs-regexp">/build/application</span>-id.html).
        applicationId <span class="hljs-string">"com.example.bloc_demo"</span>
        minSdkVersion <span class="hljs-number">16</span>
        targetSdkVersion <span class="hljs-number">28</span>
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner <span class="hljs-string">"android.support.test.runner.AndroidJUnitRunner"</span>
        multiDexEnabled <span class="hljs-keyword">true</span>
    }
</code></pre><p>In your targetSdkVersion in the defaultConfig object change the value to 28 and in your compileSdkVersion at the android level declaration change the value to 28.</p>
<p>Add google service to your gradle file if not present, you can do so by using the below snippet</p>
<pre><code><span class="hljs-attribute">apply</span> plugin: <span class="hljs-string">'com.google.gms.google-services'</span>
</code></pre><p>But in case you have any issue, below is how my gradle file look like:</p>
<pre><code>def <span class="hljs-built_in">local</span>Properties = new Properties()
def <span class="hljs-built_in">local</span>PropertiesFile = rootProject.file(<span class="hljs-string">'local.properties'</span>)
<span class="hljs-keyword">if</span> (<span class="hljs-built_in">local</span>PropertiesFile.exists()) {
    <span class="hljs-built_in">local</span>PropertiesFile.withReader(<span class="hljs-string">'UTF-8'</span>) { reader -&gt;
        <span class="hljs-built_in">local</span>Properties.load(reader)
    }
}

def flutterRoot = <span class="hljs-built_in">local</span>Properties.getProperty(<span class="hljs-string">'flutter.sdk'</span>)
<span class="hljs-keyword">if</span> (flutterRoot == null) {
    throw new GradleException(<span class="hljs-string">"Flutter SDK not found. Define location with flutter.sdk in the local.properties file."</span>)
}

def flutterVersionCode = <span class="hljs-built_in">local</span>Properties.getProperty(<span class="hljs-string">'flutter.versionCode'</span>)
<span class="hljs-keyword">if</span> (flutterVersionCode == null) {
    flutterVersionCode = <span class="hljs-string">'1'</span>
}

def flutterVersionName = <span class="hljs-built_in">local</span>Properties.getProperty(<span class="hljs-string">'flutter.versionName'</span>)
<span class="hljs-keyword">if</span> (flutterVersionName == null) {
    flutterVersionName = <span class="hljs-string">'1.0'</span>
}

apply plugin: <span class="hljs-string">'com.android.application'</span>
apply plugin: <span class="hljs-string">'kotlin-android'</span>
apply from: <span class="hljs-string">"<span class="hljs-variable">$flutterRoot</span>/packages/flutter_tools/gradle/flutter.gradle"</span>
apply plugin: <span class="hljs-string">'com.google.gms.google-services'</span>

android {
    compileSdkVersion 28

    <span class="hljs-built_in">source</span>Sets {
        main.java.srcDirs += <span class="hljs-string">'src/main/kotlin'</span>
    }

    lintOptions {
        <span class="hljs-built_in">disable</span> <span class="hljs-string">'InvalidPackage'</span>
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId <span class="hljs-string">"com.example.bloc_demo"</span>
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        <span class="hljs-built_in">test</span>InstrumentationRunner <span class="hljs-string">"android.support.test.runner.AndroidJUnitRunner"</span>
        multiDexEnabled <span class="hljs-literal">true</span>
    }

    buildTypes {
        release {
            // TODO: Add your own signing config <span class="hljs-keyword">for</span> the release build.
            // Signing with the debug keys <span class="hljs-keyword">for</span> now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    <span class="hljs-built_in">source</span> <span class="hljs-string">'../..'</span>
}

dependencies {
    implementation <span class="hljs-string">"org.jetbrains.kotlin:kotlin-stdlib-jdk7:<span class="hljs-variable">$kotlin_version</span>"</span>
    <span class="hljs-built_in">test</span>Implementation <span class="hljs-string">'junit:junit:4.12'</span>
    androidTestImplementation <span class="hljs-string">'com.android.support.test:runner:1.0.2'</span>
    androidTestImplementation <span class="hljs-string">'com.android.support.test.espresso:espresso-core:3.0.2'</span>
    implementation <span class="hljs-string">'com.google.firebase:firebase-analytics:17.2.0'</span>

}
</code></pre><ul>
<li><strong>Fixing and adding google service to build.gradle file at the project level</strong></li>
</ul>
<p>At the dependencies section in the build.gradle file, add google service to it if not present.</p>
<pre><code> <span class="hljs-attribute">classpath</span> <span class="hljs-string">'com.google.gms:google-services:4.2.0'</span>
</code></pre><p>Below is how my build.gradle file at the project level look like in case you have any issue with the file</p>
<pre><code>buildscript {
    ext.kotlin_version = <span class="hljs-string">'1.2.71'</span>
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath <span class="hljs-string">'com.android.tools.build:gradle:3.2.1'</span>
        classpath <span class="hljs-string">"org.jetbrains.kotlin:kotlin-gradle-plugin:<span class="hljs-variable">$kotlin_version</span>"</span>
        classpath <span class="hljs-string">'com.google.gms:google-services:4.2.0'</span>

    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = <span class="hljs-string">'../build'</span>
subprojects {
    project.buildDir = <span class="hljs-string">"<span class="hljs-variable">${rootProject.buildDir}</span>/<span class="hljs-variable">${project.name}</span>"</span>
}
subprojects {
    project.evaluationDependsOn(<span class="hljs-string">':app'</span>)
}

task clean(<span class="hljs-built_in">type</span>: Delete) {
    delete rootProject.buildDir
}
</code></pre><ul>
<li><strong>Enable AndroidX in your gradle.properties file </strong></li>
</ul>
<p>To enable AndroidX at the root level, open gradle.properties file and paste below snippet</p>
<pre><code>android.useAndroidX=<span class="hljs-literal">true</span>
android.enableJetifier=<span class="hljs-literal">true</span>
</code></pre><p>Below is how my gradle.properties file looks like in case you want to compare with yours</p>
<pre><code>org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=<span class="hljs-literal">true</span>
android.enableJetifier=<span class="hljs-literal">true</span>
</code></pre><h1 id="conclusion">Conclusion</h1>
<p>Wow! that&#39;s the end of the article if you get to this point, you would have definitely fix AndroidX error in your flutter application and your application is working well. If you have an issue or encounter any error, feel free to drop it in the comment box I will respond to it asap.</p>
]]></content:encoded></item><item><title><![CDATA[[Widget of the Week]: StreamBuilder]]></title><description><![CDATA[Before  I dive into StreamBuilder let me quickly digress to Stream, StreamController, they are the building blocks of Streambuilder.
What is a Stream

Well, you are thinking, Is that stream I'm talking about! No it's not But think of it has the typic...]]></description><link>https://blog.dammak.dev/widget-of-the-week-streambuilder</link><guid isPermaLink="true">https://blog.dammak.dev/widget-of-the-week-streambuilder</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Dart]]></category><category><![CDATA[Android]]></category><category><![CDATA[android apps]]></category><category><![CDATA[iOS]]></category><dc:creator><![CDATA[Damola Adekoya]]></dc:creator><pubDate>Mon, 02 Dec 2019 11:15:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1575285308855/rtM8vmIUP.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1574682137208/9zfJ9CF7S.gif" alt="giphy.gif"></p>
<p>Before  I dive into StreamBuilder let me quickly digress to Stream, StreamController, they are the building blocks of Streambuilder.</p>
<h1 id="what-is-a-stream">What is a Stream</h1>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1574682362456/UXmmiaG0h.gif" alt="stream.gif"></p>
<p>Well, you are thinking, Is that stream I&#39;m talking about! No it&#39;s not But think of it has the typical stream, A stream is an Event that&#39;s uncontrolled, that can be generated from a Future, network access, reading of files(local/network) e.t.c.which has an input(i.e where it&#39;s coming from) and output(i.e where it&#39;s going). You can also think of Stream as a pipe that has an input called the sink and output called stream. 
How to create a stream</p>
<ul>
<li>From Future:     Stream.fromFuture(future);
-From Iterable:    Stream.fromIterable(Iterable &lt;T&gt; elements);
-From StreamController </li>
</ul>
<p>Read more about Stream:https://api.flutter.dev/flutter/dart-async/Stream-class.html</p>
<h1 id="streamcontroller">StreamController</h1>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1574926515202/M2EUAmbUq.gif" alt="streamcontroller.gif"></p>
<p>the GIF image above explains a lot about StreamController, a StreamController allows you to have control over your Stream, i.e you can listen to a stream, add Stream to your StreamController, you can pause, stop your stream. if there are errors, StreamController allows you to catch those errors and handle them gracefully, StreamController gives you access to the 360-degree life cycle of a stream. StreamController API exposes some method such as:
sink(which allows you to add data event)
stream(the stream StreamController is controlling)
map, transform (which allows you to modify or intercept your data before it emits out as a stream).</p>
<p>Adding Event via StreamController
StreamController exposes a sink method which allows you to add item to the stream which will be emitted as a stream using stream method.</p>
<pre><code>StreamController _streamController = StreamController();
<span class="hljs-comment">//Add event/Data to the StreamController</span>
_streamController.sink.add(<span class="hljs-keyword">data</span>);  <span class="hljs-comment">//NB: data can be any type i.e primitive/non-primitive</span>

<span class="hljs-comment">//data added to the Controller via the sink is emitted as Stream via stream method.</span>
Stream strem = _streamController.stream;
</code></pre><p>Read more about stream https://api.flutter.dev/flutter/dart-async/StreamController-class.html.</p>
<h1 id="streambuilder">StreamBuilder</h1>
<p>StreamBuilder is a widget that allows you to convert your stream object to a widget. rebuilding widget is basically done using setState, but performance-wise it isn&#39;t efficient because setState rebuild the whole widget and every child(s) widget, come to think of it, if you only need to rebuild a single widget then setState is a bad idea, so using StreamBuilding is your best shot. You can rebuild a single widget of your choice without touching or rebuilding the whole widget family tree.</p>
<pre><code><span class="hljs-comment">//let assume we have a stream will want to consume</span>

 Stream stream =Stream.fromFuture(Favourite().getAllFavourite(<span class="hljs-keyword">data</span>));
  StreamBuilder(
    stream: stream,
    builder: (BuildContext context, AsyncSnapshot snapshot){
      <span class="hljs-keyword">if</span>(snapshot.<span class="hljs-keyword">data</span> !=<span class="hljs-literal">null</span>){
        <span class="hljs-keyword">return</span> Widget();
      }

    },
  );
</code></pre><p>NB: in the above snippet we try to convert our Stream to a widget, in the builder function which accepts BuildContext and AsyncSnapshot as a parameter it looks exactly like FutureBuilder if you are familiar with it. we can get access to our Stream data using snapshot.data. </p>
<p>if you want to check your connection state, maybe to perform a specific operation, you can do that with the below snippet;</p>
<pre><code class="lang-dart">StreamBuilder(
    stream: stream,
    builder: (BuildContext context, AsyncSnapshot snapshot){
      if(snapshot.connectionState == ConnectionState.active){
         // Your statement when the connection mode is in active state
      }
      else if(snapshot.connectionState == ConnectionState.done){
             //Your statement when the operation has finished execution
      }
      else if (snapshot.connectionState == ConnectionState.none){
           //Your statement when the connection is not available
      }
      else if( snapshot.connectionState == ConnectionState.waiting){
        //Your statement when the connection state is in waiting mode
      }
      else{
        // else Statement
      }
    },
  );
</code></pre>
<p>below is the demo of how I used Streambuilder on flutter boilerplate counter app instead of setState.</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'dart:async'</span>;

<span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;

<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>=&gt; runApp(MyApp());

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyApp</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  <span class="hljs-comment">// This widget is the root of your application.</span>
  <span class="hljs-meta">@override</span>
  <span class="hljs-function">Widget <span class="hljs-title">build</span><span class="hljs-params">(BuildContext context)</span> </span>{
    <span class="hljs-keyword">return</span> MaterialApp(
      title: <span class="hljs-string">'Flutter Demo'</span>,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: <span class="hljs-string">'Flutter Demo Home Page'</span>),
    );
  }
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyHomePage</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatefulWidget</span> </span>{
  MyHomePage({Key key, <span class="hljs-keyword">this</span>.title}) : <span class="hljs-keyword">super</span>(key: key);

  <span class="hljs-keyword">final</span> String title;

  <span class="hljs-meta">@override</span>
  <span class="hljs-function">_MyHomePageState <span class="hljs-title">createState</span><span class="hljs-params">()</span> </span>=&gt; _MyHomePageState();
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">_MyHomePageState</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">State</span>&lt;<span class="hljs-title">MyHomePage</span>&gt; </span>{
  <span class="hljs-keyword">int</span> _counter = <span class="hljs-number">0</span>;
  StreamController _streamController ;
  Stream _stream;

  <span class="hljs-meta">@override</span>
  <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">initState</span><span class="hljs-params">()</span> </span>{
    _streamController = StreamController();
    _stream= _streamController.stream;

  }

  <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">_incrementCounter</span><span class="hljs-params">()</span> </span>{
  _streamController.sink.add(_counter++);
  }

  <span class="hljs-meta">@override</span>
  <span class="hljs-function">Widget <span class="hljs-title">build</span><span class="hljs-params">(BuildContext context)</span> </span>{
    <span class="hljs-keyword">return</span> Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: &lt;Widget&gt;[
            Text(
              <span class="hljs-string">'You have pushed the button this many times:'</span>,
            ),
           StreamBuilder(
             stream: _stream,
             builder: (BuildContext context, AsyncSnapshot snapshot){

               <span class="hljs-keyword">return</span>  Text(
               snapshot.data!=<span class="hljs-keyword">null</span> ? snapshot.data.toString() : <span class="hljs-string">"0"</span>,
                 style: Theme.of(context).textTheme.display1,
               );
             }
           )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: <span class="hljs-string">'Increment'</span>,
        child: Icon(Icons.add),
      ), <span class="hljs-comment">// This trailing comma makes auto-formatting nicer for build methods.</span>
    );
  }

  <span class="hljs-meta">@override</span>
  <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">dispose</span><span class="hljs-params">()</span> </span>{

  }
}
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1574931810668/ieT2q3Kg2.gif" alt="20191128100054_1_.gif"></p>
<p>you can check out the source code on Github: https://github.com/DAMMAK/flutter-counter-app-with-stream</p>
]]></content:encoded></item><item><title><![CDATA[Managing multiple themes in flutter application]]></title><description><![CDATA[One of the trending concepts in the mobile application is the ability to have multiple themes such as light and dark themes, and you can have as many themes as possible in your application. the question right now is how to manage the theme in order t...]]></description><link>https://blog.dammak.dev/managing-multiple-themes-in-flutter-application</link><guid isPermaLink="true">https://blog.dammak.dev/managing-multiple-themes-in-flutter-application</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Mobile apps]]></category><category><![CDATA[Mobile Development]]></category><category><![CDATA[Android]]></category><category><![CDATA[ShowHashnode]]></category><dc:creator><![CDATA[Damola Adekoya]]></dc:creator><pubDate>Sun, 17 Nov 2019 17:07:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1574010431838/5PheDhfJx.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>One of the trending concepts in the mobile application is the ability to have multiple themes such as light and dark themes, and you can have as many themes as possible in your application. the question right now is how to manage the theme in order to cut across all pages. thinking about managing the state of your theme in the application. one of the ways of managing the state is using stateful widget which is a terrible approach and it&#39;s inefficient and the other approach is to use statement package, there are a lot of statement management packages in flutter such as Providers, BLOC, Redux, Mobx e.t.c in this article I will be chosen provider state management package.</p>
<h1 id="provider-state-management-package">Provider State management package</h1>
<p>using a state management package allows you to manage your state globally in your application, it is more like having a global store where each page, widgets can connect directly to and access and manipulate data.</p>
<h3 id="steps-">Steps:</h3>
<ol>
<li>How to install Provider Package
add below snippet in your pubspec.yml file under the dependencies  section</li>
</ol>
<pre><code><span class="hljs-selector-tag">provider</span>: ^3<span class="hljs-selector-class">.1</span><span class="hljs-selector-class">.0</span>+1
</code></pre><p>OR</p>
<pre><code><span class="hljs-comment">//to have the latest provider package</span>
provider:
</code></pre><p>2.
create a dart file that has all your theme definition</p>
<pre><code><span class="hljs-comment">//theme.dart</span>

ThemeData darkTheme = ThemeData.dark().copyWith(
    primaryColor: Color(<span class="hljs-number">0xff1f655d</span>),
    accentColor: Color(<span class="hljs-number">0xff40bf</span>7a),
    textTheme: TextTheme(
        title: TextStyle(color: Color(<span class="hljs-number">0xff40bf</span>7a)),
        subtitle: TextStyle(color: Colors.white),
        subhead: TextStyle(color: Color(<span class="hljs-number">0xff40bf</span>7a))),
    appBarTheme: AppBarTheme(color: Color(<span class="hljs-number">0xff1f655d</span>)));

ThemeData lightTheme = ThemeData.light().copyWith(
    primaryColor: Color(<span class="hljs-number">0xfff5f5f</span>5),
    accentColor: Color(<span class="hljs-number">0xff40bf</span>7a),
    textTheme: TextTheme(
        title: TextStyle(color: Colors.black54),
        subtitle: TextStyle(color: Colors.grey),
        subhead: TextStyle(color: Colors.white)),
    appBarTheme: AppBarTheme(
        color: Color(<span class="hljs-number">0xff1f655d</span>),
        actionsIconTheme: IconThemeData(color: Colors.white)));
</code></pre><p>3.
Create a theme model </p>
<p>you need to create your theme model</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:whatsapp/theme.dart'</span>;

<span class="hljs-keyword">enum</span> ThemeType { Light, Dark }

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ThemeModel</span> <span class="hljs-title">extends</span> <span class="hljs-title">ChangeNotifier</span> </span>{
  ThemeData currentTheme = darkTheme;
  ThemeType _themeType = ThemeType.Dark;

  toggleTheme() {
    <span class="hljs-keyword">if</span> (_themeType == ThemeType.Dark) {
      currentTheme = lightTheme;
      _themeType = ThemeType.Light;
      <span class="hljs-keyword">return</span> notifyListeners();
    }

    <span class="hljs-keyword">if</span> (_themeType == ThemeType.Light) {
      currentTheme = darkTheme;
      _themeType = ThemeType.Dark;
      <span class="hljs-keyword">return</span> notifyListeners();
    }
  }
}
</code></pre><p>Explanation:</p>
<ul>
<li><p>we are creating an enum type for our theme, which we allow us to assign a type to each Themedata, it also helps us to check currently theme efficiently</p>
</li>
<li><p>We create a class that extends ChangeNotifier, create currentTheme as a property of ThemeData and set the default value to darkTheme and also property _themeType  then assign your current themeType to it. you can set any theme of your choice, it&#39;s the theme that will be the default app theme</p>
</li>
<li><p>create a method that handles the toggling of your theme from theme 1 to theme 2. But the most important part is to call notifyListener() method, it is the method that informs your store that your state value has changed.</p>
</li>
</ul>
<p>Wrap provider Class as a parent of your MaterialApp, which will allow all pages, widgets e.t.c have access to the provider value.</p>
<pre><code><span class="hljs-built_in">void</span> main() =&gt; runApp(
ChangeNotifierProvider&lt;ThemeModel&gt;(
    builder: <span class="hljs-function">(<span class="hljs-params">BuildContext context</span>) =&gt;</span> ThemeModel(), child: MyApp()));
</code></pre><p>Consuming your state value anywhere in your application</p>
<pre><code>Provider.of&lt;<span class="hljs-keyword">object</span>&gt;(context);
</code></pre><p>it allows you to access your provider store value and access your data. by specifying the ThemeModel.</p>
<p>below is your output</p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyApp</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> {</span>
  @override
  Widget build(BuildContext context) {
    <span class="hljs-keyword">return</span> MaterialApp(
      debugShowCheckedModeBanner: <span class="hljs-literal">false</span>,
      title: <span class="hljs-string">'Flutter Demo'</span>,
      theme: Provider.<span class="hljs-keyword">of</span>&lt;ThemeModel&gt;(context).currentTheme,
      home: MyHomePage(title: <span class="hljs-string">'WhatsApp'</span>),
    );
  }
}
</code></pre><p>Finally, Adding toggle widget to your app, this is the widget that will eneable you to switch from theme 1 to theme 2 and vice-versa. for the sake of simplicity of the article, I will just add a RaisedButton widget to MyHomePage Screen. 
snippet below</p>
<pre><code><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyHomePage</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span>
</span>{
<span class="hljs-keyword">final</span> String title;

MyHomePage({<span class="hljs-keyword">this</span>.title});

<span class="hljs-function">Widget <span class="hljs-title">build</span><span class="hljs-params">(BuildContext context)</span></span>{
 <span class="hljs-keyword">return</span> Scaffold(
     appBar: AppBar(
     title: Text(widget.title)),
     body: Center(
child:RaisedButton(child: Text(<span class="hljs-string">"Change Theme"</span>,
 onpressed:(){
Provider.of&lt;ThemeModel&gt;(context).toggleTheme();
}
))
);
}

}
</code></pre><p><strong><em>NB:</em>
</strong> <em>Provider.of&lt;ThemeModel&gt;(context).toggleTheme(); </em> allows you to connect to your themeModel class and run toggleTheme() method.</p>
<h1 id="conclusion">Conclusion</h1>
<p>The main purpose of this article is to allow you, to have an understanding of how you can create your own multi-based flutter applications using Providers State management package.</p>
]]></content:encoded></item><item><title><![CDATA[Bundle your Web application with ParcelJS]]></title><description><![CDATA[Some developers enjoy writing vanilla JS but some are forced to used a framework like Vue, Angular, React e.t.c because it comes with a bundler like Webpack, some don't actually know how to implement bundler natively. With this article, you will be a...]]></description><link>https://blog.dammak.dev/bundle-your-web-application-with-parceljs</link><guid isPermaLink="true">https://blog.dammak.dev/bundle-your-web-application-with-parceljs</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Javascript library]]></category><category><![CDATA[software development]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Damola Adekoya]]></dc:creator><pubDate>Mon, 26 Aug 2019 12:03:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1566821019330/wqxE4IYSF.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Some developers enjoy writing vanilla JS but some are forced to used a framework like Vue, Angular, React e.t.c because it comes with a bundler like Webpack, some don&#39;t actually know how to implement bundler natively. With this article, you will be able to actually bundle your javascript project without relying on any framework.</p>
<h1 id="what-is-parceljs-">What is ParcelJS?</h1>
<p>ParcelJS is a web application bundler, differentiated by its developer experience. It offers blazing-fast performance utilizing multicore processing and requires zero configuration. With parcel, you don&#39;t have to set up any configuration or any loader for either CSS, JS, assets e.t.c.</p>
<h3 id="why-you-should-use-parcel">Why you should use Parcel</h3>
<ul>
<li><p>Zero configuration:</p>
</li>
<li><p>Performance</p>
</li>
<li><p>Hot Module Replacement</p>
</li>
<li><p>Code Splitting</p>
</li>
<li><p>Support many asset types</p>
</li>
</ul>
<h2 id="get-started-with-parceljs">Get Started with ParcelJS</h2>
<p>Initialize npm in order to generate package.json file</p>
<pre><code>npm <span class="hljs-keyword">init</span> -y
</code></pre><p>Install ParcelJS Bundler as a global package
<strong>using npm</strong></p>
<pre><code>npm <span class="hljs-keyword">install</span> -<span class="hljs-keyword">g</span> parcel-bundler
</code></pre><p><strong>using yarn:</strong></p>
<pre><code>yarn <span class="hljs-built_in">global</span> add parcel-bundler
</code></pre><h2 id="how-to-serve-your-project">How to serve your project</h2>
<p>ParcelJS can use any kind of file as an entry point to serve but it&#39;s advisable to serve your HTML/jS file e.g index.html/index.js, about.html/about.js.
you can serve your files with the following command: </p>
<blockquote>
<p>parcel filename.extension</p>
</blockquote>
<pre><code><span class="hljs-selector-tag">parcel</span> <span class="hljs-selector-tag">index</span><span class="hljs-selector-class">.html</span>
</code></pre><p>After you have run your parcel command it will generate an address http://localhost:1234 where you can view your website. ParcelJS also support watch mode, which basically watches every change in your project and update it directly to your browser.</p>
<pre><code><span class="hljs-selector-tag">parcel</span> <span class="hljs-selector-tag">watch</span> <span class="hljs-selector-tag">index</span><span class="hljs-selector-class">.html</span>
</code></pre><p>you can as well watch multiple entry files with parcel watch file1, file2.. file N</p>
<pre><code><span class="hljs-selector-tag">parcel</span> <span class="hljs-selector-tag">index</span><span class="hljs-selector-class">.html</span> <span class="hljs-selector-tag">about</span><span class="hljs-selector-class">.html</span> <span class="hljs-selector-tag">service</span><span class="hljs-selector-class">.html</span> <span class="hljs-selector-tag">contact</span><span class="hljs-selector-class">.html</span>
</code></pre><h2 id="importing-asset-into-your-project">Importing asset into your project</h2>
<p>You can import different types of assets such as (CSS, SCSS, LESS, STYLUS, Images e.t.c)  into any javascript. </p>
<p><strong>CSS</strong></p>
<pre><code><span class="hljs-keyword">import</span> './style.css
</code></pre><p><strong>SCSS</strong></p>
<pre><code><span class="hljs-keyword">import</span> './style.scss`
</code></pre><p><strong>NB: </strong> <em>to compile SCSS you need to install npm package called sass</em></p>
<pre><code>npm <span class="hljs-keyword">install</span> -<span class="hljs-keyword">D</span> sass
</code></pre><p><strong>JAVASCRIPT</strong></p>
<pre><code><span class="hljs-comment">//ES6 Import </span>
<span class="hljs-keyword">import</span> './script.js
</code></pre><p>or </p>
<pre><code><span class="hljs-comment">//commonJS module</span>

<span class="hljs-keyword">const</span> script = <span class="hljs-built_in">require</span>(<span class="hljs-string">'./js/script'</span>);
</code></pre><h2 id="bundling-your-project-for-production">Bundling your project for production</h2>
<p>To bundle your project for production, you don&#39;t have to do any configuration or stress yourself, Parcel will automatically figure out all your files in your project(<em>js,</em>css, <em>scss, </em>jpg, <em>png, </em>svg e.t.c) and bundle everything for you, which you can push to production. use the following command to run your build process.</p>
<pre><code><span class="hljs-selector-tag">parcel</span> <span class="hljs-selector-tag">build</span> <span class="hljs-selector-tag">index</span><span class="hljs-selector-class">.html</span>
</code></pre><h2 id="demo">Demo</h2>
<p>Let create a simple project that fetches user from  <a target='_blank' rel='noopener noreferrer'  href="https://randomuser.me/">Randomusers</a> and displays it on the screen.</p>
<p>first let install parcel-bundle as a dev dependency, because we only need the package in our development stage, it won&#39;t go with our production build. But if you have installed it as a global package you don&#39;t have to install it again. if you haven&#39;t then you can either install as a dev dependency or global dependency.</p>
<pre><code>npm <span class="hljs-keyword">install</span> -<span class="hljs-keyword">D</span> parcel-bundler
</code></pre><p>then create an index.html and index.js file in the root directory, index.html will be our starting point because the browser can only paint element/assets in HTML file on the screen.. index.js file will be the root where will be connecting all our pages/components to the DOM.</p>
<p>then let create a folder called pages, this is where all our pages files will reside.</p>
<p><strong>NB</strong>: <em>you can structure the project as you want, what matters most is when you are importing your files, make sure your path name is correct.
</em></p>
<p>in the index.html file let include our index.js file, the markup should look like below.</p>
<pre><code><span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"ie=edge"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Parcel Tutorial<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"index.js"</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre><p>then modify your package.json file, in the scripts section add dev and build command. your script section should look like the scripts section below.</p>
<pre><code><span class="hljs-string">"scripts"</span>: {
    <span class="hljs-string">"dev"</span>: <span class="hljs-string">"parcel index.html"</span>,
    <span class="hljs-string">"build"</span>: <span class="hljs-string">"parcel build index.html"</span>
  }
</code></pre><p><strong>NB:</strong> <em>the dev script command we will be using during the development stage after we are done developing, that&#39;s when we will then use build script command to bundle our files to production.</em></p>
<h2 id="adding-our-javascript-into-our-pages-folder">Adding our Javascript into our Pages folder</h2>
<p>let create a file called users.js, it going to export a function that will consume the API from  <a target='_blank' rel='noopener noreferrer'  href="https://randomuser.me">Random Users</a>  and return the list of users.
which we can later import and reuse anywhere in our application.</p>
<pre><code><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> users = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> fetch(<span class="hljs-string">"https://randomuser.me/api/?results=10"</span>).then(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> res.json())
</code></pre><p>Adding CSS to your project.</p>
<p>Personally, I always create a separate CSS file for every component/page. e.g home.css, about.css e.t.c. and each component/page in a different folder. But for the sake of this tutorial not to make it look more complex. I&#39;m just using a single component/page. You can follow the pattern and approach that works for you, what matters is when you&#39;re importing your file make sure your path is always correct.</p>
<p>let create another file called home.js, which will be component /page that will list our users. copy below snippet to the file.</p>
<pre><code>.title {
  <span class="hljs-symbol">color:</span> <span class="hljs-comment">#fff;</span>
  margin-<span class="hljs-symbol">bottom:</span> <span class="hljs-number">2</span>rem;
  text-<span class="hljs-symbol">align:</span> center;
}
.userAvatar {
  border-<span class="hljs-symbol">radius:</span> <span class="hljs-number">50</span>%;
}
.user {
  list-<span class="hljs-symbol">style:</span> none;
  <span class="hljs-symbol">display:</span> flex;
  padding-<span class="hljs-symbol">left:</span> -<span class="hljs-number">2</span>rem;
  <span class="hljs-regexp">/* padding: 0; */</span>
  margin-<span class="hljs-symbol">left:</span> -<span class="hljs-number">2.5</span>rem;
  <span class="hljs-symbol">padding:</span> <span class="hljs-number">10</span>px;

  &amp;<span class="hljs-symbol">:not</span>(<span class="hljs-symbol">:last-child</span>) {
    border-<span class="hljs-symbol">bottom:</span> solid <span class="hljs-number">1</span>px <span class="hljs-comment">#ccc;</span>
  }
  &amp;-details {
    margin-<span class="hljs-symbol">left:</span> <span class="hljs-number">10</span>px;
    margin-<span class="hljs-symbol">top:</span> <span class="hljs-number">4</span>px;
  }

  &amp;-name {
    font-<span class="hljs-symbol">weight:</span> bolder;
    font-<span class="hljs-symbol">size:</span> <span class="hljs-number">18</span>px;
  }
  &amp;-email {
    font-<span class="hljs-symbol">style:</span> italic;
  }
}
body {
  background-<span class="hljs-symbol">color:</span> rgb(<span class="hljs-number">131</span>, <span class="hljs-number">4</span>, <span class="hljs-number">153</span>);
  font-<span class="hljs-symbol">size:</span> <span class="hljs-number">16</span>px;
}

.users {
  <span class="hljs-symbol">width:</span> <span class="hljs-number">40</span>vw;
  <span class="hljs-symbol">margin:</span> auto;
  <span class="hljs-symbol">border:</span> <span class="hljs-number">1</span>px solid <span class="hljs-comment">#ccc;</span>
  border-<span class="hljs-symbol">radius:</span> <span class="hljs-number">10</span>px;
  <span class="hljs-symbol">background:</span> <span class="hljs-comment">#fff;</span>
}

.loader {
  <span class="hljs-symbol">color:</span> <span class="hljs-comment">#fff;</span>
  font-<span class="hljs-symbol">size:</span> <span class="hljs-number">30</span>px;
  font-<span class="hljs-symbol">weight:</span> bolder;
  <span class="hljs-symbol">position:</span> absolute;
  <span class="hljs-symbol">top:</span> <span class="hljs-number">50</span>%;
  <span class="hljs-symbol">left:</span> <span class="hljs-number">50</span>%;
  <span class="hljs-symbol">translate:</span> (-<span class="hljs-number">50</span>, -<span class="hljs-number">50</span>);
  z-<span class="hljs-symbol">index:</span> <span class="hljs-number">1000</span>;
}
</code></pre><p>After you have created our stylesheet and users.js file that has a list of users from https://randomuser.me. let import our stylesheet and users into our main.js file.</p>
<p>full source code for main.js below.</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">"./home.scss"</span>;
<span class="hljs-keyword">import</span> { users } <span class="hljs-keyword">from</span> <span class="hljs-string">"./users"</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> home = <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
  <span class="hljs-keyword">const</span> wrapper = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"section"</span>); <span class="hljs-comment">//Create an element that will wrap other elements i.e parent.</span>
  wrapper.classList = <span class="hljs-string">"home"</span>; <span class="hljs-comment">//assign class home from our stylesheet</span>
  <span class="hljs-keyword">const</span> title = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"h1"</span>);
  title.innerHTML = <span class="hljs-string">"Welcome to Parcel Bundler Demo"</span>;
  title.classList = <span class="hljs-string">"title"</span>;
  <span class="hljs-keyword">const</span> ul = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"ul"</span>);
  ul.classList = <span class="hljs-string">"users"</span>;
  <span class="hljs-comment">//Create a loader element</span>
  <span class="hljs-keyword">const</span> loader = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"div"</span>);
  loader.innerHTML = <span class="hljs-string">"Loading..."</span>;
  loader.classList = <span class="hljs-string">"loader"</span>;
  wrapper.appendChild(loader); <span class="hljs-comment">// add the loader to home wrapper element</span>

  users().then(<span class="hljs-function">(<span class="hljs-params">{ results }</span>) =&gt;</span> {
    loader.style.display = <span class="hljs-string">"none"</span>; <span class="hljs-comment">// hide loader when users are available from the API.</span>
    results.forEach(<span class="hljs-function"><span class="hljs-params">user</span> =&gt;</span> {
      <span class="hljs-keyword">const</span> li = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"li"</span>);
      li.classList = <span class="hljs-string">"user"</span>;
      <span class="hljs-comment">//create User Avatar element</span>
      <span class="hljs-keyword">const</span> userAvatar = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"img"</span>);
      userAvatar.setAttribute(<span class="hljs-string">"src"</span>, user.picture.thumbnail);
      userAvatar.classList = <span class="hljs-string">"userAvatar"</span>;
      li.appendChild(userAvatar); <span class="hljs-comment">// append user avatar to the list</span>
      <span class="hljs-comment">//Create user details element</span>
      <span class="hljs-keyword">const</span> userDetails = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"div"</span>);
      userDetails.classList = <span class="hljs-string">"user-details"</span>;
      <span class="hljs-comment">//user's name element</span>
      <span class="hljs-keyword">const</span> userName = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"div"</span>);
      userName.classList = <span class="hljs-string">"user-name"</span>;
      userName.innerHTML = <span class="hljs-string">`<span class="hljs-subst">${capitalize(user.name.title)}</span> <span class="hljs-subst">${capitalize(
        user.name.first
      )}</span> <span class="hljs-subst">${capitalize(user.name.last)}</span>`</span>; <span class="hljs-comment">//assign name to user's name element</span>
      userDetails.appendChild(userName); <span class="hljs-comment">// append it to userdetail element</span>
      <span class="hljs-comment">//Create user's email address element</span>
      <span class="hljs-keyword">const</span> userEmail = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"div"</span>);
      userEmail.classList = <span class="hljs-string">"user-email"</span>;
      userEmail.innerHTML = <span class="hljs-string">`<span class="hljs-subst">${user.email}</span>`</span>; <span class="hljs-comment">//assign email address to user's email address element</span>
      userDetails.appendChild(userEmail); <span class="hljs-comment">//append it to userdetail element</span>
      li.appendChild(userDetails); <span class="hljs-comment">//append userdetail element to the list</span>
      ul.appendChild(li); <span class="hljs-comment">// append the list to parent element ul</span>
    });
  });

  wrapper.appendChild(title);
  wrapper.appendChild(ul);

  <span class="hljs-keyword">return</span> wrapper;
};

<span class="hljs-comment">//Accept a string and return the string in capitalize format</span>
<span class="hljs-keyword">const</span> capitalize = <span class="hljs-function"><span class="hljs-params">string</span> =&gt;</span> {
  <span class="hljs-keyword">return</span> <span class="hljs-built_in">string</span>.charAt(<span class="hljs-number">0</span>).toUpperCase() + <span class="hljs-built_in">string</span>.slice(<span class="hljs-number">1</span>);
};
</code></pre><p>after we have created our home.js and pasted the source code above inside the file, take a look where we declare the home function, we export the function i.e we are to use it somewhere else (reuseable).</p>
<p>go to index.js file that we create earlier which is going to be the starting point of our project. if you remember we include the index.js into our index.html. it is the index.js file that the index.html file will load and index.js file will actually make use of every page will create.</p>
<pre><code><span class="hljs-keyword">import</span> { home } <span class="hljs-keyword">from</span> <span class="hljs-string">"./pages/home"</span>;

<span class="hljs-keyword">const</span> app = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"div"</span>);
app.setAttribute(<span class="hljs-string">"id"</span>, <span class="hljs-string">"app"</span>);
app.appendChild(home());
<span class="hljs-built_in">document</span>.body.appendChild(app);
</code></pre><p><strong>NB:</strong> Basically, what index.js file does is to collect the view created in the home.js page and append it into the document body. i.e (browser screen).</p>
<p>Running your Application
To run your application, we will execute the npm script command we created earlier</p>
<pre><code><span class="hljs-built_in">npm</span> run dev
</code></pre><p><strong>NB:</strong> if you are having an error in your project that was due to ES7 syntax used in the project. you can try to install the following npm package @babel/core and @babel/plugin-transform-runtime</p>
<pre><code><span class="hljs-built_in">npm</span> install -D @babel/core @babel/plugin-transform-runtime
</code></pre><p>then create a .babelrc file in the project root folder telling your project to use one of the babel transform runtime plugins that will transpile the ES7 to what your browser can understand. use below snippet.</p>
<pre><code>{
  "<span class="hljs-attr">plugins</span>": [<span class="hljs-string">"@babel/plugin-transform-runtime"</span>]
}
</code></pre><p><strong><em>Demo result below</em></strong>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1566808371566/5kHxMrt22.png" alt="demo.PNG"></p>
<h2 id="bundling-your-application-for-production-">Bundling your application for production.</h2>
<p>After the development of your project, you will want to deploy your application to production, that&#39;s one of the main purposes of using Parcel is minified and reduce your project files size. you can run your build command you set in your script section</p>
<pre><code><span class="hljs-built_in">npm</span> run build
</code></pre><h2 id="conclusion-">Conclusion.</h2>
<p>The main purpose of this article is to introduce you to ParcelJs and get you started with ParcelJs, with this article you will be able to develop and deploy any javascript project to production. parcel js helps to bundle your app into small size
You can find the demo for this project on  <a target='_blank' rel='noopener noreferrer'  href="https://qyib9.csb.app/">Codesandbox</a>  and the source on  <a target='_blank' rel='noopener noreferrer'  href="https://github.com/DAMMAK/ParcelJS-bundler-demo">Github</a>.</p>
<p><em>NB:</em>, <em>if you have any questions or any part is not clear. you can drop it in the comment box. I&#39;m always at your service.</em></p>
]]></content:encoded></item><item><title><![CDATA[Setting up ESLINT in your JavaScript Project with VS Code]]></title><description><![CDATA[ESLINT: have you ever heard of ESLINT? or have you been wondering how to get started with ESLINT but you have no idea how to get started with ESLINT, But in few minutes with this article you will start using ESLINT in your next project. Yeah in few m...]]></description><link>https://blog.dammak.dev/setting-up-eslint-in-your-javascript-project-with-vs-code</link><guid isPermaLink="true">https://blog.dammak.dev/setting-up-eslint-in-your-javascript-project-with-vs-code</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[eslint]]></category><category><![CDATA[Visual Studio Code]]></category><category><![CDATA[developers]]></category><category><![CDATA[Web Development]]></category><dc:creator><![CDATA[Damola Adekoya]]></dc:creator><pubDate>Sun, 18 Aug 2019 13:58:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1566137978711/ZDV4il7__.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>ESLINT:</em> have you ever heard of ESLINT? or have you been wondering how to get started with ESLINT but you have no idea how to get started with ESLINT, But in few minutes with this article you will start using ESLINT in your next project. Yeah in few minutes</p>
<p><strong>ESLINT</strong> is a pluggable linting utility for Javascript and JSX, it helps to discover possible errors.</p>
<p><strong>VS Code</strong> is one of the top editors for development it was developed and maintained by Microsoft it helps to improve productivity and also comes with many features, one of the features I am going to emphasize on is an extension. Extensions are external packages in VS Code that allows you to extend the functionalities of your editor
you can download VS Code from their official website VS Code Download</p>
<p><strong>NB:</strong> <em>I won’t be digging deep into VS Code..everything on VS Code in this post will only be related to ESLINT.</em></p>
<p><strong>steps:</strong></p>
<ul>
<li><p>create a javascript project</p>
</li>
<li><p>install eslint as an extension in your VS Code Editor</p>
</li>
<li><p>Install eslint as a global package using npm</p>
</li>
<li><p>initialize eslint in your javascript project</p>
</li>
<li><p>modify your eslint configuration file in your project.</p>
</li>
</ul>
<p>let create a simple javascript project using</p>
<pre><code><span class="hljs-built_in">npm</span> init --<span class="hljs-literal">yes</span>
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1565949790550/n7BjvIENK.png" alt="1_ezX07vJWOCLAFv0za-fbgA.png"></p>
<p>after the operation was successful it will create a package.json file that will manage all configuration for our project.</p>
<p>let try to install ESLINT extension on vs code editor</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1565949858685/8luhCJZtQ.png" alt="1_MJZezjD3B5_SNUlsdF2Jfg-22.png"></p>
<p>once we have installed eslint extension on our vs code editor then let install eslint as a global package via npm using the below code</p>
<pre><code>npm <span class="hljs-keyword">install</span> eslint -<span class="hljs-keyword">g</span>
</code></pre><p>you need to initialize eslint in your project so you can leverage the power of eslint. From your root project enter the below code to initialize eslint</p>
<pre><code>eslint --<span class="hljs-keyword">init</span>
</code></pre><p>during the initialization, eslint will ask you some questions, more like to set up your configuration file.</p>
<h2 id="how-would-you-like-to-use-eslint-">How would you like to use ESLint?</h2>
<ul>
<li><p><strong>To check syntax only</strong> =&gt; it helps you correct your syntax and make sure it conforms to the standard.</p>
</li>
<li><p><strong>To check syntax and find problems</strong> =&gt; to help you check for syntax correctness and also help to find any problems in your codebase.</p>
</li>
<li><p><strong>To check syntax, find problems, and enforce code style</strong> =&gt; to help you check for syntax, find problems and enforce style, enforcing style means to conforms to a particular coding standard such as Airbnb, Google, and other Standard coding styles. But I always go for the last option the one with syntax, find problems and enforce code style.</p>
</li>
</ul>
<h2 id="what-type-of-modules-does-your-project-use-">What type of modules does your project use?</h2>
<ul>
<li><p><strong>Javascript module (import/export)</strong> =&gt; if your project has babel installed then you definitely need to choose this option. If you are working on a project such as React, Vue, Angular e.t.c they all use babel so you need to choose this option.</p>
</li>
<li><p><strong>CommonJS (require/exports)</strong> =&gt; this option is meant for commonJS that has nothing to do with babel, maybe your nodejs project and any other javascript project.</p>
</li>
</ul>
<h2 id="which-framework-does-your-project-use-">Which framework does your project use?</h2>
<ul>
<li><strong>React </strong>=&gt; if you are using react in/for your project then this option is for you</li>
<li><p><strong>Vue </strong>=&gt; if you are using Vue in/for your project then this option is for you.</p>
</li>
<li><p><strong>None of these </strong>=&gt; if you are using neither React or Vue in your project choose this option</p>
</li>
</ul>
<h2 id="where-does-your-code-run-">Where does your code run?</h2>
<ul>
<li><strong>Browser</strong> =&gt; if your project runs on browser e.g React, Angular, Vue e.t.c then go for this option</li>
<li><strong>Node</strong> =&gt; if your project is a node based then gladly choose this option
How would you like to define a style for your project?</li>
<li><p><strong>Use a popular style guide</strong> =&gt; This allows you to choose from a set of popular styles such as Airbnb, Standard and Google style guide, it is advisable to choose this option in order for you to follow the popular and most used style guide and I will be choosing this option in this post.</p>
</li>
<li><p>Answer questions about your style: This is for the custom style guide</p>
</li>
<li><p>Inspect your JavaScript file(s).: custom style guide</p>
</li>
</ul>
<p><strong>What format do you want your config file to be in?</strong></p>
<ul>
<li><strong>Javascript</strong> =&gt; whether you want your eslint config file to be in .jsfile
<strong>YAML</strong> =&gt; whether you want your eslint config file to be in .yamlfile
<strong>JSON</strong> =&gt; whether you want your eslint config file to be in .jsonfile you can choose any option in this section.</li>
</ul>
<p>after you have chosen your preferred configuration file type it will then prompt you to install all necessary dependencies. after all necessary dependencies have been successfully installed it will now generate a config file with “.eslintrc”.”js/json/yaml”.
example of the the configuration file shown below</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1565975312328/Zk6FnUctP.png" alt="1_QU_hTwNgd7QkPjfF2gtKBgXX.png"></p>
<p>below is a little animated image that shows how vs code works with eslint to notify you of errors in your javascript project</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1565975456680/POHJZ7dKA.gif" alt="1_0oPrycm0s5HI86yEiXx3HgTTYUI.gif"></p>
<h2 id="setting-up-rules-for-eslint-in-your-project">Setting up rules for ESLINT in your project</h2>
<p>Defining rules for ESLINT in your project informed eslint the kind of rules you want to add or remove. you can modify/set your rules in the rules section in the configuration file
example of rules to set are</p>
<pre><code>"<span class="hljs-selector-tag">rules</span>" : {
  <span class="hljs-attribute">no-console</span>: <span class="hljs-number">0</span>; 
  <span class="hljs-attribute">no-empty</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">no-irregular-whitespace</span>:<span class="hljs-number">0</span>;
}
</code></pre><p>you can define as many rules as possible, you can read more on ESLINT rules on their official documentation ESLINT Rules  <a target='_blank' rel='noopener noreferrer'  href="https://eslint.org/docs/rules/">Documentation.</a> </p>
<p>Lastly, I am going to show you how you can link your eslint to your javascript project compiler/transpiler</p>
<p><strong>steps below</strong></p>
<ul>
<li>Goto your <em>package.json</em> file, in the script segment in your file, add the following</li>
</ul>
<pre><code>script:{
    <span class="hljs-string">"lint"</span>:<span class="hljs-string">"eslint"</span>
}
</code></pre><p><strong>NB:</strong> <em>“lint”</em> is just an ordinary word, you can use any word you are comfortable with
then in your root project, you can run your linting script with</p>
<pre><code><span class="hljs-built_in">npm</span> run lint
</code></pre><h2 id="conclusion">Conclusion</h2>
<p>ESLINT will help you to increase your productivity, write your code according to standard and flag errors when your codebase is breaking style guide rules. With this post, you should be able to integrate ESLINT in your JavaScript project.</p>
]]></content:encoded></item><item><title><![CDATA[Test Driven Development with Jest]]></title><description><![CDATA[Test Driven Development is a principle of software development that ensure your code work exactly as you want it, it is a principle that should be follow by every development although there are lot of people who are yet to follow the principle, But i...]]></description><link>https://blog.dammak.dev/test-driven-development-with-jest</link><guid isPermaLink="true">https://blog.dammak.dev/test-driven-development-with-jest</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Developer]]></category><category><![CDATA[Facebook]]></category><category><![CDATA[Testing]]></category><category><![CDATA[Jest]]></category><dc:creator><![CDATA[Damola Adekoya]]></dc:creator><pubDate>Wed, 14 Aug 2019 04:03:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1565358440314/NQ8L5CMUT.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Test Driven Development is a principle of software development that ensure your code work exactly as you want it, it is a principle that should be follow by every development although there are lot of people who are yet to follow the principle, But if you did not follow test driven development then you will follow debug later development.</p>
<h1 id="why-you-should-follow-test-driven-development-principle">Why you should follow Test Driven Development Principle</h1>
<ol>
<li><p><strong>It makes debugging easier: </strong>Just imagine their is a bug or issue in your codebase with test driven development approach, your test cases will definitely fail and you will know exactly where to look, what to look for and what to modify. it makes development more easier.</p>
</li>
<li><p><strong>It works the way you wanted it: </strong>Test Driven Development helps and ensure your code works exactly the way you want it.</p>
</li>
</ol>
<h1 id="types-of-test-driven-development">Types of Test Driven Development</h1>
<h2 id="unit-test">Unit Test</h2>
<p>Unit test is a type of software development testing where individual/unit component of a software are tested. The process is done during the development of an application, to ensure and verify the correctness of a units/component of code.</p>
<h2 id="integration-test">Integration Test</h2>
<p>Integration test is the process of testing collection/group of unit/component. Integration test is done upon completion of unit tests.</p>
<h2 id="acceptance-e2e-end-to-end-test">Acceptance/E2E(end to end) Test</h2>
<blockquote>
<p>End-to-end testing is a methodology used to test whether the flow of an application is performing as designed from start to finish. The purpose of carrying out end-to-end tests is to identify system dependencies and to ensure that the right information is passed between various system components and systems.</p>
</blockquote>
<h1 id="test-driven-development-cycle">Test Driven Development Cycle</h1>
<p>There are 3 cycle behind test Driven Development,Red, Green and Refactor just like there are 3 cycle behind traffic light control red, yellow and green.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1565329122355/fT-17ZOcb.jpeg" alt="1_lw2PITaABshBiaBvkHdOwQ.jpeg"></p>
<ul>
<li><p><strong>Red:</strong> write a test and it fail</p>
</li>
<li><p><strong>Green:</strong> write a test for a functionality and make sure it pass the test</p>
</li>
<li><p><strong>Refactor:</strong> Optimizing the previous passed test and make sure all test cases pass.</p>
</li>
</ul>
<h1 id="what-is-jest-">What is Jest?</h1>
<blockquote>
<p>Jest is a delightful JavaScript Testing Framework with a focus on simplicity.
It works with projects using: Babel, TypeScript, Node, React, Angular, Vue and more!</p>
</blockquote>
<h2 id="how-to-install-jest-in-your-javascript-project">How to install jest in your Javascript Project</h2>
<p>using yarn you install jest with below code</p>
<pre><code><span class="hljs-attribute">yarn</span> add --dev jest
</code></pre><p>using npm you can install jest with below code</p>
<pre><code>npm <span class="hljs-keyword">install</span> <span class="hljs-comment">--save-dev jest</span>
</code></pre><h1 id="tdd-keyword-you-should-know-in-jest">TDD keyword you should know in Jest</h1>
<p><strong>expect: </strong> When you&#39;re writing tests, you often need to check that the values met certain conditions. expect gives you access to a number of &quot;matchers&quot; that let you validate different things. expect accept a value(a value you want to check against what you are expecting).</p>
<p><strong>E.g</strong></p>
<pre><code><span class="hljs-keyword">expect</span>(sum(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>)).toBe(<span class="hljs-number">3</span>);
<span class="hljs-keyword">expect</span>(sum(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>)).toBeA(number);
<span class="hljs-keyword">expect</span>(sum(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>).toEqual(<span class="hljs-number">3</span>);
</code></pre><p>expect function has some matcher you can use and chain with in jest. such as <em>.toBe()</em> , toBeA , toEqual ,toContainEqual e.t.c. check the  <a target='_blank' rel='noopener noreferrer'  href="https://jestjs.io/docs/en/expect.html">official documentation</a>  for more expect matchers.</p>
<p><strong>test/it:</strong> test or it is a function that run the test, it allows you to test your unit function For Example. Let Say there is a function called sum that accept two parameter and return the addition of the parameters.</p>
<pre><code>test(<span class="hljs-string">'Sum of two numbers'</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
 expect(Sum(<span class="hljs-number">5</span>,<span class="hljs-number">9</span>)).toBe(<span class="hljs-number">14</span>); }
);
</code></pre><p>check the official documentation for matcher.</p>
<h1 id="how-to-get-started-with-jest-using-javascript">How to get started with Jest using Javascript</h1>
<p>initialize javascript project with npm using your terminal</p>
<pre><code>npm <span class="hljs-keyword">init</span> --y
</code></pre><p>install jest into your project using terminal</p>
<pre><code>npm <span class="hljs-keyword">install</span> <span class="hljs-comment">--save-dev jest</span>
</code></pre><p>NB: You can create your test file with .test.js extension which will allows jest to locate your file and run your test cases. To organise and structure your project you can create a folder with the name <strong>test</strong> in your project directory which will house all test cases file.</p>
<p><strong>Example</strong></p>
<p>Let assume you are given a task to write a function that will accept two values as a parameter and sum the two values. the question now is what should you test for. There are lot of things to test for all you need to do is to think about what kind of output/result you want to return to the user. Below are what you can test for.</p>
<ul>
<li><p>Test if the parameters value is number data type, if it is not a number then the test should fail.</p>
</li>
<li><p>Test if the sum of parameter a and parameter b is logically correct, if not the test should fail.</p>
</li>
</ul>
<p><strong>NB: </strong> If you want your parameter should accept array and also sum the array. you can write a test case that check if the user supply array as a parameter and check if it does return correct answer.</p>
<p><strong>Solution</strong></p>
<p>There are two way to TDD either you write your test cases first before you actually start your development or write test cases later after development but the best practice is test case first then development. that&#39;s the approach we are going to follow now.</p>
<p>Let create a folder called <strong>test</strong> in root level of our project, inside the folder create a file called sum.test.js, all our test cases for sum function will be in the file.</p>
<p><strong>NB:</strong> <em>I will be using commonJS, you can use and configure your project to use babel, if it&#39;s already configured with babel so all is good</em></p>
<pre><code><span class="hljs-comment">//import sum</span>
<span class="hljs-keyword">const</span> { sum } = <span class="hljs-built_in">require</span>(<span class="hljs-string">"./sum"</span>);
describe(<span class="hljs-string">'Addition of Two Number functionality test'</span>,<span class="hljs-function"><span class="hljs-params">()</span>=&gt;</span>{
test(<span class="hljs-string">"Add 1 + 2 should be 3"</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
expect(sum(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>)).toBe(<span class="hljs-number">3</span>);
expect(sum(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>)).toBeA(<span class="hljs-built_in">number</span>);
});
test(<span class="hljs-string">"it should fail if string as parameter"</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
expect(sum(<span class="hljs-string">"Hello"</span>, <span class="hljs-string">"World"</span>))
.toEqual(<span class="hljs-built_in">Error</span>(<span class="hljs-string">"Expecting number type as parameter"</span>));
});
});
</code></pre><h1 id="explanation">Explanation</h1>
<p>First test case will check if first parameter and second parameter value return correct answer. i.e if 1+2 equal to 3.</p>
<pre><code>test(<span class="hljs-string">"Add 1+2 should be 3"</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
expect(sum(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>)).toBe(<span class="hljs-number">3</span>);
});
</code></pre><p>Second test case will check if first parameter or second parameter value is string and return error.</p>
<pre><code>test(<span class="hljs-string">"it should fail if string as parameter"</span>, <span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
expect(sum(<span class="hljs-string">"Hello"</span>, <span class="hljs-string">"World"</span>))
.toEqual(<span class="hljs-built_in">Error</span>(<span class="hljs-string">"Expecting number type as parameter"</span>));
</code></pre><p>Now that our test cases has been written, we only need to make sure that our sum function pass all the test cases. Let create a file called sum.js in the root folder, the file will contain a function that accept two number and sum the two numbers</p>
<pre><code><span class="hljs-keyword">const</span> sum = <span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> {
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> a !== <span class="hljs-string">"number"</span> || <span class="hljs-keyword">typeof</span> b !== <span class="hljs-string">"number"</span>)
<span class="hljs-keyword">return</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">"Expecting number type as parameter"</span>);
<span class="hljs-keyword">return</span> a + b;
};
<span class="hljs-built_in">module</span>.exports = { sum };
</code></pre><p><strong>NB:</strong> the above snippet first check the data type of the parameter if it is not number it should return an error with the message Expecting number type as parameter
What next now is to run our test, before then we need to configure our project to work with jest, let go directly to package.json file and add &quot;test&quot;: &quot;jest&quot; to the script section. our script should look something related to the below code.</p>
<pre><code><span class="hljs-string">"scripts"</span>: {
 <span class="hljs-string">"test"</span>: <span class="hljs-string">"jest"</span>
},
</code></pre><p>we can now run our test with npm test or yarn test command, below is the result/output of our test</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1565358199378/1bhgVjCSX.png" alt="1_PsM3efGAtxmSC7Pt0CatSw.png"></p>
<p>Okay, let me show one of test cases i wrote for login, there are many ways of test cases, all you need to do is to think about what you want to check for.</p>
<pre><code>describe(<span class="hljs-string">"Login Module for test cases"</span>, () =&gt; {
it(<span class="hljs-string">"should return the user if the name is valid"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">done</span>) </span>{
request(app)
.post(<span class="hljs-string">"/login"</span>)
.send({ username: <span class="hljs-string">"DAMMAK"</span>, password: <span class="hljs-string">"Adedamola"</span> })
.end(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, res</span>) </span>{
expect(res.statusCode).toEqual(<span class="hljs-number">200</span>);
expect(res.text).toEqual(
<span class="hljs-built_in">JSON</span>.stringify({ username: <span class="hljs-string">"DAMMAK"</span>, password: <span class="hljs-string">"Adedamola"</span> })
);
done();
});
});
it(<span class="hljs-string">"fails if login details is wrong"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">done</span>) </span>{
request(app)
.post(<span class="hljs-string">"/login"</span>)
.send({ username: <span class="hljs-string">"wrongUser"</span>, password: <span class="hljs-string">"wrongPass"</span> })
.end(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, res</span>) </span>{
expect(res.statusCode).toEqual(<span class="hljs-number">400</span>);
done();
});
});
it(<span class="hljs-string">"fails if empty request data was sent"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">done</span>) </span>{
request(app)
.post(<span class="hljs-string">"/login"</span>)
.send({})
.end(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, res</span>) </span>{
expect(res.statusCode).toEqual(<span class="hljs-number">400</span>);
done();
});
});
});
</code></pre>]]></content:encoded></item></channel></rss>