<?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 Minh Ho on Medium]]></title>
        <description><![CDATA[Stories by Minh Ho on Medium]]></description>
        <link>https://medium.com/@minh.ho89?source=rss-47a83fb58a90------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8uSOi4SGzjgy1PDzCrPfqQ@2x.jpeg</url>
            <title>Stories by Minh Ho on Medium</title>
            <link>https://medium.com/@minh.ho89?source=rss-47a83fb58a90------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:36:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@minh.ho89/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[How to Automate WebApp Deployment with GitHub Actions and SSH]]></title>
            <link>https://medium.com/@minh.ho89/deploying-a-webapp-with-docker-on-a-linux-server-using-github-actions-and-ssh-00248b9b4c60?source=rss-47a83fb58a90------2</link>
            <guid isPermaLink="false">https://medium.com/p/00248b9b4c60</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[deployment-automation]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[ssh]]></category>
            <dc:creator><![CDATA[Minh Ho]]></dc:creator>
            <pubDate>Sat, 25 May 2024 01:57:41 GMT</pubDate>
            <atom:updated>2024-05-25T02:06:46.203Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Deploying a web application manually can be time-consuming and repetitive. In this post, I’ll show you how to automate the deployment process using GitHub Actions and SSH, making your workflow more efficient and less error-prone.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CzQAyWyIceQ5EqxA" /><figcaption>Photo by <a href="https://unsplash.com/@lazizli?utm_source=medium&amp;utm_medium=referral">Lala Azizli</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Overview</h3><ul><li>Step 1: Create a User on the Linux Server</li><li>Step 2: Create a Dockerfile for the WebApp</li><li>Step 3: Store Secrets in GitHub</li><li>Step 4: Set Up a GitHub Actions Workflow</li></ul><p>Typically, deploying a WebApp built with Docker involves the following steps:</p><ol><li><strong>SSH into the server.</strong></li><li><strong>Clone the Git repository.</strong></li><li><strong>Stop the Docker container.</strong></li><li><strong>Remove the Docker container and its image.</strong></li><li><strong>Build a new Docker image from the updated code.</strong></li><li><strong>Run the Docker container and expose the necessary ports.</strong></li></ol><p>While these steps aren’t difficult, they can become tedious when done repeatedly. After some research, I decided to use GitHub Actions to automate this process.</p><p><em>In this tutorial, I’ll show you how to use SSH to deploy a WebApp with Docker.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U5TkAtOAToo5uVuy" /><figcaption>Photo by <a href="https://unsplash.com/@rubaitulazad?utm_source=medium&amp;utm_medium=referral">Rubaitul Azad</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Step 1: Create a User on the Linux Server</h4><p>First, you need to create a user on your server and grant it the <em>sudo</em> privileges.</p><p>On the server, run the following command:</p><pre>sudo adduser deployer</pre><p>Next, set a password for the new user:</p><pre>sudo passwd deployer</pre><p>After setting the password, grant sudo privileges to the user:</p><pre>sudo usermod -aG sudo deployer</pre><p>To allow SSH login with a password, edit the SSH configuration file. Use your preferred text editor (I use <em>nano</em>):</p><pre>sudo nano /etc/ssh/sshd_config</pre><p>Find the following line and set its value to yes</p><pre>PasswordAuthentication yes</pre><p>Save the changes and restart the SSH service to apply the changes:</p><pre>sudo systemctl restart sshd</pre><p>Now, you can log in to the server using the username and password.</p><h4>Step 2: Create a Dockerfile to Build the Docker Image for the WebApp</h4><p>For this tutorial, my WebApp uses NodeJS Express as the backend. Here’s a simple Dockerfile configuration:</p><pre>FROM node:21.3.0<br># Set the working directory in the container<br>WORKDIR /usr/src/app<br><br># Copy package.json and package-lock.json to the working directory<br>COPY package*.json ./<br><br># Install app dependencies<br>RUN npm install<br><br># Copy the rest of the application code<br>COPY . .<br><br># Expose the port the app runs on<br>EXPOSE 3000<br><br># Command to run your application<br>CMD [&quot;npx&quot;, &quot;nodemon&quot;, &quot;app.js&quot;]</pre><h4>Step 3: Create and Store Secrets in GitHub Secrets</h4><p>Secrets are values that should not be exposed in your repository, such as passwords.</p><p>To create GitHub Action Secrets:</p><ol><li>On GitHub, select your repository.</li><li>In the top menu, click on Settings.</li><li>In the left menu, select Secrets.</li><li>Click on Add a new secret.</li><li>Name your secret and provide the value. For this project, I used the following secrets:</li></ol><ul><li>APP_ROOT: Path to the source code directory on the server</li><li>USER_NAME: SSH server username (e.g., &quot;deployer&quot;)</li><li>PASSWORD: SSH server password</li><li>SERVER_ADDRESS: IP address of the SSH server</li><li>SSH_PORT: Port of the SSH server</li></ul><p>In the workflow, you can reference these secrets using the expression ${{ secrets.SECRET_NAME }}.</p><h4>Step 4: Create a GitHub Actions Workflow to Deploy to the Server</h4><p>If your project does not have a workflow yet, follow these steps:</p><ol><li>On GitHub, go to the Actions tab, and select Set up a workflow yourself.</li><li>Name the workflow, for example, deploy.yml.</li><li>You will be directed to the workflow editor.</li></ol><p>First, set the on attribute to specify when the workflow should be triggered. Here, it runs on a push to the dev branch:</p><pre>on:<br>  push:<br>    branches: [ dev ]</pre><p>Next, set the jobs and specify the steps to be performed in the workflow. Choose the operating system for the server runner (I chose the latest version of Ubuntu):</p><pre>jobs:<br>  deploy:<br>    runs-on: ubuntu-latest</pre><p>Define the steps. Typically, it’s good to break steps into smaller tasks, but since we need to maintain the SSH session, we combine them into one step:</p><pre>steps:<br>  - name: Access to Server, Remove Docker Containers, Build Docker Image, Run Docker Container<br>    run: |<br>      sshpass -p ${{ secrets.PASSWORD }} ssh -o StrictHostKeyChecking=no ${{ secrets.USER_NAME }}@${{ secrets.SERVER_ADDRESS }} -p ${{ secrets.SSH_PORT }} &quot;<br>      echo ✅ SSH connection successful &amp;&amp;<br>      cd ~/${{ secrets.APP_ROOT }}/ &amp;&amp;<br>      echo ✅ Pulling from GitHub &amp;&amp;<br>      git pull &amp;&amp;<br>      running_containers=$(docker ps -q --filter ancestor=motlitleetcode) &amp;&amp;<br>      if [ -n \&quot;$running_containers\&quot; ]; then<br>      echo ✅ Stopping and removing running containers &amp;&amp;<br>      docker stop $running_containers &amp;&amp;<br>      docker rm $running_containers<br>      fi &amp;&amp;<br>      echo ✅ Building Docker Image &amp;&amp;<br>      docker build -t motlitleetcode . &amp;&amp;<br>      echo ✅ Running Docker Container &amp;&amp;<br>      docker run -d -p 80:3000 -p 443:443 --name motlitleetcode motlitleetcode &amp;&amp;<br>      echo ✅ Deployed successfully &amp;&amp;<br>      exit&quot;</pre><p>Here is the complete workflow:</p><pre>name: Deploy<br>on:<br>  push:<br>    branches: [ dev ]<br>jobs:<br>  deploy:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Access to Server, Remove Docker Containers, Build Docker Image, Run Docker Container<br>        run: |<br>          sshpass -p ${{ secrets.PASSWORD }} ssh -o StrictHostKeyChecking=no ${{ secrets.USER_NAME }}@${{ secrets.SERVER_ADDRESS }} -p ${{ secrets.SSH_PORT }} &quot;<br>          echo ✅ SSH connection successful &amp;&amp;<br>          cd ~/${{ secrets.APP_ROOT }}/ &amp;&amp;<br>          echo ✅ Pulling from GitHub &amp;&amp;<br>          git pull &amp;&amp;<br>          running_containers=$(docker ps -q --filter ancestor=motlitleetcode) &amp;&amp;<br>          if [ -n \&quot;$running_containers\&quot; ]; then<br>          echo ✅ Stopping and removing running containers &amp;&amp;<br>          docker stop $running_containers &amp;&amp;<br>          docker rm $running_containers<br>          fi &amp;&amp;<br>          echo ✅ Building Docker Image &amp;&amp;<br>          docker build -t motlitleetcode . &amp;&amp;<br>          echo ✅ Running Docker Container &amp;&amp;<br>          docker run -d -p 80:3000 -p 443:443 --name motlitleetcode motlitleetcode &amp;&amp;<br>          echo ✅ Deployed successfully &amp;&amp;<br>          exit&quot;</pre><p>With this setup, every time you push new code to the dev branch, GitHub Actions will automatically SSH into your server and deploy the updated code from start to finish.</p><h4>Conclusion</h4><p>In this post, I demonstrated how to use GitHub Actions to automate the deployment of a WebApp to a server. I’ve tested this approach successfully with my WebApp, and I encourage you to give it a try!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WVXIPNkklvTGyKeH" /><figcaption>Photo by <a href="https://unsplash.com/@victoriaorvicky?utm_source=medium&amp;utm_medium=referral">Victoria Tronina</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Feel free to share your experiences or any questions in the comments below. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=00248b9b4c60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Bloc for beginners: building a countdown timer using flutter bloc (part 2)]]></title>
            <link>https://medium.com/@minh.ho89/bloc-simple-explain-and-walkthrough-building-a-countdown-timer-using-flutter-bloc-part-2-bb1129b0fb90?source=rss-47a83fb58a90------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb1129b0fb90</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[bloc]]></category>
            <dc:creator><![CDATA[Minh Ho]]></dc:creator>
            <pubDate>Sat, 19 Mar 2022 13:24:19 GMT</pubDate>
            <atom:updated>2022-03-19T14:12:33.194Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Read part 1 </em><a href="https://medium.com/@minh.ho89/bloc-simple-explain-and-walkthrough-building-a-countdown-timer-using-flutter-bloc-part-1-e128e3ea26ac"><em>here</em></a></p><p>In part 1, we have finished setting up BloC classes. In this part, we are going to implement the bloc into our UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UaqdhQXFbvx8ctumQMMMhw.jpeg" /></figure><h3>WIDGET USAGES</h3><p>To implement BLoC to UI, we need to use below widgets and methods.</p><ul><li>BlocProvider: creates a new bloc which then will be used in the rest of the subtree.</li><li>BlocBuilder: has builder function to build a new widget and requires a bloc (which had been created by BlocProvider) in response to new states of the bloc. Please note that the builder function will potentially be called many times, even it belongs to a stateless widget.</li></ul><p>Make sure BlocBuilder belongs to BlocProvider’s subtree, otherwise an error will be thrown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*4QC6O8WQILsGYQXjjxinYg.png" /><figcaption>How to and how not to implement the BlocBuilder under a BlocProvider</figcaption></figure><h3>BLOCPROVIDER</h3><p>In main.dart file, let’s add the following codes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8126efb050c0821b8deeb547be331e49/href">https://medium.com/media/8126efb050c0821b8deeb547be331e49/href</a></iframe><h4>context.select</h4><p>context.select listens to the change of the closest bloc provided in the tree. The special characteristic of context.select is it allows us to listen for changes in a smaller part of a state.</p><p>In our application, we only need to listen to the change of duration value.</p><p>Under MyApp class, let’s create our MyHomePage widget:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e593f78c00e8d98158c1c79ce57c746/href">https://medium.com/media/9e593f78c00e8d98158c1c79ce57c746/href</a></iframe><p>ActionButtons will be implemented later. The widget’s task is changing the buttons according to the application state.</p><h3>context.read &amp; BUILDING ACTIONBUTTONS</h3><p>context.read retrieves the closest instance of Bloc in the tree. It is mainly used for adding an event to a bloc instance within onPressed callbacks.</p><p>Under MyHomePage class, we add ActionButtons as StatelessWidget:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6c1c0c3dc02aca906aa41c663b65020/href">https://medium.com/media/a6c1c0c3dc02aca906aa41c663b65020/href</a></iframe><p>We use BlocBuilder to build and rebuild widgets when states change. The buttons are rebuilt depending on the current state.</p><p>To change the state, we add the desired state to context.read function.</p><p>Combine, we have the final version of main.dart file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25abefccf44f556e7824fe036c338e31/href">https://medium.com/media/25abefccf44f556e7824fe036c338e31/href</a></iframe><p>Now, let’s run the app!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*sijRoF8S_dsMofjH92fP_Q.gif" /></figure><h3>CONCLUSION</h3><p>There are many state management approaches. The most popular probably are BLoC and Provider. BLoC separates view and business logic components pretty well. Although it takes a great effort to learn and also a big amount of code, but BLoC can deal with more complicated apps pretty well.</p><p>I hope these posts can help you somewhat easier in term of approaching BLoC.</p><p>Happy coding!</p><p><em>You can download the repository </em><a href="https://github.com/minhho89/flutter_bloc_countdown_app"><em>here</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb1129b0fb90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Bloc for beginners: building a countdown timer using flutter bloc (part 1)]]></title>
            <link>https://medium.com/@minh.ho89/bloc-simple-explain-and-walkthrough-building-a-countdown-timer-using-flutter-bloc-part-1-e128e3ea26ac?source=rss-47a83fb58a90------2</link>
            <guid isPermaLink="false">https://medium.com/p/e128e3ea26ac</guid>
            <category><![CDATA[simple]]></category>
            <category><![CDATA[bloc]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Minh Ho]]></dc:creator>
            <pubDate>Sat, 19 Mar 2022 11:59:40 GMT</pubDate>
            <atom:updated>2022-03-20T01:51:58.695Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UaqdhQXFbvx8ctumQMMMhw.jpeg" /></figure><p>BLoC is a powerful architecture for state management in Flutter, but also complicated for beginners.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*sijRoF8S_dsMofjH92fP_Q.gif" /></figure><p>In this post, I am going to explain BLoC simply, using a showcase app in the BLoC <a href="https://bloclibrary.dev/#/fluttertimertutorial">document</a> as an example. However, I trimmed most of the elegant parts from the original tutorial to make the walkthrough becomes friendlier and more digestible.</p><p>OK, let’s get our hands dirty!</p><h3>ANALYSE EVENTS AND STATES OF THE APP</h3><p>The timer starts at 60 and counts down until 0. The app contains some basic activities below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*FgC1GMa5AWJcLGMWV0hzvA.png" /><figcaption>Analysis table</figcaption></figure><h3>INSTALLING PACKAGES</h3><p>We use two packages: flutter_blocand equatable.</p><p>To install the packages, run those commands in your terminal or shell command:</p><p>$ flutter pub add flutter_bloc</p><p>$ flutter pub add equatable</p><p>flutter_blocis for sure the BLoC core package for Flutter, but what is equatable?</p><p>Well, as you can see in the above table, BLoC architecture requires many states and events. During running our application, the states and events shall change from one to another. BLoC needs to keep track of the current state/ event by comparing it with the states/ events which we had listed before.</p><p>However, comparing two objects in Dart is quite tricky. Native Dart compares two objects by their reference addresses in the memory instead of their contents of them. So equatable helps us to compare two objects properly by their certain properties without implementing any comparison algorithms. And we can even define which properties are going to be compared with equatable.</p><h3>CREATE THE TICKER MODEL</h3><p>We are creating a Ticker object to help us count down and keep track of the counting value.</p><p>I use the code from the BLoC documentation website because it is kind of compact and neat.</p><p>In the lib directory, create a new directory, named models.</p><p>In the models directory, create a file named ticker.dart. In the file, we make the Ticker object by the following code:</p><pre>class Ticker {<br> const Ticker()<strong>;<br> </strong>Stream&lt;int&gt; tick({required int ticks}) {<br> return Stream.periodic(Duration(seconds: <strong>1</strong>)<strong>, </strong>(x) =&gt; ticks — x — <strong>1</strong>)<br> .take(ticks)<strong>;<br>    </strong>}<br> }</pre><p>The Ticker object releases a continuous stream of integer values for every 1 second.</p><ul><li>(x)=&gt; ticks — x -1<strong> </strong>means for every value of x (integer), a value ofticks — x — 1 will be returned under the form of a stream.</li></ul><p>- take(ticks)<strong> </strong>means the stream will stop after ticks’ time return (basically it means the timer will stop at 0).</p><h3>BUILDING BLoC CLASSES</h3><p>In the lib directory, create a new directory, name blocs.</p><p>In blocs directory, create three following classes:</p><ul><li>timer_bloc.dart</li><li>timer_event.dart</li><li>timer_state.dart</li></ul><pre><strong>Hint: </strong>You can install a plug-in called `<strong>Bloc</strong>` in both VS Code and IntelliJ for effectively creating blocs classes.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*mTnrRTnH8EThXIHaigrtKA.png" /><figcaption>The “Bloc” plug-in in IntelliJ</figcaption></figure><p>Once you installed the plugin, there would be a “<strong>Bloc Class</strong>” option available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*WJM3CWc2KvdpZSTJ4f3npw.png" /><figcaption>There will be a “Bloc Class” option</figcaption></figure><h4>Building timer_state class</h4><p>In timer_state.dart create a TimerState class, extend from Equatable.</p><p>Let’s think about the countdown timer, it shows a value for every ticking (a.k.a every state), right? Therefore, the state class takes an integer value to show.</p><p>To help state instances compare each other, we take the duration variable as a comparator. To do this, we override the get props method of Equatable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5607f8f685ad06f4a0457cdebb9ef635/href">https://medium.com/media/5607f8f685ad06f4a0457cdebb9ef635/href</a></iframe><p>Let’s look at the analysis table in section 1. We have four states:</p><ul><li>TimerInitial</li><li>TimerRunInProgress</li><li>TimerRunPause</li><li>TimerRunComplete</li></ul><p>Let’s create those classes:</p><pre>class TimerInitial extends TimerState {<br> const TimerInitial(duration) : super(duration)<strong>;<br> </strong>}<br> <br> class TimerRunInProgress extends TimerState {<br> const TimerRunInProgress(int duration) : super(duration)<strong>;<br> </strong>}<br> <br> class TimerRunPause extends TimerState {<br> const TimerRunPause(int duration) : super(duration)<strong>;<br> </strong>}<br> <br> class TimerRunComplete extends TimerState {<br> <em>/// at this state, timer’s value is 0<br> </em>const TimerRunComplete() : super(<strong>0</strong>)<strong>;<br> </strong>}</pre><p>Combine all together:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db6ea6cc40da9d049cbcc0777b7cf067/href">https://medium.com/media/db6ea6cc40da9d049cbcc0777b7cf067/href</a></iframe><h4>Building timer_event. dart</h4><p>This class is in charge of managing all the events that occurred in our application. According to the analysis table, we have five events in total:</p><ul><li>TimerStarted event: timer starts counting down from a certain value. We must pass in that value; therefore, the event is going to take an integer value as property.</li><li>TimerPaused event: pause the timer.</li><li>TimerResumed event: resuming counting down from the TimerRunPause state. The event needs to keep track of the current value, so we must pass in the value.</li><li>TimerReset event: restart the timer to the TimerInitial stage.</li><li>TimerTicked event: occurs every second and overrides the counting down value. The activity requires comparing the previous value and current value, so we override the get props method of the Equatable class.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7bd08ef7f6d09693fe23527a96e5d70/href">https://medium.com/media/a7bd08ef7f6d09693fe23527a96e5d70/href</a></iframe><h4>Building timer_bloc.dart</h4><p>The mission of the bloc class is mapping events and states. A BLoC takes events as input.</p><p>To create a BLoC, we have to specify an initial state first. In our case, the initial state is TimerInitial.</p><p>To create an instance of the TimerInitial state, we have to pass an integer value that indicates the total seconds are going to be counted down. In this code below, the_duration variable is the value.</p><p>To keep track of the stream of the timer, we use StreamSubscription to listen to the ticker.</p><p>Finally, of course, we also need a Ticker.</p><pre>class TimerBloc extends Bloc&lt;TimerEvent<strong>, </strong>TimerState&gt; {<br>   final Ticker _ticker<strong>;</strong></pre><pre><em>/// counting down from 60</em><strong><br>   </strong>static const <em>_duration </em>= <strong>60; </strong><em><br> <br>   /// to listen to the ticker stream<br>   </em>StreamSubscription&lt;int&gt;? _tickerSubscription<strong>;<br> <br>   </strong>TimerBloc({required Ticker ticker})<br>       : _ticker = ticker<strong>,<br>         </strong><em>/// we have to specify the initial stage<br>         </em>super(const TimerInitial(<em>_duration</em>)) {<br>     <strong>  </strong>}</pre><pre>}</pre><p>Next, we must tell BLoC what every event is going to do. To do that, inside the TimerBloC constructor, we define that by the following syntax:</p><pre>on&lt;Event&gt;(eventHandler);</pre><ul><li>Event: an event class</li><li>eventHandler: a handler function that takes in an event and an Emitter to tell the above event what it is doing.</li><li>An Emitter pushes the application to another state, using its emit method.</li></ul><p>We have five events. So we map them with five corresponding event handlers.</p><p>In the TimerBloc construction method, write the code below:</p><pre>TimerBloc({required Ticker ticker})<br>     : _ticker = ticker<strong>,</strong><em><br>       </em>super(const TimerInitial(<em>_duration</em>)) {<br>   on&lt;TimerStarted&gt;(_onStarted)<strong>;<br>   </strong>on&lt;TimerTicked&gt;(_onTicked)<strong>;<br>   </strong>on&lt;TimerPaused&gt;(_onPaused)<strong>;<br>   </strong>on&lt;TimerResumed&gt;(_onResumed)<strong>;<br>   </strong>on&lt;TimerReset&gt;(_onReset)<strong>;<br> </strong>}</pre><p>The events will carry activities as below:</p><ul><li>TimerStated event -&gt; triggers TimerRunInProgress state, and binds TimerTicked state to the _tickerSubscription’s listener.</li><li>TimerTicked event -&gt; triggers TimerRunInProgress event if value &gt; 0, otherwise triggers TimerRunComplete.</li><li>TimerPaused event -&gt; triggers TimerRunPause state.</li><li>TimerResumed event -&gt; triggers TimerRunInProgress.</li><li>TimerReset event -&gt; triggers TimerInitial state.</li></ul><p>We override the close method, use it to cancel _tickerSubscription to avoid memory leaks.</p><p>Putting them together:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3acd440d6c16376cae6a8e18057f0aa/href">https://medium.com/media/e3acd440d6c16376cae6a8e18057f0aa/href</a></iframe><p>So, we have finished setting up BLoC architecture. In the next post, let’s implement our BLoC to UI.</p><p><em>The project repository can be downloaded </em><a href="https://github.com/minhho89/flutter_bloc_countdown_app"><em>here</em></a><em>.</em></p><p><em>Part 2: </em><a href="https://medium.com/@minh.ho89/bloc-simple-explain-and-walkthrough-building-a-countdown-timer-using-flutter-bloc-part-2-bb1129b0fb90"><em>click here</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e128e3ea26ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Becoming a software developer after 30]]></title>
            <link>https://medium.com/@minh.ho89/ive-got-my-first-job-as-a-software-developer-at-32-6244f3c8eb70?source=rss-47a83fb58a90------2</link>
            <guid isPermaLink="false">https://medium.com/p/6244f3c8eb70</guid>
            <category><![CDATA[career-paths]]></category>
            <category><![CDATA[devafter30]]></category>
            <category><![CDATA[careers]]></category>
            <dc:creator><![CDATA[Minh Ho]]></dc:creator>
            <pubDate>Sat, 12 Mar 2022 05:21:16 GMT</pubDate>
            <atom:updated>2022-03-12T11:38:06.985Z</atom:updated>
            <content:encoded><![CDATA[<p>Today is one of the most meaningful days in my career since I have just officially become a software developer at age 32.</p><p>I was not a software developer before. Though I loved computers as a kid, I have been working as a garment merchandiser for a garment trading company for most of my work life.</p><p>The job was interesting at first, but it was getting boring and boring over time. Since day by day is just replica tasks, endless incidents with a blurry career path as well as no new skills have chance to develop except dealing with minor problems.</p><p>I started to worry, that If I keep on working like this for the next 10 years, I would become a boring old man that can be replaced at any time by any younger staff who is willing to take a cheaper salary. Not to mention, the salary rise was meaningless, and the situation seemed to be like this for the rest of my career.</p><p><strong>I decided to take action…</strong></p><p>Recently in my country, a lot of Japanese have been opening their outsourcing companies here in the tech industry. And they make up a job called “Bridge Engineer”, for whom whoever can communicate in both my mother tougue and Japanese with a certain amount knowledge of tech. The offering salary is very good, at least 3 to 3.5 times compared with my current job’s offer.</p><p>I was amazed because the job satisfy both my interests that are the Japanese language and technology. So I decided to take my first step by enrolling in an online University majoring in Software Engineer.</p><p><strong>But changing was difficult…</strong></p><p>My salary at the company could be considered descent in the industry for that position. At the moment, it was not high but not too low, I can make a good living from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lSP7Yb3GYM-hL_aBztq2CA.jpeg" /><figcaption>There is no free lunch, I have to pay somehow…</figcaption></figure><p>The worry about starting everything again from the beginning with a junior position income scared me a lot. And also, there is a myth in my country that you cannot code well beyond the 30s. Moreover, I was worried about whether I can be successful in this new career or not.</p><p>The instinct of avoiding stepping out of my comfort zone put me in a dilemma of keeping living with a boring job but comfortable or taking risks to do what I like but uncertain.</p><p>Luckily my family listened and understood for me, my parents and my wife encouraged me to do what I like, they contributed much of my motivation to push me to go onward.</p><p><strong>Studying was challenging also…</strong></p><p>In the first year of school, I worked in the daytime and studied at night time. Honestly, coding is full of frustrations. Especially It was hard to study after a long day of stressful work.</p><p>Luckily, the more I studied, the more I like it. There were indeed some challenging subjects like algorithms &amp; data structures, but they’re also were some subjects that I enjoyed very much like OOP or mobile application development, I truly wished I had learned to code earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V1oVK0UIBGN__-E56g2oHg.jpeg" /><figcaption>Coding is full of frustration, but full of fun also.</figcaption></figure><p>Eventually, I decided not to be a Bridge Engineer but instead, I would become a software developer. Because I’ve learned that, coding is what I want to do in my work life.</p><p><strong>I have full of enthusiasm…</strong></p><p>I wanted to change my job as quickly as possible since I did not want to waste my life doing office grinds anymore, also I had turned 31, I did not have much time. So I quit my job and concentrated to study full time for a year.</p><p>During my time studying, I was amazed by the fascinating features of Flutter. I can build beautiful applications for a lot of platforms with ease. That was when I know that I would like to become a mobile developer using Flutter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*gg2_rk93rPlosFiNXccRHQ.png" /><figcaption>Luckily I found Flutter! This is such an amazing tool.</figcaption></figure><p>I focused on Flutter for a couple of months, successfully built one pet project, and published one package to pub.dev. With all of my knowledge about Web, database, Java, and Dart-Flutter plus my ability as a trilingual person, I was confident about finding a job.</p><p>I posted my CV to LinkedIn and started to get job interview offers, and I felt energized for my new dream job.</p><p><strong>… but that is just not enough…</strong></p><p>I interviewed a couple of Japanese outsources and products companies. Everything was smooth, I got compliments for my Japanese ability in communication with them.</p><p>But I got rejected from all of them.</p><p>What they wanted was a developer who can code rather than an untrained coder who can speak their language well. Besides, my expected salary was out of their range for an entry-level. Not to mention, since I concentrated too much to Flutter study, I did not solve many algorithms problems. Therefore, I could not pass most of the algorithms challenges.</p><p>That was when I know my position. I must train myself more with algorithms challenges and lower my salary. After being refreshed, I tried again.</p><p>Eventually, I got accepted by an outsourcing company, a second top company in my country. In terms of income, this is a substantial backward. But that was not more important than the fact that finally, I can do my dream job. Besides, in this company, I believe that I would have a lot of opportunities for skill development and technology access.</p><p>Looking back to the last two years of transformation, I felt somewhat proud of myself for letting things go to pursue what I love to do. Finally, At the end of the day, one would feel sorry not for what he has done but for what he did not do.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6244f3c8eb70" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>