<?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 Ali Ghanbari on Medium]]></title>
        <description><![CDATA[Stories by Ali Ghanbari on Medium]]></description>
        <link>https://medium.com/@ali.gh2236?source=rss-e48bbdec3e4b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hCKKN-DsGeH-amBP2cwogQ.png</url>
            <title>Stories by Ali Ghanbari on Medium</title>
            <link>https://medium.com/@ali.gh2236?source=rss-e48bbdec3e4b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 01:48:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ali.gh2236/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[My Flutter Islamic Calendar App]]></title>
            <link>https://medium.com/@ali.gh2236/my-flutter-islamic-calendar-app-30fa793ca360?source=rss-e48bbdec3e4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/30fa793ca360</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Ali Ghanbari]]></dc:creator>
            <pubDate>Fri, 15 Apr 2022 21:05:44 GMT</pubDate>
            <atom:updated>2022-04-15T21:05:44.728Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tJTmX4aLHZ_AiC05VQpQtA.png" /></figure><p>Today I’m posting about one of my apps called “Prayer Time” and the story of how it evolved.</p><p>Prayer Time is an Islamic calendar with adhan reminders.</p><p>I originally made it using Cordova(html+css+js) when I was just a beginner. But it had the big problem of not being able to schedule reminders. At this point, the entire app was about 300 lines of code.</p><p>So I rewrote it using kotlin for android. And it worked fine but. The UI wasn’t consistent across devices and the only suitable calendar library I found was really clunky and the code was BAD. Like a ball of mud Bad. If there was a bug, good luck fixing it! It was hell to maintain.</p><p>That was where I decided to actually learn how to write better code. I read a lot of articles and got really inspired by Clean Code and Clean Architecture and decided to reimagine how would I write a calendar app from scratch.</p><p>That was around the same time a certain new cross-platform UI framework that you might know as Flutter was getting popular. I tried it a little bit and it seemed like a lot of fun so I said why I don’t make a new app for managing social media posts with lots of tools and a calendar.</p><p>But using flutter was different in the sense that it didn’t have any calendar package that did the things that I wanted and There were no easy date conversion packages. So I made my own! and it was A LOT better than anything available at the time! I’ll write more about it in a separate post.</p><p>The calendar was so good that I decided I actually wanted to make a stand-alone calendar app.</p><p>The new calendar app called “Fanoos” was separated into two projects. One was ‘fanoos’ for all the presentation code(flutter pages) and the other was ‘fanoos_lib’ for business logic which itself was partitioned by domain into several smaller projects like fanoos_date, fanoos_location, fanoos_prayer and …. each package contained all the models, interfaces and default implementation needed for that package.</p><p>Unfortunately, my goals for fanoos were too big and I couldn’t complete it. But the same could not be said for fanoos_lib! It was everything that you ever needed to make a calendar or an Islamic calendar app!</p><p>I used it to make several different calendars where the last one was the moon_calender which was later renamed to prayer_times_flutter as it was the same as the old Android app in terms of looks but far superior in terms of functionality, maintainability and code quality!</p><p>It was published as an update for Prayer Times. I have published several updates after the flutter one and added new features and fixed bugs easily without having to deal with any pesky side effects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30fa793ca360" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Completer class in Dart]]></title>
            <link>https://medium.com/@ali.gh2236/the-completer-class-in-dart-6276e9153c7?source=rss-e48bbdec3e4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6276e9153c7</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[future]]></category>
            <category><![CDATA[async]]></category>
            <dc:creator><![CDATA[Ali Ghanbari]]></dc:creator>
            <pubDate>Wed, 02 Mar 2022 19:37:28 GMT</pubDate>
            <atom:updated>2022-03-02T19:37:28.902Z</atom:updated>
            <content:encoded><![CDATA[<p>I would occasionally see the Completer class and never knew what it did. now that I know, it’s actually really useful and I’ve been using it a lot.</p><p>The documentation for this class has been updated and it is described very well:</p><blockquote>A way to produce Future objects and to complete them later<br>with a value or error.</blockquote><p>It’s a way of creating Futures without using the Future class because you are the one completing the future using the “Completer” object.</p><p>This class is used in async functions for converting a <em>callback-based API into a Future-based one.</em></p><p>Almost all of the Dart &amp; Flutter API uses Future-based callbacks, but there are some functions that only return a callback, for example, ui.instantiateImageCodec or ImageProvider.resolve.</p><p>Let&#39;s say we need to write a function that returns the size of an image from an ImageProvider. before knowing about the completer class, I used a stream controller + await for to get the data out of the callback into a stream, into a variable, closed the stream and returned the value:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a17c91cc549b5589f23a45cdd14a8c99/href">https://medium.com/media/a17c91cc549b5589f23a45cdd14a8c99/href</a></iframe><p>As you saw, unnecessarily complicated.</p><p>This was later greatly simplified after discovering what does the Completer class does:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43b4af808dca92877cb56175e6e65d4d/href">https://medium.com/media/43b4af808dca92877cb56175e6e65d4d/href</a></iframe><p>It’s a lot simpler now :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6276e9153c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trying out dart:ffi]]></title>
            <link>https://medium.com/@ali.gh2236/trying-out-dart-ffi-4c934a9ce290?source=rss-e48bbdec3e4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c934a9ce290</guid>
            <category><![CDATA[ffi]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[c]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Ali Ghanbari]]></dc:creator>
            <pubDate>Tue, 13 Oct 2020 11:19:28 GMT</pubDate>
            <atom:updated>2020-10-13T14:52:31.645Z</atom:updated>
            <content:encoded><![CDATA[<p>Dart FFI has been out since September of 2019 and since then I really wanted to try it out. so this blog post is about my first interaction with ‘dart:ffi’.</p><p>First, let’s start with what is FFI?<br>FFI stands for foreign function interface and it allows us to call functions from other programming languages.</p><p>In my case, I wanted to call a function that is written in the C programming language.</p><p>For my experiment, I decided to use the unoptimized recursive algorithm for calculating Fibonacci numbers, as it runs very slowly on higher-level languages.</p><p>I started with my Fibonacci C code (fibonacci.c):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f2b541541afbd28edd5726663c1bcba/href">https://medium.com/media/2f2b541541afbd28edd5726663c1bcba/href</a></iframe><p>Then for using dart:ffi on windows you need a dll to call. so I used GCC to compile my C code into a dll:</p><blockquote>gcc -shared -o fibonacci.dll fibonacci.c</blockquote><p>Then I moved the dll to the root of my Dart project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*2WbvjSOefidN-JABJqzIFQ.png" /></figure><p>Next, we need to declare the C and Dart function types using typedef(you can also spcify the types directly when looking up functions but I’m not going to do that here).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*fupZteGLTBbcnG5uRMwXeQ.png" /></figure><p>For the sake of having cleaner code, I’m going to factor all the ffi code into a class called `Fibonacci`.<br>In this class I load the dll into memory using `DynamicLibary.open` and then look up the function using the function types that we have declared and the name of the function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*oKQQWkzVdv6mONIqhQRjcg.png" /></figure><p>And, we are done. the `Fibonacci` class should work(hopefully!). next, I added a dart implementation of the same function for speed comparison.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*6yi7DTV5hsfBAzyzPaWf1A.png" /></figure><p>Next, I added main for testing and now we finnaly get to benchmarking these againset each other!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/960ee8e731d8b6037d27b8d57885f8ca/href">https://medium.com/media/960ee8e731d8b6037d27b8d57885f8ca/href</a></iframe><h4>The Results:</h4><blockquote>n = 45<br>Native C: 1836311903 in 0:00:07.551995<br>DartVM: 1836311903 in 0:00:05.751678</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*guuHR77WU0T3r-8oRGz-tw.jpeg" /><figcaption>My face after seeing the results</figcaption></figure><p>What just happened? did the Dart implementation just beat the C version by more than 30%! (dart probably runs faster than I thought)</p><h4>Conclusion</h4><p>Maybe don’t use dart:ffi for calling recursive functions!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*hDmd0W6dkWmDl5Ns2HXeTg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c934a9ce290" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to enable Flutter web on the stable channel]]></title>
            <link>https://medium.com/@ali.gh2236/how-to-enable-flutter-web-on-the-stable-channel-f4f1762c79cb?source=rss-e48bbdec3e4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4f1762c79cb</guid>
            <category><![CDATA[flutter-web]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <dc:creator><![CDATA[Ali Ghanbari]]></dc:creator>
            <pubDate>Thu, 14 May 2020 13:39:07 GMT</pubDate>
            <atom:updated>2020-08-24T08:51:27.205Z</atom:updated>
            <content:encoded><![CDATA[<p>Currently, if you want to try Flutter web, you need to change your branch to beta, dev or master but what if you absolutely need to be on the Stable channel?</p><p>Here, I&#39;m going to show you how to enable Flutter web on the Stable channel.</p><p>The first step is to locate your flutter folder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*7e-_loXx_EP2e-DkQWEqEw.png" /></figure><p>My flutter folder is in C:\src\flutter .</p><p>Then go to /packages/flutter_tools/lib/src and find features.dart and open in a text editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*vOYczhPP_a9zN1MfVtYt7g.png" /></figure><p>Find flutterWebFeature , it should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*6Lp6YWj5R--Tq1YkFX4Iyw.png" /></figure><p>Find flutterWebFeature and Modify the code to look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*J4jv1VT24SI7dHc7HMUAEA.png" /></figure><pre>// paste this before the last parenthesis<br>stable: FeatureChannelSetting(<br>  available: true,<br>  enabledByDefault: false,<br>)</pre><p>After that, go to flutter/bin/cache and delete flutter_tools.snapshot</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*VzzkYmkikkc1dcMhnRr1YQ.png" /></figure><p>Finally, Run flutter config --enable-web to enable web if you haven’t enabled it already. if you have an old project that doesn’t have the web folder, you can add it using flutter create . .</p><p>Congratulations! now you can build flutter web apps 🎉.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4f1762c79cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is the smallest apk file size for Flutter?]]></title>
            <link>https://medium.com/@ali.gh2236/what-is-the-smallest-apk-file-size-for-flutter-230af43a431b?source=rss-e48bbdec3e4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/230af43a431b</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[apk]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[apk-size]]></category>
            <dc:creator><![CDATA[Ali Ghanbari]]></dc:creator>
            <pubDate>Wed, 13 May 2020 20:15:08 GMT</pubDate>
            <atom:updated>2020-10-13T16:51:23.388Z</atom:updated>
            <content:encoded><![CDATA[<p>For some people, app size is one of the reasons to not use flutter, so in this post, I want to see what is the smallest flutter apk size that you can build or to say it differently, what is the minimum base apk size for a flutter based app.</p><p>When creating a new project in android studio, the first thing I did was to not include kotlin, because it adds about 1Mb to our app size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*6xcqLkfYpOmSL8tFm7cmIg.png" /></figure><p>That’s about all the changes I made in the wizard. now we have the counter app, which I tried to build using flutter build apk .</p><p>The resulting APK was 14.9Mb in size which is huge compared to an equivalent native app. so let’s see if we can reduce it.</p><p>The reason the apk file was so big, is that we built what we call as a fat apk, an apk that contains all the machine code for all different CPU architectures. if you’re using app bundles in google play, the store will only serve an apk with the compatible machine code. if you are only outputting one apk, it is better to include all of the abi code, but we are not going to do that.</p><p>Currently, 3 major CPU architectures are supported by flutter; ARMv7, ARMv8 and X86–64. Looking at the market shares, ARM processors make up almost all of the market, so our priority should be supporting ARM processor. The good news is that ARMv8 is backwards compatible with ARMv7 machine code with only a 10–15% performance hit. even better is that some X86 devices can run ARMv7 machine code by using a translation layer called lib Houdini with the downside being a performance penalty of about 50%.</p><p>In theory, we can build an apk that only includes ARMv7 code, and it will run on almost all android devices.</p><p>Using what we learned in the last two paragraphs we can use the following build command to only include ARMv7 machine code in our apk.</p><pre><em>flutter build apk --target-platform android-arm</em></pre><p>And… the output file size is 4.9Mb!</p><p>Next, I tried using progaurd, a java bytecode minifier and obfuscator And the results weren’t promising, 5.0Mb. The app has increased in size. The reason for it is that flutter already uses R8 which is a “better” minifier than progaurd.</p><p>So I wasn’t successful at minifig the java bytecode any further but what about dart code?</p><p>In v1.17 we can obfuscate dart code. according to the documentation, we can use —obfuscateto our build command to do that. so here is the updated build command:</p><pre><em>flutter build apk --obfuscate --split-debug-info=/&lt;project-name&gt;/&lt;directory&gt; --target-platform android-arm</em></pre><p>you need to replace &lt;project-name&gt; and &lt;directory&gt; with your project name and a directory name.</p><p>I ran the command and I got 4.7Mb apk output!</p><p>Disabling AndroidX didn’t affect the app size.</p><p>You can also see the android studio project that I used <a href="https://github.com/ali2236/smallest_flutter">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eqFRLkR2KMS7bu3lVKxHnQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=230af43a431b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Experiment #2: adding functionality to flutter XML layout]]></title>
            <link>https://medium.com/@ali.gh2236/flutter-experiment-2-adding-functionality-to-flutter-xml-layout-ed0c441010a6?source=rss-e48bbdec3e4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed0c441010a6</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mustache]]></category>
            <category><![CDATA[xml]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[brackets]]></category>
            <dc:creator><![CDATA[Ali Ghanbari]]></dc:creator>
            <pubDate>Tue, 12 May 2020 12:39:58 GMT</pubDate>
            <atom:updated>2020-05-13T09:48:59.282Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter XML Part 2: Adding Functionality To Flutter XML Layout</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tb2WpU8NfHaGJFsZQOtXmw.png" /></figure><p>In the first part, we made a static flutter page from an XML file. in this part, I want to add functionality to our XML layout by showing variables and calling functions.</p><p>Here is my upgraded XML layout that I want to parse:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*49mspeVt4-sd1LueXJk8uA.png" /></figure><p>This XML layout requires us to be able to show variables and call dart functions. I also upgraded the parser from the last part to be able to parse column and button.</p><p>First thing is to figure out how to inject variables into the XML. in native android, we assign an id to each element that we want to change, then use that id to interact with the backing class of the XML element. another commonly used way in front-end javascript frameworks and static back-end renders is using {{brackets}}. I also really like the {{bracket}} method and want to use it. fortunately, there is a dart package that does that. The `mustache_template` package will take the XML with {{brackets}} and a data map and give us an XML layout with all the {{brackets}} replaced with their corresponding variable from the data map.</p><pre><strong>// using [</strong>mustache_template<strong>] we can generate a template based<br>// on the inital xml string and update it each time our variebles<br>// change<br>var template </strong>= Template(xml);</pre><pre><strong>// a map that stores our variables<br>Map&lt;String, dynamic&gt; variables </strong>= {<br>  <strong>&#39;counter&#39;</strong>: 1,<br>};</pre><p>Now, We can show variables in our XML layout by rendering the template using the variables map.</p><pre><strong>var renderedXml = template</strong>.renderString(<strong>variables</strong>);</pre><p>The second part is to figure out how to call functions from the XML elements. again, in native android, we use ids to access the backing class and add a callback to OnClickListener. but the way I want to try to implement is very similar to HTML, where you can write the name of the javascript function and it gets added to the onclickListeners of the element.</p><p>So I made a functions map that stores all the functions that are used in the XML file.</p><pre><strong>Map&lt;String, Function&gt; functions </strong>= {<br>  <strong>&#39;increment&#39;</strong>: () {<br>    setState(() {<br>      <strong>variables</strong>[<strong>&#39;counter&#39;</strong>] += 1;<br>    });<br>  },<br>};</pre><p>We can feed the functions map to the element parser and add the functions directly to the widgets that use them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*-EecX6rBtrdIk6-3gheO_w.png" /></figure><p>I refactored most of the code to a stateless widget named XmlLayoutBuilder .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*YAreWSAuTrI4-65RewizrQ.png" /></figure><p>Using this widget we can write a flutter page where the dart file doesn’t contain any UI code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*gOQCDJ9t4dq7-Xn64b2YFw.png" /></figure><p>And here is the final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*QSd-Ge6Dy2ktDB9WXwiS6Q.png" /><figcaption>The number above the button will increase by one when you tap on the button</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed0c441010a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Experiment #1:   Flutter layout from xml]]></title>
            <link>https://medium.com/@ali.gh2236/flutter-experiment-1-flutter-layout-from-xml-4346558cc930?source=rss-e48bbdec3e4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4346558cc930</guid>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[parser]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[xml]]></category>
            <dc:creator><![CDATA[Ali Ghanbari]]></dc:creator>
            <pubDate>Mon, 11 May 2020 19:21:06 GMT</pubDate>
            <atom:updated>2020-05-13T09:49:24.489Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter XML Part 1: Static Flutter Layout From XML</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YCbMWUHJS2ZC8UPGcfs2NA.png" /></figure><p>If you ever worked with any front-end framework before, you would know that the standard way of declaring your app’s UI is using some sort of markup language, like Html or XAML, and it’s been that way for a long time for the good reason of separating logic code from UI code.</p><p>Here in flutter land, we use code for everything, but what if we used XML with flutter? is it even possible to do that? well… that’s what I want to find out.</p><p>So here I wrote a very simple flutter page layout using XML:</p><pre>&lt;<strong>scaffold</strong>&gt;<br>    &lt;<strong>appbar</strong>&gt;<br>        &lt;<strong>title</strong>&gt;<br>            &lt;<strong>text</strong>&gt;Counter App&lt;/<strong>text</strong>&gt;<br>        &lt;/<strong>title</strong>&gt;<br>    &lt;/<strong>appbar</strong>&gt;<br>    &lt;<strong>body</strong>&gt;<br>        &lt;<strong>center</strong>&gt;<br>            &lt;<strong>text</strong>&gt;hello world&lt;/<strong>text</strong>&gt;<br>        &lt;/<strong>center</strong>&gt;<br>    &lt;/<strong>body</strong>&gt;<br>&lt;/<strong>scaffold</strong>&gt;</pre><p>This piece of XML is just something I wrote and can use to conduct my experiment. for parsing the XML I will be using the XML package for dart from pub.dev.</p><p>The first step is to find a way to parse the body. because we don’t know what widget is inside the body element, we need to check the name of the XML element. Here is a recursive function that can convert the body element of the XML above to an equivalent flutter widget:</p><pre>Widget parseWidget(BuildContext context, XmlElement element) {<br>  <strong>if</strong>(element == <strong>null</strong>){<br>    <strong>return </strong>Container();<br>  } <strong>else if </strong>(element.<strong>name.local </strong>== <strong>&#39;center&#39;</strong>) {<br>    <strong>return </strong>Center(<br>      child: parseWidget(context, element.<strong>firstElementChild</strong>),<br>    );<br>  } <strong>else if</strong>(element.<strong>name</strong>.<strong>local </strong>== <strong>&#39;text&#39;</strong>){<br>    <strong>return </strong>Text(element.<strong>text</strong>);<br>  } <strong>else </strong>{<br>    <strong>throw &#39;</strong>${element.<strong>name</strong>.<strong>local</strong>}<strong> is not implemented.&#39;</strong>;<br>  }<br>}</pre><p>I also made a custom widget that can help us construct our layout from XML:</p><pre><strong>class </strong>XmlWidgetBuilder <strong>extends </strong>StatelessWidget {<br>  <strong>final </strong>String <strong>name</strong>;<br>  <strong>final </strong>String <strong>namespace</strong>;<br>  <strong>final </strong>XmlElement <strong>element</strong>;<br>  <strong>final </strong>String <strong>xml</strong>;<br>  <strong>final </strong>Widget Function(BuildContext context, XmlElement element) <strong>builder</strong>;</pre><pre><strong>const </strong>XmlWidgetBuilder({<br>    Key key,<br>    @required <strong>this</strong>.<strong>name</strong>,<br>    <strong>this</strong>.<strong>namespace</strong>,<br>    @required <strong>this</strong>.<strong>builder</strong>,<br>    <strong>this</strong>.<strong>element</strong>,<br>    <strong>this</strong>.<strong>xml</strong>,<br>  })  : <strong>assert</strong>(element != <strong>null </strong>|| xml != <strong>null</strong>,<br>            <strong>&#39;xml string or an XmlElement must be provided.&#39;</strong>),<br>        <strong>assert</strong>(!(element != <strong>null </strong>&amp;&amp; xml != <strong>null</strong>),<br>            <strong>&#39;you can either provide xml string or an XmlElement.&#39;</strong>),<br>        <strong>assert</strong>(name != <strong>null</strong>, <strong>&#39;you should have the name of the element&#39;</strong>),<br>        <strong>super</strong>(key: key);</pre><pre>@override<br>  Widget build(BuildContext context) {<br>    <strong>var </strong>el = <strong>xml </strong>!= <strong>null<br>        </strong>? parse(<strong>xml</strong>).getElement(<strong>name</strong>)<br>        : <strong>null </strong>?? <strong>element</strong>.getElement(<strong>name</strong>);<br>    <strong>return builder</strong>(context, el);<br>  }<br>}</pre><p>This widget will take an XML string or an XML element and using them to call the builder function.</p><p>Using the parser function and the XmlWidgetBuilder, we can finally construct our page:</p><pre>@override<br>Widget build(BuildContext context) {<br>  <strong>return </strong>XmlWidgetBuilder(<br>    name: <strong>&#39;scaffold&#39;</strong>,<br>    xml: <strong>xml</strong>, // this is the xml string<br>    builder: (context, scaffold) {<br>      <strong>var </strong>appbar = scaffold.getElement(<strong>&#39;appbar&#39;</strong>);<br>      <strong>var </strong>title = appbar.getElement(<strong>&#39;title&#39;</strong>);<br>      <strong>return </strong>Scaffold(<br>        appBar: AppBar(<br>          title: parseWidget(context, title.<strong>firstElementChild</strong>),<br>        ),<br>        body: XmlWidgetBuilder(<br>          name: <strong>&#39;body&#39;</strong>,<br>          element: scaffold,<br>          builder: (context, body) {<br>            <strong>return </strong>parseWidget(context, body.<strong>firstElementChild</strong>);<br>          },<br>        ),<br>      );<br>    },<br>  );<br>}</pre><p>And here is the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*tnDUFarPXAzSNH9CdoYL_w.png" /></figure><p>So as we found out(if it wasn’t obvious from the beginning), it is possible to create a flutter layout from XML. this can also be used in a variety of ways, for example: creating an Html rendering widget.</p><p>This was a very basic experiment, in the next parts, I want to experiment with displaying variables and calling functions from an XML layout.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4346558cc930" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The story of my app getting blocked by google play protect]]></title>
            <link>https://medium.com/@ali.gh2236/the-story-of-my-app-getting-blocked-by-google-play-protect-4784c83481be?source=rss-e48bbdec3e4b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4784c83481be</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-malware]]></category>
            <category><![CDATA[headache]]></category>
            <category><![CDATA[google-play]]></category>
            <dc:creator><![CDATA[Ali Ghanbari]]></dc:creator>
            <pubDate>Tue, 23 Oct 2018 05:34:45 GMT</pubDate>
            <atom:updated>2020-08-24T09:52:43.663Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>The story of my app getting blocked by google play protect</strong></p><p>After 3 months of hard work, I completed my FIRST android app and went to publish it.</p><p>because I am in Iran and you can’t publish to google play in Iran, my only other option is <em>Cafe Bazaar,</em> the biggest Android app store in Iran with about 37 Million users. so I made a developer account and uploaded the release build of my app and hit the publish button.</p><p>In <em>Cafe Bazaar</em> there is an app verification process and my app didn’t get approved for publishing the first time because it was getting blocked on their testing devices <strong>by google play protect</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*lMSXAhToidAWrI7IfFGeZA.png" /></figure><p>I removed google analytics and all unnecessary dependencies and uploaded a new build of my app and it got blocked as well.</p><p>I ended up uploading about 10 more times until one got approved and wasn’t blocked by google play protect.</p><p>About a day or two after that, I wanted to publish an update but saw that it got blocked again by Google play protect and didn’t get approved for publishing.</p><p>I searched for the cause of the blocking and saw that some people said it could be from the Keystore, so I changed the Keystore But that didn’t fix it either.</p><p><strong>10 Days of Headache</strong></p><p>I did some more research and found that you can submit a play protect appeal because they use “Machine Learning” to decide if your app is malicious or not.</p><p>At this point, I couldn’t even install my app on my phone because of the blocking.</p><p>After I found out about the appeal page I went to the form page and filled the first three fields and got stuck on the “ URL to download your APK file” field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*YlVpX0f2--cAz3DE-C4XGg.png" /></figure><p><strong>URL to download your APK file</strong></p><p>You will need a direct download link for this field.</p><p>I tried about a dozen direct link generator websites, that none of them worked and I got this email:</p><blockquote>Hi</blockquote><blockquote>You recently submitted an appeal for an app with Google Play Protect.</blockquote><blockquote>We were unable to download the APK file from the link you provided. Please submit a new appeal and make sure that the link is publicly browsable.</blockquote><blockquote>Thank You,<br>Google Play Protect Team</blockquote><p><strong>The Solution to the link problem</strong></p><p>Finally, a link I tried worked and here is how to make it for FREE.</p><ol><li>Make a DropBox Account</li><li>Upload the apk to your DropBox Account</li><li>Get the share link</li><li>Edit the link from “https://www.dropbox.com/s/example/app.apk?dl=0” to “https://www.dropbox.com/s/example/app.apk?dl=1” by changing the 0 at the end to 1</li><li>drop the edited link in <a href="http://bit.ly/">bit.ly</a> to shorten it to like “http://bit.ly/example”</li><li>paste the generated link in the “ URL to download your APK file” field.</li></ol><p>Using this new link, I finally submitted my app for review and I got this email:</p><blockquote>Hi</blockquote><blockquote>You recently submitted an appeal for an app with Google Play Protect.</blockquote><blockquote>We noticed that an appeal for this app is already pending review. Our team will review the app and remove the warning if an error was made. There is no need to resubmit the app for review.</blockquote><blockquote>Thank You,<br>Google Play Protect Team</blockquote><p><strong>Conclusion</strong></p><p>Turns out that when you make a new app it is considered malicious until it’s scanned and entered into Google play protect’s safe apps database.</p><p>If your app is blocked, I recommend waiting for about 10–30 days before submitting an appeal because it may already be in the scanning queue.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4784c83481be" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>