<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by CurlyCoder on Medium]]></title>
        <description><![CDATA[Stories by CurlyCoder on Medium]]></description>
        <link>https://medium.com/@shwetapanwar97?source=rss-6093b2f35d39------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QmQb42mFgNX0mQw8h-x9rg.jpeg</url>
            <title>Stories by CurlyCoder on Medium</title>
            <link>https://medium.com/@shwetapanwar97?source=rss-6093b2f35d39------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 10:30:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shwetapanwar97/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Mastering IoC, DIP, and DI in Flutter and Ruby on Rails]]></title>
            <link>https://medium.com/@shwetapanwar97/mastering-ioc-dip-and-di-in-flutter-and-ruby-on-rails-d4f498580ecf?source=rss-6093b2f35d39------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4f498580ecf</guid>
            <category><![CDATA[inversion-of-control]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[dependency-inversion]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[CurlyCoder]]></dc:creator>
            <pubDate>Wed, 23 Oct 2024 16:30:10 GMT</pubDate>
            <atom:updated>2024-10-23T17:49:15.097Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Unlock the power of clean architecture to build scalable and maintainable applications.</em></p><h3><strong>Introduction</strong></h3><p>In the ever-evolving world of software development, writing clean, maintainable, and testable code is more important than ever. Three fundamental concepts that can help achieve these goals are:</p><p>- <strong>Inversion of Control (IoC)</strong><br>- <strong>Dependency Inversion Principle (DIP)</strong><br>- <strong>Dependency Injection (DI)</strong></p><p>While these concepts might seem abstract at first, understanding and applying them can significantly improve your codebase’s architecture and scalability.</p><p>In this article, we’ll delve deep into these principles, using <strong>Flutter</strong> for frontend development and <strong>Ruby on Rails</strong> for backend development. We’ll provide concrete code examples to illustrate how these concepts can be applied in real-world applications.</p><h3><strong>Inversion of Control (IoC)</strong></h3><h4><strong>What is IoC?</strong></h4><p><strong>Inversion of Control (IoC)</strong> is a design principle that reverses the traditional flow of control in a program. Instead of the application code controlling the flow and calling libraries when needed, a framework or external code controls the flow and calls into the application code.</p><p><strong>Traditional Approach:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBbiVFMX8EdyFxE39DMV3A.png" /></figure><p>Here, our code directly controls the execution of the library functions. When we need to perform specific tasks, we call functions like “Function 1” or “Function 2” from a library (external code). Our code dictates the flow, deciding when and how to use the functions provided by the library. Unlike Inversion of Control, here the control is with our code, not handed over to a framework. This is typical in simpler applications where we manually call libraries to handle specific tasks.</p><p><strong>Inversion of Control:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zl2RAZI-FP9s4X9LTCV6Xg.png" /></figure><p>Here, we see that the framework (on the left) is responsible for setting up an event loop. This event loop is what drives the application and executes the code we write (on the right). In this case, the event loop triggers specific actions or handlers like “Handler 1” or “Controller 2,” which are part of our custom code. The key takeaway is that the framework takes control over when and how our code is executed, typically in response to events, thus “inverting” the traditional flow where the code would normally call the framework.</p><h4><strong>Why Use IoC?</strong></h4><p>- <strong>Decoupling:</strong> Separates the execution of tasks from their implementation.<br>- <strong>Reusability:</strong> Encourages the creation of generic, reusable components.<br>- <strong>Testability:</strong> Facilitates testing by allowing components to be tested in isolation.<br>- <strong>Maintainability:</strong> Simplifies updates or replacements of components without affecting the entire system.</p><h4><strong>IoC in Flutter</strong></h4><p>In Flutter, the framework manages the event loop and widget rendering. Your application defines the widget tree, but Flutter controls when and how the widgets are built and rendered.</p><p><strong>Example:</strong></p><pre>import &#39;package:flutter/material.dart&#39;;<br><br>void main() {<br>  runApp(MyApp()); // Flutter takes control here<br>}<br><br>class MyApp extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    // The framework calls this method to build the widget tree<br>    return MaterialApp(<br>      home: Scaffold(<br>        appBar: AppBar(<br>          title: Text(&#39;IoC in Flutter&#39;),<br>        ),<br>        body: Center(<br>          child: Text(&#39;Hello, Inversion of Control!&#39;),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p><strong>Explanation:</strong></p><p>- <em>runApp(MyApp())</em>: Hands control over to the Flutter framework.<br>- <em>build(BuildContext context):</em> The framework calls this method to render the UI components.</p><h4><strong>IoC in Ruby on Rails</strong></h4><p>Ruby on Rails embraces the IoC principle by controlling the flow of web requests and responses.</p><p><strong>Example:</strong></p><pre># config/routes.rb<br>Rails.application.routes.draw do<br> resources :articles<br>end</pre><pre># app/controllers/articles_controller.rb<br>class ArticlesController &lt; ApplicationController<br> def index<br>   @articles = Article.all<br>   # Rails automatically renders the corresponding view<br> end<br>end</pre><p><strong>Explanation:</strong></p><p>- <strong>Routing:</strong> Rails maps HTTP requests to controller actions based on predefined routes.<br>- <strong>Controller Actions:</strong> You define what happens in each action, but Rails controls when and how these actions are invoked.</p><p>In both the Flutter and Ruby on Rails examples, the frameworks are clearly in control. In Flutter, the runApp method hands over control to the framework, which then dictates when and how the widget tree is built. Similarly, in Ruby on Rails, the framework manages the web request-response cycle, automatically mapping routes to controllers and handling much of the underlying flow. As developers, we are only responsible for plugging our application-specific logic into the hooks provided by the frameworks. This inversion of control allows us to focus on business logic without worrying about the lower-level mechanics of how the system runs.</p><h3><strong>Dependency Inversion Principle (DIP)</strong></h3><h4><strong>Understanding DIP</strong></h4><p>The <strong>Dependency Inversion Principle</strong> is the “D” in the SOLID principles of object-oriented design. It states:</p><p>1. High-level modules should not depend on low-level modules. Both should depend on abstractions.<br>2. Abstractions should not depend on details. Details should depend on abstractions.</p><p><strong>Key Idea:</strong> Decouple high-level and low-level modules by introducing an abstraction layer (interfaces or abstract classes).</p><h4><strong>Benefits of DIP</strong></h4><p>- <strong>Reduced Coupling:</strong> Minimizes dependencies between modules.<br>- <strong>Increased Flexibility:</strong> Easier to swap out implementations without affecting other parts of the system.<br>- <strong>Enhanced Testability:</strong> Facilitates mocking dependencies in tests.</p><h4><strong>DIP in Flutter</strong></h4><p><strong>Scenario: </strong>You have a notification system that can send messages via email or SMS.</p><p><strong>Step 1: Define an Abstraction</strong></p><pre>abstract class NotificationService {<br> void send(String message);<br>}</pre><p><strong>Step 2: Implement Concrete Classes</strong></p><pre>class EmailNotificationService implements NotificationService {<br> @override<br> void send(String message) {<br> // Code to send email<br> print(‘Email sent: $message’);<br> }<br>}<br><br>class SMSNotificationService implements NotificationService {<br> @override<br> void send(String message) {<br> // Code to send SMS<br> print(‘SMS sent: $message’);<br> }<br>}</pre><p><strong>Step 3: High-Level Module Depends on Abstraction</strong></p><pre>class NotificationManager {<br>  final NotificationService service;<br>  NotificationManager(this.service);<br>  void notify(String message) {<br>    service.send(message);<br>  }<br>}</pre><p><strong>Usage:</strong></p><pre>void main() {<br>  NotificationService service = EmailNotificationService();<br>  NotificationManager manager = NotificationManager(service);<br>  manager.notify(&#39;Hello, DIP in Flutter!&#39;);<br>}</pre><h4><strong>DIP in Ruby on Rails</strong></h4><p><strong>Scenario: </strong>You need a payment processing system that supports multiple payment gateways.</p><p><strong>Step 1: Define an Interface</strong></p><p>Using Ruby’s duck typing:</p><pre>module PaymentGateway<br> def process(amount)<br>   raise NotImplementedError, ‘You must implement the process method’<br> end<br>end<br></pre><p><strong>Step 2: Implement Concrete Classes</strong></p><pre><br>class StripeGateway<br> include PaymentGateway<br><br> def process(amount)<br>   # Code to process payment with Stripe<br>   puts “Processed $#{amount} with Stripe.”<br>  end<br>end<br><br>class PaypalGateway<br> include PaymentGateway<br><br> def process(amount)<br>   # Code to process payment with PayPal<br>   puts “Processed $#{amount} with PayPal.”<br> end<br>end</pre><p><strong>Step 3: High-Level Module Depends on Abstraction</strong></p><pre>class PaymentProcessor<br> def initialize(gateway)<br>   @gateway = gateway<br> end<br> def pay(amount)<br>   @gateway.process(amount)<br> end<br>end</pre><p><strong>Usage:</strong></p><pre>gateway = StripeGateway.new<br>processor = PaymentProcessor.new(gateway)<br>processor.pay(100)</pre><h3><strong>Dependency Injection (DI)</strong></h3><h4><strong>What is Dependency Injection?</strong></h4><p><strong>Dependency Injection </strong>is a technique where an object receives its dependencies from external sources rather than creating them itself. This approach adheres to both IoC and DIP.</p><h4><strong>Types of Dependency Injection</strong></h4><p>1. <strong>Constructor Injection: </strong>Dependencies are provided through a class constructor.<br>2. <strong>Setter Injection:</strong> Dependencies are provided through setter methods.<br>3. <strong>Method Injection:</strong> Dependencies are provided as parameters to methods.</p><h4><strong>DI in Flutter</strong></h4><p><strong>Scenario: </strong>A UserService depends on a UserRepository to fetch user data.</p><p><strong>Without DI:</strong></p><pre>class UserService {<br>  final UserRepository _repository = UserRepository();<br>  void fetchUser() {<br>    _repository.getUser();<br>  }<br>}</pre><p><strong>Issues:</strong></p><p>- Tight coupling between UserService and UserRepository.<br>- Difficult to test UserService in isolation.</p><p><strong>With Constructor Injection:</strong></p><pre>class UserService {<br>  final UserRepository repository;<br>  UserService(this.repository);<br>  void fetchUser() {<br>    repository.getUser();<br>  }<br>}</pre><p><strong>Mock Implementation for Testing:</strong></p><pre>class MockUserRepository implements UserRepository {<br>  @override<br>  void getUser() {<br>    // Return mock user data<br>    print(&#39;Mock user data fetched&#39;);<br>  }<br>}</pre><p><strong>Usage:</strong></p><pre>void main() {<br>  UserRepository repository = UserRepository();<br>  UserService service = UserService(repository);<br>  service.fetchUser();<br>}</pre><p><strong>Testing:</strong></p><pre>void main() {<br>  UserRepository mockRepository = MockUserRepository();<br>  UserService service = UserService(mockRepository);<br>  service.fetchUser(); // Outputs: Mock user data fetched<br>}</pre><h4><strong>DI in Ruby on Rails</strong></h4><p><strong>Scenario:</strong> A UserNotifier depends on a Mailer service to send emails.</p><p><strong>Without DI:</strong></p><pre>class UserNotifier<br> def send_welcome_email(user)<br>   mailer = Mailer.new<br>   mailer.send_email(user.email, ‘Welcome!’)<br> end<br>end</pre><p><strong>Issues:</strong></p><p>- UserNotifier is tightly coupled to Mailer.<br>- Hard to substitute Mailer in tests.</p><p><strong>With Setter Injection:</strong></p><pre>class UserNotifier<br> attr_writer :mailer<br><br> def send_welcome_email(user)<br>   mailer.send_email(user.email, ‘Welcome!’)<br>   endprivatedef mailer<br>   @mailer ||= Mailer.new<br> end<br>end</pre><p><strong>Mock Implementation for Testing:</strong></p><pre>class MockMailer<br> def send_email(email, message)<br>   # Log or store emails for testing<br>   puts “Mock email sent to #{email} with message: #{message}”<br> end<br>end</pre><p><strong>Usage:</strong></p><pre>notifier = UserNotifier.new<br>notifier.send_welcome_email(user)</pre><p><strong>Testing:</strong></p><pre>notifier = UserNotifier.new<br>notifier.mailer = MockMailer.new<br>notifier.send_welcome_email(user)<br># Outputs: Mock email sent to user@example.com with message: Welcome!</pre><h3><strong>Without IoC and DI</strong></h3><pre>class JioSMSNotificationService {<br>  final String apiKey;<br><br>  // Constructor<br>  JioSMSNotificationService(this.apiKey);<br><br>  // Method to send SMS<br>  void sendSMS(String phone, String message) {<br>    // SMS sending logic goes here<br>    print(&#39;Sending SMS to $phone: $message&#39;);<br>  }<br>}<br><br>class UserController {<br>  // Instantiate the JioSMSNotificationService with the API key<br>  final JioSMSNotificationService notifier = JioSMSNotificationService(&quot;Jio SMS API key here&quot;);<br><br>  // Method to add a user<br>  void addUser() {<br>    // Your user-adding logic here<br><br>    // Send an SMS after adding the user<br>    notifier.sendSMS(&quot;0123456789&quot;, &quot;Registered successfully!&quot;);<br>  }<br>}<br><br>void main() {<br>  UserController userController = UserController();<br>  userController.addUser();  // Simulate adding a user<br>}</pre><p><strong>Issues</strong></p><p>The code violates <strong>Inversion of Control (IoC)</strong> and <strong>Dependency Injection (DI)</strong> principles in the following ways:</p><p><strong>Inversion of Control (IoC) Violation:</strong></p><ul><li><strong>Tight coupling</strong>: The UserController class directly creates an instance of JioSMSNotificationService using the new keyword. This creates a strong dependency between the two classes, making it difficult to swap out the notification service with another implementation in the future.</li><li><strong>Lack of abstraction</strong>: The UserController class is dependent on a concrete class (JioSMSNotificationService), rather than depending on an abstract interface or contract. This breaks the principle of <strong>IoC</strong>, where the higher-level class should not control the instantiation of lower-level components.</li></ul><p><strong>Dependency Injection (DI) Violation:</strong></p><ul><li><strong>Service instantiated inside the controller</strong>: The JioSMSNotificationService is created directly inside the UserController. In <strong>Dependency Injection</strong>, the dependencies (in this case, JioSMSNotificationService) should be provided to the UserController from the outside, either via constructor injection, method injection, or property injection.</li><li><strong>No flexibility</strong>: Since the JioSMSNotificationService is hardcoded inside the UserController, you cannot easily switch to a different SMS service (e.g., for testing or changing the SMS provider) without modifying the controller code. Proper <strong>Dependency Injection</strong> would allow different implementations of the service to be injected as needed, increasing flexibility.</li></ul><p>By violating IoC and DI principles, the code becomes less modular, less testable, and harder to maintain.</p><h3><strong>With IoC and DI</strong></h3><pre>abstract class NotificationService {<br>  void notify(int userID, String message);<br>}<br><br>class JioSMSNotificationService implements NotificationService {<br>  final String apiKey;<br><br>  JioSMSNotificationService(this.apiKey);<br><br>  @override<br>  void notify(int userID, String message) {<br>    // Implementation for sending SMS using Jio API<br>  }<br>}<br><br>class AirtelSMSNotificationService implements NotificationService {<br>  final String apiKey;<br><br>  AirtelSMSNotificationService(this.apiKey);<br><br>  @override<br>  void notify(int userID, String message) {<br>    // Implementation for sending SMS using Airtel API<br>  }<br>}<br><br>// EmailNotificationService class<br>class EmailNotificationService implements NotificationService {<br>  @override<br>  void notify(int userID, String message) {<br>    // Implementation for sending an email<br>  }<br>}<br><br>// UserController class with constructor injection<br>class UserController {<br>  final NotificationService notifier;<br><br>  // Constructor injection<br>  UserController(this.notifier);<br><br>  void addUser(int userID) {<br>    // Adding user logic<br>    notifier.notify(userID, &#39;Registered successfully!&#39;);<br>  }<br>}</pre><p>Here’s how the given Dart code follows <strong>Inversion of Control (IoC)</strong> and <strong>Dependency Injection (DI)</strong>:</p><p><strong>Inversion of Control (IoC):</strong></p><ul><li><strong>Separation of Responsibilities</strong>: The UserController doesn&#39;t decide how to send notifications. It just uses the NotificationService, while the actual notification logic is handled by other classes (Jio, Airtel, Email).</li><li><strong>Flexibility</strong>: UserController works with any type of notification service. The details of sending notifications are controlled by the specific service classes, not the controller.</li></ul><p><strong>Dependency Injection (DI):</strong></p><ul><li><strong>Constructor Injection</strong>: The notification service is provided to UserController through the constructor, making it easy to swap different services (like Jio or Airtel) without changing the controller.</li><li><strong>Easier Testing</strong>: You can easily test UserController by injecting a fake notification service, making the code more flexible and testable.</li></ul><p><strong>Flexibility</strong>:</p><ul><li><strong>External configuration:</strong> The API key or other configuration needed for JioSMSNotificationService is passed externally, allowing the class to focus solely on the business logic of sending SMS without managing configuration.</li></ul><p>This implementation adheres to both IoC and DI principles by making the dependency (SMS service) externally controlled and injected.<br>Without applying the Dependency Inversion Principle, you risk writing code where high-level modules directly depend on the low-level details, creating tight coupling. For instance, imagine a notification manager that directly instantiates an email or SMS service inside its own methods. This approach makes it difficult to replace or extend functionality, as any change to the service would require changes in the manager itself.</p><p>By adhering to DIP, we decouple the high-level module from the low-level module by introducing an abstraction (like an interface or an abstract class). Now, the high-level module depends on the abstraction, and the low-level details (e.g., email or SMS services) implement that abstraction. This makes the code more flexible — new notification methods can be added without changing the notification manager — and it becomes easier to mock dependencies during testing.</p><p><strong>How They Relate to Each Other</strong></p><ul><li><strong>Inversion of Control (IoC):</strong> A general principle that inverts the control flow of a program.</li><li><strong>Dependency Inversion Principle (DIP):</strong> A design principle that suggests high-level modules should depend on abstractions.</li><li><strong>Dependency Injection (DI):</strong> A technique for providing dependencies, implementing both IoC and DIP.</li><li><strong>How IoC relates to DI:</strong> To improve flexibility and extensibility, all frameworks that use IoC also use DI</li></ul><p><strong>Relationship Diagram:</strong></p><pre>Inversion of Control<br> ↑<br>Dependency Inversion Principle<br> ↑<br>Dependency Injection</pre><p><strong>Explanation:</strong></p><p>- <strong>IoC</strong> is the overarching principle.<br>- <strong>DIP</strong> provides guidelines to decouple modules through abstraction.<br>- <strong>DI</strong> is a practical method to inject dependencies, facilitating both IoC and DIP.</p><h4><strong>Conclusion</strong></h4><p>Applying <strong>Inversion of Control</strong>, the <strong>Dependency Inversion Principle</strong>, and <strong>Dependency Injection</strong> can significantly enhance the quality of your code.</p><p>These principles help in creating systems that are:</p><p>- <strong>Maintainable:</strong> Easier to update and extend.<br>- <strong>Testable:</strong> Simplifies unit testing by allowing dependencies to be mocked.<br>- <strong>Flexible:</strong> Facilitates swapping out implementations without modifying high-level modules.<br>- <strong>Scalable:</strong> Supports the growth and evolution of your application.</p><p><strong>Key Takeaways:</strong></p><p>- <strong>Start Small: </strong>Identify tightly coupled components in your codebase.<br>- <strong>Introduce Abstractions:</strong> Use interfaces or abstract classes to decouple modules.<br>- <strong>Inject Dependencies:</strong> Provide dependencies from external sources.<br>- <strong>Embrace IoC:</strong> Let frameworks manage the control flow when appropriate.</p><h4><strong>Additional Resources</strong></h4><p><strong>- Books:</strong></p><ul><li><strong>Clean Code</strong> by Robert C. Martin</li><li><strong>Design Patterns: Elements of Reusable Object-Oriented Software</strong> by Erich Gamma, et al.</li></ul><p><strong>- Online Articles:</strong></p><ul><li><a href="https://martinfowler.com/articles/injection.html">Inversion of Control Containers and the Dependency Injection pattern</a> by Martin Fowler</li><li><a href="https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design">SOLID Principles Explained</a> by Ryan Levick</li></ul><p><strong>- Official Documentation:</strong></p><ul><li><a href="https://flutter.dev/docs">Flutter Documentation</a></li><li><a href="https://guides.rubyonrails.org/">Ruby on Rails Guides</a></li></ul><p><strong>Embrace these principles to become a more proficient and thoughtful developer. Happy coding!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4f498580ecf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Distributing a Flutter App on Firebase with Fastlane for Android]]></title>
            <link>https://medium.com/@shwetapanwar97/distributing-a-flutter-app-on-firebase-with-fastlane-for-android-0dc265c7f415?source=rss-6093b2f35d39------2</link>
            <guid isPermaLink="false">https://medium.com/p/0dc265c7f415</guid>
            <category><![CDATA[fastlane]]></category>
            <category><![CDATA[fastlane-android]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[CurlyCoder]]></dc:creator>
            <pubDate>Wed, 03 Jan 2024 20:02:54 GMT</pubDate>
            <atom:updated>2024-01-03T20:02:54.011Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O4G2xMva31A7qHe6ZHbJhw.png" /></figure><p>In the dynamic world of mobile app development, deploying an application efficiently is crucial for reaching your audience seamlessly. In this blog post, we’ll explore how to distribute a Flutter app on Firebase using Fastlane, a powerful tool that streamlines the deployment process. Fastlane simplifies tedious tasks, automates build and deployment processes, and enhances collaboration among team members.</p><p><strong>Prerequisites</strong>: Before diving into the deployment process, make sure you have the following prerequisites:</p><ul><li>A Flutter app ready for deployment.</li><li>Firebase project set up with the necessary configurations.</li><li>Fastlane installed on your development machine.</li></ul><h3>Setting Up Fastlane</h3><p>To set up Fastlane for your Flutter project, follow these steps:</p><ol><li>Install Fastlane by running the following command:</li></ol><pre>gem install fastlane</pre><p>Navigate to your Flutter project directory and run the following command to initialize Fastlane:</p><pre>fastlane init</pre><p>During the initialization process, you’ll be prompted to enter your package name. Additionally, enter the path to the secret file (.json) associated with your Google Cloud Service Account. This service account should have the following permissions:</p><ul><li>Owner</li><li>Firebase App Distribution Admin</li><li>Service Account User</li></ul><p>This ensures that Fastlane can interact with Firebase and perform the necessary deployment tasks.</p><h4>Adding Fastlane Plugins</h4><p>To enhance Fastlane’s capabilities for Flutter and Firebase deployment, add the following plugins:</p><pre>fastlane add_plugin firebase_app_distribution flutter git_switch_branch</pre><p>This command adds the firebase_app_distribution, flutter, and git_switch_branch plugins to your Fastlane configuration.</p><h4>Configuring Fastlane for Firebase Deployment</h4><p>Next, configure Fastlane to deploy your Flutter app to Firebase. Open the Fastfile in the ‘fastlane’ directory and add lane for Firebase deployment for Android platform:</p><pre>platform :android do<br>  lane :deploy_to_firebase do<br>    # Add Firebase deployment commands here<br>  end<br>end</pre><p>Replace the comments with the necessary Firebase deployment commands for Android platform.</p><p>Add Firebase distribution configurations to your ‘fastlane/Fastfile’:</p><pre>default_platform(:android)<br><br>platform :android do<br>  before_all do<br>    ENV[&quot;FIREBASE_LOGIN_CREDENTIALS&quot;] = &quot;PATH_TO_YOUR_JSON_KEY&quot;<br>    ENV[&quot;FIREBASE_APP_ID&quot;] = &quot;YOUR_ANDROID_APP_ID&quot;<br>    ENV[&quot;FIREBASE_TOKEN&quot;] = &quot;YOUR_FIREBASE_CLI_TOKEN&quot;<br>  end<br><br>  lane :deploy_to_firebase do |options|<br>    # Firebase App Distribution for Android<br>    unless options[:branch].nil?<br>      git_switch_branch(branch: options[:branch])<br>      git_pull<br>    end<br>    flutter(args: %(clean))<br>    flutter(args: %w[pub get])<br>    output_file = flutter_build(<br>      build: &#39;appbundle&#39;,<br>    )<br>    firebase_app_distribution(<br>      app: ENV[&quot;FIREBASE_APP_ID&quot;],<br>      android_artifact_type: &#39;AAB&#39;,<br>      android_artifact_path: &#39;PATH_TO_APPBUNDLE&#39;,<br>      release_notes: &quot;Fastlane Build&quot;,<br>      groups: &#39;YOUR_TESTERS_GROUP_NAME&#39;,<br>      firebase_cli_token: ENV[&quot;FIREBASE_TOKEN&quot;],<br>      service_credentials_file: ENV[&quot;FIREBASE_LOGIN_CREDENTIALS&quot;]<br>    )<br>  end<br>end</pre><p>Replace “YOUR_ANDROID_APP_ID” with your Android app bundle ID.</p><h4>Adding Firebase CLI Token</h4><p>Create a Firebase CLI Token using the following command:</p><pre>firebase login:ci</pre><p>This command will prompt you to log in and generate a Firebase CLI token, which is essential for authentication during the deployment process.</p><h4>Obtaining the JSON Key File for Firebase</h4><p>Before you can deploy your Flutter app to Firebase, obtain a JSON key file for authentication by following these steps:</p><ol><li><strong>Go to the Firebase Console</strong>: Open your web browser and navigate to the Firebase Console.</li><li><strong>Select Your Project</strong>: If you already have a Firebase project, select it from the list. If not, create a new project.</li><li><strong>Navigate to Project Settings</strong>: Click on the gear icon (settings) in the left-hand navigation menu to go to “Project settings.”</li><li><strong>Service accounts</strong>: In the Project settings, navigate to the “Service accounts” tab.</li><li><strong>Generate New Private Key</strong>: Scroll down to the “Firebase Admin SDK” section and click on “Generate new private key.”</li><li><strong>Download the JSON Key File</strong>: After clicking “Generate new private key,” the key will be downloaded as a JSON file.</li><li><strong>Securely Store the JSON Key File: </strong>The JSON key file contains sensitive information and should be handled with care. Make sure to store it securely and avoid exposing it in your version control system. It’s a good practice to add the JSON key file to your project in a location that is excluded from version control (e.g., add it to your project’s .gitignore file).</li><li><strong>Referencing the JSON Key File in Fastlane:</strong> In the Appfile of your Fastlane configuration, use the json_key_file method to specify the path to the JSON key file:</li></ol><pre>json_key_file(&quot;path/to/your/firebase/credentials.json&quot;)</pre><p>Replace “path/to/your/firebase/credentials.json” with the actual path to your downloaded JSON key file.</p><p><strong>Setup firebase app distribution through API:</strong></p><ol><li><strong>Open the Cloud Console:</strong> Go to the Google Cloud Console.</li><li><strong>Select a Project:</strong> Make sure you are working within the correct Google Cloud project. You can select your project from the project drop-down menu at the top of the page.</li><li><strong>Open the API Library:</strong> In the left-hand navigation pane, click on “APIs &amp; Services” and then select “Library.”</li><li><strong>Find the API:</strong> Use the search bar to find the “Firebase App Distribution API” to enable.</li><li><strong>Enable the API:</strong> Click on the API you want to enable, and on the next page, click the “Enable” button.</li></ol><p>Now, you can manage apps through API. To validate your json_key_file run the following command:</p><pre>fastlane run validate_play_store_json_key json_key:&quot;path/to/your/firebase/credentials.json&quot;</pre><p><strong>Deploying Your Flutter App to Firebase:</strong> Now that Fastlane is configured, deploying your Flutter app to Firebase is a breeze. Run the following command:</p><pre>fastlane deploy_to_firebase</pre><p>Fastlane will execute the specified Firebase deployment commands for Android platform. Monitor the deployment progress in the console, and once completed, your Flutter app will be available for distribution through Firebase App Distribution.</p><pre>fastlane deploy_to_firebase branch:BRANCH_NAME</pre><p>This command specifies the branch (BRANCH_NAME in this case) that you want to deploy. You can replace BRANCH_NAME with the name of your desired branch. This is particularly useful if you have different branches for development, staging, or production, allowing you to deploy specific branches as needed.</p><h3>Conclusion</h3><p>Automating the deployment process is essential for maintaining a streamlined and efficient development workflow. By integrating Fastlane into your Flutter project and configuring it for Firebase deployment, you can ensure a seamless and hassle-free distribution process. Fastlane empowers developers to focus on building great apps while automating the tedious tasks associated with deployment. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0dc265c7f415" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Flutter and Have Some Fun!]]></title>
            <link>https://medium.com/@shwetapanwar97/lets-flutter-and-have-some-fun-ac68be1b9d41?source=rss-6093b2f35d39------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac68be1b9d41</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[CurlyCoder]]></dc:creator>
            <pubDate>Tue, 12 Sep 2023 07:24:20 GMT</pubDate>
            <atom:updated>2023-10-16T16:01:51.897Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello there, Flutter enthusiasts! 🚀 Are you ready to embark on a joyful journey into the world of Flutter? Well, grab your code hats and get ready to create a Flutter app that’s not just functional but loads of fun! 😄</p><h4>Why Flutter, You Ask?</h4><p>First things first, why Flutter? Well, Flutter is an open-source UI software development kit created by Google. It’s like a magic wand for app developers because it allows you to create beautiful, natively compiled applications for mobile, web, and desktop from a single codebase. Plus, it’s super fun to work with! 🎩✨</p><h4>Let’s Get Set Up!</h4><p>Before we dive into the fun part, we need to set up our Flutter development environment. Don’t worry; it’s as easy as a piece of cake! 🍰</p><p>1. <em>Install Flutter</em>: Visit the [official Flutter website](<a href="https://flutter.dev/">https://flutter.dev/</a>) and follow the installation instructions for your operating system. Flutter comes with a handy tool called Flutter Doctor, which checks your setup and suggests any missing components.</p><p>2. <em>Choose an IDE</em>: You can use Android Studio, Visual Studio Code, or any other code editor of your choice. Just make sure to install the Flutter and Dart plugins for a smoother development experience.</p><p>3. <em>Create Your First Flutter Project</em>: Open your terminal and run the following command to create a new Flutter project:</p><pre>flutter create fun_jolly_app</pre><p>4. <em>Run Your App</em>: Navigate to your project folder and run your app on your preferred emulator or device:</p><pre>cd fun_jolly_app<br>flutter run</pre><h4>Adding Some Fun Elements</h4><p>Now, it’s time to sprinkle some fun elements into your Flutter app! Let’s start with something simple yet enjoyable — a random joke generator. 🤣</p><ol><li><em>Add Dependencies</em>: Open your `<em>pubspec.yaml</em>` file and add the following dependency for fetching jokes:</li></ol><pre>dependencies:<br>  http: ^0.13.3</pre><p>2. <em>Fetch Jokes</em>: Create a new Dart file, let’s call it `joke_service.dart`. Write a function to fetch jokes from a public API like [official-joke-api](<a href="https://github.com/15Dkatz/official_joke_api">https://github.com/15Dkatz/official_joke_api</a>):</p><pre>import &quot;package:http/http.dart&quot; as http;<br>import &quot;dart:convert&quot;;<br><br>Future&lt;String&gt; fetchRandomJoke() async {<br>  final response = await http<br>  .get(Uri.parse(&quot;https://official-joke-api.appspot.com/random_joke&quot;));<br>  if (response.statusCode == 200) <br>  {<br>    final Map&lt;String, dynamic&gt; data = json.decode(response.body);<br>    return &#39;${data[&quot;setup&quot;]} ${data[&quot;punchline&quot;]}&#39;;<br>  } <br>  else <br>  {<br>    throw Exception(&quot;Failed to load joke&quot;);<br>  }<br>}</pre><p>3. <em>Display Jokes</em>: In your main app file (`main.dart`), call the `fetchRandomJoke` function and display the joke:</p><pre>import &quot;package:flutter/material.dart&quot;;<br>import &quot;joke_service.dart&quot;;<br><br>void main() =&gt; runApp(const MyApp());<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({super.key});<br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      home: Scaffold(<br>        appBar: AppBar(<br>          title: const Text(&quot;Fun &amp; Jolly Jokes&quot;),<br>        ),<br>        body: Center(<br>          child: FutureBuilder&lt;String&gt;(<br>            future: fetchRandomJoke(),<br>            builder: (context, snapshot) {<br>              if (snapshot.connectionState == ConnectionState.waiting) {<br>                return const CircularProgressIndicator();<br>              } else if (snapshot.hasError) {<br>                return Text(&quot;Error: ${snapshot.error}&quot;);<br>              } else {<br>                return Text(<br>                  snapshot.data!,<br>                  style: const TextStyle(fontSize: 18),<br>                );<br>              }<br>            },<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Run Your App</p><p>Now, save your changes and run your app again using `flutter run`. Voilà! Your Flutter app is now a source of endless fun and laughter with a new joke every time you refresh the page.</p><p>Remember, Flutter is not just about building apps; it’s about having fun while doing it! So go ahead, experiment with widgets, add more fun features, and let your creativity run wild. Happy Fluttering! 🚀😄</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac68be1b9d41" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>