<?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 Destiny Ed on Medium]]></title>
        <description><![CDATA[Stories by Destiny Ed on Medium]]></description>
        <link>https://medium.com/@DestinyEd?source=rss-498d26d4e108------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rrahgfQ4k5JZxJNz</url>
            <title>Stories by Destiny Ed on Medium</title>
            <link>https://medium.com/@DestinyEd?source=rss-498d26d4e108------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 06:20:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@DestinyEd/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[Integrate Video Calling Feature In Flutter]]></title>
            <link>https://medium.com/@DestinyEd/integrate-video-calling-feature-in-flutter-8614119a21e6?source=rss-498d26d4e108------2</link>
            <guid isPermaLink="false">https://medium.com/p/8614119a21e6</guid>
            <dc:creator><![CDATA[Destiny Ed]]></dc:creator>
            <pubDate>Fri, 11 Aug 2023 09:00:44 GMT</pubDate>
            <atom:updated>2023-08-16T22:18:33.542Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F12eNbWaqJl2TEzHxXdzkQ.jpeg" /></figure><p>Integrating an engaging video communication experience for your Flutter users has always been challenging. In this tutorial, we will learn how to incorporate one-on-one video calling using <a href="https://www.zegocloud.com/product/video-call">ZegoCloud Video SDK</a> in your project.</p><p><strong>ZeGoCloud Video SDK</strong></p><p>The ZegoCloud Video SDK provides powerful real-time video and audio communication that can enhance your app’s experience. This SDK offers a comprehensive set of tools for adding calling features in less time. With the SDK, you can create interactive video calls, live streaming, and video conferencing functionality in your app.</p><p><em>Note: Our focus in this tutorial will only be on video and audio(one-on-one) calling.</em></p><p><strong>Let’s Go, Hero!!</strong></p><p>Hold on, we don’t want to rush this… I want us to take it one step at a time until we see ourselves on our phone screen.</p><p>Before you begin, there are certain things you need to get ready.</p><p><strong>Prerequisites</strong></p><ol><li>Zego developer account: You’ll need to sign up for an account on the <a href="https://console.zegocloud.com/dashboard">Zego Developer Portal</a> and create a project to obtain your AppID and AppSign credentials.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HTLIm40X0WJM7qvlS1K2kQ.png" /></figure><p>At some point, while creating the project, you will be presented with two methods of integrations to choose from</p><ul><li>SDK integration: We use this if we want to make the calling feature/UI dynamic and to have more control over it.</li><li>PreBuilt UiKits: Use this if you just want basic features. it’s just a Flutter widget that has some built-in functionality and visual parts.</li></ul><p>Click on <strong>Start with Custom SDK </strong>as that is what the article is going to cover.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vkG3z4RmwkZxaYAnm5zVUw.png" /></figure><p>After creating the project and selecting the type of project you want to create, you can now select the project in other to obtain the app sign and appID keys</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tYL2SCCr-83vqZcX3FvFYQ.png" /></figure><p>2. A development environment: Install Flutter and set up your preferred development environment (e.g., Android Studio, Visual Studio Code).</p><p>At this point, you also need to create a new Flutter project</p><p>It’s time we begin. but first, make sure you have already done the above steps and you have gotten your AppSign and AppID keys as these two values are what we need to connect with ZegoCloud Engine.</p><p><strong>Step 1: Set Up Your Project</strong></p><p>Create a new Flutter project or open an existing project that you would like to add the calling feature to</p><p>In other to start integrating Zego Cloud SDK, we need to add the latest versions of <a href="https://pub.dev/packages/zego_express_engine"><strong>zego_cloud_express_engine</strong></a> and <a href="https://pub.dev/packages/permission_handler"><strong>permission_handler</strong></a><strong> </strong>into our pubspec.yaml file.</p><pre>dependencies:<br>  zego_express_engine: ^3.6.1<br>  permission_handler: ^10.4.3</pre><p>Now that we have added our dependencies, we can start setting up permissions for the target platforms (Android and IOS)</p><h4>Add permissions for Android devices</h4><p>open your project’s Android manifest file app/src/main/AndroidManifest.xml, and add the following code:</p><pre>&lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot; /&gt;<br>    &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;<br>    &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;<br>    &lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; /&gt;<br>     &lt;uses-permission android:name=&quot;android.permission.MODIFY_AUDIO_SETTINGS&quot; /&gt;<br>     &lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot; /&gt;</pre><h4>Add permissions for iOS devices</h4><p>Inside your project’s IOS directory, open ios/Runner/Info.plist, and add the following code:</p><pre>&lt;key&gt;NSCameraUsageDescription&lt;/key&gt;<br> &lt;string&gt;We require camera access to connect to a call&lt;/string&gt;<br>  &lt;key&gt;NSMicrophoneUsageDescription&lt;/key&gt;<br> &lt;string&gt;We require microphone access to connect to a call&lt;/string&gt;</pre><p>Now open your Podfile ios/Podfile, and make sure it has the following code :</p><pre>post_install do |installer|<br>  installer.pods_project.targets.each do |target|<br>    flutter_additional_ios_build_settings(target)<br><br>    # Start of the permission_handler configuration<br>    target.build_configurations.each do |config|<br>   <br>      # You can enable the permissions needed here. For example to enable camera<br>      # permission, just remove the `#` character in front so it looks like this:<br>      #<br>      # ## dart: PermissionGroup.camera<br>      # &#39;PERMISSION_CAMERA=1&#39;<br>      #<br>      #  Preprocessor definitions can be found in: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler_apple/ios/Classes/PermissionHandlerEnums.h<br>      config.build_settings[&#39;GCC_PREPROCESSOR_DEFINITIONS&#39;] ||= [<br>        &#39;$(inherited)&#39;,<br>  <br>        ## dart: PermissionGroup.calendar<br>        # &#39;PERMISSION_EVENTS=1&#39;,<br>  <br>        ## dart: PermissionGroup.reminders<br>        # &#39;PERMISSION_REMINDERS=1&#39;,<br>  <br>        ## dart: PermissionGroup.contacts<br>        # &#39;PERMISSION_CONTACTS=1&#39;,<br>  <br>        ## dart: PermissionGroup.camera<br>        &#39;PERMISSION_CAMERA=1&#39;,<br>  <br>        ## dart: PermissionGroup.microphone<br>        &#39;PERMISSION_MICROPHONE=1&#39;,<br>  <br>        ## dart: PermissionGroup.speech<br>        # &#39;PERMISSION_SPEECH_RECOGNIZER=1&#39;,<br>  <br>        ## dart: PermissionGroup.photos<br>        # &#39;PERMISSION_PHOTOS=1&#39;,<br>  <br>        ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]<br>        # &#39;PERMISSION_LOCATION=1&#39;,<br>          <br>        ## dart: PermissionGroup.notification<br>        # &#39;PERMISSION_NOTIFICATIONS=1&#39;,<br>  <br>        ## dart: PermissionGroup.mediaLibrary<br>        # &#39;PERMISSION_MEDIA_LIBRARY=1&#39;,<br>  <br>        ## dart: PermissionGroup.sensors<br>        # &#39;PERMISSION_SENSORS=1&#39;,   <br>           <br>        ## dart: PermissionGroup.bluetooth<br>        # &#39;PERMISSION_BLUETOOTH=1&#39;,<br>   <br>        ## dart: PermissionGroup.appTrackingTransparency<br>        # &#39;PERMISSION_APP_TRACKING_TRANSPARENCY=1&#39;,<br>   <br>        ## dart: PermissionGroup.criticalAlerts<br>        # &#39;PERMISSION_CRITICAL_ALERTS=1&#39;<br>      ]<br>  <br>    end <br>    # End of the permission_handler configuration<br>  end<br>end</pre><p>Nice!! we have successfully defined the necessary permissions for our target platforms to work.</p><p><strong>Now let’s proceed</strong></p><p>If you are creating a new Flutter project, make sure to create directories and files like the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*nHEVaM4TDkzig3lsQTjzmg.png" /></figure><ul><li>screens: It’s a directory that holds the call_page.dart and home_page.dart of our calling app. We will fill it with code later…</li><li>constant.dart: Inside this file, we are going to create appSign and appID variables. Replace YOUR_APP_ID and YOUR_APP_SIGN with your actual Zego AppID and AppSign.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*LDEf98hk9duQ_CPDf5YwAw.png" /></figure><ul><li>utils.dart: Here, we add permissions for requesting microphone and camera access</li></ul><pre>import &#39;package:permission_handler/permission_handler.dart&#39;;<br><br>Future checkPermission() async {<br>  final permission = await Permission.camera.status;<br>  final audio = await Permission.microphone.status;<br><br>  print(&quot;permission camera : $permission&quot;);<br>  print(&quot;audio : $audio&quot;);<br><br>  if (!permission.isGranted) {<br>    await Permission.camera.request().then((value) async {<br>      if (!audio.isGranted) {<br>        await Permission.microphone.request();<br>      }<br>    });<br>  } else {<br>    if (!audio.isGranted) {<br>      await Permission.microphone.request();<br>    }<br>  }<br><br>  return Future.value(true);<br>}</pre><ul><li>main.dart: This is the starting point of our app, we will initialize the ZegoCloud engine and pass in the appSign and AppID keys</li></ul><p><strong>Step 2: Initialize the SDK</strong></p><p>Inside <strong>main.dart</strong>, we are going to initialize the Zego SDK engine using your AppID and AppSign:</p><p><em>Don’t forget to import the constant file and SDK at the top of your Dart file</em></p><pre>void main() {<br>  WidgetsFlutterBinding.ensureInitialized();<br>  // Get your AppID and AppSign from ZEGOCLOUD Console<br>  //[My Projects -&gt; AppID] : https://console.zegocloud.com/project<br>  ZegoExpressEngine.createEngineWithProfile(ZegoEngineProfile(<br>    appId,<br>    ZegoScenario.Default,<br>    appSign: appSignId,<br>  ));<br><br>  runApp(const MyApp());<br>}</pre><p><strong>Step 3: Implement Video Calling</strong></p><p>We are going to create a screen inside ‘home_page.dart’ with two input fields for taking <em>roomID</em> and <em>userName</em> and then we create two buttons for <em>joining</em> and <em>creating</em> a new meeting room.</p><ul><li>RoomID: It will be generated automatically when a user creates a new meeting and it will be required when a user tries to join an existing meeting. RoomID is going to be unique anytime a user creates a new meeting.</li><li>Username: It will be required when a user is creating or joining a new or existing meeting as it will be used as an identifier. The username can be the email address or name of the user or whatsoever you decide to use in your application.</li></ul><p>Now that we know what the RoomID and UserName are for, we can go ahead and create the UI to collect those details.</p><p>In your <strong><em>home_page.dart</em></strong> file, add the below code and import the necessary files…</p><pre>class HomePage extends StatefulWidget {<br>  const HomePage({super.key});<br><br>  @override<br>  State&lt;HomePage&gt; createState() =&gt; _HomePageState();<br>}<br><br>class _HomePageState extends State&lt;HomePage&gt; {<br>  TextEditingController roomController = TextEditingController();<br>  TextEditingController nameController = TextEditingController();<br><br>  @override<br>  void initState() {<br>    super.initState();<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: const Text(&quot;Home Page&quot;),<br>      ),<br>      body: Padding(<br>        padding: const EdgeInsets.all(10.0),<br>        child: Column(<br>          children: [<br>            TextFormField(<br>              controller: roomController,<br>              decoration: const InputDecoration(label: Text(&quot;Enter Room Id&quot;)),<br>            ),<br>            const SizedBox(<br>              height: 30,<br>            ),<br>            TextFormField(<br>              controller: nameController,<br>              decoration: const InputDecoration(label: Text(&quot;Enter Username&quot;)),<br>            ),<br>            const SizedBox(<br>              height: 30,<br>            ),<br>            Row(<br>              mainAxisAlignment: MainAxisAlignment.spaceEvenly,<br>              children: [<br>                TextButton(<br>                    onPressed: () {<br>                      if (nameController.text.isEmpty || roomController.text.isEmpty) {<br>                        message(context, &quot;All fields are required&quot;);<br>                      } else {<br>                        ///Navigate to call page<br>                        Navigator.push(<br>                          context,<br>                          CupertinoPageRoute(<br>                            builder: (context) =&gt; CallPage(<br>                              roomId: roomController.text.trim(),<br>                              name: nameController.text.trim(),<br>                            ),<br>                          ),<br>                        );<br>                      }<br>                    },<br>                    child: const Text(&quot;Join Meeting&quot;)),<br>                TextButton(<br>                    onPressed: () {<br>                      if (nameController.text.isEmpty) {<br>                        message(context, &quot;Name field is required&quot;);<br>                      } else {<br>                        ///Navigate to call page<br>                        Navigator.push(<br>                          context,<br>                          CupertinoPageRoute(<br>                            builder: (context) =&gt; CallPage(<br>                              name: nameController.text.trim(),<br>                            ),<br>                          ),<br>                        );<br>                      }<br>                    },<br>                    child: const Text(&quot;Create Meeting&quot;))<br>              ],<br>            )<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}<br><br>void message(BuildContext context, String message) {<br>  ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));<br>}</pre><p>Still, inside the <em>initState</em> of your <strong><em>home_page.dart</em> </strong>screen, add the <strong><em>checkPermission()</em></strong> method. This method will ask the user for camera and microphone permission before accessing the calling feature</p><pre>@override<br>  void initState() {<br>    super.initState();<br>    checkPermission();<br>  }</pre><p>Now that we have the home screen UI ready, we can run the app to see how it looks.</p><p>I believe everything looks fine, now let’s set up <strong>video views for local and remote users</strong>.</p><p>In your <strong>call<em>_page.dart</em></strong> file that we created at the beginning of this article, add the below code and import the necessary files…</p><pre>import &#39;dart:math&#39;;<br><br>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:video_caller/utils.dart&#39;;<br>import &#39;package:zego_express_engine/zego_express_engine.dart&#39;;<br><br>class CallPage extends StatefulWidget {<br>  String? roomId;<br>  String? name;<br>  CallPage({super.key, this.name, this.roomId});<br><br>  @override<br>  State&lt;CallPage&gt; createState() =&gt; _CallPageState();<br>}<br><br><br>class _CallPageState extends State&lt;CallPage&gt; {<br>  Widget? localView;<br>  Widget? remoteView;<br><br>  int? localViewID;<br>  int? remoteViewID;<br><br>  String getRoomId() {<br>    Random rand = Random();<br>    if (widget.roomId == null) {<br>      ///creating a meeting<br>      final id = rand.nextInt(100000000).toString();<br>      print(id);<br>      return id;<br>    } else {<br>      ///Joining a meeting<br>      return widget.roomId!;<br>    }<br>  }<br><br>  ///generate user id<br>  String getUserId() {<br>    Random rand = Random();<br>    return rand.nextInt(100000000).toString();<br>  }<br><br>  @override<br>  void initState() {<br>    super.initState();<br>  }<br><br>  String _roomId = &#39;&#39;;<br><br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: Text(&quot;Call page ${widget.name}&quot;)),<br>      body: Stack(<br>        children: [<br>          localView ?? Container(),<br>          Positioned(<br>            top: MediaQuery.of(context).size.height / 20,<br>            right: MediaQuery.of(context).size.width / 20,<br>            child: SizedBox(<br>              width: MediaQuery.of(context).size.width / 3,<br>              child: AspectRatio(<br>                aspectRatio: 9.0 / 16.0,<br>                child: remoteView ?? Container(color: Colors.transparent),<br>              ),<br>            ),<br>          ),<br>          Positioned(<br>            bottom: MediaQuery.of(context).size.height / 20,<br>            left: 0,<br>            right: 0,<br>            child: SizedBox(<br>              width: MediaQuery.of(context).size.width / 3,<br>              height: MediaQuery.of(context).size.width / 3,<br>              child: Row(<br>                mainAxisAlignment: MainAxisAlignment.center,<br>                mainAxisSize: MainAxisSize.min,<br>                children: [<br>                  ElevatedButton(<br>                    style: ElevatedButton.styleFrom(shape: const CircleBorder(), backgroundColor: Colors.red),<br>                    onPressed: () {<br>                      ///log out user before popping page<br>                      <br>                    },<br>                    child: const Center(child: Icon(Icons.call_end, size: 32)),<br>                  ),<br>                ],<br>              ),<br>            ),<br>          ),<br>        ],<br>      ),<br>    );<br>  }<br>}</pre><p>In the above code, you can see that we have :</p><ul><li>A view for local preview: To show yourself</li><li>A view for remote video: To show the other person that is joining the meeting</li><li>A Stop button: Logout the user and then close the call page</li><li>getRoomId method: It will be randomly generated when users create a new meeting and we can also get it from the constructor when a user joins an existing meeting after providing the roomID in the ‘home_page.dart’ page</li><li>getUserId method: UserId can be randomly generated based on your use case and if you are using Firebase as your backend, you can just use the user ‘uid’ since it’s generated uniquely</li></ul><p>Now that will have the video view UI in place, we can now start implementing the Zego cloud logic</p><p><strong>Set up an Event listener for the SDK</strong></p><p>We are going to add the ZegoEventHandler event handler inside our call page to listen for event callbacks, such as updates when the room streams are added or deleted, and when participants log in or log out.</p><p>Also, we will implement the start and stop stream methods when a remote user joins or leaves the room.</p><pre>void startListenEvent() {<br>    // Callback for updates on the status of other users in the room.<br>    // Users can only receive callbacks when the isUserStatusNotify property of ZegoRoomConfig is set to `true` when logging in to the room (loginRoom).<br>    ZegoExpressEngine.onRoomUserUpdate = (roomID, updateType, List&lt;ZegoUser&gt; userList) {<br>      debugPrint(<br>          &#39;onRoomUserUpdate: roomID: $roomID, updateType: ${updateType.name}, userList: ${userList.map((e) =&gt; e.userID)}&#39;);<br>    };<br>    // Callback for updates on the status of the streams in the room.<br>    ZegoExpressEngine.onRoomStreamUpdate = (roomID, updateType, List&lt;ZegoStream&gt; streamList, extendedData) {<br>      debugPrint(<br>          &#39;onRoomStreamUpdate: roomID: $roomID, updateType: $updateType, streamList: ${streamList.map((e) =&gt; e.streamID)}, extendedData: $extendedData&#39;);<br>      if (updateType == ZegoUpdateType.Add) {<br>        for (final stream in streamList) {<br>          startPlayStream(stream.streamID);<br>        }<br>      } else {<br>        for (final stream in streamList) {<br>          stopPlayStream(stream.streamID);<br>        }<br>      }<br>    };<br>  }<br><br>  Future&lt;void&gt; startPlayStream(String streamID) async {<br>    // Start to play streams. Set the view for rendering the remote streams.<br>    await ZegoExpressEngine.instance.createCanvasView((viewID) {<br>      remoteViewID = viewID;<br>      ZegoCanvas canvas = ZegoCanvas(viewID, viewMode: ZegoViewMode.AspectFill);<br>      ZegoExpressEngine.instance.startPlayingStream(streamID, canvas: canvas);<br>    }).then((canvasViewWidget) {<br>      setState(() =&gt; remoteView = canvasViewWidget);<br>    });<br>  }<br><br>  Future&lt;void&gt; stopPlayStream(String streamID) async {<br>    ZegoExpressEngine.instance.stopPlayingStream(streamID);<br>    if (remoteViewID != null) {<br>      ZegoExpressEngine.instance.destroyCanvasView(remoteViewID!);<br>      setState(() {<br>        remoteViewID = null;<br>        remoteView = null;<br>      });<br>    }<br>  }</pre><ul><li><a href="https://www.zegocloud.com/unique-api/express-video-sdk/en/dart_flutter/zego_express_engine/ZegoExpressEngine/onRoomStreamUpdate.html">onRoomStreamUpdate</a>: When new streams are published to the room or existing streams in the room stop, the SDK sends out the event notification through this callback. You can see that we called startPlayStream() and stopPlayStream() methods inside the callback and also update the value of <em>remoteViewID</em> and <em>remoteView</em> variables</li><li><a href="https://www.zegocloud.com/unique-api/express-video-sdk/en/dart_flutter/zego_express_engine/ZegoExpressEngine/onRoomUserUpdate.html">onRoomUserUpdate</a>: The callback is triggered when other users log in or log out of the room.</li></ul><h4>Log in and log out from Room</h4><p>After setting up the event handler, we need to create a ZegoUser profile using the userId and username of the user to log in to the room by calling the login method()</p><pre>  ///log in and log out<br>  Future&lt;ZegoRoomLoginResult&gt; loginRoom(String userID, String userNm) async {<br>    // The value of `userID` is generated locally and must be globally unique.<br>    final user = ZegoUser(userID, userNm);<br><br>    _roomId = getRoomId();<br><br>    // The value of `roomID` is generated locally and must be globally unique.<br><br>    // onRoomUserUpdate callback can be received when &quot;isUserStatusNotify&quot; parameter value is &quot;true&quot;.<br>    ZegoRoomConfig roomConfig = ZegoRoomConfig.defaultConfig()..isUserStatusNotify = true;<br><br>    // log in to a room<br>    // Users must log in to the same room to call each other.<br>    return ZegoExpressEngine.instance<br>        .loginRoom(getRoomId(), user, config: roomConfig)<br>        .then((ZegoRoomLoginResult loginRoomResult) {<br>      debugPrint(<br>          &#39;loginRoom: errorCode:${loginRoomResult.errorCode}, extendedData:${loginRoomResult.extendedData}&#39;);<br>      if (loginRoomResult.errorCode == 0) {<br>        startPreview();<br>        startPublish();<br>      } else {<br>        ScaffoldMessenger.of(context)<br>            .showSnackBar(SnackBar(content: Text(&#39;loginRoom failed: ${loginRoomResult.errorCode}&#39;)));<br>      }<br>      return loginRoomResult;<br>    });<br>  }</pre><p>Users also need to leave a room, so we need to add the logout method which will be called when users click on the close button</p><pre> Future&lt;ZegoRoomLogoutResult&gt; logoutRoom() async {<br>    stopPreview();<br>    stopPublish();<br>    return ZegoExpressEngine.instance.logoutRoom(_roomId);<br>  }</pre><h4>Start and stop the local video preview</h4><p>To show and dismiss the local preview of a user after login to the room, we need to call the startPreview and stopPreview methods.</p><pre>///Start and stop preview<br>  Future&lt;void&gt; startPreview() async {<br>    await ZegoExpressEngine.instance.createCanvasView((viewID) {<br>      localViewID = viewID;<br>      ZegoCanvas previewCanvas = ZegoCanvas(viewID, viewMode: ZegoViewMode.AspectFill);<br>      ZegoExpressEngine.instance.startPreview(canvas: previewCanvas);<br>    }).then((canvasViewWidget) {<br>      setState(() =&gt; localView = canvasViewWidget);<br>    });<br>  }<br><br>  Future&lt;void&gt; stopPreview() async {<br>    ZegoExpressEngine.instance.stopPreview();<br>    if (localViewID != null) {<br>      await ZegoExpressEngine.instance.destroyCanvasView(localViewID!);<br>      setState(() {<br>        localViewID = null;<br>        localView = null;<br>      });<br>    }<br>  }</pre><p>After that has been implemented, we need to start publishing the local audio and video streams to the remote users to establish the communication</p><p>To stop the stream from publishing, call the stopPublish method</p><p><em>Note: streamID must be unique for every user in the room</em></p><pre>///Start publish and stop publish<br>  Future&lt;void&gt; startPublish() async {<br>    // After calling the `loginRoom` method, call this method to publish streams.<br>    // The StreamID must be unique in the room.<br>    String streamID = &quot;roooooooooo_${widget.name}&quot;;<br>    return ZegoExpressEngine.instance.startPublishingStream(streamID);<br>  }<br><br>  Future&lt;void&gt; stopPublish() async {<br>    return ZegoExpressEngine.instance.stopPublishingStream();<br>  }</pre><p><strong>Let’s put everything together</strong></p><pre>import &#39;dart:math&#39;;<br><br>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:video_caller/utils.dart&#39;;<br>import &#39;package:zego_express_engine/zego_express_engine.dart&#39;;<br><br>class CallPage extends StatefulWidget {<br>  String? roomId;<br>  String? name;<br>  CallPage({super.key, this.name, this.roomId});<br><br>  @override<br>  State&lt;CallPage&gt; createState() =&gt; _CallPageState();<br>}<br><br>class _CallPageState extends State&lt;CallPage&gt; {<br>  Widget? localView;<br>  Widget? remoteView;<br><br>  int? localViewID;<br>  int? remoteViewID;<br><br>  String getRoomId() {<br>    Random rand = Random();<br>    if (widget.roomId == null) {<br>      ///creating a meeting<br>      final id = rand.nextInt(100000000).toString();<br>      print(id);<br>      return id;<br>    } else {<br>      ///Joining a meeting<br>      return widget.roomId!;<br>    }<br>  }<br><br>  ///generate user id<br>  String getUserId() {<br>    Random rand = Random();<br>    return rand.nextInt(100000000).toString();<br>  }<br><br>  @override<br>  void initState() {<br>    super.initState();<br><br>    startListenEvent();<br><br>    loginRoom(getUserId(), widget.name!);<br>  }<br><br>  String _roomId = &#39;&#39;;<br><br>  void startListenEvent() {<br>    // Callback for updates on the status of other users in the room.<br>    // Users can only receive callbacks when the isUserStatusNotify property of ZegoRoomConfig is set to `true` when logging in to the room (loginRoom).<br>    ZegoExpressEngine.onRoomUserUpdate = (roomID, updateType, List&lt;ZegoUser&gt; userList) {<br>      debugPrint(<br>          &#39;onRoomUserUpdate: roomID: $roomID, updateType: ${updateType.name}, userList: ${userList.map((e) =&gt; e.userID)}&#39;);<br>    };<br>    // Callback for updates on the status of the streams in the room.<br>    ZegoExpressEngine.onRoomStreamUpdate = (roomID, updateType, List&lt;ZegoStream&gt; streamList, extendedData) {<br>      debugPrint(<br>          &#39;onRoomStreamUpdate: roomID: $roomID, updateType: $updateType, streamList: ${streamList.map((e) =&gt; e.streamID)}, extendedData: $extendedData&#39;);<br>      if (updateType == ZegoUpdateType.Add) {<br>        for (final stream in streamList) {<br>          startPlayStream(stream.streamID);<br>        }<br>      } else {<br>        for (final stream in streamList) {<br>          stopPlayStream(stream.streamID);<br>        }<br>      }<br>    };<br>  }<br><br>  Future&lt;void&gt; startPlayStream(String streamID) async {<br>    // Start to play streams. Set the view for rendering the remote streams.<br>    await ZegoExpressEngine.instance.createCanvasView((viewID) {<br>      remoteViewID = viewID;<br>      ZegoCanvas canvas = ZegoCanvas(viewID, viewMode: ZegoViewMode.AspectFill);<br>      ZegoExpressEngine.instance.startPlayingStream(streamID, canvas: canvas);<br>    }).then((canvasViewWidget) {<br>      setState(() =&gt; remoteView = canvasViewWidget);<br>    });<br>  }<br><br>  Future&lt;void&gt; stopPlayStream(String streamID) async {<br>    ZegoExpressEngine.instance.stopPlayingStream(streamID);<br>    if (remoteViewID != null) {<br>      ZegoExpressEngine.instance.destroyCanvasView(remoteViewID!);<br>      setState(() {<br>        remoteViewID = null;<br>        remoteView = null;<br>      });<br>    }<br>  }<br><br>  ///log in and log out<br>  Future&lt;ZegoRoomLoginResult&gt; loginRoom(String userID, String userNm) async {<br>    // The value of `userID` is generated locally and must be globally unique.<br>    final user = ZegoUser(userID, userNm);<br><br>    _roomId = getRoomId();<br><br>    // The value of `roomID` is generated locally and must be globally unique.<br><br>    // onRoomUserUpdate callback can be received when &quot;isUserStatusNotify&quot; parameter value is &quot;true&quot;.<br>    ZegoRoomConfig roomConfig = ZegoRoomConfig.defaultConfig()..isUserStatusNotify = true;<br><br>    // log in to a room<br>    // Users must log in to the same room to call each other.<br>    return ZegoExpressEngine.instance<br>        .loginRoom(getRoomId(), user, config: roomConfig)<br>        .then((ZegoRoomLoginResult loginRoomResult) {<br>      debugPrint(<br>          &#39;loginRoom: errorCode:${loginRoomResult.errorCode}, extendedData:${loginRoomResult.extendedData}&#39;);<br>      if (loginRoomResult.errorCode == 0) {<br>        startPreview();<br>        startPublish();<br>      } else {<br>        ScaffoldMessenger.of(context)<br>            .showSnackBar(SnackBar(content: Text(&#39;loginRoom failed: ${loginRoomResult.errorCode}&#39;)));<br>      }<br>      return loginRoomResult;<br>    });<br>  }<br><br>  Future&lt;ZegoRoomLogoutResult&gt; logoutRoom() async {<br>    stopPreview();<br>    stopPublish();<br>    return ZegoExpressEngine.instance.logoutRoom(_roomId);<br>  }<br><br>  ///Start and stop preview<br>  Future&lt;void&gt; startPreview() async {<br>    await ZegoExpressEngine.instance.createCanvasView((viewID) {<br>      localViewID = viewID;<br>      ZegoCanvas previewCanvas = ZegoCanvas(viewID, viewMode: ZegoViewMode.AspectFill);<br>      ZegoExpressEngine.instance.startPreview(canvas: previewCanvas);<br>    }).then((canvasViewWidget) {<br>      setState(() =&gt; localView = canvasViewWidget);<br>    });<br>  }<br><br>  Future&lt;void&gt; stopPreview() async {<br>    ZegoExpressEngine.instance.stopPreview();<br>    if (localViewID != null) {<br>      await ZegoExpressEngine.instance.destroyCanvasView(localViewID!);<br>      setState(() {<br>        localViewID = null;<br>        localView = null;<br>      });<br>    }<br>  }<br><br>  ///Start publish and stop publish<br>  Future&lt;void&gt; startPublish() async {<br>    // After calling the `loginRoom` method, call this method to publish streams.<br>    // The StreamID must be unique in the room.<br>    String streamID = &quot;roooooooooo_${widget.name}&quot;;<br>    return ZegoExpressEngine.instance.startPublishingStream(streamID);<br>  }<br><br>  Future&lt;void&gt; stopPublish() async {<br>    return ZegoExpressEngine.instance.stopPublishingStream();<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(title: Text(&quot;Call page ${widget.name}&quot;)),<br>      body: Stack(<br>        children: [<br>          localView ?? Container(),<br>          Positioned(<br>            top: MediaQuery.of(context).size.height / 20,<br>            right: MediaQuery.of(context).size.width / 20,<br>            child: SizedBox(<br>              width: MediaQuery.of(context).size.width / 3,<br>              child: AspectRatio(<br>                aspectRatio: 9.0 / 16.0,<br>                child: remoteView ?? Container(color: Colors.transparent),<br>              ),<br>            ),<br>          ),<br>          Positioned(<br>            bottom: MediaQuery.of(context).size.height / 20,<br>            left: 0,<br>            right: 0,<br>            child: SizedBox(<br>              width: MediaQuery.of(context).size.width / 3,<br>              height: MediaQuery.of(context).size.width / 3,<br>              child: Row(<br>                mainAxisAlignment: MainAxisAlignment.center,<br>                mainAxisSize: MainAxisSize.min,<br>                children: [<br>                  ElevatedButton(<br>                    style: ElevatedButton.styleFrom(shape: const CircleBorder(), backgroundColor: Colors.red),<br>                    onPressed: () {<br>                      ///log out user before popping page<br>                      logoutRoom().then((value) {<br>                        Navigator.pop(context);<br>                      });<br>                    },<br>                    child: const Center(child: Icon(Icons.call_end, size: 32)),<br>                  ),<br>                ],<br>              ),<br>            ),<br>          ),<br>        ],<br>      ),<br>    );<br>  }<br>}</pre><p><strong>Congratulations! You’ve made it.</strong></p><p>Alright, now that we are done with the <a href="https://www.zegocloud.com/product/video-call">ZegoCloud</a> implementation of UI and Logic, you can try running the app on your target platforms… you will notice the dialogs asking for the necessary permissions.</p><p>I would advise you to test it using a physical device as Emulator or simulator might not give you the best video and audio experience.</p><p><strong>There you have it!</strong></p><p>For a detailed and more sophisticated example of ZegoCloud SDK, please watch this youtube video.<br><a href="https://www.youtube.com/watch?v=7bBZOyYwfU8&amp;t=1421s">https://www.youtube.com/watch?v=7bBZOyYwfU8&amp;t=1421s</a></p><p>Remember to always wear a smile, and be kind to people.</p><p>Happy coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8614119a21e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Localization in Flutter]]></title>
            <link>https://medium.com/@DestinyEd/localization-in-flutter-282f7cf3f330?source=rss-498d26d4e108------2</link>
            <guid isPermaLink="false">https://medium.com/p/282f7cf3f330</guid>
            <category><![CDATA[flutter-locale]]></category>
            <category><![CDATA[multiple-language-support]]></category>
            <category><![CDATA[flutter-localization]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[internationalization]]></category>
            <dc:creator><![CDATA[Destiny Ed]]></dc:creator>
            <pubDate>Thu, 07 Jul 2022 18:23:09 GMT</pubDate>
            <atom:updated>2022-07-07T18:23:09.585Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KAd4cRkIAWLnCF-lLD-xrw.png" /></figure><p>One sure way of targeting a broader audience and making your Flutter app accessible to many is by localizing your app to users that speak other languages. For this to work, you will have to write your app so that all the text will be dynamic to change instead of statically typing them in a widget.</p><p>Flutter is a mobile framework or we can say it’s a UI toolkit for drawing out beautiful interfaces and it has libraries or dependencies that will help with localizing our apps.</p><p>This article will cover in detail all you need to know to make your Flutter app support multiple locales (languages). Since this is a tutorial, we will be localizing for English(US) and Dutch(Germany). Yeah!!</p><blockquote>Note : After completing this article, you should be able to add more language support to your Flutter app</blockquote><p>In summary, we are going to learn how to change the app language base on the current language of the users’ devices. so without many words, Let’s Go!!</p><p><strong>Let’s Go, Hero!!</strong></p><p>Wait, you don’t want to rush this, do you? From all I’ve said already, are you sure you know what Flutter localization is? If not, let’s look at it in detail😄</p><h3><strong>Localization In Flutter</strong></h3><p>From this part and below, we will learn about localization and practical steps to set it up and use it in our Flutter app.</p><p><em>Localization is the process of adapting Flutter apps to appeal to users with different locales and target markets.</em></p><p>Normally, every new Flutter app only supports English(US). For more support to be added, a developer like you need to make the app adapt to different languages/locales.</p><p><strong>Now you know what localization is. Let’s Go Again!!</strong></p><h3><strong>Step 1: Adding dependencies</strong></h3><p>For localization to work we need to add a package called flutter_localizations into our <em>pubspec. yaml</em> file</p><pre>dependencies:<br>  flutter:<br>    sdk: flutter<br>  flutter_localizations: <br>    sdk: flutter         </pre><p>Now that we have our first package added, let’s go on to add the Int’l package</p><pre>dependencies:<br>  intl: ^0.17.0 </pre><blockquote>Note: As of Flutter version 3, intl is pre-installed in the Flutter SDK, but you can add it manually if you can’t import it in your dart file.</blockquote><p>That’s not all, we also need to set the <strong><em>generate</em></strong> flag in pubspec.yaml file to “true”. Adding that will make our pubspec file look like this</p><pre>dependencies:<br>  flutter:<br>    sdk: flutter<br>  flutter_localizations: <br>    sdk: flutter <br>  intl: ^0.17.0 </pre><pre>flutter:<br>  generate : true </pre><p>The generate flag will help flutter to automatically generate the code that will be needed for app_localization.dart (You will see how this works later)</p><h3><strong>Step 2: Folder Generation</strong></h3><p>In your project directory, create a new <strong>l10n.yaml</strong> file and add the below code into it.</p><pre>arb-dir: lib/l10n<br>template-arb-file: app_en.arb<br>output-localization-file: app_localizations.dart</pre><p>I know you are wondering what the above code does… you are not alone, I felt the same way too, but don’t worry, I will break it down in the next paragraph.</p><p>The configuration of your localization is done and handled by that file. Let’s look at it in detail</p><ul><li>arb-dir: lib/l10n is actually where the input files are located</li><li>output-localization-file: The app_localizations.dart file is a very important file. It is where generated localizations are placed with the help of the “generate” flag we added in pubspec.yaml file.</li><li>template-arb-file: app_en.arb provides the file template for configuring your language.</li></ul><p><strong>Now, we need to go home, yeah? No! we need to see this in action.</strong></p><p>Remember I said, we will be demonstrating in Dutch and English, right? And in our <strong>l10n.yaml </strong>file we created, we have lib/l10n as the value of arb-dir.</p><p>Now, we will create a folder with the same name “l10n’ inside our lib folder. After that, we will create two(2) dart files inside which we will write our English and Dutch language message.</p><p>If you’ve done that, then your folder structure should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*4BVOoMdfV-uNK8O9OnWIHw.png" /></figure><p>Now that we have the .arb file for Dutch and English, we are going to create a simple title with the value of “Welcome to Medium” and later display it in our Flutter appbar.</p><p>Copy and paste the below English code to app_en.arb</p><pre>{<br>    &quot;title&quot;: &quot;Welcome to Medium&quot;<br>}</pre><p>Next, add the translated Dutch message into the app_de.arb file like below</p><pre>{<br>    &quot;title&quot;: &quot;Welkom bij Medium&quot;<br>}</pre><blockquote>Note: You can add more messages and add the translated message to the other files(depending on your targeted locales) and make sure the value remains the same for each file.</blockquote><p>For example, if you want to add a submit button message, you can have something like this in English and then translate it into other languages</p><pre>{<br>    &quot;title&quot;: &quot;Welcome to Medium&quot;,<br>    &quot;submit_btn&quot; : &quot;Submit&quot;<br>}</pre><p><strong>Rules for <em>.arb</em> files</strong></p><ul><li>Always use a double string quote when creating a string</li><li>The last message in the map should not have a comma “,”</li><li>Only use a comma if you want to add another text to the next line.</li><li>Always run ‘flutter pub get’ after adding all the necessary messages.</li></ul><p>Now run your app on your emulator(Preferably a physical device) and you will notice that a new file is generated in your root folder called “.dart_tools” ${ROOT_DIRECTORY}/.dart_tool/flutter_gen/gen_l10n.</p><p>I assume your app is running and codegen has already generated the files in the above path, but the language is still in English. If my assumption is right, then hurray! we are making progress, but if not, please repeat the steps again.</p><h3><strong>Step 3: Localization of the app</strong></h3><p>In your main.dart file where you have your material app, you will need to add the import statement on app_localizations.dart</p><pre>import &#39;package:flutter_gen/gen_l10n/app_localizations.dart&#39;;</pre><p>In your material app, add the two properties below to define the supported locales and delegates.</p><pre>return MaterialApp(<br>  title: &#39;Example App&#39;,<br>  localizationsDelegates: AppLocalizations.localizationsDelegates,<br>  supportedLocales: AppLocalizations.supportedLocales,<br>  home: const HomePage(),<br>);</pre><p>We can now use localization anywhere in our app. Now, we will add the title of our app bar using the translated message we defined in the .arb files.</p><p>In our app bar, add the Text widget as the title and the value like below,</p><pre>AppBar(<br>  title : Text(AppLocalizations.of(context)!.title),<br>)</pre><p><strong>Congratulations! You’ve made it.</strong></p><p>Finally, build your app and then change the default language of your device to Germany(Dutch) and see how your app bar title changes to the translated message.</p><p><strong>There you have it!</strong></p><p>For a detailed and more sophisticated example, please watch this <a href="https://youtu.be/3HHlXBFXKFM">youtube video</a> on localization.</p><p>Remember to always wear a smile, and be kind to people.</p><p>Happy Localizing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=282f7cf3f330" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Important Topics To Know As a Flutter Developer]]></title>
            <link>https://medium.com/@DestinyEd/important-topics-to-know-as-a-flutter-developer-c261e575bdcc?source=rss-498d26d4e108------2</link>
            <guid isPermaLink="false">https://medium.com/p/c261e575bdcc</guid>
            <category><![CDATA[flutter-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-roadmap]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Destiny Ed]]></dc:creator>
            <pubDate>Sat, 18 Jun 2022 18:48:00 GMT</pubDate>
            <atom:updated>2022-06-18T18:48:00.152Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Article thumbnailE.g." src="https://cdn-images-1.medium.com/max/1024/1*HXk2hWZ-PpmUYqTpd9XOkQ.png" /></figure><p>Hello, Great Minds,</p><p>I’ve been wondering about the topics one must know to be considered as a flutter developer. Please share it in the comment if you know.</p><p>Before you start commenting, I will be sharing with you some important topics you must learn/know in this article. If you dedicate time to learn about these topics which you will be reading here, I promise you will be confident to take on any project and also be proud to call yourself a flutter developer.</p><p>Don’t worry, After learning these topics, you can move on to build projects, make mistakes, fix bugs, and grow tremendously in your mobile development journey.</p><h3><strong>Let’s Dive In: Let’s Talk About Flutter.</strong></h3><p>Flutter is a mobile development framework for building cross-platform and UI-friendly applications in less time. Flutter is one of the fastest growing frameworks/technology that grew in community and usage within one year.</p><p>This framework is fun to learn and it works with the <a href="http://dart.dev/">Dart</a> programming language to deliver fast and beautiful apps that can be installed on different platforms(Web, Mobile, Desktop, Embedded systems) with one code base.</p><h3><strong>Time To Talk About The Topics</strong></h3><p>I think I’ve said a lot about flutter already. Let’s look at the topics you must know in Flutter.</p><h3><strong>Mobile Development</strong></h3><p>Most of the time, beginners skip this topic and just dive into taking tutorials and they miss the foundations.</p><p>As someone who is new to App Development and wants to start with Flutter or any other framework, it is very important you learn about mobile development: What it is, its life cycles, and best practices for building and delivering better apps. Once you know and understand this topic, then you can move to the next topic.</p><h3><strong>Target Platform</strong></h3><p>I know I’m not supposed to add this since the article is about Flutter, but it is necessary you know about this in case someone who does not know about mobile development asks you.</p><p>There are there(3) tracks you can attach yourself to as an app developer:</p><ol><li>Native(Android) developer</li><li>Native(iOS) developer</li><li>Cross-platform developer (Flutter)</li></ol><p><strong>Android Developer</strong></p><p>These developers focus more on building native applications for the android platform. Their preferred languages include Java and Kotlin.</p><p><strong>iOS Developer</strong></p><p>Unlike the android developer, iOS developers are specialized in building native applications for iOS and macOS devices. Their preferred programming languages include Swift or Objective C.</p><p><strong>Cross Platform Developer</strong></p><blockquote>With great power comes great responsibility — Spider man</blockquote><p>Yeah, I love using that quote when it’s about flutter especially if you already know a little about Native development.</p><p>A cross-platform developer build apps that run and install on any platform and operating system (iOS, macOS, Android, and the Web). This set of mobile developers uses programming languages like Dart.</p><h3><strong>Programming Languages</strong></h3><p>One topic every developer must know whether or not they are mobile developers.</p><p>Learning and building apps with flutter is great, fast, and fun, but you need a language to write the core functionality of your app.</p><p>You might be wondering, is Flutter not a programming language? You are right to think that way if you are just starting with tech or don’t know about Flutter yet. I will try and clear this in the next paragraph…</p><p>Flutter is not a programming language, It is an open-source framework developed by Google for building beautiful and responsive user interfaces for applications. In other, for you to make your app interactive and functional, you will need a programming language like <a href="https://dart.dev/">Dart</a>.</p><blockquote>For you to learn or build apps with flutter and dart, you will definitely need an IDE(Integrated Development Environment) to write and execute your app. You can choose between Android Studio, Visual studio code, Xcode or IntelliJ Idea as your IDE for learning and development.</blockquote><h3><strong>Widgets</strong></h3><p>According to the Flutter team, Flutter is a widget as it is made up of widgets. I believe that since I know flutter is used for building User Interfaces that are made up of widgets.</p><p>Technically, Widgets are classes that are built-in within the Flutter SDK(Software development kit) or from third-party libraries that are used for building User Interface(UI). It is very important to know when and how to use widgets to build UI in Flutter.</p><p>Flutter UI can be Static or Dynamic</p><ul><li>Static user interfaces can be developed easily using built-in widgets available in the Flutter SDK and there can be made constant using the ‘const’ modifier or keyword. It means the state of a static UI can not be rebuilt throughout the app life cycle state.</li><li>Dynamic user interfaces are the opposite of the static user interface.</li></ul><p><strong>The benefit of using a const constructor to optimize rebuilds</strong></p><p>In Flutter, if we want to rebuild the app using the “SetState((){}) method, we tend to rebuild the state of every widget in the widget tree. To avoid this behavior, we can use the ‘const’ keyword to avoid rebuilding every widget in the app.</p><p>Why is the const keyword important? Well, It is important because it helps Flutter to only rebuilds the widgets that are meant to be updated and this approach enhances performance a little bit.</p><blockquote>Note : Only use the ‘const’ keyword when you know the value of a variable or widget is not going to be changed at runtime.</blockquote><h3>Responsiveness</h3><p>Flutter is a cross-platform framework. This means Flutter developers should be able to build mobile applications that are responsive and adaptive on every targeted platform.</p><p>When your app is responsive, it can adjust for every available screen size even after the device orientation changes.</p><p><strong>Keep the below approaches in mind when building a responsive app</strong></p><p>It’s very important you know about the <em>MediaQuery.of()</em> method and <em>LayoutBuilder</em> class when building a responsive app.</p><p><strong>MediaQuery.of()</strong></p><p>Using this method inside your flutter app build function helps to determine the height and width of the device your app is running on and adjust responsively to it.</p><p><strong>LayoutBuilder class</strong></p><p>This class is very important and you must learn how it’s implemented in Flutter.</p><p>LayoutBuilder class helps Flutter developers build apps that adjust perfectly, especially when the app supports rotation. It will help you determine the various constraints in other to return a specific widget or call a function based on the device height or aspect ratio when this constraint changes.</p><p>For a deeper understanding of responsiveness, please check this <a href="https://docs.flutter.dev/development/ui/layout/adaptive-responsive">article</a> by the Flutter team.</p><h3><strong>Animations</strong></h3><p>Animation is an abstract class used to enhance user experience and add a smooth feel and interaction to mobile apps.</p><p>Flutter animations make it easy to add smooth transitions and feel to your apps.</p><p>In Flutter, you can decide to use <strong>code based</strong> or <strong>drawing based</strong> animations</p><p><strong>Drawing based animation</strong></p><p>These animations involve animated drawings in flutter apps. It involves the use of plugins to handle animations… Some of the plugins to learn in other to implement drawing-based animations include: <a href="https://pub.dev/packages/rive">Rive</a> or <a href="https://pub.dev/packages/lottie">Lottie</a></p><p><strong>Code Based animation</strong></p><p>These animations are based on manipulating Flutter widgets to give a nice feel and animations when you tap, scroll, navigate or change colors.</p><p>There are two techniques for implementing code-based animation in Flutter:</p><ul><li>Implicit animation</li><li>Explicit animation</li></ul><p>I won’t say much about animation in this article, so I will recommend you check out this <a href="https://docs.flutter.dev/development/ui/animations">link</a> for a better understanding and for a higher level knowledge of animations and complex UI watch this <a href="https://www.youtube.com/watch?v=FCyoHclCqc8">video</a>.</p><p>If you are still confused about the right animation approach to take then let this video <a href="https://www.youtube.com/watch?v=wnARLByOtKA&amp;t=3s"><strong>Animation in flutter done right</strong></a> guide you.</p><h3><strong>Storage</strong></h3><p>Imagine building a Todo or social media application without a database. How do you intend to save user important data or sync data across devices?</p><p>Storage is one important topic every flutter developer must know in other to build better and more functional applications. Luckily, flutter has/supports different ways we can store/persist user data</p><ul><li>SQLite Database; you can learn about this <a href="https://docs.flutter.dev/cookbook/persistence/sqlite">here</a> and <a href="https://www.youtube.com/watch?v=ZggjeVaXChQ">here</a></li><li>Shared Preference; learn <a href="https://docs.flutter.dev/cookbook/persistence/key-value">here</a> and <a href="https://www.youtube.com/watch?v=HYUQ2FDjNAo&amp;t=96s">here</a></li><li>File Systems storage: This method involves storing data locally in the device&#39;s external and internal storage. Learn <a href="https://docs.flutter.dev/cookbook/persistence/reading-writing-files">here</a>.</li><li>Third-Party Storage; The first three(3) I listed can not be used to sync users&#39; data across devices. Users&#39; data will be lost if they misplace or format their devices. In other to avoid this as a flutter developer, you must know how to use third-party services such as F<a href="https://www.youtube.com/watch?v=Y5G2QIfhs2c&amp;list=PLpTC1FqgUpLSSZmllQ6fj99YHr6kIdjr9">irebase</a>, Aws amplify, Google cloud, Appwrite, etc.</li></ul><h3><strong>Platform API or Components</strong></h3><p>It is very important you know how to use third-party libraries and dependencies because most Flutter behavior components are provided by <a href="http://pub.dev/">plugins</a> and packages.</p><p>You can create these plugins and packages yourself assuming you know how to create <a href="https://docs.flutter.dev/development/packages-and-plugins/developing-packages">packages</a>(<a href="https://www.youtube.com/watch?v=ZV0l0bN48Fw&amp;t=1722s">video tutorial</a>) and how to use flutter <a href="https://www.youtube.com/watch?v=wJhfGdoqeH0&amp;t=3s">event</a> and <a href="https://docs.flutter.dev/development/platform-integration/platform-channels">platform channels</a></p><p>I’ve included some of the important components you must know in Flutter</p><ul><li>Notifications: <a href="https://www.youtube.com/watch?v=rKexm6mq2vI&amp;t=1071s">Local</a> and <a href="https://www.youtube.com/watch?v=yEqb3EjDolI">Push Notification</a></li><li>Video and Media Usage</li><li>File Picker</li><li>Camera and Video control</li><li>Permission handling and many more.</li></ul><h3><strong>State Management</strong></h3><p>One of my favorite topics in Flutter. Fortunately, there are so many ways and packages for handling the state of your Flutter app.</p><p>Let’s assume that you have an app with 5 pages. Now you want to display the user&#39;s name on every page of your app, how would you go about it?</p><p>Well, the first thing that would click in a beginner&#39;s mind is to create a constructor for each page and then pass the user name from one page to the other.</p><p>The above method will definitely work but it’s not a good practice because it will require you to keep passing data every time you want to navigate and it will be a huge problem when your app starts getting larger.</p><p>I have created a YouTube video tutorial about this <a href="https://www.youtube.com/watch?v=rqtUE6qQ_A4">topic</a> and you can also check and read this <a href="https://docs.flutter.dev/development/data-and-backend/state-mgmt/intro">article</a> by the flutter team.</p><h3><strong>Folder Structure</strong></h3><p>It won’t be nice when other developers find it difficult to understand the structuring of your flutter project.</p><p>If you are learning or already building with flutter and you don’t know about this topic yet, I would suggest you take this topic seriously as it will help you a lot in your flutter journey.</p><p>Feel free to watch this YouTube video <a href="https://www.youtube.com/watch?v=ImXSALl1Nvc&amp;t=780s">tutorial</a> to learn about this topic extensively.</p><h3><strong>Platform Channel</strong></h3><p>This topic is a little advance for a beginner in Flutter, but I recommend it if you want to know how flutter interacts and utilizes native API asynchronously</p><p>I wrote a detailed article explaining the Flutter platform channel <a href="https://medium.com/@DestinyEd/platform-channel-and-reversed-platform-channel-with-flutter-5e50139c5e1">here</a>.</p><h3><strong>Obfuscation / Security</strong></h3><p>This topic is underestimated by some developers and it tends to make flutter apps vulnerable.</p><p>Obfuscation is about obscuring or making most of your app&#39;s important files, and classes unreadable in case someone tries to break your app APK file through reverse engineering.</p><p>This process of decoding your APK file to read its contents and discover potential vulnerability is called reverse engineering. It’s very important you learn how to obscure and secure your Flutter app before deploying it to production.</p><h3><strong>Version Control</strong></h3><p>Say you work with a team or you want to start contributing to open source projects, how do you collaborate and share your code for other developers to see and make changes to?</p><p>This topic will teach you how to manage and track changes in your code. This tracking and managing of source code can be achieved using version control tools like Git and Github.</p><h3><strong>Testing</strong></h3><p>I don’t know why I added this topic as the last. I think it’s because I’m the lazy type that doesn’t like writing tests for my app, lol.</p><p>Sometimes I ask myself, Why do I need to write a code to test code I’ve already written… No answer from your end right? I got an answer below</p><p>This topic looks like one of the most time-consuming things to do in a Flutter app but it’s very important you learn, understand and practice how to love writing it. It helps you to discover bugs during app development before deploying them to production.</p><p>Flutter categorizes app testing into 3 parts</p><ul><li>Unit</li><li>Widget</li><li>Integration</li></ul><p>Aside from this three, You can add functional testing to the list. This method of testing involves testing your flutter app manually without writing additional code. that is, you just have to install the app on your devices and start clicking and interacting with every button and page making sure it works as intended.</p><h3><strong>There You Have It</strong></h3><p>Yeah!! We have finally come to the end of the road. You all needed this right?</p><p>I strongly believe this topic will guide you to know about the most important things to focus on and learn about as a flutter developer in other not to be frustrated.</p><p><strong>Before we wrap up</strong></p><p>Try and get your hands dirty by building projects. Lots of them. It can be personal or open source.</p><p>Building projects will challenge you to learn more and discover things that are not listed in this article and possibly make you a better and more confident Flutter developer.</p><p>Happy building with Flutter!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c261e575bdcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Platform Channel And Reversed Platform Channel With Flutter]]></title>
            <link>https://medium.com/@DestinyEd/platform-channel-and-reversed-platform-channel-with-flutter-5e50139c5e1?source=rss-498d26d4e108------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e50139c5e1</guid>
            <dc:creator><![CDATA[Destiny Ed]]></dc:creator>
            <pubDate>Wed, 13 Apr 2022 15:15:45 GMT</pubDate>
            <atom:updated>2022-04-16T10:45:13.618Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Zfg_naLXn7MSDKqo.png" /></figure><p>There are so many plugins available for using platform specific API in your flutter application. What if you want to create a new plugin or you want to implement some functionality in your app that don’t have a plugin yet?</p><p>Well, We will be looking at the possible way to write and use platform specific API in your flutter application. But first, We will be looking at platform channel showing a Native Toast message in our flutter application. After that, We will look at the Reversed Platform Channel. Don’t get scared yet about this topic because it will be broken down completely for better understanding.</p><p><em>Note : This article only focus on writing platform-specific code for Android using Kotlin(You can also use Java) but same logic can be applied to IOS if you know your way around IOS development.</em></p><p>Platform channel is a way to connect flutter app with Native API.</p><p>Flutter platform channel uses a flexible language system that works with platform(Native) API. What I mean is this, platform channel works with any type of language as long as the target platform supports that language.</p><p>Let’s say for example, you want to use some API for Android, you will be using languages like Java or Kotlin. For IOS or MacOs, you will use Swift or Objective-C. For Windows and Linux, you will use C++ and C respectively.</p><p>I guess that’s the question racing through your mind now, yeah?</p><p>Platform channel works asynchronously within your flutter application. You can imagine it as an HTTP call to the server but in this case every thing happens within your flutter application without any external call.</p><p><strong>Let me break it down using bullets</strong></p><ul><li>The flutter portion of your application makes an asynchronous call to it’s Host(Native portion). Basically, Flutter portion sends a message to the Native portion of your application using platform channel.</li><li>The Native Portion(Host) receives the call or message and then it calls any method or API matching the message sent from the flutter portion.</li><li>After performing the action, It sends a response back to the client(flutter portion) which then displays and show the response to the user.</li></ul><p>If you notice, it works like a client-server service over the internet.</p><p><strong>Some Important things to know before using platform channel</strong></p><ul><li><strong>Method Channel : </strong>This channel enables us to send messages or invoke a method that corresponds to the one declared in the native side of your application.</li><li><strong>Invoke Method : </strong>This is a method from the Method channel class for invoking native methods.</li></ul><p>No <em>te : Method Channels and Methods calls can be called in a reversed direction(Reversed Platform Channel). This way the Native platform of your application acts as a client. We will treat that later…</em></p><p><strong>Limitations:</strong></p><p>The only limitation I know for know is that you will have to write Native code with different languages depending on the platform you are targeting.</p><p>Also, Since platform channel is asynchronous, It takes some time to call and return a response depending on the Native API you are trying to use. Sometimes, this will cause some delay in your flutter app User Interface or cause Jank(UI hanging).</p><p>However, you can try as much as possible to limit the number of async functions you are calling on the UI thread to avoid most of the limitations above.</p><p><strong>Platform Channel Implementation</strong></p><blockquote>“For the things we have to learn before we can do them, we learn by doing them.”<br>―</blockquote><p>From this part until we start looking at reversed platform channel I will be showing you the most easy way of implementing platform channel.</p><p>The following code snippets will demonstrate how to write platform specific API to show a Native(Android) Toast message.</p><p><strong>Create a new flutter project</strong></p><p>I would recommend you use Android studio to implement this as you will be able to spot error easily. But if you are okay with VsCode or any other IDE then no worries.</p><p>I believe we all know know how to create a new flutter project using android studio or terminal. If you are like me and you prefer using the terminal, then run the following command</p><p><em>“flutter create toast_app”</em> <strong>Create method channel</strong></p><p>In your app “main.dart” file create a static Method channel variable with a unique “name” as parameter. In our case, we will be using “destinyed” as the channel name.</p><pre>import &#39;dart:async&#39;; import &#39;package:flutter/material.dart&#39;; import &#39;package:flutter/services.dart&#39;; class _MyHomePageState extends State&lt;MyHomePage&gt; { static const platform = MethodChannel(&#39;destinyed&#39;); // Show Toast.</pre><p><em>Note : This channel name will be used in the Native portion of your app for identification and communication because you don’t want the platform channel to be confused.</em> <strong>Create a showToast method</strong></p><p>Create a simple dart method that will handle the communication to the native portion of your application.</p><pre>Future&lt;void&gt; _showToast() async { try { final result = await platform.invokeMethod(&#39;showToast&#39;); print(&#39;result); } on PlatformException catch (e) { print(e.toString()); } }</pre><p><strong>Remember I told you before now that platform channel works asynchronously.</strong></p><p>Looking at the above method you will notice that I used async…await keyword to call the native API using the ‘invokeMethod” from the “MethodChannel” and then I passed the name of the function/method I want to call in the Native portion(We will create the method shortly).</p><p>Also, I wrap the whole code in a try…catch block for handling errors that might arise while making the call. I did that because the Native API might fail in returning the result we want and sometimes we are not in the best position to know the cause of the exception or what is happening under the hood.</p><p><strong>Trigger the flutter method to call the Native API</strong></p><p>Now that will have the method to communicate with the Native API we need to trigger the method.</p><p>So for this, We will be creating a floating action button(You can use any button) that will trigger the method and then return the response we need.</p><pre>... @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(&quot;Platform channel&quot;), ), floatingActionButton: FloatingActionButton.extended( onPressed: _showToast, label: Text(&quot;Show Toast&quot;), ), ); }</pre><p><strong>Alright, Now that will are done with the flutter implementation, lets look at the Native implementation for Android.</strong></p><p>Follow the steps below to launch the Android module of your Flutter app in Android Studio:</p><ul><li>Start Android Studio</li><li>Select the menu item File &gt; Open…</li><li>Navigate to the directory holding your Flutter app, and select the android folder inside it. Click OK.</li><li>Open the file MainActivity.kt located in the kotlin folder in the Project view.</li></ul><p>Your MainActivity.kt file should look like this after you open it… Don’t get scared as nothing serious is happening here lol.</p><pre>import androidx.annotation.NonNull import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine class MainActivity: FlutterActivity() { override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { super.configureFlutterEngine(flutterEngine) } }</pre><p><strong>Register a Method Channel with your unique channel “name”</strong></p><p>Remember we created a channel and we used ‘destinyed’ as the name. So, In this case we are also going to use the same name to avoid conflict in channel communication.</p><pre>import androidx.annotation.NonNull import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugin.common.MethodChannel class MainActivity: FlutterActivity() { private val CHANNEL = &quot;destinyed&quot; override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { super.configureFlutterEngine(flutterEngine) MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result -&gt; // Note: this method is invoked on the main thread. // TODO } } }</pre><p>From the above snippet, We have a MethodChannel that takes two(2) parameters : BinaryMessenger and Channel. This methodChannel also has a MethodCallHandler that we can use to listen to the call coming from flutter portion and also a ‘result’ which we can use to return a response back to flutter portion of our application.</p><p><strong>Finally, handle the call</strong></p><p>Now that we have the Method channel and call handler ready, we can use the ‘call’ to check for the corresponding method that the flutter portion is willing to call and ‘result’ to send a response back to the flutter portion after utilizing the API</p><pre>if (call.method == &quot;showToast&quot;) { //Show Toast Toast.makeText(this, &quot;Hello Flutter&quot;, Toast.LENGTH_LONG).show() result.success(&quot;Toast started&quot;) }else { result.unImplemented }</pre><p>Now, the above snippet actually shows a Toast message if the ‘call.method’ is same as the method we tried to call from the flutter portion with a ‘Toast started” response using the ‘result.success’ callback.</p><p>There are three callback we can return using the ‘result’</p><ul><li>result.success(“Success message”)</li><li>result.error(“Error message”)</li><li>result.unImplemented (This is called when the method we want to call from the flutter portion does not match any method from the Native portion.</li></ul><p><strong>There you have it guys</strong></p><p>In summary, Platform Channel represents a way to call native code in other to use native functionality within a Flutter application. It can be used to create flutter plugins targeting any platform of your choice.</p><p>With platform channel, You are certain to build any type of application with flutter that can also be built with Native Sdk. So no worries, Flutter has no limitation when it comes to Mobile application development.</p><p>Platform channel is well documented in the <a href="https://docs.flutter.dev/development/platform-integration/platform-channels">official documentation</a> in case you wish to check it out.</p><p>As the name reads, reversed platform channel represents the way of calling flutter methods or packages from the Native portion of your application.</p><p>In this case, Flutter portion of your app works as the Host while the Native portion works as the client that is requesting the data.</p><p><em>More on Reversed Platform Channel will be coming soon…</em></p><p>Thanks for reading… I will write to you again in the future.</p><p><em>Originally published at </em><a href="https://medium.com/@Destiny_Ed/platform-channel-and-reversed-platform-channel-with-flutter-e80b4ce98bdf"><em>https://medium.com</em></a><em> on April 13, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e50139c5e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add Ripple Effect Around Flutter Widgets]]></title>
            <link>https://levelup.gitconnected.com/add-ripple-effect-around-widgets-e98169e9e3c1?source=rss-498d26d4e108------2</link>
            <guid isPermaLink="false">https://medium.com/p/e98169e9e3c1</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[ripple]]></category>
            <category><![CDATA[flutter-ripple-effect]]></category>
            <dc:creator><![CDATA[Destiny Ed]]></dc:creator>
            <pubDate>Thu, 03 Mar 2022 06:15:17 GMT</pubDate>
            <atom:updated>2022-03-09T23:29:10.995Z</atom:updated>
            <content:encoded><![CDATA[<p>What’s the simplest way to show ripple effect around any flutter widget?</p><p>At the end of this tutorial, we will have something like this…</p><figure><img alt="Ripple Image" src="https://cdn-images-1.medium.com/max/600/1*bsGWw1gZ1oiECYtVOEdJfA.gif" /></figure><p>In this article, we will learn how to display the animated ripple effect in a flutter widget.</p><p>To achieve this, I will be using a package I created <a href="https://pub.dev/packages/flutter_ripple">flutter_ripple</a></p><p><a href="https://pub.dev/packages/flutter_ripple">flutter_ripple | Flutter Package</a></p><p>Before we start, let’s look at the agenda for this tutorial</p><ol><li>Getting Started</li><li>Depend on <a href="https://pub.dev/packages/flutter_ripple">flutter_ripple</a></li><li>Display <a href="https://pub.dev/packages/flutter_ripple">Flutter Ripple</a></li></ol><h3><strong>Getting Started</strong></h3><p>Make sure you have <a href="http://flutter.dev/">flutter</a> installed in your machine and created a new project or existing one already…</p><p>For this tutorial, I will be using flutter 2.10.0. Don’t worry any version of flutter will work as long as it’s above version 2.0.0</p><h3><strong>Add Dependency</strong></h3><p>In your flutter project, add flutter_ripple in pubspec.yaml file under dependencies…</p><pre>dependencies:<br>   flutter_ripple: ^0.0.3</pre><p>Don’t forget to run ‘flutter pub get’ in your project terminal after adding the dependency</p><p><strong>Import it</strong></p><p>Now in your Dart code, you can use:</p><pre>import &#39;package:flutter_ripple/flutter_ripple.dart&#39;;</pre><h3><strong>Display Flutter Ripple</strong></h3><p>Just a few more code and we are done…</p><p>Create a new class with Stateful widget class(You can use an existing class depending on where you want to display the ripple) with any widget of your choice and then add flutter ripple as the parent widget and set the default color and tap action. Adding flutter ripple widget around any widget will display ripple effect around it.</p><p>You code should look like this</p><pre>Scaffold(<br>  body : FlutterRipple(<br>          child: Text(&quot;Flutter Ripple&quot;),<br>          rippleColor: Colors.blue,<br>          onTap: () {<br>            print(&quot;hello&quot;);<br>          },<br>       ),<br>  )</pre><p>Note : Flutter Ripple has other properties you can manipulate</p><h3>Complete Ripple Example</h3><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter_ripple/flutter_ripple.dart&#39;;<br><br>void main() {<br>  runApp(App());<br>}<br><br>class App extends StatelessWidget {<br>  const App({ Key? key }) : super(key: key);<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br><br>      home: RippleExample(),<br>      <br>    );<br>  }<br>}<br>class RippleExample extends StatefulWidget {<br>  const RippleExample({Key? key}) : super(key: key);<br><br>  @override<br>  _RippleExampleState createState() =&gt; _RippleExampleState();<br>}<br><br>class _RippleExampleState extends State&lt;RippleExample&gt; {<br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: const Text(&#39;Flutter Ripple&#39;),<br>      ),<br>      body: Center(<br>        child: Stack(<br>          children: [<br>            ///Show Ripple Widget<br>            FlutterRipple(<br>              child: Text(&quot;Flutter Ripple&quot;),<br>              rippleColor: Colors.blue,<br>              onTap: () {<br>                print(&quot;hello&quot;);<br>              },<br>            ),<br>            Positioned(<br>              top: MediaQuery.of(context).size.height / 2 + 100,<br>              right: 50,<br>              left: 50,<br>              child: Container(<br>                child: Column(<br>                  children: [<br>                    Text(<br>                      &quot;Searching for location.&quot;,<br>                      textAlign: TextAlign.center,<br>                    ),<br>                    Container(<br>                      margin: const EdgeInsets.only(top: 10),<br>                      padding: const EdgeInsets.symmetric(<br>                          horizontal: 30, vertical: 15),<br>                      decoration: BoxDecoration(<br>                          color: Colors.blue,<br>                          borderRadius: BorderRadius.circular(50)),<br>                      child: Text(<br>                        &quot;Find All Location&quot;,<br>                        style: TextStyle(color: Colors.white),<br>                      ),<br>                    )<br>                  ],<br>                ),<br>              ),<br>            )<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>Hurry, Now we are done. This is pretty simple.</p><p>Happy Implementing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e98169e9e3c1" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/add-ripple-effect-around-widgets-e98169e9e3c1">Add Ripple Effect Around Flutter Widgets</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>