<?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 La Pyae Oo on Medium]]></title>
        <description><![CDATA[Stories by La Pyae Oo on Medium]]></description>
        <link>https://medium.com/@lapyaeootharthar?source=rss-41c56c1512aa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*x8IxvcgP_Bjv0aOLyM4nUw.jpeg</url>
            <title>Stories by La Pyae Oo on Medium</title>
            <link>https://medium.com/@lapyaeootharthar?source=rss-41c56c1512aa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 12:59:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lapyaeootharthar/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[Understanding CA SSL Certificates in Flutter App]]></title>
            <link>https://medium.com/@lapyaeootharthar/understanding-ca-ssl-certificates-in-flutter-app-69a1343cf64b?source=rss-41c56c1512aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/69a1343cf64b</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mobile-app-security]]></category>
            <dc:creator><![CDATA[La Pyae Oo]]></dc:creator>
            <pubDate>Sun, 23 Aug 2026 09:30:24 GMT</pubDate>
            <atom:updated>2026-08-23T09:30:24.923Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IXAIdJJs5GAE2siE" /><figcaption>Photo by <a href="https://unsplash.com/@fuerte?utm_source=medium&amp;utm_medium=referral">Collin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>To become a good application, not only performance and UI/ UX design important, but security has also become essential. So, as part of security, learn the best practices about SSL certificates that are needed for an application.</p><p>To understand SSL, let’s approach it with a familiar scenario.</p><p>Most of the application contain a login section to use or enter the app. Right? At generally login function always contain user and password to get authentication to use the whole app.</p><pre>Flutter App<br>     |<br>     |  Login<br>     |  username + password<br>     ↓<br>Backend API</pre><p>OK !!! Stop here about thinking complicated things and want to give a thought to think.</p><blockquote>What happens if someone is able to observe your credentials between the Flutter application and the backend? Have you already think about that? Like this scenario.</blockquote><p>Just think about it yourself for a few minutes before continuing to read ……</p><pre>Flutter App<br>     |<br>     | username/password<br>     ↓<br>   Attacker<br>     |<br>     ↓<br> Backend</pre><p>Do you get a useful solution from that???</p><p>Did you notice that when search somethings on websites, some use http and some use https? But today, the browser gives a big alert before proceeding to enter HTTP websites. That is because the purpose of HTTP websites is only to transport data between the server and the backend without confidentiality for data transmission. Someone who can observe the traffic could potentially see the information.</p><pre>&lt;/&gt; http<br><br>POST /login<br><br>username=alice<br>password=123456</pre><p>But forhttps, not likehttp, they protect the data with TLS. This means an attacker can’t do a <strong>man-in-the-middle (MitM)</strong> attack easily because of that TLS technology.</p><blockquote>In here one needed to notice is that SSL, will be discussed mainly in this topic is also used the modern system TLS. The term “<strong>SSL certificate</strong>” is still commonly used to refer to a TLS certificate.</blockquote><p>TLS system is not a difficult system to imagine.</p><p>It is like a locker: if someone has a key (Public Certificate) that can open the lock, someone can take the things from inside that locker. Others who don’t have that key shouldn’t be able to read the confidential communication. In data communication, data shouldn’t be silently modified while traveling so the client can verify that it is communicating with the intended server.</p><pre>Flutter App                         Backend<br>    |                                  |<br>    | -------- TLS Handshake --------&gt; |<br>    |                                  |<br>    | &lt;------ Certificate ------------ |<br>    |                                  |<br>    | ===== Encrypted Data ==========&gt; |<br>    |                                  |</pre><p>A certificate is essentially a digital identity document for a server. A certificate is just a pair of key (Public Key) and lock (Private Key). Here one thing to note is that the public key can be distributed publicly, and the private key can’t be exposed; make sure to store the private. Most TLS certificates used on the web are X.509 certificates. X.509 is just a modern technology for certification; that is enough to know “What is it?”. The certificate contains information such as:</p><ul><li>Domain name</li><li>Public key</li><li>Issuer</li><li>Validity period</li><li>Digital signature</li><li>Other certificate information</li></ul><p>So that is why today websites and API used https . https contains TLS certificates (Public key and Private key). In the Android system, Android 8.0 (API level 26) network connections include over 100 TLS certifications.</p><h4>Certificate Authority (CA)</h4><p>After learning about TLS technology, go on to learn about Certificate Authority (CA). CA is also the TLS system mentioned above before and is also a trusted organization that signs certificates and helps clients verify that a certificate can be trusted. Reason of using a CA is to secure data transfer and to identify whether the client’s requesting server is legitimate, because the default certificate used in the Android system is just to clarify whether it is secure or not.</p><p>Can use the server’s url to generate a <strong>CA</strong> like that.</p><pre>                 Root CA<br>                   |<br>                   ↓<br>            Intermediate CA<br>                   |<br>                   ↓<br>          Server Certificate<br>                   |<br>                   ↓<br>             api.example.com</pre><p>Using a certificate, the client app (Mobile/ Website) is more secure than now, with only the default certificate, because it passes through not only the default but also a Certificate Authority.</p><pre>App<br> |<br> | &quot;Do I trust this certificate?&quot;<br> ↓<br>Certificate chain<br> |<br> ↓<br>Trusted CA<br> |<br> ↓<br>YES ✅</pre><blockquote>In client apps, what if only use default TLS certificate without being used Certificate Authority?</blockquote><p>An attacker can still attack with MITM attack by using a fake certificate by creating himself. In here important to remind is that</p><blockquote>HTTPS is not just encryption. It also involves server authentication through certificate validation.</blockquote><pre>Flutter App<br>     |<br>     | HTTPS<br>     |<br>     X<br>   Attacker<br>     |<br>     |<br> Backend<br> -----------------------------------------<br> App<br> |<br> | &quot;Is this certificate trusted?&quot;<br> ↓<br>Trusted CA<br> |<br> └── Yes ✅</pre><p>The bold and key idea of custom CA pinning is adding an additional restriction on which server identity the application will accept. The confusing fact for most developers is that adding a custom CA is not automatically “more secure” for apps. It introduces operational risks, especially when certificates or CA infrastructure change. This is an important point because Android’s current documentation generally does not recommend certificate pinning for Android apps due to these maintenance risks.</p><pre>App<br> |<br> | &quot;Is this certificate/public key<br> |  the one I expect?&quot;<br> ↓<br>My pinned identity<br> |<br> └── Yes ✅</pre><h4>Working in a Flutter Application</h4><p>An application that doesn’t use a custom CA will work normally because when a Flutter application makes an HTTPS request, the TLS connection and certificate validation are handled by the networking stack and underlying platform, but the exact implementation can vary between Android and iOS and depending on the HTTP client being used.</p><pre>Flutter<br>   ↓<br>Dio<br>   ↓<br>HTTP networking layer<br>   ↓<br>Platform TLS / Security Provider<br>   ↓<br>Certificate validation<br>   ↓<br>HTTPS Server</pre><pre>Server Certificate<br>       ↓<br>Certificate valid?<br>       ↓<br>Expired?<br>       ↓<br>Hostname matches?<br>       ↓<br>Trusted certificate chain?<br>       ↓<br>       YES<br>       ↓<br>TLS connection ✅</pre><p>When working with SSL/TLS certificates, may come across files such as</p><p>.pem, .crt, .cer, .key, .p12, and .pfx. But use .pem format for the Flutter application. This is probably the one you will encounter most often when working with Flutter/backend security. A PEM file is text-based Base64 encoding, usually with headers like:</p><pre>-----BEGIN CERTIFICATE-----<br>MIID...<br>...<br>-----END CERTIFICATE-----</pre><p>However, the file extension does not always tell us exactly what is inside the file. PEM and DER describe how the data is encoded, while file extensions such as .crt, .cer, .key, .pem, .p12, and .pfx are commonly used to describe what the file contains or how the data is packaged.</p><p>Can use openssl command to get the TLS certificate from own website domain and save it as .pem file.</p><pre>openssl s_client -connect example.com:443 -servername example.com &lt;/dev/null 2&gt;/dev/null | openssl x509 -outform PEM &gt; certificate.pem</pre><h4>Implementation in Flutter App</h4><p>For implementation, put .pem file in the Flutter project’s assets directory and define it in the pubspec.yaml file. After putting it and defining can implement in network service file to load and work.</p><pre>your_flutter_app/<br>├── assets/<br>│   └── certificates/<br>│       └── certificate.pem<br>├── lib/<br>└── pubspec.yaml<br>-------------------------------------------<br>pubspec.yaml<br><br>flutter:<br>  assets:<br>    - assets/certificates/certificate.pem</pre><pre>import &#39;dart:io&#39;;<br>import &#39;package:flutter/services.dart&#39;;<br>import &#39;package:http/io_client.dart&#39;;<br><br>Future&lt;IOClient&gt; createHttpClient() async {<br>  final certificate = await rootBundle.load(<br>    &#39;assets/certificates/certificate.pem&#39;,<br>  );<br><br>  final securityContext = SecurityContext(withTrustedRoots: true);<br><br>  securityContext.setTrustedCertificatesBytes(<br>    certificate.buffer.asUint8List(),<br>  );<br><br>  final httpClient = HttpClient(<br>    context: securityContext,<br>  );<br><br>  return IOClient(httpClient);<br>}</pre><p>That&#39;s about it !!! (Just Rubber Duck Technique)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69a1343cf64b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leverage Dart Error handling in project]]></title>
            <link>https://medium.com/@lapyaeootharthar/leverage-dart-error-handling-in-project-8412846623d8?source=rss-41c56c1512aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/8412846623d8</guid>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[dartlang]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[La Pyae Oo]]></dc:creator>
            <pubDate>Sat, 08 Feb 2025 21:58:52 GMT</pubDate>
            <atom:updated>2025-02-08T21:58:52.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QNVRDZSQEWJ7eDO9" /><figcaption>Photo by <a href="https://unsplash.com/@introspectivedsgn?utm_source=medium&amp;utm_medium=referral">Erik Mclean</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>“Need to add to <strong>Try-catch</strong> statement in our code to prevent happening Error”. That is the fundamental sense of every developer. Cool…</p><p>That is not true quite enough that I have seen while doing a project. In this article, I will explain those facts with examples, and use cases of <strong>Try-catch</strong> custom error handling to leverage.</p><blockquote>Let’s start with basic keywords in Dart to test that did we know really?</blockquote><ul><li>try</li><li>catch</li><li>on catch</li><li>Exception</li><li>throw</li><li>rethrow</li></ul><p>I think that is enough keywords for pure Try-catch in Dart. You don’t need to read to forward if you know all of these staff. That is time-wasting. If you don’t keep reading. <br><strong>If you are a charming guy, will read till to the end :)</strong></p><h3>try</h3><p>We know in <strong>Try</strong> block we write all of the logic that we want to do, basically to get the output we want to show or implement in the future. See below function. Its work is simply fetching API with the <a href="https://pub.dev/packages/dio"><em>dio</em></a> package. But this function may not work right now and it is not complete code.</p><pre><br>Future&lt;Response&gt; _request(<br>      {required String url,<br>      required String requestType,<br>      required Map&lt;String, dynamic&gt; header,<br>      required dynamic data}) async {<br>    try {<br>      return await _dio.request(<br>        url,<br>        data: data,<br>        options: Options(<br>          method: requestType.toString(),<br>          headers: header,<br>        ),<br>      );<br>    } <br>    <br>    // catch (e) {<br>    //  rethrow;<br>    // }<br><br>  }</pre><h3>catch</h3><p><strong>catch</strong> block is not the same as <strong>on catch</strong> block. As explained to understand well, all of the errors will come to this<strong>catch</strong> block. Making wrong logic in the calculation, API fetching error or all of the wrong staff that can’t do completely in the <strong>try</strong>block will get the result in a <strong>catch</strong> block.</p><p>In this example, the error may go to <strong>catch</strong> block. I will explain with the network example in later of this post because network request error is not simply like that.</p><pre>void example() {<br>  try {<br>    int result = 10 ~/ 0; // Division by zero<br>  } catch (e) {<br>    print(&quot;Caught an exception: $e&quot;);<br>  }<br>}</pre><h3>on catch &amp; Exception</h3><p>Between <strong>on</strong> and <strong>catch</strong> keyword needs to <strong>Exception</strong> keyword. That means need to add not only a <strong>Exception</strong> keyword. There are a lot of Exception keywords depending on the situation such as <strong>IOException</strong> to handle file read/write errors, <strong>FormatException</strong> to handle wrong data type format, and so on. To more about <strong>Exception</strong> check the Exception part of <a href="https://api.flutter.dev/flutter/dart-core/Exception-class.html"><em>Dart Documentation</em></a>.</p><p>Different between <strong>catch</strong> block is that it only handles what you want to accept. If other errors occur that you don’t accept, the program will get the error even though you wrap with <strong>try</strong>. As my advice, if you don’t know which error will come, just warp with <strong>on Exception catch</strong> or you can accept the error wrap with exact <strong>Exception</strong>. Check the example code to understand better.</p><pre>void example() {<br>  try {<br>    int result = 10 ~/ 0; // Division by zero<br>  } on IntegerDivisionByZeroException catch (e) {<br>    print(&quot;Caught an exception: $e&quot;);<br>  }<br>}</pre><p>In this example, this can change <strong>IntegerDivisionByZeroException</strong> because we know that only this error will be exactly when 10 was divided by 0. (Now <strong>IntegerDivisionByZeroException</strong> is deprecated and used <strong>UnsupportedError</strong> instead). <br>But example code with only <strong>IntegerDivisionByZeroException</strong> will get the error when giving <strong>String</strong> value to <strong>result</strong> variable. So as I said before just wrapping with <strong>Exception</strong> is safe to prevent the program from being crushed. <br>In an alternative way want to handle both excepted error and un-excepted error, need to write <strong>catch</strong> afteron <strong>IntegerDivisionByZeroException</strong> <strong>catch</strong> block.</p><pre>void example() {<br>  try {<br>    int result = 10 ~/ 0; // Division by zero<br>  } on Exception catch (e) {<br>   // Will work in here<br>    print(&quot;Caught an exception: $e&quot;);<br>  }<br>}<br><br>// Or<br><br>/* In this example error will only be catched on catch block<br>  because give String value to integer variable */<br>  <br>void example() {<br>  try {<br>    int result = &quot;10&quot;;<br>  } on IntegerDivisionByZeroException catch (e) {<br>    print(&quot;Caught with exception: $e&quot;);<br>  } catch (e){<br>   // Only work in here<br>    print(&quot;Caught without exception: $e&quot;);<br>  }<br>}<br><br>// Or<br>/* In this example error will only be catched on Exception block<br>  because Exception can catch any error that specific type */<br>void example() {<br>  try {<br>    int result = &quot;10&quot;;<br>  } on Exception catch (e) {<br>   // Only work in here<br>    print(&quot;Caught with exception: $e&quot;);<br>  } catch (e){<br>    print(&quot;Caught without exception: $e&quot;);<br>  }<br>}</pre><h3>throw</h3><p><strong>throw</strong> is used to create an excepted error / new error propagation. That means can be used without using the <strong>try</strong> block or can propagate a new <strong>Exception</strong> from another catch block but propagation new must be the same type of Exception.</p><pre>/* Just throw custom exception String as Exception */<br>void validateAge(int age) {<br>  if (age &lt; 18) {<br>    throw Exception(&quot;Age must be 18 or above.&quot;);<br>  }<br>}<br><br>void main() {<br>  try {<br>    validateAge(16);<br>  } catch (e) {<br>    print(&quot;Caught an error: $e&quot;);<br>  }<br>}<br><br>// Or<br><br>void example() {<br>  try{<br>    int result = 10 ~/ 0;<br>  }catch(e){<br>    throw UnsupportedError(&quot;Can&#39;t divied by 0&quot;);<br>  }<br>}<br><br>void main() {<br>  try {<br>    example();<br>  } on UnsupportedError catch (e) {<br>   // Get exception in here<br>    print(&quot;Caught an error: $e&quot;); // Caught an error: Unsupported operation: Can&#39;t divied by 0<br>  }<br>}</pre><h3>rethrow</h3><p><strong>rethrow</strong> is just propagating error without modifying. Most of the use cases <strong>rethrow</strong> are in API fetching functions. If want to show the error message in UI but the API fetching method is mainly located in the repository, can carry as original that error without modifying it. I will show with network fetching function.</p><p><strong>api_service.dart</strong></p><pre>class ApiService {<br>  final String baseUrl;<br>  late final Dio _dio;<br><br>  ApiService({required this.baseUrl}) {<br>    _dio = Dio(BaseOptions(<br>      baseUrl: baseUrl,<br>      connectTimeout: const Duration(seconds: 5),<br>      receiveTimeout: const Duration(seconds: 3),<br>    ));<br>    _dio.interceptors.add(PrettyDioLogger(<br>        requestHeader: true, requestBody: true, responseBody: true));<br>  }<br>  <br>  Future _request(<br>      {required String url,<br>      required String requestType,<br>      required Map&lt;String, dynamic&gt; header,<br>      required dynamic data}) async {<br>    try {<br>      return await _dio.request(<br>        url,<br>        data: data,<br>        options: Options(<br>          method: requestType.toString(),<br>          headers: header,<br>        ),<br>      );<br>    } on DioException catch (e) {<br>      if (e.type == DioExceptionType.connectionTimeout) {<br>        throw Exception(<br>          &#39;The request connection took long&#39;,<br>        );<br>      } else{<br>        rethrow;<br>      }<br>    } catch (e) {<br>   print(&quot;Unexcepted error $e&quot;)<br>    }<br>  }<br>}</pre><p>In the <strong>DioException</strong> of <strong>_request()</strong> function use <strong>rethrow</strong> . <strong>DioException</strong> is to handle network problems but when want to filter specific exceptions like <strong>DioExceptionType.connectionTimeout</strong> and don’t want to care about other exceptions as this example use rethrow for other <strong>DioExceptionType</strong> .</p><p>If want to use that <strong>_request()</strong> function in a business logic file, <strong>profile_repository</strong>. <br>We can only transform <strong>DioExceptionType.connectionTimeout</strong> as <strong>Exception</strong> and others <strong>DioExceptionType</strong> will still remain.</p><p><strong>profile_repository.dart</strong></p><pre>class ProfileRepository {<br>  final ApiService _apiService;<br><br>  Future&lt;ProfileResp&gt; getProfile() async {<br>    try {<br>      final ProfileResp resp = await _apiService.post&lt;ProfileResp&gt;(<br>        url: ApiRoute.profile,<br>        header: {&quot;Accept-Language&quot;: AppConstants.apiAcceptLanguage},<br>        data: {},<br>        fromJson: ProfileResp.fromJson,<br>      );<br>      return resp;<br>    } on Exception catch (e) {<br>      // Here is DioExceptionType.connectionTimeout<br>       throw Exception(&quot;Connection timeout Error: $e&quot;);<br>    } on DioException catch (e) {<br>      // Here is other DioExceptionType<br>       throw Exception(&quot;Other type of Dio Exception: $e&quot;);<br>    } catch (e) {<br>      // Here is catch unexcepted errors<br>       throw Exception(e.toString());<br>    }<br>  }<br>}</pre><p>Last but not least, we can define custom exceptions by extending the <strong>Exception</strong> class. The purpose is to get pure error value to show in UI. In Dart, all of the <strong>Exception</strong> contain labels to describe exceptions. Showing in UI with the label may lead to worse UI and annoy the user. Instead of showing “<strong>Connection timeout</strong>” display “<strong>DioException Type: connection timeout</strong>” in the error screen.</p><pre>class ApiServiceExceptionWithMessage implements Exception {<br>  final String message;<br><br>  ApiServiceExceptionWithMessage(this.message);<br><br>  @override<br>  String toString() {<br>    return message; // You can customize this format<br>  }<br>}<br><br>class ProfileRepository {<br>  final ApiService _apiService;<br><br>  Future&lt;ProfileResp&gt; getProfile() async {<br>    try {<br>      final ProfileResp resp = await _apiService.post&lt;ProfileResp&gt;(<br>        url: ApiRoute.profile,<br>        header: {&quot;Accept-Language&quot;: AppConstants.apiAcceptLanguage},<br>        data: {},<br>        fromJson: ProfileResp.fromJson,<br>      );<br>      return resp;<br>      <br>      // Here is change Exception to ApiServiceExceptionWithMessage<br>    } on ApiServiceExceptionWithMessage catch (e) {<br>      // Here is DioExceptionType.connectionTimeout<br>       throw ApiServiceExceptionWithMessage(&quot;Connection timeout Error: $e&quot;);<br>    } on DioException catch (e) {<br>      // Here is other DioExceptionType<br>       throw ApiServiceExceptionWithMessage(&quot;Other type of Dio Exception: $e&quot;);<br>    } catch (e) {<br>      // Here is catch unexcepted errors<br>       throw ApiServiceExceptionWithMessage(e.toString());<br>    }<br>  }<br>}</pre><p>After most of the Error-handling keywords, continue why not to use <strong>try</strong>-<strong>catch</strong> in everywhere.</p><ol><li>Using everywhere to lead error to prone and hard to find error to fix in development state.</li><li>In Flutter, if we are using other packages to detect network connection (connected/ disconnected) state. <br>Dio also has <strong>DioExceptionType.connectionError</strong> and become complex to handle with two conditions coming from different packages. <br>It doesn’t mean don’t use <strong>try-catch</strong> , need to neglect <strong>DioExceptionType.connectionError</strong> that come from Dio using <strong>throw</strong> to filter.</li></ol><p>!!! Hope to more understand about error handling and wish to develop bug-free Flutter applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8412846623d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter mobile app distribution with Firebase by Fastlane]]></title>
            <link>https://medium.com/@lapyaeootharthar/flutter-mobile-app-distribution-with-firebase-by-fastlane-d37542c2b7f8?source=rss-41c56c1512aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/d37542c2b7f8</guid>
            <category><![CDATA[firebase-app-distribution]]></category>
            <category><![CDATA[fastlane]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[La Pyae Oo]]></dc:creator>
            <pubDate>Fri, 06 Sep 2024 19:12:26 GMT</pubDate>
            <atom:updated>2024-09-06T19:12:26.549Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V5suyYPkaeJ62SfEBPwV5g.png" /></figure><p>I explained this article in the Google I/O Extended 2024 (Yangon). In this context, I explain in detail using code and examples.</p><p>I assume As a mobile developer, application distribution is one of the required skills that need to know. The most effective way is distribution on Google Play (for Android) and App Store (for IOS). But if you need to distribute internally within a limited timeframe (as soon as possible) and only on a single platform by inviting once to stakeholders and trusted testers, Firebase distribution is the best and quick tool for developers.</p><p>Here I forgot to say is, delivering applications on Firebase with the aid of Fastlane is the optimal approach. So I will implement with Fastlane. Let’s dive in and dirty hand to know more.</p><blockquote>“Delivering should be easy”</blockquote><p><strong>Setup in Firebase</strong></p><p>First, need to go to the <a href="https://console.firebase.google.com/">Firebase</a> console. In the console page create a project to settle the application for distribution and to use any other Firebase services. If you create a project for the first time, there will be no application in your project like that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5yw1cN0XTOhHJ-frpp6Fjg.png" /><figcaption>Empty application view</figcaption></figure><p>Then choose a platform for your project. Here, choose the Flutter icon for the Flutter application. If you are not using Flutter for app development, you don’t need to do the Setup <strong>Firebase for the Flutter app</strong> step and you can start manually for a specific platform.</p><h4>Setup Firebase for Flutter app</h4><p>Install requirement as documentation of Flutter shown.</p><ul><li>Install Flutter SDK from <a href="https://docs.flutter.dev/get-started/install">Flutter</a> documentation.</li><li>Create a Flutter application by terminal <strong>flutter create</strong> or you can create from UI in Android Studio.</li><li>Install Firebase CLI by running <br><strong>curl -sL &lt;https://firebase.tools&gt; | bash</strong> it in your terminal and then login with<br> <strong>firebase login</strong>.</li><li>If you use more than one account and already use Firebase you can switch with <strong>firebase login:use [xxxxxxx@gmail.com]</strong> command to change your desired account. In Firebase important to highlight is you can use only <strong>Gmail</strong>, any other domain mail will not validate.</li><li>To activate Firebase globally in your machine, run <br><strong>dart pub global activate flutterfire_cli</strong> .</li><li>To configure your project with Firebase, go to the root of the project and run the command as shown in the documentation. For now, this is the command for this example project <br><strong>flutterfire configure --project=fir-distributionapp-b34e5</strong> .</li><li>After running this command, there will pop up a list and select your desired OS for your application. You can choose multiple in the list. After that Firebase setup requests your application package name and adds the package name for this example package name is <strong>com.example.firebasedistribution.firebase_distribution</strong>.</li><li>After all of the Firebase CLI setup, will generate each app ID for your app depending on the OS that your previously chosen list and generate a dart file <strong>lib/firebase_options.dart</strong> that is associated with your app on the Firebase project.</li></ul><p>At the last configuration, you need to call <strong>Firebase.initializeApp()</strong> the method of <strong>lib/firebase_options.dart .</strong></p><pre><br>void main() async {<br>  WidgetsFlutterBinding.ensureInitialized();<br>  await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform);<br>  runApp(App());<br>}</pre><p>These steps are only required for the Flutter application and you don’t need to do them for Native mobile applications or apps with other languages.</p><h4>Setup Firebase app distribution service</h4><p>If you already have an application in your Firebase project, you can start from here.</p><p>Under the <strong>Product categories</strong> title, select <strong>App Distribution</strong> service under the <strong>Run</strong> drop-down. There is a place ready to distribute your app. If you chose both Android and IOS in the previous step, there are two categories for both platform in the tab at the header. The default tab will be selected as Android.</p><p><strong><em>Product categories &gt; Run &gt; App Distribution</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZgUjzeOvjV_CZ3PyGou-GA.png" /><figcaption>applications for both Android and IOS inside Firebase project</figcaption></figure><p>Under the <strong>App Distribution</strong> service, it has three sections tabs: Invite links, Testers, and Groups.</p><ul><li><strong>Releases:</strong> Can store and check detailed information of all the released apps with versions.</li><li><strong>Invite links:</strong> To deliver the application to the trusted testers by invitation link.</li><li><strong>Testers and Groups:</strong> Here, you can create a group of testers depend on their type.</li></ul><h4>Fastlane installation</h4><p>There are three ways to install Fastlane:</p><ul><li>Managed Ruby environment + Bundler (macOS/ Linux/ Windows)</li><li>Homebrew (macOS)</li><li>System Ruby + Ruby Gems (macOS/ Linux/ Windows)</li></ul><p>Managed Ruby environment + Bundler is the recommended way by Fastlane documentation but I install with Homebrew because it is more easy for me.</p><p><strong>Managed Ruby environment + Bundler (macOS / Linux/ Windows)</strong></p><p>As documentation, Fastlane supports Ruby version 2.5 or newer. So you need to upgrade your Ruby version before installing Fastlane. Check the Ruby version and install the bundler with:</p><pre>$ ruby --version<br>ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin23]<br>gem install bundler</pre><p><strong>Homebrew (macOS)</strong></p><p>In this installation, there is no need to do special and just install with <strong>brew</strong>.</p><pre>brew install fastlane</pre><p><strong>System Ruby + Ruby Gems (macOS/ Linux/ Windows)</strong></p><p>This way is not recommended by documentation because it modifies file permission by the <strong>sudo</strong> command, which can cause unexpected errors.</p><pre>sudo gem install fastlane </pre><p>After all of these steps, Fastlane installation is done. In the next step initialize Fastlane to distribute on both Android and IOS.</p><p>Fastlane initialization on Android and IOS is a bit different. For IOS is more complicated than Android but not worry I will explain step by step for IOS.</p><h4>Android distribution</h4><p>With other programming languages, we only need to initialize once in the project root folder, but in Flutter we need to initialize inside /android folder. So go to the Android directory and type.</p><pre>cd android<br>fastlane init</pre><p>This command will ask you for your app package name and other requirement to register in Fastlane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aBTSjPDVB61UVGUHp-S2Jw.png" /><figcaption>Fastlane registering</figcaption></figure><ul><li><strong>As 1st step</strong> — Fastlane asks for your application package name. You must enter your application package name.</li><li><strong>As 2nd step</strong> — Fastlane will ask for requirements to upload on the Google Play Store. For now, we don’t distribute on Play Store so we can skip by <strong>Enter</strong> for all of those steps.</li></ul><p>After all of that, Fastlane will generate two files in the Fastlane folder located in the Android directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*9lylWwTbJvQFLhc5r8Y5ng.png" /><figcaption>fastlane directory location in Android folder</figcaption></figure><p>In the fastlane folder there is Appfile and Fastfile will be generated.</p><p><strong>Appfile</strong> can be neglected for now. It is the configuration file for your keys to upload on the Play Store. But for the best practice, you should declare keys that are associated with Fastlane.<br><strong>Fastfile</strong> is important for now to write configuration to upload to not only Firebase but also Stores(Play Store, App Store).</p><p>Let’s code the script to upload to the app store.</p><pre>fastlane_require &#39;fastlane-plugin-firebase_app_distribution&#39;<br>update_fastlane<br><br>default_platform(:android)<br><br>platform :android do<br>  desc &quot;Runs all the tests&quot;<br>  lane :test do |options|<br>    flutter_version = options[:flutter_version]<br>    sh &quot;flutter run lib/main.dart&quot;<br>  end<br># ---------------- 1st path -----------------------------<br>  desc &quot;Deploy Android build&quot;<br>  lane :deployAndroid do<br>    gradle(<br>      task: &#39;assemble&#39;,<br>      build_type: &#39;Release&#39;,<br>      flags: &#39;-Ptarget=lib/main.dart&#39;<br>    )<br># ---------------- 2nd path -----------------------------<br>    firebase_app_distribution(<br>      app: &quot;1:53836225305:android:a1ae227902b297f34e0388&quot;,<br>      firebase_cli_path: &quot;/usr/local/bin/firebase&quot;,<br>      groups: &quot;stakeholders, testers&quot;,<br>      # release_notes_file: &quot;../release_note.txt&quot;,<br>      android_artifact_type: &quot;APK&quot;,<br>      apk_path: &quot;../build/app/outputs/flutter-apk/app-release.apk&quot;,<br>      debug: true<br>    )<br># ---------------- 3rd path -----------------------------<br>  end<br>end</pre><p>In this code block, we can divide into three paths. But don’t want to misunderstand that three paths are not part of a lane. Fastlane works with lanes likes methods in programming. One lane should do one task. As the upper code block, there are two lanes: the first lane is the test lane and the second lane is the <strong>deployAndroid</strong> lane.</p><p>At first of the block, this script is only for the Android platform, so needs to be declared as <strong>platform :android do</strong>.</p><p>For <strong>test</strong> lane, description <strong>desc</strong> is just to describe the lane task. In <strong>test</strong> lane, tasks are to check the local Flutter version and run only for testing.</p><p><strong>deployAndroid</strong> lane can be divided into two parts: <br>The first part is to build the application and the second part is to distribute on Firebase. In the build application part, I build from Android <strong>gradle</strong> so I write gradle. Inside of it <strong>task:’assemble’</strong> means I just only compile app, <strong>build_type: ‘Release’</strong> mean build application with Release version, flags: <strong>‘-Ptarget=lib/main.dart’</strong> script is the point of entry to build the application.<br>Inside the second part, use <strong>firebase_app_distribution()</strong>. To use this feature, we should install the plugin by this code:</p><pre>fastlane add_plugin firebase_app_distribution</pre><p>In firebase_app_distribution() :</p><ul><li>app parameter is the ID of the application on the Firebase we did in the previous step.</li><li>firebase_cli_path: &quot;/usr/local/bin/firebase&quot; is the Firebase CLI path.</li><li>groups: &quot;stakeholders, testers&quot; mean groups in Firebase to distribute our application. In this line we can only distribute to our desire group by writing only those groups name.</li><li>release_notes_file: &quot;../release_note.txt&quot; as the release note, we can create a text file inside of the root directory of our project.</li><li>android_artifact_type: &quot;APK&quot; this line means that our bundle type. If we compiled it as <strong>aab, </strong>we should declare it as aab<strong>.</strong> For now, I compiled it as <strong>apk</strong> so I declared it as APK. The case is not important.</li><li>apk_path: &quot;../build/app/outputs/flutter-apk/app-release.apk&quot; is the point to bundle location to upload on Firebase.</li><li>debug: true is to verbose while compiling and distributing the process.</li></ul><p>That’s all of the scripts to upload the Android app to distribute with Firebase. As final to distribute with this command that contains lane name:</p><pre>Bundle exec fastlane deployAndroid</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uwBvMxD-7Qahmuvrv3j32w.png" /><figcaption>Application now on Firebase</figcaption></figure><p>Boom !!! Now our android app can be distributed on the Firebase by Fastlane without waiting being to wait reviews and time.</p><h4>IOS distribution</h4><p>The first and essential requirement to distribute an IOS app is an “ IOS developer account”. I assume that if you read until this you will have an IOS developer account or you are familiar with IOS app distribution. Let’s write the code to distribute the IOS app to Firebase app distribution.</p><pre>fastlane_require &#39;fastlane-plugin-firebase_app_distribution&#39;<br>update_fastlane<br><br>default_platform(:ios)<br><br>platform :ios do<br>  desc &quot;Deploy IOS build&quot;<br>  lane :deployIos do<br>  gym(<br>      workspace: &quot;../ios/Runner.xcworkspace&quot;,<br>      # scheme: &quot;uat&quot;, # to build app with flavor<br>      configuration: &quot;Release&quot;,<br>      output_directory: &quot;../build/ios/&quot;,<br>      clean: true,<br>      export_options: {<br>                        method: &quot;development&quot;,<br>                        teamID: &quot;xxxxx&quot;,<br>                        provisioningProfiles: {<br>                            &quot;com.xx.xxx.xx&quot; =&gt; &quot;App Provisioning&quot;<br>                        }<br>                    }<br>  )<br>  # ---------------- 1st path -----------------------------<br>  firebase_app_distribution(<br>               app: &quot;1:53836225305:ios:b9f8fece18085c534e0388&quot;,<br>               ipa_path: &quot;../build/ios/App.ipa&quot;,<br>          groups: &quot;stakeholders, testers&quot;,<br>  )<br>  # ---------------- 2nd path -----------------------------<br>  end<br>end</pre><p>As an Android distribution, this code can be divided into two sections. But contain one lane. Combine building app section and Firebase app distribution into one lane. I suppose you already understand Android, as like that most upper code until to <strong>gym</strong> in the 1st path lane name, description, and plugin declaration.</p><p>Inside <strong>gym()</strong>, <strong>workspace</strong> , <strong>configuration</strong> , <strong>output_directory</strong> is nothing special. Just point to the location of the Runner file, build configuration, and app output directory.<br>Inside <strong>export_options</strong> option, you can also use the <strong>method</strong> to <strong>development</strong> if you don’t distribute directly to the App Store.</p><p>For <strong>teamID</strong> , you can search under Singing &amp; Capabilities of Runner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4fCX80cRaJBJbiELjhLAcA.png" /><figcaption>teamId for IOS app</figcaption></figure><p>To make <strong>provisioningProfiles</strong>, a lot of steps you need to do.</p><ul><li>First invite tester on Firebase by Gmail.</li><li>After importing the tester on Firebase Export Apple UDIDs file from Firebase testers.</li><li>Add this Apple UDIDs file to the <strong>Devices</strong> tab under the <a href="https://developer.apple.com/account/resources/profiles/list">Certificates, Identifiers &amp; Profiles</a> title of your Apple developer account. This process is to register testers&#39; devices to test this app.</li><li>Build your app profile inside the <strong>profiles</strong> tab.</li><li>Then download your app profile from the <strong>profiles</strong> tab. Extension of this downloaded file will end with <strong>.mobileprovision</strong>. (Example: YourApp_Provisioning.mobileprovision)</li><li>Lastly, clicking that file will route to Xcode and will sync with your new provision file again.</li></ul><p>End of all these procedures, In here <strong>&quot;com.xx.xxx.xx&quot; =&gt; &quot;App</strong> <strong>Provisioning&quot;</strong> you can change your application package name and provision name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pVfqW0Mi2fE52g5Butdyng.png" /><figcaption>Exporting Apple UDIDs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L8wV3Z8CwM6C46KiuhsiqA.png" /><figcaption>Apple developer account profiles tab</figcaption></figure><p>Then you can run with lane name and your IOS app (ipa) will be uploaded to Firebase and you can distribute it to invited testers.</p><pre>Bundle exec fastlane deployIos</pre><p>In IOS app distribution you must invite your testers first. If you forgot to invite the tester, you need to make the provision file again as above procedure.</p><p><strong>Great!</strong> Now you can easily distribute your applications via Firebase. I hope this article will help you. If helpful for you please clap as motivation for me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d37542c2b7f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decoupling (Less coupling) in Flutter]]></title>
            <link>https://medium.com/@lapyaeootharthar/decoupling-less-coupling-in-flutter-718c3a8db060?source=rss-41c56c1512aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/718c3a8db060</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[solid]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[decoupling]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[La Pyae Oo]]></dc:creator>
            <pubDate>Mon, 18 Mar 2024 19:49:15 GMT</pubDate>
            <atom:updated>2024-03-19T04:25:07.356Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b4eHNLcreGwlInYJ" /><figcaption>Photo by <a href="https://unsplash.com/@marcsm?utm_source=medium&amp;utm_medium=referral">Marc Sendra Martorell</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Most of the software developers already knew or heard about <strong>S.O.L.I.D</strong> principle. But actually in practical for a project, as a junior developer or mid level developer including me face many difficulties and very hard to obey at least one principle from <strong>S.O.L.I.D</strong>. In this article not discuss all of the principle of <strong>S.O.L.I.D</strong> because it is a long journey to learn and not enough with one article. But will emphasize about <strong>Coupling/ Decoupling</strong> in Flutter with example code snippet to better understand.</p><p>In <strong>S.O.L.I.D</strong>, Decoupling is indirectly promoted by other <strong>S.O.L.I.D</strong> principles including (S — <strong>Single Responsibility Principle</strong>), (O — <strong>Open Close Principle</strong>). In a project if modules (Classes, methods or widgets) are dependent too much each other, it is hard in maintenance or to change codes as business requirement. But in software development, can’t remove coupling between modules completely, so decoupling mean loosening the existing coupling. Let’s start with the example.</p><p>Imaging implement the below tappable card design in project …..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dLZkm2qceB_9R6ea0hp5OA.png" /><figcaption>A tappable card of setting page from an application of AYA Innovation Lab</figcaption></figure><p>As a junior or less-experienced developer will surely writes the most coupling codes by using may if/ else statements and other duplicated code that don’t obey (<strong>DRY — Don’t Repeat Yourself</strong>).</p><p><strong><em>Most coupling codes</em></strong><em> </em><strong><em>(Should avoid of using like that)</em></strong></p><p><strong>Codes in parent screen</strong></p><pre>Container(<br>              decoration: BoxDecoration(<br>                color: AppColor.grayScale60Light,<br>                border: Border.all(<br>                  color: AppColor.borderColor,<br>                ),<br>                borderRadius: BorderRadius.circular(smallRadius),<br>              ),<br>              child: Column(<br>                children: [<br>                  mediumVerticalSpace,<br>                  ItemCard(<br>                    onTap: (){<br>                      print(&#39;Go to security page&#39;);<br>                    },<br>                    label: &#39;Security &amp; Privacy&#39;,<br>                    svgIcon: AppGraphic.securityIcon,<br>                    rightArrow: AppGraphic.rightArrowIcon,<br>                  ),<br>                  const Padding(<br>                    padding: EdgeInsets.symmetric(horizontal: 15.0),<br>                    child: Divider(thickness: 1,),<br>                  ),<br>                  ItemCard(<br>                    onTap: (){<br>                      print(&#39;Go to language page&#39;);<br>                    },<br>                    label: &#39;Language&#39;,<br>                    svgIcon: AppGraphic.languageIcon,<br>                    rightArrow: AppGraphic.rightArrowIcon,<br>                  ),<br>                  mediumVerticalSpace,<br>                ],<br>              ),<br>            ),</pre><p><strong>Codes as widget components</strong></p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter_svg/svg.dart&#39;;<br><br>import &#39;../../../../app/config/app_color.dart&#39;;<br>import &#39;../../../../app/config/app_size.dart&#39;;<br><br>class ItemCard extends StatelessWidget {<br>  const ItemCard(<br>      {super.key,<br>      required this.onTap,<br>      required this.label,<br>      required this.svgIcon,<br>      required this.rightArrow<br>      });<br><br>  final Function onTap;<br>  final String label;<br>  final String svgIcon;<br>  final String rightArrow;<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return GestureDetector(<br>      onTap: onTap(),<br>      child: Row(<br>        children: [<br>          mediumHorizontalSpace,<br>          SvgPicture.asset(<br>            svgIcon,<br>          ),<br>          mediumHorizontalSpace,<br>          Text(label),<br>          Expanded(<br>            child: Row(<br>              mainAxisAlignment: MainAxisAlignment.end,<br>              children: [<br>                SvgPicture.asset(<br>                  rightArrow,<br>                ),<br>                mediumHorizontalSpace,<br>              ],<br>            ),<br>          ),<br>        ],<br>      ),<br>    );<br>  }<br>}</pre><p>Seeing above code snippets, codes are being tight coupling and hard to maintain in future. In other way if want to change spacing vertically, may change all of the SizedBox() spacing or if business want to add more item sections in this card, need to call again and again every time we need ItemCard() class.</p><p>It is a very boring thing in software development and if want to change in a place, need to do in so many lines of code.</p><p><strong><em>Less coupling (Decoupling)</em></strong></p><p><strong>Codes in parent screen</strong></p><pre>ListView(<br>          children: [<br>            SettingHeader(),<br>            ItemCard(<br>              items: [<br>                SettingItemUseCase(<br>                  icon: AppGraphic.securityIcon,<br>                  label: &#39;Security &amp; Privacy&#39;,<br>                  tralierIcon: AppGraphic.rightArrowIcon,<br>                  onTap: () {},<br>                ),<br>                SettingItemUseCase(<br>                  icon: AppGraphic.languageIcon,<br>                  label: &#39;Language&#39;,<br>                  tralierIcon: AppGraphic.rightArrowIcon,<br>                  onTap: () {},<br>                ),<br>              ],<br>            ),<br>          ],<br>        ),</pre><p><strong>Codes as widget component</strong></p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter_svg/svg.dart&#39;;<br><br>import &#39;../../../../app/config/app_color.dart&#39;;<br>import &#39;../../../../app/config/app_size.dart&#39;;<br>import &#39;../use_case_model/setting_item_use_case.dart&#39;;<br><br>class ItemCard extends StatelessWidget {<br>  ItemCard({required this.items});<br><br>  List&lt;SettingItemUseCase&gt; items;<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Container(<br>      decoration: BoxDecoration(<br>        color: AppColor.grayScale60Light,<br>        border: Border.all(<br>          color: AppColor.borderColor,<br>        ),<br>        borderRadius: BorderRadius.circular(smallRadius),<br>      ),<br>      child: Column(<br>        crossAxisAlignment: CrossAxisAlignment.start,<br>        children: items<br>            .asMap()<br>            .map(<br>              (index, e) =&gt; MapEntry(<br>                index,<br>                Column(<br>                  children: [<br>                    smallVerticalSpace,<br>                    GestureDetector(<br>                      onTap: e.onTap,<br>                      child: Row(<br>                        children: [<br>                          smallHorizontalSpace,<br>                          SvgPicture.asset(<br>                            e.icon,<br>                          ),<br>                          smallHorizontalSpace,<br>                          Text(e.label),<br>                          mediumVerticalSpace,<br>                          Expanded(<br>                            child: Row(<br>                              mainAxisAlignment: MainAxisAlignment.end,<br>                              children: [<br>                                SvgPicture.asset(<br>                                  e.tralierIcon,<br>                                ),<br>                                mediumHorizontalSpace,<br>                              ],<br>                            ),<br>                          ),<br>                        ],<br>                      ),<br>                    ),<br>                    smallVerticalSpace,<br>                    index != items.length - 1<br>                        ? const Padding(<br>                            padding: EdgeInsets.symmetric(horizontal: 16.0),<br>                            child: Divider(<br>                              thickness: 1,<br>                            ),<br>                          )<br>                        : const SizedBox(),<br>                  ],<br>                ),<br>              ),<br>            )<br>            .values<br>            .toList(),<br>      ),<br>    );<br>  }<br>}</pre><p>But for less coupling, use an entity class (use-case model) to maintain in future.</p><p><strong>Entity Class</strong></p><pre>class SettingItemUseCase {<br>  const SettingItemUseCase({<br>    required this.icon,<br>    required this.label,<br>    required this.tralierIcon,<br>    required this.onTap,<br>  });<br><br>  final Function() onTap;<br>  final String icon;<br>  final String label;<br>  final String tralierIcon;<br>}</pre><p>As this code snippet example, I suppose you will understand less coupling principle easily.</p><p>Please Clap more and more, if this article can explain easily to you.</p><p>Ref: <br>- <a href="https://youtu.be/WvAf2IhrxFo?si=drDxra0vTDD9B6P-">Single Responsibility and Software Development Layers by Ko Htain Lin Shwe</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=718c3a8db060" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Refactor with polymorphism in Dart]]></title>
            <link>https://medium.com/@lapyaeootharthar/refactor-with-polymorphism-in-dart-e4ec529d6e17?source=rss-41c56c1512aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4ec529d6e17</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[polymorphism]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[myanmar]]></category>
            <dc:creator><![CDATA[La Pyae Oo]]></dc:creator>
            <pubDate>Tue, 21 Nov 2023 18:16:41 GMT</pubDate>
            <atom:updated>2023-11-21T18:16:41.863Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Image to describe polymorphism" src="https://cdn-images-1.medium.com/max/1024/0*ukPdwTXqhEY_eRjt" /><figcaption>Image from Unsplash Website to Describe describe Polymorphism</figcaption></figure><p><strong>Project</strong> တခုရေးရင် အသုံးများဆုံး <strong>Statement</strong> တွေကတော့ <strong>if</strong>တို့ <strong>switch</strong> တို့လို <strong>Conditional Statement</strong> တွေဖြစ်တယ်ဆိုတာ မြင်မိကြမှာပါ။အဲ့လို <strong>Conditional</strong> <strong>Statment</strong> တွေကိုအသုံးများလာတဲ့ အခါ <strong>Project</strong> ထဲမှာ Code တွေရှုပ်ထွေးလာတာမျိုး <strong>Function</strong> အသစ်ထည့်ရင် ဥပမာ <strong>Network Call</strong> လုပ်တဲ့ <strong>Class</strong> လိုမျိုးတွေမှာ ခက်ခက်ခဲခဲပြင်နေရတာမျိုးတွေကိုကြုံလာရလိမ့်မယ်။</p><p><strong>Theory</strong> အရကြည့်ရင်လည်း <strong>OCP ( Open Close Principal)</strong> ကိုမလိုက်နာထားတဲ့အတွက် <strong>Code Smell</strong> ဖြစ်လာတယ်၊ နောက်တချိန်မှာ ပြန်ပြင်တဲ့အခါကြတော့လည်း တနေရာကိုပြင်ရင် နောက်တနေရာက <strong>Error</strong> တက်လာတာမျိုး အဲ့လိုအခက်အခဲတွေကြုံလာရနိုင်တယ်။ အဲ့တော့ <strong>Conditional Statement</strong> တွေသုံးမယ့်အစား <strong>Polymorphism</strong> သဘောတရားကိုသုံးပြီး ဘယ်လို ရေးကြမလဲဆိုတာ ပြောပြသွားမှာဖြစ်ပါတယ်။</p><p><strong>Polymorphism</strong> ဆိုတာကတော့ <strong>OOP language</strong> တွေရဲ့ <strong>Feature</strong> ဖြစ်ပြီး <strong>Code</strong> <strong>Block</strong> တခုမှာ <strong>Ability</strong> တူတဲ့ <strong>Statement</strong> တွေကို ဘုံထုတ်ပြီး လိုတဲ့ နေရာ တိုင်းမှာ ပြန်သုံးတဲ့ သဘောကိုပြောတာပေါ့။ <strong>Dart</strong> မှာဆိုရင်တော့ <strong>Class</strong> တခုထဲမှာ <strong>Ability</strong> တူတဲ့ <strong>Method Name</strong> တွေကို အရင် <strong>Declare</strong> လုပ်ထားပြီး လိုတဲ့နေရာကနေ <strong>Object</strong> ဆောက်ပြီး <strong>Implement</strong> လုပ်တာမျိုးဖြစ်တယ်။ ဥပမာ အနေနဲ့ ပြောရရင် <strong>Animal</strong> ဆိုတဲ့ <strong>Abstract Class</strong> မှာ <strong>move()</strong> , <strong>makeSound()</strong> တို့လို <strong>Method Name</strong> တွေကို <strong>Declare</strong> လုပ်ခဲ့ပြီး <strong>Cat Class</strong> က အဲ့ဒီ <strong>Animal Abstract Class </strong>ကို <strong>Extends</strong> လုပ်ပြီး အထဲက <strong>Method</strong> တွေကို <strong>Implement</strong> လုပ်လို့ရသလို <strong>Dog Class</strong> ကနေ လည်း <strong>Animal Class</strong> ကို <strong>Extends</strong> လုပ်ခြင်းအားဖြင့် ဘုံတူညီတဲ့ <strong>Ability</strong> တွေကို ထပ်ခါခါရေးနေစရာမလိုတာမျိုးကို <strong>Polymorphism</strong> လုပ်တယ်လို့သတ်မှတ်တယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*3f3OP0vHNzvUC4gZkTxqRw.png" /><figcaption>Polymorphism UML diagram</figcaption></figure><p>ဒီနေရာမှာ <strong>OCP</strong> ဆိုတဲ့ သဘောတရားနဲ့ ဥပမာပေး‌ပြောရင် ဘာလို့ <strong>Polymorphism</strong> ကို <strong>switch</strong> <strong>Case</strong> အစားသုံးသင့်လဲဆိုတာကို ပိုမြင်နိုင်မယ်ထင်ပါတယ်။ <strong>OCP</strong> ဆိုတာက <strong>(Open Close Principal)</strong> လို့အရှည်ဖြစ်ပြီး <strong>Code Block(Class, Method, Module) </strong>တခုရေးပြီးသွားပြီဆိုရင် တခြား <strong>Code Block</strong> ဒါမှမဟုတ် <strong>Statement</strong> တခုကနေ သူ့ကို <strong>Extension</strong> လုပ်ပြီးသုံးဖို့အတွက်ပဲ <strong>Open</strong> ဖြစ်နေရမယ် လုပ်လို့ရရမယ်ပေါ့။ တခြားတနေရာကနေ သူ့ကို လာပြင်ပြီးလို့ ရနေတာမျိုးသူ့ကို <strong>Modified</strong> လုပ်ပြီးမှ သုံးတာမျိုး အတွက်ကို <strong>Close</strong> လုပ်ထားရမယ်။ <strong>Private Variable</strong> တို့ <strong>Private Contructor</strong> တွေသုံးရခြင်းသည် အဲ့လိုမျိုး <strong>Close</strong> ဖြစ်နေအောင် ယူသုံးလို့မရအောင်လုပ်ထားဖို့လည်း ဖြစ်တယ်။</p><p>အဲ့ဒါကြောင့် <strong>Open for Extension, Close for modification (Open Close Principal)</strong> လို့ခေါ်တာ။ ဒီလို <strong>Refactor</strong> လုပ်တဲ့ <strong>Process</strong> တွေမှာသတိထားစရာတခုကတော့ <strong>Refactor</strong> လုပ်ခြင်းက <strong>Code</strong> ကို ပိုတိုသွားအောင် လုပ်တာမဟုတ်ဖူးလို့ မှတ်ယူရမယ်။ <strong>Refactor</strong> လုပ်လိုက်တာက နဂိုထက် <strong>Code</strong> လိုင်းရေ ဒါမှမဟုတ် <strong>Code Block</strong> ပိုများလာတာမျိုး ဖြစ်ကောင်းဖြစ်လာနိုင်‌‌ပေမယ့် ပြင်လို့ပြောင်းလို့လွယ်တဲ့ <strong>Code</strong> မျိုး ဖြစ်လာတဲ့အတွက် <strong>Code Quality</strong> ပိုမြင့်လာမှာပါ။</p><p>အောက်က <strong>Code</strong> ကို နမူနာအနေနဲ့ ကြည့်မယ်ဆိုရင်</p><pre>void checkedScannedQr(String qrCodeString) {<br><br> switch (qrCodeString) {<br>   case &#39;000001&#39;:<br>     Navigator.pushNamed(context, &#39;/CustomerOne&#39;);<br>     break;<br>   case &#39;000002&#39;:<br>     Navigator.pushNamed(context, &#39;/CustomerTwo&#39;);<br>     break;<br>   case &#39;000003&#39;:<br>     Navigator.pushNamed(context, &#39;/CustomerThree&#39;);<br>     break;<br>   default:<br>     showErrorToast(&#39;Wrong QR!&#39;);<br>     break;<br> }<br><br>}</pre><p>ဒီမှာ <strong>Code</strong> အလုပ်လုပ်ပုံက <strong>QR Scan</strong> ဖတ်တဲ့ <strong>Method</strong> ဖြစ်တယ်။ <strong>qrCodeString()</strong> <strong>Argument</strong> ပေါ်မူတည်ပြီး သွားမည့် <strong>Screen</strong> တွေကို စစ်ထားတာ။ အဲ့မှာ ဘာပြဿနာရှိလဲဆိုတော့ တကယ်လို့ <strong>Screen</strong> ကို <strong>Route</strong> သွားတာပဲမဟုတ်ပဲ တခြား အလုပ်တွေပါလုပ်ချင်တာမျိုး <strong>Changes</strong> ဖြစ်လာရင်ဖြစ်ဖြစ်‌နောက်ထပ် <strong>Route</strong> မည့် <strong>Screen</strong> အသစ်ထပ်ထည့်မယ်ဆိုရင် နောက်ထပ် <strong>Navigation Code</strong> တကြောင်းထပ်တိုးရမယ်ပေါ့။ အဲ့လိုနေရာမျိုးမှာ <strong>Code</strong> တွေထပ်နေပြီး ကြည့်ရပြင်ရပိုခက်လာမယ်ပေါ့။</p><p>အဲ့အပေါ်က <strong>Code</strong> ကို <strong>Polymorphism</strong> ပုံစံပြန်ပြောင်းမယ်ဆိုရင်</p><pre>abstract class QrType{<br><br>  void screenNavigation();<br><br>}<br><br>class CustomerOne extends QrType {<br><br>  @override<br>  screenNavigation() {<br><br>    Navigator.pushNamed(context, &#39;/CustomerOne&#39;);<br><br>  }<br>}<br><br>class CustomerTwo extends QrType {<br><br>  @override<br>  screenNavigation() {<br><br>    Navigator.pushNamed(context, &#39;/CustomerTwo&#39;);<br><br>  }<br>}<br><br>class CustomerThree extends QrType {<br><br>  @override<br>  screenNavigation() {<br><br>    Navigator.pushNamed(context, &#39;/CustomerThree&#39;);<br><br>  }<br>}<br><br><br>class QrController{<br><br> void checkedScannedQr(String qrCodeString) {<br><br>    QrType? qrType;<br><br>    if (qrCodeString.contains(&#39;000001&#39;)) {<br>      qrType = CustomerOne();<br>    } else if (qrCodeString.contains(&#39;000002&#39;)) {<br>      qrType = CustomerTwo();<br>    } else if (qrCodeString.contains(&#39;000003&#39;)) {<br>      qrType = CustomerThree();<br>    } else {<br>      showErrorToast(&#39;Wrong QR!&#39;);<br>    }<br><br>    qrType?.screenNavigation();<br>  }<br>}</pre><p>အပေါ်က <strong>Polymorphism</strong> ပုံစံပြောင်းထားတဲ့ <strong>Code</strong> မှာဆိုရင် <strong>QrType</strong> <strong>Class</strong> ကို <strong>Abstract Class</strong> ဆောက်ပြီး အဲ့ <strong>Class</strong> ထဲမှာ <strong>Implement</strong> လုပ်ချင်တဲ့ <strong>Method</strong> တခုချင်းကို ကြို <strong>Declare</strong> လုပ်ထားမယ် <strong>Condition</strong> တခုချင်းစီအတွက် <strong>Class</strong> တခုဆောက် <strong>Extends</strong> လုပ်ပြီး အထဲက <strong>Method</strong> တွေကို <strong>Implementation</strong> လုပ်ထားမယ် အဲ့ဒီနောက် <strong>checkedScannedQr()</strong> <strong>Method</strong> ထဲမှာ စစ်လိုက်တဲ့ပုံစံပြောင်းလိုက်တာက <strong>Code Line</strong> အရေအတွက်ပိုများသွားပေမယ့် ပြန်ပြင်ချင်တဲ့ <strong>Condition</strong> တခုချင်းစီအတွက် <strong>Extends</strong> လုပ်ထားတဲ့ <strong>Class</strong> ကိုဖြုတ်လိုက်တာမျိုးက မူရင်း <strong>Logic</strong> ကို မထိခိုက်စေပဲ ပြင်လို့ရတဲ့အတွက် <strong>OCP</strong> ကိုလိုက်နာတဲ့ <strong>Code</strong> မျိုးဖြစ်ပြီး <strong>Code</strong> <strong>Smell</strong> လည်း အနည်းဆုံး အခြေအနေကို ပြောင်းလဲသွားမှာဖြစ်တယ်။</p><blockquote>Thanks for reading.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4ec529d6e17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apply Gaussian Distribution function in a Flutter Animation]]></title>
            <link>https://medium.com/@lapyaeootharthar/apply-gaussian-distribution-function-in-a-flutter-animation-1b02fde0e5a7?source=rss-41c56c1512aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b02fde0e5a7</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[myanmar]]></category>
            <dc:creator><![CDATA[La Pyae Oo]]></dc:creator>
            <pubDate>Wed, 26 Jul 2023 17:39:34 GMT</pubDate>
            <atom:updated>2023-07-26T17:39:34.843Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tI_mwKZCew6O6nRx" /><figcaption>Photo by <a href="https://unsplash.com/@markkoenig?utm_source=medium&amp;utm_medium=referral">Mark König</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Myanmar Version</strong></p><p>ဒီ Article မှာတော့ Flutter ၊ Dart programming နဲ့ Physic (Science) ပိုင်းရဲ့ Theory တစ်ခုဖြစ်တဲ့ <strong>Gaussian function</strong> ကို ဘယ်လို <strong>Calculate</strong> လုပ်လို့ရပြီး ဘယ်လို <strong>Applied</strong> လုပ်လို့ရလဲဆိုတာကို ဖတ်မိတဲ့ <strong>Flutter Artilce</strong> တခုကနေပြန် share ပေးမှာဖြစ်ပါတယ်။</p><p>စပြောရရင် အဓိကရည်ရွယ်တာကတော့ Science equation တွေကို ကျွန်တော်တို့‌တွေအ‌နေနဲ့ဟာ တော်တော်ကို ကြီးကျယ်ခမ်းနားတဲ့ ပညာတွေရပ်မှာပဲ သုံးတယ်လို့ အမှတ်စွဲထင်နေခဲ့ကြတာကို။ ဥပမာ Science Theory တခုကို Rocket Science တွေမှာမှ သုံးမယ် ဒါမှမဟုတ်လည်း အနိမ့်ဆုံးတော့ လမ်းတံတားတည်ဆောက်ရေးမှာတို့ တော်တော်ခက်ခဲတဲ့ နေရာတွေမှာပဲ သုံးကြမှာပါ ၊ Computer Science မှာဆိုလည်း ML တို့ AI တို့လို အစရှိသဖြင့် OS တွေ Build တဲ့နေရာလိုမျိုးလောက်မှာပဲ လိုအပ်တယ်ထင်ကြတာများတာပေါ့။ တကယ်တော့ အဲ့လိုမဟုတ်ပါဖူး အခုပြောပြသွားမည့် အကြောင်းလိုမျိုး <strong>Gaussian Theory</strong> ကိုသုံးပြီး သေးသေးမွှားမွှားလေးဖြစ်တဲ့ <strong>Screen Animation</strong> လေးတခုကိုတောင် <strong>Applied</strong> လုပ်လို့ရတယ်ပါတယ်။ အဲ့ဒီတော့ ဒီ <strong>Theory</strong> တွေသိမှ <strong>Programmer</strong> လုပ်လို့ရတာလားဆိုပြီးတော့လည်း မဖြစ်မနေတော့မဟုတ်ပါဖူး။<br>မသိလည်းလုပ်လို့ရပါတယ်။ ဒီလို ကြီးကြီးမားမားလို့ထင်နေတဲ့ Theory တွေဆိုတာကလည်း အသုံးချလို့ရနိုင်ကြောင်းကို ဖတ်မိတဲ့ article လေးတခုကနေပြန်ရှင်းပြတာဖြစ်တယ်။<br>အဲ့တော့ ပြန်စရရင်</p><h3><strong>What is Gaussian Function?</strong></h3><p><strong>Gaussian function</strong> ဆိုတာ <strong>Carl Friedrich Gauss</strong> ဆိုတဲ့ သင်္ချာ ပညာရှင်ကြီးကထုတ်ထားတဲ့ <strong>Equation</strong> ဆိုတာနဲ့စရမယ်။ တကယ်တော့ ကိုယ်လည်း ဒါကို စိတ်ဝင်စားလို့ အာချောင်လို့ရအောင်ပြန်ဖတ်ထားတာပါ။ မှတ်မိခဲ့တာဆိုလို့ ဆယ်တန်း <strong>Physics</strong> မှာသင်ခဲ့ဖူးတယ်ဆိုတဲ့ နာမည်လေးလောက်ပဲမှတ်မိတော့တာ။ အစအဆုံးသိချင်ရင်တော့ ပြန်လေ့လာကြည့်ကြပါ။</p><p>ဘယ်နေရာတွေမှာ အဓိကသုံးကြလဲဆိုတော့ wave processing တို့လို image processing တို့လို အစရှိတဲ့နေရာတွေမှာ အဓိက ထားသုံးကြတယ်ပေါ့။</p><p><strong>Guassian Distribution</strong> မှာ သူ့ရဲ့ <strong>Wave</strong> က <strong>Shape</strong> အနေနဲ့ဆိုရင် <strong>Bell Shape Curve</strong> ပုံစံရှိတယ်။ ထပ်မြင်အောင်ပြောရရင် အရာတခုက စမှတ်ရှိမယ် အမြင့်ဆုံး Value တစ်ခုအထိရှိမယ်နောက်ပြန်ကျလာရင် အဲ့စတဲ့ Value ကိုပဲ ပြန်ဆင်းသွားတယ်ဆိုတဲ့ပုံစံပါ။</p><blockquote><strong>It is assumed that during any measurement values will follow a normal distribution with an equal number of measurements above and below the mean value.</strong></blockquote><p>အပေါ်က <strong>Guassian Distribution Curve</strong> ရဲ့ Defination မှာ <strong>Mean Value</strong> ဆိုတာ <strong>Average Value of All Values</strong> လို့ပြောရမယ်။ ထွက်လာတဲ့ <strong>Distribution Point</strong> တွေ ရဲ့ <strong>Average Point</strong> တစ်ခုလို့ပြောချင်တာပါ။ မြန်မာလို ဆရာတွေ ပြန်ထားတဲ့ <strong>Article</strong> တွေတော့ရှိပါတယ်။ ကိုယ်လည်း Science တို့ Math တို့ က<br>မကျွမ်းကျင်တဲ့နယ်ပယ်တခုဆိုတော့ ကိုယ်မကျွမ်းကျင်တဲ့အပိုင်းကို အများကြီးရှင်းမပြနိုင်လို့ပါ။</p><h4><strong>Gaussian Equation</strong> ရဲ့အရိုးရှင်းဆုံး <strong>Formula</strong> ကတော့</h4><blockquote>f(x) = exp(-x²)</blockquote><p><strong>Exponential</strong> ရဲ့ <strong>Power</strong> ဖြစ်တဲ့ <strong>x</strong> ကိုမှ <strong>Power 2 </strong>ထပ်တင်ထားပြီး <strong>Minus Sign (-)</strong> ယူထားတဲ့သဘောပါ။</p><p><strong>What is e in math?</strong></p><p><strong>e</strong> ဆိုတာက <strong>Euler’s Number</strong> လို့လည်း ခေါ်တယ်။ <strong>Natural Logarithm</strong> ရဲ့ <strong>Base</strong> လည်းဖြစ်တယ်။ တန်ဖိုးအရကတော့ <strong>2.7182818</strong> အစရှိသဖြင့် မဆုံးနိုင်တဲ့ကိန်းတွေပါဝင်တဲ့ <strong>Value</strong> တခု။ ဒီ <strong>Equation</strong> အရဆို မသိကိန်း <strong>e</strong> ကို မသိကိန်း <strong>x</strong> တင်တယ် <strong>( အဲ့ဒါကို Exponential Equation)</strong> လို့ခေါ်တယ် အဲ့ <strong>Exponential Equation</strong> ကိုမှ <strong>Power 2</strong> ထပ်တင်ထားပြီး<strong> (-) Minus Sign</strong> ယူထားတာပါ။</p><p>ဒီ <strong>Theory</strong> ကို <strong>Dart Language</strong> နဲ့ Calculate လုပ်လို့ရနိုင်တာကတော့ မဆန်းကျယ်လှပေမယ့် <strong>Flutter</strong> အနေနဲ့ဘယ်နေရာမှာ သုံးလဲဆိုတော့</p><p><strong>Screen Animation</strong> တွေ Develop လုပ်တဲ့အခါမှာ <strong>Bounce</strong> ဖြစ်သွားတဲ့ <strong>Animation</strong> မျိုးတွေပြုလုပ်တဲ့အခါမှာ ဒီ Equation ကို အသုံးပြုလို့ရတယ်ဆိုတာပြောချင်တာပါ။ <strong>Flutter</strong> နဲ့ မြင်အောင်ပြောရရင် Screen တခုကို လက်နဲ့ Screen ပေါ်မှာ <strong>Transaction</strong> လုပ်လိုက်ရင် အဲ့ကနေ <strong>Transaction Offset Point</strong> တွေရမယ်။ အဲ့ <strong>Offset</strong> တွေကိုမှ ခုနက <strong>Gaussian Distribution Equation</strong> နဲ့ထည့်တွက်ပြီး <strong>Offset Point</strong> တွေကို <strong>Align</strong> ပြန်ချိန်မယ်ဆိုရင် <strong>Screen Transaction</strong> မှာ <strong>Bounce</strong> ပါတဲ့ <strong>Animation</strong> တခုကို <strong>Develop</strong> လုပ်လို့ရနိုင်သွားတယ်ပေါ့။</p><p>ဒါဆို Flutter နဲ့ code ဘယ်လိုရေးရမလဲဆိုရင်တော့</p><pre>import &#39;dart:math&#39; as math;<br><br>void calculateGaussianEquation(){<br><br>    double bounceValuePoint = math.exp(-math.pow(offset, 2));<br><br>}</pre><ul><li><strong>Flutter</strong> မှာ <strong>Math function</strong> တွေသုံးချင်ရင် <strong>Math Library</strong> ကိုအရင်ဆုံး <strong>import</strong> လုပ်မှ Math နဲ့ဆိုင်တဲ့ Calculation တွေတွက်ဖို့ Function တွေယူသုံးလို့ရမှာပါ။ အဲ့ဒါကြောင့် <strong>Dart</strong> ရဲ့ <strong>Math Library</strong> ကို <strong>import</strong> လုပ်လိုက်တာပါ။</li><li><strong>as</strong> နဲ့သုံးတာကတော့ <strong>Dart Library</strong> ပါတဲ့ <strong>Name</strong> နဲ့ <strong>Collision</strong> မဖြစ်အောင်လို့ <strong>Type Cast</strong> တခု <strong>Attempt</strong> လုပ်လိုက်တဲ့သဘောပါပဲ။</li><li>အဲ့တော့ <strong>exp()</strong> ဆိုတဲ့ Function က ခုန <strong>Gaussian Distribution Equation</strong> က <strong>Exponential Function</strong> ပါ။ <strong>exp()</strong> မှာ <strong>Parameter Variable</strong> ထည့်ပေးလိုက်မယ်ဆိုရင် <strong>e Power</strong> <strong>Parameter Variable</strong> ပေါ့။ အခုကတော့ <strong>pow()</strong> Function ကို Parameter အနေနဲ့ယူပြီး <strong>e Power</strong> တင်လိုက်တာ။</li><li><strong>pow()</strong> Function ကတော့ Number တခုကို <strong>Power</strong> လုပ်ပေးတဲ့ <strong>Dart Function</strong> ပါ။ pow() မှာတော့ Parameter အနေနဲ့ နှစ်ခုပါရမှာဖြစ်ပြီး အရှေ့ကတော့ ကိုယ်တွက်မည့် <strong>Value</strong> ဖြစ်ပြီး အနောက်ကတော့ <strong>Power Value</strong> ပါ။ အဲ့တော့ <strong>Gaussian Equation</strong> အရ <strong>Power</strong> 2 ဆိုတော့ အနောက်က <strong>Parameter</strong> နေရာမှာ <strong>2</strong> ထည့်ပေးလိုက်တာပါ။</li><li>ဒါဆို အ‌‌ပေါ်မှာ ပြောခဲ့သလိုပဲ Screen ပေါ်မှာ ရွေ့သွားတဲ့ <strong>Offset Value</strong> တွေကို <strong>pow()</strong> ရဲ့ <strong>Base Value Paramter</strong> မှာထည့်ပေးလိုက််မယ်ဆိုရင်။ ထွက်လာတဲ့တန်ဖိုးတွေနဲ့ ပြန် <strong>Align</strong> ချရင် <strong>Bounce</strong> ဖြစ်တဲ့ Animation ကို <strong>Gaussian Equation</strong> နဲ့တွက်ထုတ်နိုင်ပြီ။</li><li>ဘာလို့ တွက်လို့ရတာလဲဆိုတော့ <strong>Guassian Equation</strong> အရကိုက <strong>Bell Shape Curve Wave</strong> ဖြစ်နေတဲ့အတွက် <strong>Bounce Animation</strong> ကလည်း <strong>Value</strong> တခုရောက်ခါနီးမှ ခုန်သွားသလိုဖြစ်ပြီး ပြန်ကျသွားတဲ့ <strong>Animation</strong> ဖြစ်တဲ့အတွက် သုံးရခြင်းဖြစ်တယ်။</li><li>အခုဟာက <strong>Gaussian Distribution</strong> ကို <strong>Flutter</strong> မှာတွက်ထုတ်ပုံပြီးသွားရင်တော့ နောက် <strong>Article</strong> တခုမှာ <strong>Bounce Animation</strong> ပါတဲ့ <strong>Screen Swiping Animation</strong> တခုနဲ့ <strong>Application</strong> ကို ပြောဖြစ်မယ်ထင်ပါတယ်။</li></ul><h3>The End, Thanks for Reading.</h3><p>Ref : <br>- <a href="https://www.sciencedirect.com/topics/biochemistry-genetics-and-molecular-biology/gaussian-distribution">https://www.sciencedirect.com/topics/biochemistry-genetics-and-molecular-biology/gaussian-distribution</a></p><p>- <a href="https://en.wikipedia.org/wiki/Gaussian_function">https://en.wikipedia.org/wiki/Gaussian_function</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b02fde0e5a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gitlab CI/CD deployment of Flutter application (android) on app-center]]></title>
            <link>https://medium.com/@lapyaeootharthar/gitlab-ci-cd-deployment-of-flutter-application-android-on-app-center-92abaff2f7b0?source=rss-41c56c1512aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/92abaff2f7b0</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[appcenter]]></category>
            <dc:creator><![CDATA[La Pyae Oo]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 16:49:42 GMT</pubDate>
            <atom:updated>2023-07-07T17:07:24.950Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>MYANMAR version</strong></p><p><a href="https://en.wikipedia.org/wiki/CI/CD">CI/ CD</a> ဆိုတာ ဘာလဲဆိုတာစပြောရရင် meaning အနေနဲ့ကတော့<br>Continuous Integration, Continuous Delivery/ Continuous Deployment <br>လို့ပဲ ပြောရမှာပေါ့။<br>ဒီ Article မှာတော့ Flutter android application တခုကို Gitlab ရဲ့ အကူအညီနဲ့ appcenter ပေါ်မှာ ဘယ်လို CI/ CD လုပ်ပုံကို ပြောပြသွားမှာပါ။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b5Lv9Z--ZoL7JbdTkkC4eg.png" /><figcaption>© La Pyae</figcaption></figure><h3>Table of contents</h3><ul><li>Why use CI/ CD process</li><li>How to implement on Gitlab</li><li>How to build script file in local</li><li>How to write script in script file</li><li>How to connect with app center</li><li>How to distribute on app center</li></ul><p><strong><em>Why use CI/ CD process?</em></strong></p><p>Website developer, Backend developer, Full-stack developer တွေအ‌‌နေနဲ့ <br>CI/ CD deployment ကမစိမ်းပေမယ့် Mobile developer တယောက်အနေနဲ့ အနည်းငယ်စိမ်းနေလိမ့်မယ်။<br>ဘာလို့လည်းဆိုတော့ Mobile developer တွေက ပုံမှန် လုပ်ငန်းခွင်မှာဆို <strong>Code</strong> ရေးမယ်၊ <strong>Bug trace</strong> လိုက်မယ်၊ <strong>Release application</strong> ထုတ်ပေးမယ်နဲ့ အလုပ်က<br>တော်တော်ဖြစ်သွားကြတာပဲ။ Testing (QA team) ဘက်က reject ဖြစ်တော့ Code ထပ်ပြင် ထပ်ပြီး release application ထပ်ထုတ်ပေးပေါ့။</p><p>အဲ့မှာ Testing or UAT application က Testing team တွေက Bug ဒါမှမဟုတ် အကြောင်းတစုံတခုကြောင့် applicationကို ပြန်ပြင်၊ ပြန် compile လုပ်နဲ့ build ထားတဲ့ application တွေက storage တခုခုထဲမှာပြည့်လာမယ်</p><blockquote>App ID တွေထပ်တိုးလာတာနဲ့အမျှ မှတ်စရာကိစ္စတွေ relase application တွေအတွက် storage တွေပိုလိုလာတဲ့ ပြဿနာတွေ၊ <br>နောက်ထပ်အနေနဲ့ testing team ဘက်ကို bug fixed လုပ်ပြီးသား application ကိုပေးရင်ရော ဘယ် versionလဲ ဘယ်အချိန်ကပေးတာလဲ အစရှိသဖြင့် ပြဿနာတွေအများကြီး ကြုံတွေ့လာရနိုင်တယ်ပေါ့။ <br>ဒါဆို ဘယ်လိုလုပ်ကြမလဲ?</blockquote><p><em>ခုနက ပြဿနာတွေဖြေရှင်းဖို့ အတွက် </em><strong><em>CI/ CD</em></strong><em> ကို သုံးပြီးဖြေရှင်းလိုက်တာနဲ့ project ရဲ့ release လုပ်ရတဲ့ process ကတော်တော်သက်သာသွားမယ်။<br>အဲ့ဒါကြောင့် </em><strong><em>CI/ CD deployment </em></strong><em>ကိုသုံးရခြင်းဖြစ်တယ်။</em></p><p><strong>CI/ CD</strong> က ဘယ်လိုအလုပ်လုပ်သလဲဆိုတော့ Project ထဲမှာ script file တခုရေးထားမယ်၊ အဲ့ project ကို version control system တခုခုပေါ် တင်ရင်ပဲဖြစ်ဖြစ် ခုန script ကို run လိုက်ရင်ပဲဖြစ်ဖြစ် project ကို compile auto လုပ်ထားပြီးထားဖြစ်နေပြီး ကိုယ် distribute လုပ်ချင်တဲ့ <strong>Playstore</strong>, <strong>Appcenter</strong> ပေါ်တင်ပြီးသားဖြစ်သွားမယ်၊ သက်ဆိုင်ရာ associated mail (ဥပမာ QA team ရဲ့mail) တွေကိုလည်း လှမ်းပြီး notification ပို့ပြီးသားဖြစ်တော့ ကိုယ် bug fixed ပြီးသွားရင် ပြောစရာတောင်မလိုတဲ့ အခြေအနေတခုကိုရောက်သွားမယ်ပေါ့။</p><p>အဲ့ဒီအပြင် <strong>function testing </strong>တွေ <strong>unit testing</strong> တွေကိုလည်း ခုန script ထဲမှာပဲရေးထားမယ်ဆိုရင် တခါတည်းလည်း function testing တွေအတွက်ပါ အလုပ်ပြီးသွားတာပေါ့။</p><p>ဒါဆို CI/ CD deployment ကို gitlab ရဲ့ pipeline တို့ runner တို့အကူအညီနဲ့ appcenter ပေါ်မှာ ဘယ်လို distibute လုပ်ရမလဲ‌ဆိုတာကို တဆင့်ချင်း ရှင်းသွားကြတာပေါ့။<br>ဒီ article မှာတော့ အခြေခံအကျဆုံးဖြစ်တဲ့ Gitlab နဲ့ပဲရှင်းပြပြီးနောက် article တွေမှာတော့ third-party ဖြစ်တဲ့ <strong>Fastlane</strong> နဲ့ <strong>Playstore</strong> ပေါ်မှာ ဘယ်လို distibute လုပ်ရမလဲ ရှင်းပြပေးသွားပါမယ်။</p><ul><li><strong><em>How to implement on Gitlab?</em></strong></li></ul><p>ပထမဆုံးအနေနဲ့ gitlab ပေါ်မှာ project repository ရှိနေဖို့တော့ လိုပါတယ်။ Project repository ရှိပြီးသွားရင်တော့ Repositoryရဲ့ ဘယ်ဘက် <strong>drawer</strong> ထဲက အောက်ဆုံးနားက Setting &gt; CI/ CD ထဲကို ဝင်လိုက်ရင် main screen မှာ CI/ CD setting ပေါ်လာလိမ့်မယ်။</p><blockquote><strong>Setting &gt; CI/CD &gt; CI/CD setting screen</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJAF58Cp9u2Ahqg8A1WzZQ.png" /><figcaption>Gitlab CI/ CD setting screen path</figcaption></figure><p>CI/ CD settings screen မှာ CI/ CD နဲ့သက်ဆိုင်တဲ့ title တွေပေါ်နေလိမ့်မယ်၊ အဲ့မှာ <strong>Runners</strong> title ကို Expand လုပ်လိုက်ရင် <strong>project runners</strong> နဲ့ <strong>shared runners</strong> ဆိုပြီး subtitle နှစ်ခုထပ်တွေ့ရလိမ့်မယ်၊ Project တခုတည်းအတွက်ပဲ လုပ်မှာဖြစ်တဲ့အတွက် <strong>project runners</strong> အောက်က <strong>new project runner</strong> မှာပဲ လက်ရှိ project ရဲ့ deployment ကိုလုပ်သွားမှာဖြစ်တယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FTURS0y5c1lJz6d2HHO0Dw.png" /><figcaption>To create new project runner</figcaption></figure><p><strong>Project runners</strong> အောက်က <strong>new project runner</strong> ကိုနှိပ်လိုက်ရင် ‌‌အောက်ကပုံလို Platform, Tags, Detail(optional), Configuration(optional), Maximum job timeout တွေ ဖြည့်စရာနေရာတွေပေါ်လာလိမ့်မယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dQU2MOVVoM4EFJ3rKLEWXg.png" /><figcaption>Fields screen shoot one to fill</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KulxrXeME0vKOCUOKxe2QA.png" /><figcaption>Fields screen shoot two to fill</figcaption></figure><p>ဖြည့်ရမယ့် တခုချင်းစီကတော့</p><ul><li><strong>Platform</strong> → ကိုယ်လက်ရှိသုံးနေတဲ့ system ကိုရွေးပေးရမယ်။</li><li><strong>Tags → </strong>local က script file ကနေ လှမ်းတင်တဲ့အခါမှာ အဲ့ tags နဲ့တွဲတင်ပေးရမှာ။ ဥပမာ tag က testing ဆိုရင် gitlab ပေါ်မှာရှိတဲ့ testing tag နဲ့ဆိုင်တဲ့ runner ကိုပဲ run သွားမှာဖြစ်တယ်။</li><li><strong>Detail → </strong>ဒါကတော့ ဘာလုပ်ဖို့လဲ ဘယ်အတွက်လဲ အစရှိသဖြင့် ထည့်ရေးတာပေါ့ Optional ဖြစ်လို့ မထည့်ချင်လည်း ကိစ္စမရှိပါဖူး။</li><li><strong>Configuration</strong> <strong>→ </strong>အခု runner ရဲ့ configurations တွေဖြစ်တယ်၊ runner တခုတည်းနဲ့ run နေတာဖြစ်လို့ နောက် runner တွေအများကြီးနဲ့ ပြိုင် run မှာမဟုတ်လို့ မရွေးလို့လည်း အဆင်ပြေပါတယ်။</li><li><strong>Maximum job timeout</strong> <strong>→ </strong>ဒါကလည်း runner အနေနဲ့ ကိုယ်သတ်မှတ်ထားတဲ့ second ကျော်သွားရင်ဆက်မ run ဖို့ သတ်မှတ်ထားရတာပေါ့။ ဒါလည်း ကျော်သွားလို့အဆင်ပြေပါတယ်။</li></ul><p>ပြီးရင်တော့ Create runner ကိုနှိပ်လိုက်ရင်</p><blockquote>Step 1 အောက်နားက <strong>runner token</strong> ကိုတော့ တနေရာရာမှာ copy ကူးထားဖို့လိုလိမ့်မယ်။ ဘာလို့လည်းဆိုတော့ ကိုယ်လည်း ပြန်မြင်ရမှာမဟုတ်သလို local က script file ကိုဆောက်တဲ့အချိန်မှာလည်း ထည့်သုံးဖို့လိုမှာဖြစ်တဲ့အတွက်ဖြစ်တယ်။</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LRqN35GDdDpTwwRqYC5yKQ.png" /><figcaption>Runner token</figcaption></figure><p>ဒါဆိုရင် ဒါကတော့ Gitlab ပေါ်မှာ runner တည်ဆောက်တဲ့အပိုင်းတော့ ပြီးသွားပြီ၊ ဆက်ပြီးတော့ local မှာ script file ဘယ်လိုဆောက်မလဲဆိုတာ ဆက်သွားကြတာပေါ့။</p><ul><li><strong><em>How to build script file in local?</em></strong></li></ul><p>ခုနကအပေါ်အဆင့်ထိကတော့ Gitlab ပေါ်မှာ pipeline process နဲ့ CI/ CD လုပ်ဖို့ runner တခုဆောက်ထားတဲ့သဘော။</p><p>အခုအဆင့်မှာတော့ Gitlab ပေါ်က runner file ကိုလှမ်းပြီး ချိတ်ဖို့နဲ့ project ကို run ဖို့ လုပ်ရတဲ့ လုပ်ငန်းစဉ်ပေါ့။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*2-TBD_l_XyuTOEJtcfOVjw.png" /><figcaption>Create runner file in project root directory</figcaption></figure><p>ကိုယ့်ရဲ့ project ရဲ့ root directory မှာ <strong>.gitlab-ci.yml</strong> ဆိုတဲ့ script file တခုကို manual ဆောက်ရမယ်။ <br>gitlab-ci.yml ဆိုတဲ့ name ရှေ့မှာ (.) dot ထည့်ဖို့မမေ့ပါနဲ့။</p><p>အဲ့ file ဆောက်ပြီးသွားရင်တော့ Gitlab runner system ကို install လုပ်ဖို့ အောက်က command နှစ်ခုကို terminal မှာ run လိုက်ပါ။</p><pre>sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64<br>sudo chmod +x /usr/local/bin/gitlab-runner</pre><ul><li>ပထမ Command က install လုပ်တဲ့ အလုပ်ကိုလုပ်ပြီး</li><li>ဒုတိယ Command ကတော့ install လုပ်ထားတဲ့ file ကို chmod +X နဲ့ executable permission ပေးလိုက်တဲ့သဘောပါ။</li><li>အဲ့နှစ်ခုပြီးရင်တော့ စပြီး register လုပ်ဖို့ <strong>gitlab-runner register</strong> ဆိုတဲ့ command ‌ကို run လို့ရပြီ။</li></ul><pre>gitlab-runner register</pre><p>Register command ကို run လိုက်ရင်တော့ terminal မှာ Gitlab ပေါ်က runner file နဲ့ချိတ်ဆက်ဖို့ ထပ်ပြီးလိုအပ်တဲ့ field တွေ ဖြည့်ရပါလိမ့်မယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V8F5P8hvj88UqPeERIc2Ow.png" /><figcaption>Fill field to register runner</figcaption></figure><ul><li>Gitlab instance URL ထည့်ဖို့လိုတဲ့နေရာမှာတော့ <a href="https://gitlab.com/"><strong>https://gitlab.com/</strong></a> ကိုပဲပြန်ရိုက်ထည့်လိုက်ယုံပါပဲ။</li><li>ဒုတိယအဆင့်အနေနဲ့ ခုနမှတ်ထားတဲ့ <strong>Gitlab runner registration token key</strong> ကိုထည့်ပေးဖို့လိုပါလိမ့်မယ်။ တကယ်လို့ မမှတ်ထားခဲ့ဖူးဆိုရင်တော့ Gitlab မှာ runner file အသစ်‌‌ထပ်ဆောက်ပြီးအပေါ်က procedure တွေပြန်လုပ်ဖို့လိုပါလိမ့်မယ်။</li><li>နောက် <strong>Enter a description for the runner:</strong> အနေနဲ့ကတော့ အကြောင်းအရာ တခုခု ရေးပေးဖို့လိုတယ်။ ဥပမာ <strong>Dev version release runner</strong> ပေါ့။</li><li><strong>Enter tags for the runner (comma-separated): </strong>ထည့်ဖို့နေရာမှာတော့ Gitlab runner file ကို create လုပ်တုန်းက ထည့်ခဲ့ရတဲ့ <strong>tag</strong> ကိုပြန်ထည့်ပေးရမှာပါ။ မမှတ်မိရင် ပြန်သွားကြည့်လို့ရပါတယ်။ token key လို encrypt မဟုတ်တဲ့အတွက် ပြန်သွားကြည့်ပြီးထည့်လိုက်ပါ။</li><li><strong>Enter optional maintenance note for the runner: ‌</strong>ဒီနေရာမှာလည်း ကိုယ် ဘာအတွက်လဲဆိုတာ <strong>Note</strong> ရေးဖို့ပေါ့ Optional ဖြစ်လို့မထည့်ချင်လည်းဖြစ်ပါတယ်။</li><li><strong>Runner type</strong> ရွေးတဲ့နေရာမှာတော့ shell လို့ပဲရိုက်လိုက်ရင် ရပါပြီ။<br><strong>shell runner type</strong> ဖြစ်တယ်ဆိုတဲ့သဘောပေါ့။</li></ul><p>အဲ့ဒါတွေထည့်ပြီးရင် create လုပ်ပြီးသွားပါပြီ။ <br>Connection လုပ်ဖို့ကိုက</p><pre>gitlab-runner install <br><br>gitlab-runner start</pre><p>ဆိုတဲ့ Command နှစ်ခုကို ထပ် run လိုက်ရင် Gitlab ပေါ်က runner နဲ့ local က runner script နဲ့ linked ဖြစ်သွားပါပြီ။</p><blockquote><strong>install</strong> နဲ့ <strong>start</strong> command နှစ်ခုကို run တဲ့အခါ တခါတလေ error တက်တတ်ပါတယ်၊ ဘာလို့လည်းဆိုတော့ အရင် run ပြီးသား runner file တွေရှိနေတာမျိုး run နေဆဲဖြစ်နေလို့ပါ။</blockquote><p>အဲ့ကျရင်တော့ gitlab-runner uninstallလုပ်ပြီးမှ install/start command ကိုပြန် <strong>run</strong> ဖို့လိုပါလိမ့်မယ်။ ဒါဆို runner script file ကို local မှာဆောက်ပြီး linked လုပ်တဲ့အပိုင်းလည်း ပြီးသွားပါပြီ။<br>နောက် တဆင့်အနေနဲ့ကတော့ script ရေးတဲ့ အပိုင်းကို ဆက်သွားတာပေါ့။</p><ul><li><strong><em>How to write script in script file?</em></strong></li></ul><p>Runner script file ကတော့ ချိတ်ပြီးသွားပေမယ့် Gitlab ပေါ်မှာ ကိုယ်က ဘယ်လို pipeline process တွေလုပ်မယ် ဘာတွေလုပ်မယ်ဆိုတာကို procedure အလိုက်ရေးဖို့ လိုလာပြီပေါ့ …</p><p>ပထမဆုံးအနေနဲ့ pipeline process ကို ဘယ်လို <strong>stages</strong> တွေနဲ့ run မှာလဲဆိုတာ define လုပ်ရမယ်ပေါ့။<br>ဒုတိယအဆင့်အနေနဲ့မှ အဲ့ <strong>stage</strong> တခုချင်းစီထဲမှာ ဘာအလုပ်တွေလုပ်မှာလဲဆိုတာကို ရေးမယ်။<br>ဒါဆို မြင်လောက်ပြီထင်တယ်။ script အနေနဲ့ရေးကြမယ်ဆိုရင်</p><pre>stages:<br>  - update<br>  - build</pre><p>ဒီမှာတော့ အတိုချုံ့အနေနဲ့ pipeline နှစ်ခုပဲ ဆောက်လိုက်မယ်။ အဲ့နေရာမှာ ကိုယ်က test အစရှိသဖြင့် ကိုယ်ထားချင်သလောက် stage ထားလို့ရတယ်။<br>ဒါဆို<strong> pipeline job</strong> တွေကို စပြီး <strong>define</strong> လုပ်ရအောင်</p><pre>update_project_packages: #Job name<br>  stage: update          # kind of job<br>  before_script:<br>    - export PATH=&quot;$PATH:/Users/&lt;YOUR_FLUTTER_DIR_PATH&gt;/bin&quot;<br>  only:<br>    - lite_version/lite_DEV<br>  script:<br>    - flutter pub get<br>    - flutter packages run build_runner build --delete-conflicting-outputs<br>  tags:<br>    - liteDev</pre><ul><li>အဲ့မှာ အပေါ်ဆုံး အကြောင်း <strong>update_project_packages:</strong> က <strong>pipline</strong> ထဲမှာ job အနေနဲ့ run မည့် <strong>job</strong> ကို နာမည်ပေးတဲ့သဘောပါ။ ကိုယ်အဆင်ပြေတဲ့ name ပေးလို့ရပါတယ်။ ဒါပေမယ့် ကိုယ့်ရဲ့ job state နဲ့ name က အဓိပ္ပာယ်ရှိရင်တော့ ပိုကောင်းတာပေါ့။</li><li>ဒုတိယ line <strong>stage:</strong> ကတော့ အပေါ်က declare လုပ်ထားတဲ့ stage name ပေါ့။</li><li>တတိယ line က <strong>before_script:</strong>ကတော့ တကယ့် run မဲ့ script မစသေးခင် ကြိုလုပ်မယ့် script ပေါ့။ ဒီမှာက အများအားဖြင့် compile လုပ်မည့် Language ရဲ့ path တွေ global access တွေကြိုပေးထားကြတာများတယ်။<br>ဒီမှာကတော့ ကိုယ့် <strong>local</strong> ထဲက <strong>flutter sdk</strong> ရှိတဲ့နေရာကို ပေးထားရမှာဖြစ်တယ်။ မသိတော့ရင်တော့ <strong>flutter doctor -v</strong> နဲ့ပြန်ကြည့်ပြီး <br>ကူးထည့်လိုက်ပါ။</li><li><strong>only:</strong> ဆိုတဲ့ script ကတော့ ကိုယ် project ရဲ့ ဘယ် <strong>branch</strong> ကို run ချင်တာလဲဆိုတာကိုသတ်မှတ်ရတာဖြစ်တယ်။ ဒီမှာကတော့ <strong>lite_version</strong> sub-folder ထဲက <strong>lite_DEV branch</strong> ကိုပဲ pipeline process နဲ့ application distribute လုပ်ချင်တာဖြစ်တယ်။</li><li>အခုကတော့ <strong>script:</strong> ဆိုတဲ့ keyword ကတော့ pipeline ထဲမှာ လုပ်မဲ့ job ရဲ့အဓိကလုပ်မဲ့အရာပေါ့။ ရှင်းအောင်ထပ်ပြောရရင်တော့ <strong>stage</strong> ငါးခုရှိရင် <strong>script</strong> ငါးခုရှိတယ် pipeline ရဲ့ <strong>job</strong> ငါးခုပေါ့။ ဒီ stage မှာကတော့ <strong>stage: update</strong> လို့ နာမည်ပေးထားတဲ့အတိုင်း <strong>flutter package</strong> တွေကို <strong>ymal file</strong> မှာ get ပြန်လုပ်တဲ့ process နဲ့ <strong>flutter package build_runner file</strong>တွေပြန်ပြီး auto generate လုပ်တာပဲထည့်ထားတာပါ။</li></ul><p>ဒါဆိုရင်တော့ job တခုတော့ ပြီးသွားပြီ။</p><p>ဒုတိယ job အနေနဲ့ကတော့ Application build လုပ်တဲ့ <strong>build</strong>stage ပေါ့။</p><pre>build_android_application: #Job name<br>  stage: build # kind of job<br>  before_script:<br>    - flutter pub global activate dart_code_metrics<br>    - export PATH=&quot;$PATH:/Users/&lt;YOUR_FLUTTER_DIR_PATH&gt;/bin&quot;<br>    - flutter pub get<br>    - flutter packages run build_runner build --delete-conflicting-outputs<br>  only:<br>    - lite_version/lite_DEV<br>  script:<br>    - echo storePassword=$ANDROID_KEY_STORE_PASSWORD &gt; android/key.properties<br>    - echo keyPassword=$ANDROID_KEY_PASSWORD &gt;&gt; android/key.properties<br>    - echo keyAlias=$ANDROID_KEY_ALIAS &gt;&gt; android/key.properties<br>    - flutter build apk<br>  artifacts:<br>    paths:<br>      - build/app/outputs/apk/release/app-release.apk<br>  tags:<br>    - liteDev</pre><p>ဒီနေရာမှာ ပိုလာတာကတော့ <strong>android key store</strong> တွေနဲ့ <strong>Playstore</strong> ပေါ်တင်မည့် Application build တဲ့အချိန်လိုတဲ့ key တွေရဲ file path တွေထည့်ပေးရတဲ့အပိုင်းတွေနဲ့ <strong>artifacts:</strong> အပိုင်းပေါ့</p><p><strong>artifacts:</strong>ကတော့ release လုပ်ထားတဲ့ application ကို project ထဲမှာသိမ်းမဲ့ <strong>directory</strong> ပါ။</p><p><strong>android key store </strong>တွေက အရေးကြီးတဲ့ <strong>public</strong> အနေနဲ့ သိလို့မရတဲ့အရာတွေဖြစ်တဲ့အတွက် Gitlab ထဲမှာ key အနေနဲ့ သွားထည့်လို့ရတဲ့ နေရာရှိပါတယ်။ အဲ့မှာ တခုချင်းရဲ့ value တွေကို ထည့်ပြီး key သတ်မှတ်ပြီး <strong>mask</strong> လုပ်ထားခဲ့ယုံပါပဲ။</p><p>အပေါ်က သွားခဲ့တဲ့ Setting &gt; CI/ CD ထဲကို ဝင်လိုက်ရင် main screen မှာ CI/ CD setting ပေါ်လာလိမ့်မယ်။ အဲ့ထဲက <strong>Variables </strong>title ကို expand လုပ်လိုက်ရင်တွေ့ရလိမ့်မယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nzQDIGR22QsnWIolPve-jw.png" /><figcaption>Place to add credentials value</figcaption></figure><p>အဲ့ကသတ်မှတ်ခဲ့တဲ့ key တွေကိုတော့ ပေးခဲ့တဲ့ name နဲ့ပြန်ထည့်ပေးရမယ်ပေါ့။</p><pre>echo storePassword=$ANDROID_KEY_STORE_PASSWORD</pre><p>ဒါဆို app build တဲ့အထိ stage ပြီးသွားပြီဆိုရင် Gitlab ပေါ်ကို <strong>push</strong> လိုက်ယုံနဲ့ Gitlab က <strong>auto build</strong> သွားပါလိမ့်မယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFbHBofrcrtcA0VXoD_f0Q.png" /><figcaption>Successful pipeline</figcaption></figure><p>ဒီနေရာမှာ ပုံထဲကလို ‌‌အမှန်ခြစ်ဖြစ်သွားရင်တော့ pipeline process က အောင်မြင်တယ်ပေါ့။<br>အခု<strong> job</strong> နှစ်ခုပြီးသွားရင် တတိယ job အနေနဲ့က<strong> App-Center</strong> ပေါ် တင်တဲ့ job ကိုဆက်သွားမယ်။</p><ul><li><strong><em>How to connect with app center?</em></strong></li></ul><p>အခုကတော့ <a href="https://appcenter.ms/"><strong>app-center</strong></a> website ထဲကိုမှာ register မလုပ်ရသေးရင် register လုပ်လိုက်ပါ။ ပြီးရင် ညာဘက်က</p><blockquote>profile &gt; Account Settings &gt; User API tokens &gt; New API token</blockquote><p>မှာ token ကို full access နဲ့ generate လုပ်ပြီး copy ကူးထားခဲ့လိုက်ပါ။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*2U1ivcahCWJQ9B4Ot8oi4A.png" /><figcaption>Generate App-center user tokens</figcaption></figure><p>အဲ့ဒီကနေ ရလာတဲ့ token ကို ခုန Gitlab ရဲ့ Variables တွေ mask လုပ်ထားတဲ့ နေရာမှာ ထပ်ထည့်လိုက်ရင် Gitlab နဲ့ App-center က linked ဖြစ်သွားပြီလို့ပြောရမယ်။</p><ul><li><strong><em>How to distribute on app center?</em></strong></li></ul><p>ဒါကတော့ App-Center မှာ distibute လုပ်ဖို့အတွက် script ပေါ့။</p><pre>deploy_android_to_appcenter:<br>  stage: deploy<br>  only:<br>    - lite_version/lite_DEV<br>  script:<br>    - appcenter login --token $APPCENTER_API_TOKEN<br>    - appcenter distribute release --app [USER_NAME]/[APP_NAME] --file build/app/outputs/apk/release/app-release.apk --group Collaborators --release-notes &quot;$(cat release_notes.*)&quot;<br>  tags:<br>    - liteDev</pre><p>အခုနေ <strong>gitpush</strong> လိုက်ရင်တော့ deploy လုပ်တဲ့ state မှာ pipeline က fail သွားမှာဖြစ်ပါတယ်။အဲ့တော့ pipeline <strong>success</strong> ဖြစ်အောင်ဘယ်လိုပြင်ရမလဲဆိုတာကို Code လိုင်းတိုင်းနဲ့ ပြန်ရှင်းရမယ်။</p><ul><li>Distribute လုပ်ဖို့ကတော့ App-center မှာ အရင်ဆုံး application release လုပ်ဖို့အတွက် Add new ဆိုတဲ့ နေရာမှာ အရင်ဆုံး space တခုဆောက်ထားဖို့လိုအပ်တယ်။</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L2QEB15TOVln_e9pt3Ehvw.png" /><figcaption>Create release space to distribute</figcaption></figure><p><strong>Add new app</strong> ကိုနှိပ်လိုက်မယ်ဆိုရင်တော့ အခုတင်မည့် application အတွက် လိုအပ်တဲ့ field တွေထပ်ဖြည့်ရလိမ့်မယ်။<br><strong>App name</strong> နေရာမှာတော့ အခု distribute လုပ်မည့် <strong>name</strong> ကိုထည့်၊ <br><strong>os</strong> နေရာမှာတော့ App-center မှာ flutter မပါသေးတဲ့အတွက်<br> <strong>android</strong> ပဲရွေးပြီး <br><strong>Platform</strong> နေရာမှာတော့ <strong>Java/ Kotlin</strong> ကိုရွေးပြီး <strong>Add new app</strong> ကိုနှိပ်လိုက်ရင်တော့ new app တင််ဖို့ space ရသွားပြီ။</p><pre>appcenter distribute release --app [USER_NAME]/[APP_NAME] --file build/app/outputs/apk/release/app-release.apk --group Collaborators --release-notes &quot;$(cat release_notes.*)&quot;</pre><p>အပေါ်က cod ရဲ့ [USER_NAME] နဲ့ [APP_NAME] နေရာဖြည့်ဖို့ကတော့ <br>ခုန App-center ရဲ့ app တင်ဖို့ အဆင်သင့်ဖြစ်နေတဲ့ page ရဲ့ link မှာကြည့်လိုက်ရင် <strong>users/ </strong>ဆိုတဲ့အနောက်က <strong>name</strong> ကို <strong>[USER_NAME]</strong> နေရာမှာ ဖြည့်ပြီး၊ <strong>apps/</strong> ဆိုတဲ့အနောက်က <strong>name</strong> ကိုတော့ [<strong>APP_NAME]</strong> နေရာမှာဖြည့်ပေးရမှာဖြစ်တယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7GdGg4gIn2-E2yOBOC2vfw.png" /><figcaption>App-center app publish link</figcaption></figure><p>ဒီမှာဆိုရင်တော့<br>lapyaeoo-ayainnovation က <strong>[USER_NAME]</strong> ဖြစ်ပြီး <br>Test-App ကတော့ <strong>[APP_NAME]</strong> ပေါ့</p><p>အခုချိန်မှာမှ ခုန runner script မှာ <strong>stage: deploy</strong> ဆိုတဲ့ stage တခုထပ်ထည့်ပြီး script အနေနဲ့က App-center <strong>CLI</strong> ကို အစောက build ထားတဲ့ project ထဲက application ရဲ့ <strong>path</strong> နဲ့ပေါင်းထည့် ပေးလိုက်ပြီး <strong>git push</strong>ထပ်လုပ်လိုက်ရင် App-center ပေါ်မှာ <strong>publish</strong> လုပ်ပြီးသား ဖြစ်သွားပါပြီ။</p><p>အဲ့မှာမှ <strong>release note</strong> ထပ်ထည့်ချင်တယ်ဆိုရင်တော့ project ထဲမှာ readme file (<strong>release_note.md</strong>) တည်ဆောက်ပြီး <strong>cat command</strong> နဲ့ထပ်ထည့်လိုက်ရင် release note ပါတင်ပြီးသွားဖြစ်သွားပါလိမ့်မယ်။<br><strong>yml file </strong>ရဲ့ code အပြည့်အစုံကတော့ ဒီမှာပါ။</p><pre>stages:<br>  - update<br>  - build<br>  - deploy<br><br>update_project_packages: #Job name<br>  stage: update # kind of job<br>  before_script:<br>    - flutter pub global activate dart_code_metrics<br>    - export PATH=&quot;$PATH:/Users/&lt;YOUR_FLUTTER_DIR_PATH&gt;/bin&quot;<br>  only:<br>    - lite_version/lite_DEV<br>  script:<br>    - flutter pub get<br>    - flutter packages run build_runner build --delete-conflicting-outputs<br>  tags:<br>    - liteDev<br><br>build_android_application: #Job name<br>  stage: build # kind of job<br>  before_script:<br>    - flutter pub global activate dart_code_metrics<br>    - export PATH=&quot;$PATH:/Users/&lt;YOUR_FLUTTER_DIR_PATH&gt;/bin&quot;<br>    - flutter pub get<br>    - flutter packages run build_runner build --delete-conflicting-outputs<br>  only:<br>    - lite_version/lite_DEV<br>  script:<br>    - echo storePassword=$ANDROID_KEY_STORE_PASSWORD &gt; android/key.properties<br>    - echo keyPassword=$ANDROID_KEY_PASSWORD &gt;&gt; android/key.properties<br>    - echo keyAlias=$ANDROID_KEY_ALIAS &gt;&gt; android/key.properties<br>    - flutter build apk<br>  artifacts:<br>    paths:<br>      - build/app/outputs/apk/release/app-release.apk<br>  tags:<br>    - liteDev<br><br>deploy_android_to_appcenter:<br>  stage: deploy<br>  only:<br>    - lite_version/lite_DEV<br>  script:<br>    - appcenter login --token $APPCENTER_API_TOKEN<br>    - appcenter distribute release --app lapyaeoo-ayainnovation/Test-App --file build/app/outputs/apk/release/app-release.apk --group Collaborators --release-notes &quot;$(cat release_notes.*)&quot;<br>  tags:<br>    - liteDev</pre><p>ဒါဆိုရင်တော့ <strong>Gitlab</strong> ရဲ့ pipeline process နဲ့ <strong>App-center</strong> ပေါ်ကို distibute လုပ်တဲ့ process ကတော့ ဒီမှာတင် ပြည့်စုံသွားပါပြီ။ နောက် <strong>article</strong> မှာတော့ third-party ဖြစ်တဲ့ <a href="https://fastlane.tools/">fatlane</a> ကိုသုံးပြီး <strong>Flutter Android Application</strong> ကို <strong>Playstore</strong> ပေါ် <strong>distribute</strong> လုပ်တဲ့ အကြောင်းကိုထပ်ပြောကြတာပေါ့။</p><p><strong>Thanks for Reading<br>If this article useful for you please CLAP …</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92abaff2f7b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Better understanding of Align for flutter application]]></title>
            <link>https://medium.com/@lapyaeootharthar/better-understanding-of-align-for-flutter-application-8b1b1a52685b?source=rss-41c56c1512aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b1b1a52685b</guid>
            <category><![CDATA[myanmar]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[alignment]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <dc:creator><![CDATA[La Pyae Oo]]></dc:creator>
            <pubDate>Sun, 28 May 2023 17:41:00 GMT</pubDate>
            <atom:updated>2023-05-28T17:41:00.591Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*htP7dJsW6j7r4MAI_vz2VQ.jpeg" /><figcaption><a href="https://unsplash.com/photos/qo0GIeUrE0s">Alignment the Stone Image from unsplash Website</a></figcaption></figure><p><strong>Table of Contents<br>(Myanmar Version)</strong></p><blockquote>About Coordinate System Learn at Height School</blockquote><blockquote>Calculation of Coordinate System in Flutter</blockquote><blockquote>Align Widget Constructor</blockquote><blockquote>Alignment Value</blockquote><blockquote>FractionalOffset Value</blockquote><p><strong>About Coordinate System learn at Height School</strong></p><p>ဒီ Article ကတော့ Flut‌ter ရဲ့ Align Widget အလုပ်လုပ်ပုံကို အသေးစိတ်ပြောပြသွားမှာပါ။အစဦီးဆုံးပြောရရင်တော့ အလယ်တန်း အထက်တန်း Math ‌မှာ သင်ခဲ့ရတဲ့ X-axis နဲ့ Y-axis အကြောင်းကိုမှတ်မိရမယ်ပေါ့။ မမှတ်မိရင်လည်း အောက်မှာပုံဆွဲဲဲဲဲဲဲပြပြီး ထပ် ပြောပြထားပါတယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*7hLgx1MIjCPfF3dVP2dCyw.png" /><figcaption>Cartesian Coordinate System</figcaption></figure><p><strong>Cartesian Coordinate System</strong> အရ Horizontal (‌ရေပြင်ညီ) အတိုင်းက X-axis ဖြစ်ပြီးတော့၊ Vertical (‌ဒေါင်လိုက်) ကတော့ Y-axis ဖြစ်လို့ (x,y) နဲ့သတ်မှတ် ကြတယ်။ Coordinate system မှာဆို မျဥ််း၂ကြောင်း ဆုံတဲ့ နေရာ Horizontal ရော Vertical ရောရဲ့ ဗဟိုစမှတ်က x = 0, y = 0 ဖြစ်တာကြောင့် (0,0) ဖြစ်တယ်။<br>အပေါ်က ပြောတာကတော့ Cartesian Coordinate system ရဲ့ Axis တွက်ပုံဖြစ်ပြီးတော့ Flutter မှာတော့ အဲ့လိုမတွက်ဘူး။ ကွဲပြားအောင် ပြန်ပြောလိုက်တဲ့သ‌ဘောပါ။</p><p><strong>Calculation of Coordinate System in Flutter</strong></p><p>Flutter ရဲ့ UI အတွက် Coordinate System တွက်ချက်ပုံက အကြမ်းဖျဥ််််််းပြောရရင်တော့ X-Axis, Y-Axis ပါပြီး <strong>Cartesian System</strong> နဲ့မတူတဲ့ system ဖြစ်တယ်။ အဲ့ဒါကို <strong>Visual Coordiante System</strong> လို့ခေါ်တယ်။ ဒါကတော့ math ရဲ့ calculation ဟုတ်ပုံ မရဘူး။ programming မှာ UI တွေဆွဲတဲ့အခါ တွက်ချက်ပုံ သတ်သတ်ပဲဖြစ်လိမ့်မယ်။</p><p>တခြား language တွေမှာတော့ ဘယ်လို rendering ပြန်လုပ်လဲမသိ၊ အခုက Flutter အကြောင်းပဲပြောနေတာဆိုတော့ Flutter မှာတော့ UI မှာသာ အဲ့လိုတွက်ချက်ပေမယ့် Rendering လုပ်တဲ့ အချိန်မှာတော့ Cartesian Coordinate System အနေနဲ့ပဲတွက်ပြီး Render လုပ်တယ်။ Documentation မှာတော့ widget tree နဲ့ render tree မှာ ‌background process အနေနဲ့ချိန်းပေးတယ်လို့ ပြောထားတယ်။ Developer အနေနဲ့ deep down မဟုတ်သေးပဲ UI ဆွဲဖို့အတွက်သတ်သတ်ကတော့သိထားသင့်ယုံပါပဲ။ တကယ် <strong>Align</strong> Widget မှာတော့ <strong>Visual Coordinate System</strong> နဲ့ပဲ တွက်ရမှာပါ။ အဲ့တော့ coordinate calculation တဲ့ system အကြောင်းကိုသိပြီးပြီဆိုတော့ X-Axis နဲ့ Y-Axis ဘယ်လိုတွက်လဲဆိုတာကို ဆက်ကြည့်ကြမယ်။</p><p>အပေါ်မှာပြောခဲ့သလိုပါပဲ Cartesian Coordinate System လိုပဲ X, Y axis ၂ခုပဲပါတယ် ဒါပေမယ့် X-Axis အတွက်ဆို <strong>Left to Right</strong> (Ascending) သွားပြီး Y-Axisအတွက်ဆို <strong>Top to Bottom</strong> ( Ascending) သွားတယ်။ ထူးခြားတာတခုကတော့ <strong>Align</strong> Widget က Visual Coordinate System ရဲ့ -1,0,1 point တွေကြားထဲမှာပဲ အလုပ်လုပ်တယ်။ ဘယ်လိုလဲဆိုတာကို အောက်််မှာပဲ ထပ်ပြောပြသွားပေးပါမယ်။ အောက်ကပုံလိုပေါ့။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*bnTtZhikven4hzalMRC2lw.png" /><figcaption>Visual Coordinate System</figcaption></figure><p>ဒီ Visual Coordinate ရဲ့ Axis တွေယူပုံက <strong>Align</strong> Widget မှာ child widget တွေကို alignment လုပ်တဲ့အခါ coordinate calculation သတ်သတ်တွေဖြစ်ပြီး <strong>Align</strong> Widget ရဲ့ constructor တွေနဲ့ တွဲပြောမှ ပိုမြင်သာနိုင်လိမ့်မယ်။ ဒါဆို <strong>Align</strong> class (widget) အကြောင်း လေ့လာရအောင်။</p><p><strong>Align Widget Constructor</strong></p><pre><br>Align({Key? key, <br>AlignmentGeometry alignment = Alignment.center,<br>double? widthFactor,<br>double? heightFactor, <br>Widget? child})</pre><p>အခု code က <strong>Align</strong> class ရဲ့ constructor ထဲမှာပါတဲ့ parameter တွေဖြစ်ပြီး <strong>Align</strong> widget က parent widget ကနေသူ့ထဲမှာရှိတဲ့ child widgetကို position ချပေးတဲ့အလုပ်ကို လုပ်တာဖြစ်တယ်။ အဓိကကတော့ <strong>Align</strong> widget ထဲက <strong>alignment</strong> parameter က ‌‌‌‌‌child widget ကို position ချပေးတဲ့အလုပ်ကိုလုပ်တာ။</p><p>ဥပမာ အနေနဲ့ <strong>Container</strong> widget တခုထဲမှာ child widget တခုအနေနဲ့ <strong>FlutterLogo</strong> widget ကို position ချမယ်ဆိုရင် ဒီလိုရေးရမယ်ပေါ့။ ဒါပေမယ့် ဒီမှာပြောစရာရှိတာက <strong>Container</strong> Widget က သူ့ရဲ့ child ဖြစ်တဲ့ <strong>FlutterLogo</strong> widget ကို position ချတာမဟုတ်ပဲ <strong>FlutterLogo</strong> က သူ့ဘာသူနေရာချတာဖြစ်တယ်။ ဘာကွာသွားလဲဆိုတော့ child widget က parent widget အပြင်ကိုလည်း ကျော်သွားနိုင်တဲ့သဘောရှိတာမျိုး ဖြစ်သွားတာပါပဲ။</p><pre>Center(<br>  child: Container(<br>    height: 120.0,<br>    width: 120.0,<br>    color: Colors.blue[50],<br>    child: const Align(<br>      alignment: Alignment.topRight,<br>      child: FlutterLogo(<br>        size: 60,<br>      ),<br>    ),<br>  ),<br>)</pre><p><strong>alignment</strong> ရဲ့ value အနေနဲ့ <strong>Alignment</strong> နဲ့ <strong>FractionalOffset</strong> ထည့်ပေးလို့ရတယ်။ Example code အနေနဲ့ဆို</p><blockquote>With <strong>Alignment</strong> value</blockquote><pre>const Align(<br>      alignment: Alignment(0.2, 0.6),<br>      child: FlutterLogo(<br>        size: 60,<br>      ),<br>    ),</pre><blockquote>With <strong>FractionalOffset</strong> value</blockquote><pre>const Align(<br>      alignment: FractionalOffset(0.2, 0.6),<br>      child: FlutterLogo(<br>        size: 60,<br>      ),<br>    ),</pre><p><strong>Alignment Value</strong></p><p>ဒီနေရာမှာ‌‌တော့ <strong>Alignment</strong> value အနေနဲ့ <strong>Visual Coordinate</strong> တွေဘယ်လို အလုပ်လဲ၊ point တွေကို parent widget မှာ ဘယ်လိုယူလဲ၊ child widget နဲ့ parent widget ကြားဘယ်လို position ချလဲ ကြည့်ကြရအောင်။</p><p>ဥပမာ parent class အနေနဲ့ <strong>Container</strong> widget ပဲဆိုကြပါစို့ ဒါဆို<strong> Visual coordinate system</strong> အနေနဲ့က <strong>Container</strong> ရဲ့ အလယ်ကနေစတွက်တယ်။ <strong>Container</strong> အလယ်က X-Axis ရဲ့စမှတ် 0 , Y-Axis ရဲ့ စမှတ် 0 ဖြစ်တယ်။ <strong>Container</strong> widgetက width က ဘယ်လောက် ရှည်ရှည်၊ တိုတို <strong>Container</strong> ရဲ့ horizontalလိုက် ဘယ်အစွန်က -1 ကစပြီး ညာအစွန် 1 point မှာပဲဆုံးတယ်။ height အရလည်းထိုနည်း အတိုင်းပဲ အပေါ်အစွန်ဆုံးက -1 ကစပြီး အောက်ဘက်အစွန်ဆုံးက 1 မှာပဲဆုံးတယ်။ အဲ့ဒါကြောင့် -1,0,1 point သုံးခုကြားမှာပဲ အလုပ်လုပ်တယ်ပြောတာ။ စုစုပေါင်း segment အနေနဲ့ဆိုရင်တော့ <strong>2 units</strong> ရှိတယ်ပြောရမှာပါ။ အဲ့တော့ (-1,-1) ဆိုရင် <strong>Container</strong> ရဲ့ ဘယ်ဘက်‌‌အပေါ်ဒေါင့်အစွန်ဆုံးဖြစ်တယ်။ ကျန်တဲ့ ‌‌position ကိုလည်းအဲ့လိုပဲတွက်တာပေါ့ ပုံမှာကြည့်ရင်တော့ပိုရှင်းသွားလိမ့်မယ်။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*J9iWVMk2354IxmW22empjA.png" /><figcaption>Visual Coordinate System for Alignment</figcaption></figure><p>အဲ့တော့ <strong>Alignment</strong> value ကိုpoint တွေနဲ့ မတွက်ချင်ဖူးဆိုရင်တော့ <strong>Alignment.center</strong>, <strong>Alignment.topLeft</strong>, <strong>Alignment.topRight</strong>, <strong>Alignment.bottomRight</strong>, <strong>Alignment.bottomLeft</strong> အစရှိသဖြင့် ပေးလို့ရတယ်။ အခုလိုမဟုတ်ပဲ အတိအကျ ကိုယ်လိုချင်တဲ့ position အတိအကျ နေရာချချင်ရင်တော့ point တွေနဲ့ အသေးစိတ်တွက်မှပဲရမယ်။</p><blockquote>Flutter <a href="https://api.flutter.dev/flutter/painting/Alignment-class.html"><strong>Documentation</strong></a> အရ ဒီ Equation နဲ့တွက်တယ်</blockquote><pre>(x * w/2 + w/2, y * h/2 + h/2)</pre><p>ဘယ်လို တွက်လဲဆိုတော့ အပေါ်က equationနဲ့ child widget နဲ့ parent ရဲ့ width နဲ့ height ကိုတွက် ပြီးရင် ရလာတဲ့ parent widget ရဲ့ (width, height) value ထဲကနေ child widget ရဲ့ (width, height) value ကိုနှုတ်လိုက်ရင် ခုန child widget က parent widget ပေါ်မှာရှိနေမဲ့ position အတိအကျကိုရလာမယ်။</p><blockquote>Equation မှာပါတဲ့ <br><strong><em>x</em></strong><em> နဲ့ </em><strong><em>y</em></strong><em> က </em><strong><em>alignment</em></strong><em> value က value တွေဖြစ်ပြီး<br></em><strong><em>w</em></strong><em> နဲ့ </em><strong><em>h </em></strong><em>က child နဲ့ parent widget ရဲ့ width, height ဖြစ်တယ်။</em></blockquote><pre>return Center(<br>              child: Container(<br>                height: 120,<br>                width: 120,<br>                color: Colors.blue[50],<br>                child: Align(<br>                  alignment: FractionalOffset(0.2, 0.6),<br>                  child: Container(<br>                    color: Colors.red[200],<br>                    child: FlutterLogo(<br>                      size: 60,<br>                    ),<br>                  ),<br>                ),<br>              ),<br>            );</pre><p>ဒီ code snippet အရ parent widget ဖြစ်တဲ့ <strong>Container</strong> ရဲ့ visual coordinate ပေါ်မှာရှိတဲ့ position ကိုတွက်ရင်</p><blockquote><strong>Horizontal value position of Container</strong><br>((0.2 *120/2) + (120/2)) = 72<br><strong>Vertical value position of Container</strong><br>((0.6*120/2)+(120/2) = 96<br>အဲ့တော့ Container ရဲ့ <strong>visual coordinate position</strong> က (72, 96)</blockquote><p>နောက် child widget ဖြစ်တဲ့ FlutterLogo ရဲ့ coordinate position ကိုတွက်ရင်</p><blockquote><strong>Horizontal value position of FlutterLogo</strong><br>((0.2 *60/2) + (60/2)) = 36<br><strong>Vertical value position of FlutterLogo</strong><br>((0.6*60/2)+(60/2)) = 48<br>အဲ့တော့ FlutterLogo ရဲ့ <strong>visual coordinate position</strong> က (36, 48)</blockquote><p>ပြီးတဲ့အခါကြရင်တော့ <strong>Container</strong> ရဲ့ position point အမှတ်နှစ်ခု ထဲကနေ <strong>FlutterLogo</strong> ရဲ့position အမှတ်နှစ်ခုကိုနှုတ်လိုက်ရင် <strong>FlutterLogo</strong> ရဲ့ position အတိအကျကို ရမှာဖြစ်တယ်။</p><blockquote>(72, 96) — (36, 48) = <strong>(36,48)</strong></blockquote><p>ရလာတဲ့ result (36,48) ရဲ့ ဆိုလိုရင်းကတော့ <strong>FlutterLogo</strong> widget က visual coordinate ရဲ့ horizontal (X-Axis) 36 နဲ့ vertical (Y-Axis) 48 ‌‌<br>ဆိုတဲ့အမှတ်တခုမှာရှိနေမှာဖြစ်တယ်။</p><p><em>UI Result for FractionalOffset</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JyW-T4ltI8RIpxIprd_Hug.jpeg" /><figcaption>FlutterLogo position with Alignment Value</figcaption></figure><p>result အနေနဲ့ child widget ရဲ့ position ကတော့ ဒီလိုပုံထွက်လာမယ်‌။</p><p><strong>FractionalOffset Value</strong></p><p><strong>FractionalOffset</strong> value အနေနဲ့ကတော့ visual coordinate system က <strong>Alignment</strong> value လို parent widget ရဲ့အလယ်ကနေတွက်တာမဟုတ်ပဲ widget ရဲ့ <strong>TopLeft</strong> အစွန်ကနေ စတွက်တာပဲကွာတာပါ။ ပုံကိုကြည့်လိုက်ရင်တော့ ရှင်းသွားမှာပါ။</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*vATSsijCst8NvVpwSmB4PA.png" /><figcaption>Visual Coordinate System for FractionalOffset</figcaption></figure><p>အဲ့နေရာမှာပဲကွာတာ ဖြစ်ပြီး child widget နဲ့ parent widget ‌တွေ visual coordinateပေါ်မှာ position ယူတဲ့ equation ကတော့ အတူတူပါပဲ။ ဒါပေမယ့် ဘယ်အစွန်ကစတွက်တဲ့အတွက် point အပေါ်မူတည်ပြီး child position ကတောါ ကွာခြားသွားမှာဖြစ်တယ်။ တခုပိုလွယ်သွားတာကတော့ ထောင့်အစွန်းတွေအတွက် ဆိုရင်တွက်ရတာပိုလွယ်တဲ့အတွက် child widget အနေနဲ့ parent widget အတွင်းထဲက ထောင့်စွန်းနေရာတွေမှာ ထားချင်ရင်တော့ <strong>FractionalOffset</strong> parameter ကိုသုံးတာက ပိုအဆင်ပြေတာပေါ့။</p><p><em>Example Code for Fractional Offset</em></p><pre>return Center(<br>              child: Container(<br>                height: 120,<br>                width: 120,<br>                color: Colors.blue[50],<br>                child: Align(<br>                  alignment: FractionalOffset(0.2, 0.6),<br>                  child: Container(<br>                    color: Colors.red[200],<br>                    child: FlutterLogo(<br>                      size: 60,<br>                    ),<br>                  ),<br>                ),<br>              ),<br>            );</pre><p><em>UI Result for FractionalOffset</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UNgW9d8oKeSly9eav3FlbA.jpeg" /><figcaption>FlutterLogo position with FractionalOffset Value</figcaption></figure><p>FractionalOffset ရဲ့ result အနေနဲ့ child widget ရဲ့ position ကတော့ ဒီလိုပုံထွက်လာမယ်‌။အခုပုံကတော့ <strong>FractionOffset</strong> value ပြောင်းသုံးလိုက်တဲ့အခါ child widget ရဲ့ position resultပေါ့။ စမှတ်တွေသတ်မှတ်တာကွာတာဖြစ်တဲ့အတွက် <strong>Alignment</strong> value သုံးတုန်းက position နဲ့ကွဲပြားနေတာဖြစ်တယ်။</p><p><strong>Align</strong> widget အနေနဲ့ position အသေးစိတ်ကတော့ ဒီလောက်ဆို အဆင်ပြေမယ်ထင်ပါတယ်။ ဖတ်လို့ အဆင်မပြေနားလည်းလည်ရင်လည်း မေးလို့ရပါတယ်။</p><p><strong>The END (Thanks for Reading)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b1b1a52685b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Canonical instance or Explanation of final and const keyword in Dart]]></title>
            <link>https://medium.com/@lapyaeootharthar/canonical-instance-or-explanation-of-final-and-const-keyword-in-dart-9a1782d06a10?source=rss-41c56c1512aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a1782d06a10</guid>
            <category><![CDATA[canonicalinstance]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[La Pyae Oo]]></dc:creator>
            <pubDate>Wed, 03 May 2023 17:38:41 GMT</pubDate>
            <atom:updated>2023-05-04T07:29:50.768Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Myanmar version</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Klez20OJZueLeuBd2nDeJA.jpeg" /></figure><p>Dart Language မှာ <strong>const</strong> keyword ကို သုံးတော့သုံးနေရတယ်၊ နောက်ကွယ်မှာ ဘယ်လို အလုပ်လုပ်လဲဆိုတာကို ဘာကြောင့် သုံးရလဲဆိုတာ မသိပဲ သုံးနေရတာမျိုး မဖြစ်သင့်ဖူးပေါ့။ နောက် <strong>const</strong> နဲ့ ယေဘူယျ အမြင်အားဖြင့်တူတဲ့ <strong>final</strong> keyword တို့ရဲ့ နောက်ကွယ်မှာ အလုပ်လုပ်ပုံအများကြီးခြားနားပုံ၊ application တခုကို ဘယ်လို impact ဖြစ်သွားစေလဲဆိုတာကို ဒီ article မှာ အသေးစိတ် ရှင်းပြသွားမှာပါ။</p><p><strong><em>What is const? (Compile time constant)</em></strong></p><p><strong>const</strong> keyword က value အသစ်ကို ထပ်ပြီး assign လုပ်လို့မရဖူးဆိုတဲ့အကြောင်းကို Programmer တော်တော်များများတော့သိပြီးသားဖြစ်နေကြမှာပါ။</p><p>Technical term အရ const variable က compile time constant ဖြစ်တယ်။</p><pre>void main (){<br><br>   const aConstant = &quot;Something&quot;;<br><br>}</pre><p>အပေါ်က code မှာဆို “Something” ဆိုတဲ့ String value က compile time မှာတည်းက const variable ဖြစ်တဲ့ <strong>aConstant</strong> ထဲကို assign လုပ်သွားမှာ ဖြစ်တယ်။ အဲ့ဒါကြောင့် <strong>compile time constant</strong> ဖြစ်ပြီး value အသစ်တခု assign လုပ်လို့မရတာဖြစ်တယ်။</p><p><strong><em>What is final? (Run time constant)</em></strong></p><p>final variable ကလည်း const variable လိုပဲ value အသစ်တခုကို ထပ်ပြီး assign လုပ်လို့မရနိုင်ဖူး။ Term အရဆိုရင် run time constant လို့ခေါ်တယ်။ ဒါဆို ဘာလို့ run time constant လို့ခေါ်တာလဲ။</p><pre>void main (){<br><br>   final exampleFinalVariable = &quot;Something&quot;;<br><br>}</pre><p>အပေါ်က ပြထားတဲ့ code မှာဆိုရင် “<strong>Something</strong>” ဆိုတဲ့ value ကို compile time မှာ compile လုပ်ထားပြီး အဲ့ precompile value ကို run time ရောက်တဲ့အချိန်ကြမှ <strong>exampleFinalVariable</strong> ထဲကို assign လုပ်တာ ဖြစ်တယ်။ အဲ့ဒါကြောင့် final variable ကလည်း value အသစ်တခုကို assign ထပ်လုပ်လို့မရပေမယ့် run time ရောက်တဲ့ အခါမှ assign လုပ်တာ ဖြစ်လို့ <strong>run time constant</strong> လို့ ခေါ်တာဖြစ်တယ်။</p><p><strong><em>When and where should use const keyword?</em></strong></p><p>variable တွေကို <strong>const</strong> အနေနဲ့က <strong>top- level variable</strong>, <strong>static variable</strong> နဲ့ <strong>local variable</strong> အနေနဲ့ပဲ Dart language မှာသုံးသင့်တယ်။</p><p>static field အနေနဲ့မှာ သုံးမှာတွေကို const အနေနဲ့ပဲ declar လုပ်သင့်တယ် (must) ပေါ့။ အဲ့လိုမှ const variable တွေအနေနဲ့ static variable အဖြစ်မသုံးချင်ဖူးဆိုရင်တော့ အဲ့ variable တေွကို constructor နဲ့ populate ပြန်လုပ်မှ declare လုပ်သင့်တယ်။</p><p>ထပ်မြင်အောင်ပြောရရင် const keyword ကို static variable တို့ class တခုရဲ့ constructor, instanceတို့မှာပဲသုံးသင့်တယ်လို့ dart မှာသတ်မှတ်ထားတယ်။</p><pre>class MyClass{<br><br>   static const int myConstField = 5;<br>  <br>}<br><br>void main(){<br><br>   int addNum = MyClass.myConstField + 5;<br><br>}</pre><p><strong><em>When and where should use </em></strong><strong><em>final? Why should not use </em></strong><strong><em>const…</em></strong></p><p>Dart မှာ String, <strong>int</strong>, <strong>List</strong>, <strong>Map</strong>, <strong>Set</strong> စတဲ့ value တွေအကုန်လုံးက constant ဖြစ်‌‌‌နေတယ်ဆိုရင် <strong>const</strong> variable ထဲကို assign လုပ်လို့ရတယ်။</p><p>အဲ့ constant တန်ဖိုးတွေကို <strong>final</strong> variable ထဲမှာလည်း ထည့်လို့ရတယ်။ ဒါပေမယ့် <strong>const</strong> variable တွေက compile time မှာတည်းက assign လုပ်တာ ဖြစ်နေပြီး final variable ‌‌တွေက run time မှာမှ assign လုပ်တာဖြစ်နေတဲ့အတွက် <strong>final</strong> variable ကိုတော့ ထပ်ပြီးတော့ <strong>const</strong> variable ထဲမှာ assign လုပ်လို့မရနိုင်ဖူး။</p><p>ပြောင်းပြန်အနေနဲ့တော့ <strong>const</strong> variable ကို <strong>final</strong> variable ထည့်လို့ရတယ်။ <strong>final</strong> variable က run time မှာမှ assign လုပ်တာဖြစ်တဲ့အတွက်ဖြစ်တယ်။</p><p>ဒါကြောင့် တန်ဖိုးအသေထားမည့် class level variable တွေကိုတော့ final နဲ့ပဲ declare လုပ်သင့်တယ်။</p><pre>class MyClass{<br> final int field1;<br> const MyClass({required this.field1});<br>}<br><br>void main(){<br><br> const myString = &#39;hello world&#39;;<br> const myInt = 1;<br> const myList = [1,3,5];<br> const myMap = {&quot;key&quot;:1, &quot;key1&quot;:2,&quot;key3&quot;:3};<br> const mySet = {1,3,4};<br><br> final finalVar = &quot;Hello&quot;;<br> const constVar = &quot;Hello&quot;;<br><br> const notWorking = finalVar; /// can not assign final variable to const<br> const work = constVar; /// only const can assigned<br><br>}</pre><p><strong><em>Why use </em></strong><strong><em>const with constructor? How to pronounce that?</em></strong></p><p><strong>const</strong> keyword နဲ့ <strong>final</strong> keyword တွေကို variable တွေမှာ ဘယ်လို သုံးသင့်ကြောင်း သိသွားပြီးရင် နောက်တဆင့် အနေနဲ့ flutter နဲ့ application တွေရေးတဲ့အခါ ဘာလို့ IDE tool တွေမှာ အမြဲလိုလို <strong>const</strong> keyword ကို suggest လုပ်နေတာလဲ ဆိုတာ ပြောရမယ်။</p><pre>Divider(height: 5); /// without const<br><br>const Divider(height: 5); /// with const</pre><p>အပေါ်ကလိုမျိုး <strong>Divider</strong>() Class ရဲ့ instance မျိုးကို သုံးတဲ့အခါ <strong>const</strong> keyword ထည့်ဖို့ suggest ပေးနေတာက application တခုမှာ <strong>Divider</strong> instance ကို parameter value ( <strong>height: 5</strong> ) အတူတူကို အများကြီးသုံးတဲ့အခါမျိုးမှာ <strong>const</strong> keyword မထည့်ရင် အဲ့ဒီ ပုံစံတူ instance တွေဆောက်တဲ့အရေအတွက်အတိုင်း memory ပေါ်မှာ အမြဲ compile သွားလုပ်နေမှာဖြစ်တယ်။</p><p>IDE tool က suggest လုပ်တဲ့အတိုင်း const keyword ကိုထည့်ရင်တော့ အဲ့လို တန်ဖိုးတူ constructor တွေအားလုံးအတွက် memory ပေါ်မှာ တခါပဲ နေရာယူမှာ ဖြစ်တယ်။ တန်ဖိုးတူတွေအတွက် memory က reusable လုပ်နေတာမျိုးပေါ့။ အဲ့လို reusable လုပ်နေတော့ memory လည်း leak မဖြစ်သလို application က performance ပိုမြန်လာတယ်။ အဲ့လို <strong>const</strong> instance ကို <strong>Canonical instance</strong> လို့ခေါ်တယ်။</p><pre>class ExampleClass{<br> final int variable1;<br> const ExampleClass({required this.variable1});<br>}<br><br>void main (){<br>  final finalVar = 123;<br>  const constantVar = 123;<br>  <br>  const x =  ExampleClass(variable1: constantVar);<br>}</pre><p><strong>ExampleClass</strong> က code မှာလိုမျိုး constructor သုံးတဲ့ class တခုရဲ့ field တွေသည် <strong>final</strong> ဖြစ်ရမယ်။ အဲ့ဒါမှ class ကို instantiated လုပ်ပြီးတိုင်း class ရဲ့ field တွေသည် immutable ဖြစ်နေမှာ။</p><p>အဲ့အပြင် <strong>ExampleClass</strong> ကို လက်ခံထားတဲ့ variable ကလည်း const ဖြစ်နေတဲ့ အတွက် <strong>main</strong> method ထဲမှာ <strong>ExampleClass</strong> instance ရဲ့ parameter ကို <strong>constantVar</strong> ပဲ pass ပေးလို့ရနိုင်မယ်။<strong>final</strong> variable ဖြစ်တဲ့ <strong>finalVar</strong> ကို pass ပေးလို့မရနိုင်ဖူး။</p><p>ဒါပေမယ့် တခုရှိတာက အပေါ်က code လိုမျိုး <strong>ExampleClass</strong> instance အရှေ့မှာ <strong>const</strong> မထည့်ဖူးဆိုရင်တော့ ပြောခဲ့သလို Dart Compiler က ဒါကို <strong>new</strong> instance အနေနဲ့ပဲ ထပ်သတ်မှတ်ပြီး same instance တိုင်းအတွက်ကို <strong>new</strong> instance အဖြစ်သတ်မှတ်သွားလိမ့်မယ်။ Dart မှာတော့ instance အရှေ့က <strong>new</strong> keyword ကို Dart version 2.0 မှာတည်းက redundant လုပ်လိုက်ပြီဖြစ်တဲ့အတွက် manual ထည့်စရာမလိုတော့ဖူး။ အဲ့လိုမျိုး <strong>new</strong> instance ဖြစ်တဲ့ ဖြစ်စဉ်ကိုတော့ <strong>instantiation context</strong> လုပ်တယ်လို့ခေါ်တယ်။ new instance ရဲ့ field တွေအနေနဲ့ကတော့ <strong>const</strong> context ပဲဖြစ်ဖြစ် <strong>const</strong> မဟုတ်တဲ့ context တွေရောဖြစ်လို့ရတယ်။</p><pre>class AnotherExampleClass{<br><br>   final Future&lt;int&gt; futureVar;<br>   const AnotherExampleClass({required this.futureVar});<br><br>}<br><br>void main (){<br><br>  final exp =  AnotherExampleClass(futureVar: Future.value(9));<br><br>}</pre><p><strong>AnotherExampleClass</strong> ရဲ့ field အနေနဲ့မှာ Future လိုမျိုး const မဟုတ်တဲ့ field/ variable တခု ပါနေပေမယ့် constructor ကို const အနေနဲ့အသုံးပြုလို့ရတယ်။ class တခုရဲ့ instance တွေက constant မဖြစ်ရင်တောင် constructor တွေကို constant ဖြစ်လို့ရအောင် လုပ်ထားတဲ့ Dart language ရဲ့ architecture တခုပဲ။ constant မဟုတ်တဲ့ field တခုပါနေတဲ့ class ရဲ့ constructor က <strong>const</strong> ဖြစ်လို့ရပေမယ့် instance တွေ assign လုပ်မဲ့ variable တွေရော instance တွေကတော့ အမြဲ <strong>new</strong> instanceနေလိမ့်မယ်။</p><p>ဒီလောက်ဆို နားလည်နိုင်လိမ့်မယ်လို့ ထင်ပါတယ်။ တကယ်လို့နားမလည်တာမျိုး ရှိရင်‌‌လည်း လာပြောလို့ရပါတယ်။</p><p>တကယ်လို့ အဆင်ပြေသွား နားလည်သွားရင်တော့ ရေးရအားတက်‌အောင် Clap တွေအများကြီး ပေးသွားပေးပါ‌နော်.</p><p>Reference: from <strong><em>ResoCoder</em></strong> Youtube channel.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a1782d06a10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Generate Routes]]></title>
            <link>https://medium.com/@lapyaeootharthar/flutter-generate-routes-cd77f7733e06?source=rss-41c56c1512aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd77f7733e06</guid>
            <category><![CDATA[route]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[generateroute]]></category>
            <dc:creator><![CDATA[La Pyae Oo]]></dc:creator>
            <pubDate>Wed, 14 Dec 2022 17:00:04 GMT</pubDate>
            <atom:updated>2022-12-14T17:00:04.345Z</atom:updated>
            <content:encoded><![CDATA[<p>For a Flutter application, either state management is import or to manage route for many difference screens you should use GenerateRoute Widget. Usage of that widget will help you for reusable and maintainable code.</p><p>In Flutter, when you do with routes, you may also need to carry data from one screen to another. At that situation, if you used traditional material page route function for each every screen, there is very difficult when need to fix route system, that will cost most of time with the searching of “where you used that function ( Material page route ). For these painfulness, there is two solutions to solve that painfulness. These are route table widget and on generate route. In this article I will explain OnGenerateRoute widget as mainly so will not explain route tables in detailed. In briefly, the way that using routes table may face a lot of difficult when carrying argument through the constructor of screen. So let start learning about the method of OnGenerateRoute in deeply.</p><p><strong>Basic of onGenerateRoute in Material App Widget</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2_Gi_XYFrhL3FxFkfR5g5g.png" /><figcaption>Same routing with generateRoute file</figcaption></figure><p>In detailed,</p><p>firstly give anonymous function for the onGenerateRoute parameter of MaterialApp widget. Use RouteSettings as the parameter of that anonymous function . And then that anonymous function return the constructor of the screen that you want to build the route from the builder function of MaterialPageRoute .</p><p><strong>Generate route within two pages to carry arguments</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0CA_-C0g9lJs8o29TEB8vg.png" /><figcaption>route_constant.dart</figcaption></figure><p>This the constant file that declare name of the route for the material page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZyPMB7c67ddQLW03lMGpnA.png" /><figcaption>login_screen.dart</figcaption></figure><p>Add route name of the home screen in the login screen to go the home screen with the Navigation of pushedName function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V-PfRCgRa77DZXJvgnnrVA.png" /><figcaption>main.dart</figcaption></figure><p>At last, check the route name of the RouteSettings with if else statement and call the constructor of the class of the screen that you want to go from the builder of MaterialPageRoute object that located inside of the main file or MaterialApp widget. That will totally work. If you want to carry data (Argument) from the one screen to other, can build that I write below with the help of the RouteSettings.</p><p>For multiple screens that more than 3 screen, you can used switch statement instead of if elsestatement.</p><pre>final args = settings.arguments;<br><br>MaterialPageRoute(<br>  builder: (context) {<br>    return RouteTest(id: args asint);<br>  },<br>);</pre><p>Now, you are done with the flutter GenerateRoute Widget. Hopefully you will understand. If you don’t understand enough fell free to ask me. And give clap as motivation for me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd77f7733e06" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>