<?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 Yassin Saddem on Medium]]></title>
        <description><![CDATA[Stories by Yassin Saddem on Medium]]></description>
        <link>https://medium.com/@saddemyassin?source=rss-961051a50d52------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KsSHBTaCyIDh7aeZaory6w.png</url>
            <title>Stories by Yassin Saddem on Medium</title>
            <link>https://medium.com/@saddemyassin?source=rss-961051a50d52------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:08:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saddemyassin/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[Dart: Can be a Powerful Tool for Automating Your Everyday Tasks with Simple Scripts]]></title>
            <link>https://medium.com/@saddemyassin/dart-can-be-a-powerful-tool-for-automating-your-everyday-tasks-with-simple-scripts-0e59051df372?source=rss-961051a50d52------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e59051df372</guid>
            <dc:creator><![CDATA[Yassin Saddem]]></dc:creator>
            <pubDate>Tue, 03 Dec 2024 11:39:43 GMT</pubDate>
            <atom:updated>2024-12-03T11:39:43.619Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Ns9aMQikUyoXA--UBw8Nlw.png" /></figure><p>We usually think about using Python or Go when writing a script to automate repetitive tasks we regularly encounter as software developers or engineers.</p><p>Last week, I faced one of those boring tasks — updating our translation JSON files based on an Excel sheet. The process involved manually copying the key and corresponding translation for each word into a JSON file for multiple languages. Of course, no one enjoys such tedious work. So, I decided to automate this task once and for all with a script.</p><p>As I use Dart every day in my development work, I thought, why not use Dart for this task? It’s fast, has a great ecosystem of packages, and I’m already comfortable with it. Plus, I was curious to see how Dart would perform for a simple automation task like this.</p><h3>Setting Up the Dart Script</h3><p>First, I started by creating a Console Application using Android Studio. To parse an Excel file, I discovered <a href="https://pub.dev/packages/excel">excel</a> the package on pub.dev, which perfectly matched my needs.</p><h4>Step 1: Basic Script to Read Excel</h4><p>I began with a static script to read the Excel file and create JSON files. Here’s the initial part of the implementation:</p><pre>import &#39;dart:convert&#39;;<br>import &#39;dart:io&#39;;<br>import &#39;package:excel/excel.dart&#39;;<br><br>void main() async {<br>  // Define the path to your Excel file<br>  var filePath = &#39;./bin/to_translate.xlsx&#39;;<br><br>  // Read the Excel file<br>  var bytes = File(filePath).readAsBytesSync();<br>  var excel = Excel.decodeBytes(bytes);<br>}</pre><p>In this snippet, I imported the necessary packages and defined the path to the Excel file. I also read the file into memory.</p><h4>Step 2: Checking for Sheets</h4><p>Next, I wanted to ensure that the Excel file contained sheets. Here’s how I did that:</p><pre>// Check if we have sheets<br>if (excel.tables.isEmpty) {<br>  print(&#39;No sheets found in the Excel file.&#39;);<br>  return;<br>}<br><br>// Get the first sheet<br>var sheet = excel.tables.values.first;</pre><p>This code checks if the Excel file has any sheets and retrieves the first sheet if it exists.</p><h4>Step 3: Validating Rows</h4><p>After confirming the sheet’s existence, I needed to check if it had any rows:</p><pre>// Check if there are rows<br>if (sheet.rows.isEmpty) {<br>  print(&#39;No rows found in the sheet.&#39;);<br>  return;<br>}</pre><p>This step ensures there is data to process.</p><h4>Step 4: Extracting Headers</h4><p>Next, I extracted the header row, which contains the language codes:</p><pre>// Extract the header row (language codes)<br>var headers = sheet.rows.first;<br>if (headers.isEmpty) {<br>  print(&#39;Header row is empty.&#39;);<br>  return;<br>}</pre><p>This code captures the headers for later use.</p><h4>Step 5: Processing Translations</h4><p>Now, I implemented the logic to process each language and extract translations:</p><pre>// Process each language (excluding the first column which contains keys)<br>for (var i = 1; i &lt; headers.length; i++) {<br>  var languageCode = headers[i]?.value.toString();<br>  var translations = &lt;String, String&gt;{};<br><br>  // Process each row (excluding the header row)<br>  for (var row in sheet.rows.skip(1)) {<br>    if (row.length &gt; i) {<br>      var key = row[0]?.value.toString();<br>      var value = row[i]?.value.toString();<br><br>      if (key != null &amp;&amp; value != null) {<br>        translations[key] = value;<br>      }<br>    }<br>  }<br>}</pre><p>This loop iterates through each language, skipping the first column (which contains the keys) and collecting translations into a map.</p><h4>Step 6: Writing JSON Files</h4><p>Finally, I wrote the translations to JSON files:</p><pre>// Write the translations to a JSON file<br>var jsonFilePath = &#39;${languageCode?.trim()}_${languageCode?.trim().toUpperCase()}.json&#39;;<br>var jsonFile = File(jsonFilePath);<br>await jsonFile.create();<br>await jsonFile.writeAsString(getPrettyJSONString(translations), mode: FileMode.write);<br><br>print(&#39;Translations for language &quot;$languageCode&quot; saved to $jsonFilePath&#39;);</pre><p>Each JSON file is named using the language code, and the translations are saved in a pretty-printed format.</p><h3>Enhancing User Experience with Command-Line Arguments</h3><p>To make the script more versatile, I wanted to allow users to specify the input file and output directory. For this, I used the <a href="https://pub.dev/packages/args">args</a> package.</p><h4>Step 7: Adding Command-Line Argument Parsing</h4><p>Here’s how I set up the argument parser:</p><pre>import &#39;package:args/args.dart&#39;;<br><br>const String defaultFilePath = &#39;to_translate.xlsx&#39;;<br><br>ArgParser buildParser() {<br>  return ArgParser()<br>    ..addFlag(<br>      &#39;help&#39;,<br>      abbr: &#39;h&#39;,<br>      negatable: false,<br>      help: &#39;Print this usage information.&#39;,<br>    )<br>    ..addOption(<br>      &#39;inputFilePath&#39;,<br>      abbr: &#39;i&#39;,<br>      help: &#39;Specify the path to the input Excel file.&#39;,<br>    )<br>    ..addOption(<br>      &#39;outDir&#39;,<br>      abbr: &#39;o&#39;,<br>      help: &#39;Specify the output directory for JSON files.&#39;,<br>    );<br>}</pre><p>This parser allows users to provide the input file and output directory as command-line arguments.</p><h4>Step 8: Implementing Argument Handling</h4><p>Next, I integrated the argument parser into the main function:</p><pre>void main(List&lt;String&gt; arguments) async {<br>  final ArgParser argParser = buildParser();<br>  try {<br>    final ArgResults results = argParser.parse(arguments);<br>    var inputFilePath = defaultFilePath;<br>    var outputDirPath = &#39;&#39;;<br>    <br>    if (results.wasParsed(&#39;inputFilePath&#39;)) {<br>      inputFilePath = results.option(&#39;inputFilePath&#39;) ?? defaultFilePath;<br>    }<br>    <br>    if (results.wasParsed(&#39;outDir&#39;)) {<br>      outputDirPath = results.option(&#39;outDir&#39;) ?? &#39;&#39;;<br>    }<br>    // Additional code for reading the file and writing output...<br>  } on FormatException catch (e) {<br>    print(e.message);<br>    printUsage(argParser);<br>  }<br>}</pre><p>This code parses the command-line arguments, allowing users to customize the input and output paths.</p><p>Writing a script with Dart was a smooth and enjoyable experience for me. I’ve seen Dart mature day by day in my programming tasks, not just within Flutter development. Discovering how to use Dart for automating tedious tasks has opened up new possibilities for my workflow.</p><p>Full example code:</p><pre>import &#39;dart:convert&#39;;<br>import &#39;dart:io&#39;;<br>import &#39;package:excel/excel.dart&#39;;<br>import &#39;package:args/args.dart&#39;;<br><br>const String defaultFilePath = &#39;to_translate.xlsx&#39;;<br><br>ArgParser buildParser() {<br>  return ArgParser()<br>    ..addFlag(<br>      &#39;help&#39;,<br>      abbr: &#39;h&#39;,<br>      negatable: false,<br>      help: &#39;Print this usage information.&#39;,<br>    )<br>    ..addOption(<br>      &#39;inputFilePath&#39;,<br>      abbr: &#39;i&#39;,<br>      help: &#39;Show additional command output.&#39;,<br>    )<br>    ..addOption(<br>      &#39;outDir&#39;,<br>      abbr: &#39;o&#39;,<br>      help: &#39;Print the tool version.&#39;,<br>    );<br>}<br><br>void printUsage(ArgParser argParser) {<br>  print(&#39;Usage: dart excel_to_jsons.dart &lt;flags&gt; [arguments]&#39;);<br>  print(argParser.usage);<br>}<br><br>void main(List&lt;String&gt; arguments) async {<br>  final ArgParser argParser = buildParser();<br>  try {<br>    final ArgResults results = argParser.parse(arguments);<br><br>    // Define the path to your Excel file<br>    var inputFilePath = defaultFilePath;<br>    var outputDirPath = &#39;&#39;;<br>    Directory? outDir;<br><br>    if(results.wasParsed(&#39;inputFilePath&#39;)) {<br>      inputFilePath = results.option(&#39;inputFilePath&#39;) ?? defaultFilePath;<br>    }<br><br>    if(results.wasParsed(&#39;outDir&#39;)) {<br>      outputDirPath = results.option(&#39;outDir&#39;) ?? &#39;&#39;;<br>      if(outputDirPath.trim().isNotEmpty){<br>        outDir = Directory(outputDirPath);<br>        if(!await outDir.exists()){<br>          await outDir.create(recursive: true);<br>        }<br>      }<br>    }<br><br><br><br><br>    // Read the Excel file<br>    var bytes = File(inputFilePath).readAsBytesSync();<br>    var excel = Excel.decodeBytes(bytes);<br><br>    // Check if we have sheets<br>    if (excel.tables.isEmpty) {<br>      print(&#39;No sheets found in the Excel file.&#39;);<br>      return;<br>    }<br><br>    // Get the first sheet<br>    var sheet = excel.tables.values.first;<br><br>    // Check if there are rows<br>    if (sheet.rows.isEmpty) {<br>      print(&#39;No rows found in the sheet.&#39;);<br>      return;<br>    }<br><br>    // Extract the header row (language codes)<br>    var headers = sheet.rows.first;<br>    if (headers.isEmpty) {<br>      print(&#39;Header row is empty.&#39;);<br>      return;<br>    }<br><br>    // Process each language (excluding the first column which contains keys)<br>    for (var i = 1; i &lt; headers.length; i++) {<br>      var languageCode = headers[i]?.value.toString();<br>      var translations = &lt;String, String&gt;{};<br><br>      // Process each row (excluding the header row)<br>      for (var row in sheet.rows.skip(1)) {<br>        if (row.length &gt; i) {<br>          var key = row[0]?.value.toString();<br>          var value = row[i]?.value.toString();<br><br>          if (key != null &amp;&amp; value != null) {<br>            translations[key] = value;<br>          }<br>        }<br>      }<br><br>      // Write the translations to a JSON file<br>      var jsonFilePath = &quot;${outputDirPath.trim().isNotEmpty ? outputDirPath.trim() + &#39;/&#39; : &#39;&#39;}${languageCode?.trim()}_${languageCode?.trim()<br>          .toUpperCase()}.json&quot;;<br>      var jsonFile = File(jsonFilePath);<br>      await jsonFile.create();<br>      await jsonFile.writeAsString(<br>          getPrettyJSONString(translations), mode: FileMode.write);<br><br>      print(&#39;Translations for language &quot;$languageCode&quot; saved to $jsonFilePath&#39;);<br>    }<br>  } on FormatException catch (e) {<br>    // Print usage information if an invalid argument was provided.<br>    print(e.message);<br>    printUsage(argParser);<br>  }<br>}<br><br>String getPrettyJSONString(jsonObject){<br>  var encoder = JsonEncoder.withIndent(&quot;     &quot;);<br>  return encoder.convert(jsonObject);<br>}</pre><p>Do not forget the <a href="https://pub.dev/packages/args">args</a> and <a href="https://pub.dev/packages/excel">excel</a> packages as dependencies.</p><p>Full example in including the example .xlsx file on <a href="https://github.com/saddemYassin/excel_to_jsons">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e59051df372" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Flutter] Configure Google mobile ads for different app flavors]]></title>
            <link>https://medium.com/@saddemyassin/flutter-configure-google-mobile-ads-for-different-app-flavors-c9053a790a9e?source=rss-961051a50d52------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9053a790a9e</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[admob]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[ads]]></category>
            <dc:creator><![CDATA[Yassin Saddem]]></dc:creator>
            <pubDate>Tue, 02 Jan 2024 13:28:28 GMT</pubDate>
            <atom:updated>2024-01-09T15:38:37.342Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2x85GvzU378cXzCt9fMinQ.jpeg" /><figcaption>Configure Google mobile ads for different app flavors</figcaption></figure><p>Throughout this article, I’m going to explain how to configure Google Admob apps while respecting the app’s flavors.</p><p>How can I easily configure different flavors in my app?</p><p>You can start by checking this link: <a href="https://docs.flutter.dev/deployment/flavors">https://docs.flutter.dev/deployment/flavors</a></p><p>The problem I have encountered while configuring my app in different flavors is that the flavors don’t have the same package name.</p><p>The AdMob configuration is required to add the app id in the manifest.xml (android) and the Info.plist (ios).</p><p>To fix this problem, some configurations must be done in both Android and ios.</p><p>Throughout the article, we will be using the test appId provided by Google Admob for the dev flavor.</p><blockquote><strong>IOS</strong></blockquote><p>For the IOS configuration, we will be using XCode.</p><p>First, you will start by creating a new configuration file to store your variables.</p><blockquote>click right mouse on the runner &gt; new file &gt; Configuration Settings File &gt; give Admob.xcconfig as name &gt; check Targets runer if is not checked &gt; create</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rOBBQViaqGHeMw6bczIFkg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x-9muZ7zOleIxqrZ4IMYtg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*nI8Kxk1KObgvN6gWJKsJoQ.png" /></figure><p>After creating the file successfully, you have to set the two flavors of the admob app ids inside the file.</p><pre>ADMOB_APP_ID_DEV=ca-app-pub-3940256099942544~1458002511<br>ADMOB_APP_ID_PROD=ca-app-pub-xxxxxxxx~xxxxxxxxx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ucjkstUesR4s9JpZ4uthA.png" /></figure><p>After setting your variables, you will add going the configuration in the build settings. Go to the runner file &gt; Build settings &gt; click the ‘+’ button on the left.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n2ntyMuk1ru3wJzdTdMMBg.jpeg" /></figure><p>Click Add User-Defined Setting</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OfY9ixNIbY2Fnu8_g8a4Xw.png" /></figure><p>Name the new user-defined setting ADMOB_APP_ID and then expand the setting by clicking on the “&gt;” where you will find all the flavors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ue9kOQcWwR0KiFb1cpINhQ.png" /></figure><p>Click the circular “+” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QMqyBhMj2etFD5Ug6pzbwQ.png" /></figure><p>Put $(ADMOB_APP_ID_DEV) in the dev settings (In our case Debug-dev, Profile-dev, and Release-dev).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKkvPtP4RQTWd_PXmEjx0g.png" /></figure><p>And put $(ADMOB_APP_ID_PROD) in the production settings (In our case Debug-prod, Profile-prod, and Release-prod).</p><blockquote><em>Of course, you should go through the same steps for all 6 configurations (Debug-dev, Debug-prod, Release-prod, Release-dev, Profile-prod, and Profile-dev).</em></blockquote><p>After adding the build Settings User-Defined variables you should return to the info tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*22RCDlUc4ridmljSry5qdA.png" /></figure><p>Expand the first-row “Debug-prod” by clicking on the “&gt;” and then clicking the up-down arrows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TxDhrVuYSMWWtNwUigF1tA.jpeg" /></figure><p>Select Admob.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FrHphB8uYWyusYed1RqcSw.png" /></figure><blockquote>Apply the last step for the 6 configurations (Debug-dev,Debug-prod, Release-prod, Release-dev, Profile-prod and Profile-dev). Your configuration should look like the following screenshot.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f-qTNXSYKspc8Qu--j3IjA.png" /></figure><p>Back to your Build Settings, it should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eS3XHuEdJ_iqBJulSVziiQ.jpeg" /></figure><p>Now let’s move to the Info.plist file and update the GADApplicationIdentifier by giving it a value of $(ADMOB_APP_ID)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7k58PNYrJTfdauhu7wc5tA.png" /></figure><p>The IOS configuration is done. Let’s move to Android.</p><p><strong><em>Android</em></strong></p><p>The steps in Android are more straightforward.</p><p>ps: We consider the flavors setup in your project already done.</p><p>You must open the Android folder of the Flutter project with android studio.</p><p>First, start by removing/commenting on the adMob config in the manifest.xml.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jVlvwlk6xa63okYKWYihZw.png" /></figure><p>Then create a new manifest.xml for the dev flavor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HFvEmvwcHsJfMBLlcqEP1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mHLVOd4V2r-fvJSKmnMtew.png" /></figure><p>And in the same way, create another manifest.xml for the prod flavor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*BOIRxnKSvaHE4EriKnE0eQ.png" /></figure><p>Then in the menu on the left switch the Android project as a project view (not an Android view).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*sXnUotZUm5tE50_lYGZxZA.jpeg" /></figure><p>You will find three manifest files:</p><ul><li>The first inside dev[main],</li><li>The second inside prod,</li><li>The initial manifest file is inside the main.</li></ul><p>The dev[main]/AndroidManifest.xml code should be like this:</p><pre>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; <br>xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;<br><br>    &lt;application tools:node=&quot;merge&quot;&gt;<br>        &lt;!--Google admob config--&gt;<br>        &lt;meta-data<br>            android:name=&quot;com.google.android.gms.ads.APPLICATION_ID&quot;<br>            android:value=&quot;ca-app-pub-3940256099942544~3347511713&quot;/&gt;<br>    &lt;/application&gt;<br><br>&lt;/manifest&gt;</pre><p>And the prod/AndroidManifest.xml code should be like this</p><blockquote>ps: don’t forget to change “ca-app-pub-xxxxxxxxxxx~xxxxxxxxx”</blockquote><pre>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; <br>xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;<br><br>    &lt;application tools:node=&quot;merge&quot;&gt;<br>        &lt;!--Google admob config--&gt;<br>        &lt;meta-data<br>            android:name=&quot;com.google.android.gms.ads.APPLICATION_ID&quot;<br>            android:value=&quot;ca-app-pub-xxxxxxxxxxx~xxxxxxxxx&quot;/&gt;<br>    &lt;/application&gt;<br><br>&lt;/manifest&gt;</pre><p>Back to the main AndroidManifest, you should add:</p><blockquote><em>xmlns:tools</em>=”http://schemas.android.com/tools&quot;</blockquote><pre>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    package=&quot;com.example.appName&quot; <br>xmlns:tools=&quot;http://schemas.android.com/tools&quot; &gt;<br> ...<br>&lt;/manifest&gt;</pre><p>And finally, inside your application node, you must add</p><blockquote>tools:node=”merge”</blockquote><pre>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    package=&quot;com.example.appName&quot;&gt;<br><br>    <br>   &lt;application<br>        android:label=&quot;youAppLabel&quot;<br>        android:name=&quot;${applicationName}&quot;<br>        android:icon=&quot;@mipmap/ic_launcher&quot;<br>       tools:node=&quot;merge&quot;&gt;<br>    ....<br>  &lt;/application&gt;<br>&lt;/manifest&gt;</pre><p>By adding this code, the gradle will merge all the manifests together when building your code.</p><p>With that, we are done with the Android configuration as well.</p><p>As we finish with the configuration, you will just need to test in your Flutter code which flavor to use (Prod/Dev) and which target platform (IOS/ Android) to assign your ad units when calling your ads.</p><p>I want to thank The company I’m working with (<a href="https://t4ulabs.com/">T4ULabs</a>) that offered me the opportunity to work on this topic.</p><p>I want to thank Lamis Massoudi for giving feedback and improvement to this article.</p><p>Ultimately, I wish this content was explicit and beneficial and I welcome comments, feedback, and questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9053a790a9e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>