<?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 Suryakant Dubey on Medium]]></title>
        <description><![CDATA[Stories by Suryakant Dubey on Medium]]></description>
        <link>https://medium.com/@suryakant.dubey.dev?source=rss-60b6ed8ed064------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nCEFkrUaEr6C0XMFQYu1qw.png</url>
            <title>Stories by Suryakant Dubey on Medium</title>
            <link>https://medium.com/@suryakant.dubey.dev?source=rss-60b6ed8ed064------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:46:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@suryakant.dubey.dev/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[Method channel in Flutter]]></title>
            <link>https://medium.com/@suryakant.dubey.dev/method-channel-in-flutter-d4fb1a012e9?source=rss-60b6ed8ed064------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4fb1a012e9</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Suryakant Dubey]]></dc:creator>
            <pubDate>Fri, 12 Apr 2024 02:14:27 GMT</pubDate>
            <atom:updated>2024-04-12T02:18:10.329Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is method channel?</h3><p>MethodChannel in Flutter is like a phone line between your Flutter app and the underlying Android or iOS system. It lets your Flutter app talk to the system’s code, which is written in languages like Java, Kotlin, Swift, or Objective-C.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*4DtHPJHwhr5Zw01MAZjhrw.png" /></figure><h4><strong>Here is few steps to create method channel in flutter.</strong></h4><p><strong>Setting up the Channe</strong>l:</p><p>Create a special communication channel with a unique name which will be common in your flutter app as well as native side Android and iOS you can use Kotlin/Java for android and Swift/Objective-C</p><pre> static const platform = MethodChannel(&#39;samples.flutter.dev/battery&#39;);</pre><p><strong>Invoking Methods</strong>: From your Flutter app, you can use this channel to call functions in the system’s code. You can also send information to these functions and get back results.</p><pre> var result = await platform.invokeMethod(&#39;passDataToNative&#39;, [<br>        {&quot;text&quot;: userName}<br>      ]);</pre><p>Native Implementation: On the native side, you write the actual code that does the work when your Flutter app calls a function. This code can do things specific to the Android or iOS system.<br>Let’s have a look that how we can listen this code from native. here I’m using Kotlin for Android and Swift for iOS you can use whatever you want.</p><h4><strong>Android:</strong></h4><pre>private val channel = &quot;samples.flutter.dev/battery&quot;<br><br>  override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {<br>        super.configureFlutterEngine(flutterEngine)<br>        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel).setMethodCallHandler {<br>            // This method is invoked on the main thread.<br>                call, result -&gt;<br><br>            if (call.method == &quot;passDataToNative&quot;) {<br><br>                // Your code here<br><br>            } else {<br>                result.notImplemented()<br>            }<br>        }<br>    }</pre><h4>iOS</h4><pre>      let controller : FlutterViewController = window?.rootViewController as! FlutterViewController<br>       let batteryChannel = FlutterMethodChannel(name: &quot;samples.flutter.dev/battery&quot;,<br>                                                 binaryMessenger: controller.binaryMessenger)<br>      batteryChannel.setMethodCallHandler({<br>        [weak self] (call: FlutterMethodCall, result: FlutterResult) -&gt; Void in<br>        // This method is invoked on the UI thread.<br>        guard call.method == &quot;passDataToNative&quot;<br>          else {<br>          result(FlutterMethodNotImplemented)<br>          return<br>        }<br>         // Your code here<br>      })</pre><p>4. Once the system’s code finishes its job, it can send back results to your Flutter app. Your app can then use these results as needed.</p><p>In simple terms, a MethodChannel is like a secret line that lets your Flutter app talk to the system’s code when it needs to do things that only the system can handle.</p><p>Let’s explore an example of passing a username from a Flutter app to the native side and displaying a message from the native side back to Flutter. This can help you learn how to pass and receive data in Flutter from native code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*7MtXgf_AAIKv20wqVMkm-Q.gif" /><figcaption>Let’s do it.</figcaption></figure><h4>Dart:</h4><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter/services.dart&#39;;<br>import &#39;package:provider/provider.dart&#39;;<br><br>void main() {<br>  runApp(<br>    const MyApp(),<br>  );<br>}<br><br>class MyApp extends StatelessWidget {<br>  const MyApp({Key? key}) : super(key: key);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return const MaterialApp(<br>      home: MyHomePage(),<br>    );<br>  }<br>}<br><br>class MyHomePage extends StatefulWidget {<br>  const MyHomePage({Key? key}) : super(key: key);<br><br>  @override<br>  State&lt;MyHomePage&gt; createState() =&gt; _MyHomePageState();<br>}<br><br>class _MyHomePageState extends State&lt;MyHomePage&gt; {<br>  static const platform = MethodChannel(&#39;samples.flutter.dev/battery&#39;);<br>  String msgFromNative = &#39;&#39;;<br><br>  Future&lt;void&gt; _passDataToNative(String userName) async {<br>    try {<br>      var result = await platform.invokeMethod(&#39;passDataToNative&#39;, [<br>        {&quot;text&quot;: userName}<br>      ]);<br>      msgFromNative = &#39; $result.&#39;;<br>    } on PlatformException catch (e) {<br>      msgFromNative = &quot;Failed to get battery level: &#39;${e.message}&#39;.&quot;;<br>    }<br>    setState(() {<br>      msgFromNative = msgFromNative;<br>    });<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: const Text(&#39;Example&#39;),<br>      ),<br>      body: Center(<br>        child: Column(<br>          mainAxisSize: MainAxisSize.min,<br>          mainAxisAlignment: MainAxisAlignment.center,<br>          children: &lt;Widget&gt;[<br>            ElevatedButton(<br>              onPressed: () {<br>                  _passDataToNative(&#39;Flutter Dev&#39;);<br>              },<br>              child: const Text(&#39;Pass data to native&#39;),<br>            ),<br>            Text(msgFromNative),<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><h4>Kotlin:</h4><pre>package com.example.flutter_demo_app<br>import androidx.annotation.NonNull<br>import io.flutter.embedding.android.FlutterActivity<br>import io.flutter.embedding.engine.FlutterEngine<br>import io.flutter.plugin.common.MethodChannel<br>import android.content.Context<br>import android.content.ContextWrapper<br>import android.content.Intent<br>import android.content.IntentFilter<br>import android.os.Build.VERSION<br>import android.os.Build.VERSION_CODES<br>import android.util.Log<br><br><br>class MainActivity: FlutterActivity() {<br>    private val channel = &quot;samples.flutter.dev/battery&quot;<br><br>    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {<br>        super.configureFlutterEngine(flutterEngine)<br>        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel).setMethodCallHandler {<br>            // This method is invoked on the main thread.<br>                call, result -&gt;<br><br>            if (call.method == &quot;passDataToNative&quot;) {<br>                // Your code here<br>                val arguments = call.arguments as List&lt;Map&lt;String, Any&gt;&gt;<br>                val userName = arguments.first()[&quot;text&quot;] as String<br>               println( &quot;Received userName::: $userName&quot;)<br>                result.success(&quot;Received userName::: $userName&quot;)<br>               <br>            } else {<br>                result.notImplemented()<br>            }<br>        }<br>    }<br>}</pre><h4>Swift:</h4><pre>import UIKit<br>import Flutter<br><br>@UIApplicationMain<br>@objc class AppDelegate: FlutterAppDelegate {<br>  override func application(<br>    _ application: UIApplication,<br>    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?<br>  ) -&gt; Bool {<br>      let controller : FlutterViewController = window?.rootViewController as! FlutterViewController<br>       let batteryChannel = FlutterMethodChannel(name: &quot;samples.flutter.dev/battery&quot;,<br>                                                 binaryMessenger: controller.binaryMessenger)<br>      batteryChannel.setMethodCallHandler({<br>        [weak self] (call: FlutterMethodCall, result: FlutterResult) -&gt; Void in<br>        // This method is invoked on the UI thread.<br>        guard call.method == &quot;passDataToNative&quot;<br>          else {<br>          result(FlutterMethodNotImplemented)<br>          return<br>        }<br>          self?.passDataToFlutter(result: result,call:call)<br>      })<br>    GeneratedPluginRegistrant.register(with: self)<br>    return super.application(application, didFinishLaunchingWithOptions: launchOptions)<br>  }<br>private func passDataToFlutter(result: FlutterResult, call: FlutterMethodCall) {<br>    guard let arguments = call.arguments as? [[String: Any]],<br>        let firstArgument = arguments.first,<br>        let userName = firstArgument[&quot;text&quot;] as? String else {<br>            result(FlutterError(code: &quot;INVALID_ARGUMENT&quot;, message: &quot;Invalid arguments&quot;, details: nil))<br>            return<br>    }<br>    // Print the userName<br>    print(&quot;Received userName: \(userName)&quot;)<br>    // Send the result back to Flutter<br>    result(&quot;Received userName: \(userName)&quot;)<br>}<br>}</pre><p>By using above code you can pass the data from your flutter app and receive it in your native side and perform whatever you want in your native side of code because sometimes hybrid sdk like flutter doesn’t provide all the things so we can achieve it using native communication.</p><p>In flutter we can perform native communication by two ways.</p><p>1: Method Channel</p><p>2: Event Channel</p><p>In this blog I have covered method channel let me know in the commet section if you want to learn event channel so I will write another detailed blog it.</p><h4>Reference:</h4><p><a href="https://docs.flutter.dev/platform-integration/platform-channels?tab=android-channel-kotlin-tab">Writing custom platform-specific code</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4fb1a012e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Flutter Web App on Firebase]]></title>
            <link>https://medium.com/@suryakant.dubey.dev/deploy-flutter-web-app-on-firebase-effdfe63d858?source=rss-60b6ed8ed064------2</link>
            <guid isPermaLink="false">https://medium.com/p/effdfe63d858</guid>
            <category><![CDATA[web-deployment]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[deployment]]></category>
            <dc:creator><![CDATA[Suryakant Dubey]]></dc:creator>
            <pubDate>Thu, 30 Nov 2023 14:59:14 GMT</pubDate>
            <atom:updated>2023-11-30T14:59:14.725Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey, are you willing to deploy your Flutter web app or want to learn how? You are in the right place! I will try to explain all the steps to deploy your Flutter web app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*IDl7FIOE8PNRy-UFtBRp1w.gif" /></figure><p>I am assuming that you have already set up a Flutter project with Firebase. I am going to cover only the deployment process. If you want to know about setting up a Firebase project in Flutter, let me know in the comments, and I will cover that as well.</p><p>You will require Node.js installed on your system for using the command-line tools of Firebase. If you already have it, you can move on to the next step.</p><p>To download Node.js, please visit <a href="https://nodejs.org/">https://nodejs.org</a> and download the latest version of Node.</p><p>After installing Node.js, run this command in the terminal:</p><pre>npm install -g firebase-tools</pre><p>After running the above command, you need to run the following commands in the terminal again:</p><pre>firebase login</pre><p>Complete the authentication process to enable CLI for the Flutter project.</p><p>Once successfully logged in, you will see an image like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*dtYRwCimso00h20jVR7vLA.png" /></figure><p>Now run:</p><pre>firebase init</pre><p>You will see something like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lvxa7WvfyWfiZu8DZ_wvGA.png" /></figure><p>Now select hosting configuration as below using the “arrow” keys and press “space” to select. You will see a green dot on the selected project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7i4EcSyUx6q3mgKeA9WxLQ.png" /></figure><p>Now press enter and select the existing project, or you can create a new project. I am using an existing project here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_khJJBBpINxIuLdyrClQ5Q.png" /></figure><p>Now you have to select your project from the console and hit enter. After that, it will ask for the public folder, which you need to deploy. Enter as below for the Flutter web app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k0agx-jmaPX7uzNdUEJ9Ag.png" /></figure><p>After entering the public path, hit enter. Now type ’N’ and hit enter again. Note: Use “/” for the path on Mac and “\” for Windows. This is the only difference in deployment between Windows and Mac, i.e., “build/web” for Mac and “build\web” for Windows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ef_HHHQuNS0cCL0aYq-FwA.png" /></figure><p>After that, you will be asked for CI/CD. Now type ’N’ again and hit enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAOpAvnJCrK30lf_mQzsYQ.png" /></figure><p>Boom! You have successfully set up Firebase for web deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QkgPhMjZu_01-Pt6zYJk8Q.png" /></figure><p>Now build the Flutter web app using the command:</p><pre>flutter build web</pre><p>Now run our final command for web app deployment:</p><pre>firebase deploy</pre><p>Boom! Your web app is deployed on Flutter web.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gS_5KHVxtumHfaUpXxwOPQ.png" /></figure><p>Deploying your Flutter web app on Firebase is a simple and effective process. By following the provided steps, you’ve successfully set up Firebase for web deployment and launched your app with ease. Firebase’s reliable hosting ensures a smooth showcase for your web application.</p><p>Your web app is now live, so share it with the world and celebrate this accomplishment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=effdfe63d858" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>