<?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 Ken Lee Chiaw Huat on Medium]]></title>
        <description><![CDATA[Stories by Ken Lee Chiaw Huat on Medium]]></description>
        <link>https://medium.com/@kenaragorn?source=rss-38a153c91705------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lB4gBEz0R9SX0BLK.</url>
            <title>Stories by Ken Lee Chiaw Huat on Medium</title>
            <link>https://medium.com/@kenaragorn?source=rss-38a153c91705------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 19:54:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kenaragorn/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[Multiple Builds Environment in Flutter for Firebase Using Provider and Flavor]]></title>
            <link>https://medium.com/flutter-community/multiple-builds-environment-in-flutter-for-firebase-using-provider-and-flavor-883b1a30096d?source=rss-38a153c91705------2</link>
            <guid isPermaLink="false">https://medium.com/p/883b1a30096d</guid>
            <category><![CDATA[provider]]></category>
            <category><![CDATA[flavor]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Ken Lee Chiaw Huat]]></dc:creator>
            <pubDate>Thu, 23 Apr 2020 07:33:32 GMT</pubDate>
            <atom:updated>2020-05-05T00:03:48.561Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ptHpspo4s-Vvc2rATOTL2w.png" /></figure><p>It is always a good practice to build separate apps from the same source code and for different environment such as development, staging and production. Why? When you build a system, most of the time, there will be additional bugs fixing and enhancements. Thus, in order not to break the production environment especially the database side of it, we need to separate the development and the testing environment.</p><p>Officially, the team behind Flutter recommended the approach of using flavors — a common practice for native Android development.</p><p>The word flavor means ‘version’ and basically, we create multiple flavors of our mobile app that we can build the app with different configuration options and styles such as different database environment (development, staging or production).</p><p>We will be using the previous Flutter with Firebase CRUD project template (<a href="https://github.com/KenAragorn/create_flutter_provider_app">here</a>) that I created previously, and further enhance it to include flavors. If you would like to know more about the template that I created, click on the link <a href="https://medium.com/flutter-community/flutter-provider-architecture-with-firebase-full-guide-by-building-a-working-crud-app-4824cec04e59">here</a>.</p><p>At the end of this article, we will have a working Flutter project that support 2 environments (development and production) using flavor. Each app will display the app name specifically to their flavor and connecting to different Firebase project.</p><p>Take note, this article is mainly for Flutter in Android environment and not the iOS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*vZOeQkMOpxXWO_fS2W9nHg.gif" /></figure><h3><strong>Step 1: Create 2 Different Firebase Projects and Configuration</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*wGheocPYP97_6PnRpaPb_g.png" /></figure><p>For this, as mentioned earlier, we will be defining 2 environments namely development and production, so we will need to create <strong>2 Firebase projects</strong>.</p><p>Then, for each Firebase projects, create a <strong>Cloud Firestore database</strong>. Do remember to have at least 1 <strong>sign-in method</strong> enabled for both projects — for this example, we are using Email/Password only.</p><p>Next, we need to get the <strong>google-services.json</strong> for each Firebase project. To do that, lets assume we will be using the following applicationId for both environment:</p><ul><li>- <em>Note App Prod: </em>applicationId: com.example.create_flutter_provider_app.prod</li><li>- <em>Note App Dev: </em>applicationId: com.example.create_flutter_provider_app.dev</li></ul><p>You can use your preference naming convention for the applicationId, as long it is understandable that 1 is for production environment and another is for development environment.</p><p>With the applicationId defined, we will used it to add Firebase to our project. Go to each Firebase project, click on the small Android icon and the following screen will appear. Add the applicationId to the right Firebase project as specified above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*jV3TUemaNGuVgkB3_SxREA.png" /></figure><p>Once registering the app, download the google-services.json for each Firebase projects.</p><p>At the end of this step, you should have 2 Firebase projects with the following setup done:</p><ul><li><strong>Note App Prod</strong></li></ul><p>→ Sign-in method configured</p><p>→ Created Cloud Firestore Database</p><p>→ applicationId: com.example.create_flutter_provider_app.prod</p><p>→ google-services.json file downloaded</p><ul><li><strong>Note App Dev</strong></li></ul><p>→ Sign-in method configured</p><p>→ Created Cloud Firestore Database</p><p>→ applicationId: com.example.create_flutter_provider_app.dev</p><p>→ google-services.json file downloaded</p><h3><strong>Step 2: Updating Project Config Files</strong></h3><p>Add in the following configuration into the project android/app/build.gradle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*a-D1FkpBtTy5gMX3EUubxQ.png" /></figure><p>Here, we created 2 flavor. 1 is for development environment (dev) and another is for production (prod). The most important piece of information that you must remember is the applicationId field. Again, take note, the applicationId must match those specified in Step 1. As for the versionCode and versionName, this is just example. For me, I prefer to have some version name that I can refer later without touching the code layer.</p><h3><strong>Step 3: Create 2 folders Representing Development and Production</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/1*wCFGQd0jhvtPVDDw8Xqt9g.png" /></figure><p>The folder name must match the named specified in productFlavors (android/app/build.gradle). The previous downloaded google-services.json files for both Firebase projects need to be moved to the right folder. For the file downloaded from Note App Prod, place it under the folder prod and for the same file name downloaded from Note App Dev, place it under the dev folder.</p><p>For the sub folder called ‘res’, ignore it for now. We will go through that shortly.</p><h3><strong>Step 4: Having different app name and app icon for Dev and Prod</strong></h3><p>We want to have a different app name for our project. This is helpful as with Flavor setup, we can install both app in the same devices for testing. Having app name such as NoteApp-Dev or Note-Dev or Note-Prod helps us to identify which app is for which environment — development or production.</p><p>The same concept and benefits if we have different app icon for each apps that are connecting to different environment.</p><p>For app name, create file called strings.xml and with the following content:</p><pre><em>&lt;?</em><strong>xml version=”1.0&quot; encoding=”utf-8&quot;</strong><em>?&gt;<br> </em>&lt;<strong>resources</strong>&gt;<br> &lt;<strong>string name=”app_name”</strong>&gt;Note-Dev&lt;/<strong>string</strong>&gt;<br> &lt;/<strong>resources</strong>&gt;</pre><p>Change the app_name to fit your Dev app. Put this file under the dev/res/values:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*--xaQrHMhoieyFoCIabxdg.png" /></figure><p>Do the same for the prod environment but name your app_name to be Note-Prod or something that represent it is the app for Production.</p><pre><em>&lt;?</em><strong>xml version=”1.0&quot; encoding=”utf-8&quot;</strong><em>?&gt;<br> </em>&lt;<strong>resources</strong>&gt;<br> &lt;<strong>string name=”app_name”</strong>&gt;Note-Prod&lt;/<strong>string</strong>&gt;<br> &lt;/<strong>resources</strong>&gt;</pre><p>The final step for the app name is to change the Android manifest file to refer to the String name app_name. To do that, open the file AndroidManifest.xml located at android/app/src/main folder. Update the android:label as follow:</p><pre><strong>android:label=&quot;@string/app_name&quot;</strong></pre><p>Next, for the images, copied all 5 sub folders that start with the name mipmap-xxx from main/res/, and paste it to the res folder for both dev and prod. At the end, you should have the following view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*OCzgMxfv8mP1uQgIf_dfSA.png" /></figure><p>If you notice, each sub-folder with the name minimap contains images and that image is the app icon image. Change it to your needs.</p><h3><strong>Step 5: New Dart files and Code Updates</strong></h3><p>Create a <strong>flavor.dart</strong> file. This will just contain enum value that represent both dev and prod environment that the main class can refer and decide. The code:</p><pre><strong>enum </strong>Flavor {<strong>dev</strong>, <strong>prod</strong>}</pre><p>Since we are using the Flutter template shared above, we will need to create additional main.dart that represent the production build and using the original main.dart to be representing as development build.</p><p>Our goal is to able to build and run different flavor as follow:</p><pre><em>flutter run --flavor dev -t lib/main.dart<br> flutter run --flavor prod -t lib/main_prod.dart</em></pre><p>First, update the main.dart as follow:</p><pre><strong>void </strong>main() {<br>   WidgetsFlutterBinding.<em>ensureInitialized</em>();<br>   SystemChrome.<em>setPreferredOrientations</em>([DeviceOrientation.<strong>portraitUp</strong>]).then((_) <strong>async </strong>{<br>     runApp(<em><br>       </em>MultiProvider(<br>         providers: [<br>           Provider&lt;Flavor&gt;.value(value: Flavor.<strong>dev</strong>),<br>           ChangeNotifierProvider&lt;ThemeProvider&gt;(<br>             create: (context) =&gt; ThemeProvider(),<br>           ),<br>           ChangeNotifierProvider&lt;AuthProvider&gt;(<br>             create: (context) =&gt; AuthProvider(),<br>           ),<br>           ChangeNotifierProvider&lt;LanguageProvider&gt;(<br>             create: (context) =&gt; LanguageProvider(),<br>           ),<br>         ],<br>         child: MyApp(<br>           databaseBuilder: (_, uid) =&gt; FirestoreDatabase(uid: uid),<br>         ),<br>       ),<br>     );<br>   });<br> }</pre><p>As mentioned before, we will make the main.dart as the representative of building a development build. As this project is using Provider, we will pre-set the main.dart to use the dev flavor.</p><p>Duplicate this file and renamed it as main_prod.dart. Update the Flavor.dev to Flavor.prod.</p><p>Then, apart from the previous app name and app icon changes, we felt it is also necessary to display some info at the first screen namely the sign-in screen. Thus, since we are using Provider to set the initial value of the both main.dart and main_prod.dart, we then can access this initial default value at the sign-in screen as follow:</p><pre>Text(<br>   Provider.<em>of</em>&lt;Flavor&gt;(context).toString(),<br> ),</pre><p>So, what will happen if we were to run the following code:</p><pre><em>flutter run --flavor dev -t lib/main.dart</em></pre><p>Flutter will try to build and run the app using the flavor dev and using the main.dart file. This will result the following display of sign-in screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/1*xtGhyg9fShM_1e472rdjQA.png" /></figure><p>Notice the bottom part, it contains the value of the enum value dev.</p><p>The command: <strong><em>flutter run — flavor dev -t lib/main.dart</em></strong><em> </em>is basically telling Flutter to build the app for testing using the flavour dev specified in the build.gradle. Also, the second part is basically telling it to run it using main.dart file. And since our main.dart has the initial flavor value pre-set as dev, it will be display as Flavor.dev.</p><p>If were to run the command: <em>flutter run — flavor prod -t lib/main_prod.dart,</em> will result the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*8AxJWyctpAxTLN41Rs9wFQ.png" /></figure><p>Notice the bottom of the screen, it is displaying Flavor.prod.</p><p>There you have it, a more complete and updated Flutter template that utilizing the benefits of flavors.</p><p>Link to github is <a href="https://github.com/KenAragorn/create_flutter_provider_app.git">here</a>.</p><p>Again, I do hope the above explanation and additional improvement to the Flutter template will help even more in your project as much as it helps me.</p><p>Cheers.</p><p><a href="https://www.twitter.com/FlutterComm">JavaScript is not available.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=883b1a30096d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/multiple-builds-environment-in-flutter-for-firebase-using-provider-and-flavor-883b1a30096d">Multiple Builds Environment in Flutter for Firebase Using Provider and Flavor</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Provider Architecture with Firebase Full Guide — by building a working CRUD app]]></title>
            <link>https://medium.com/flutter-community/flutter-provider-architecture-with-firebase-full-guide-by-building-a-working-crud-app-4824cec04e59?source=rss-38a153c91705------2</link>
            <guid isPermaLink="false">https://medium.com/p/4824cec04e59</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[provider]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Ken Lee Chiaw Huat]]></dc:creator>
            <pubDate>Sun, 15 Mar 2020 15:17:20 GMT</pubDate>
            <atom:updated>2020-03-31T23:39:23.172Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Flutter Provider Architecture with Firebase Full Guide — by building a working CRUD app</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*Avdlz_ScH4Mwx8RYrrwppg.png" /></figure><h3><strong>Introduction</strong></h3><p>Ever since the creation of Flutter by the Google team few years back, I have been busy creating a numbers of Flutter projects, mostly in the aspect of mobile app. However, regardless of the state management that been used (ScopedModel, bloc, flutter_bloc, provider), most of the starting time was used to setting up the project folder structure, creating main key files such as theme, routes, models and services.</p><p>Instead of doing this repeatedly every time when creating a new Flutter projects, I’m going to spend some time with creating a boilerplate project that contains the minimum key folder structures, files, naming conventions and how to keep things better organised and maintainable using Provider package.</p><p>To make things more helpful, most of the Flutter projects that needed a backend is using Firebase and Cloud Firestore for user login/new user registration and CRUD capabilities, thus I added a simple Firebase user login using email/password and a simple notes CRUD features as part of the project.</p><p>Most of the times, is very common for any application to have user login and CRUD features. Thus, it makes more sense to added this to the boilerplate project for easier to understand and anyone can change from there.</p><p>So, let’s get started.</p><h3><strong>What are we building?</strong></h3><p>A boilerplate project for anyone that want to create a Flutter mobile application using Provider, Shared Preferences and Firebase.</p><h3><strong>What are the goals?</strong></h3><p>The main goal is to define a reference architecture that can be used as the foundation for Flutter app that require the usage of Firebase and eventually:</p><ul><li>To reduce developer time in re-writing common code and project structure from scratch</li><li>To have a common folder and package structure that can be further extended should it require</li><li>Clearing define the app layer — UI layer, business logic layer and service layer</li></ul><p>The 3 main layers:</p><ul><li>UI layer — all UI widgets files</li><li>Business logic layer — contains all app business and presentation logic</li><li>Service layer — contains services needed to interact with between the app and 3rd party services such as APIs</li></ul><p>This project bundled with a demo app as a practical example of this architecture. This is very important and useful for anyone to jump start right into the code and working app. From there, we can make modification as require for easily, faster and convenient.</p><p>The demo app is a working Todo app that comes with Firebase authentication using email and password and full CRUD capabilities.</p><p>The app demonstrates a simple but a comprehensive enough to capture the various challenges and use cases of state management across multiple screens and different modules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*6gMJXzimhKnL9UBGBMyMPg.png" /></figure><h3><strong>Setting Up</strong></h3><p>As this guide is for creating a mobile app using the boilerplate project, first download or clone the following repo:</p><p><a href="https://github.com/KenAragorn/create_flutter_provider_app.git">https://github.com/KenAragorn/create_flutter_provider_app.git</a></p><p>Then, follow the official guide in the above link and in less than few minutes, you will have the workable todo app that not just come with common codes that works for Firebase Authentication, but also all possible CRUD features that are commonly practise in any application that relied on Firestore as database.</p><h3><strong>Folder Structure</strong></h3><pre>lib/</pre><pre>|- constants/ — contains all application level constants for theme, font types and app strings.</pre><pre>|- caches/ — contains data layer such as shared preferences.</pre><pre>|- models/ — contains all the plain data models.</pre><pre>|- services/ — contains all services files that handle the API calling for CRUD related functionalities.</pre><pre>|- providers/ — contains all Provider models for each of the widget views.</pre><pre>|- ui/ the main folder that will contains all UI related breaking down further by different modules (such as authentication, home, etc) and sub section (reusable widgets and screens).</pre><pre>|- routes.dart</pre><pre>|- auth_widget_builder.dart</pre><pre>|- main.dart</pre><p><strong>What inside constants?</strong></p><p>Basically, all needed constant files for the application to work will be here.</p><pre>constants/<br>|- app_themes.dart – the theme file for the app<br>|- app_font_family.dart – the app global supported font family<br>|- app_strings.dart – the strings value used by the app</pre><p><strong>What inside cache?</strong></p><p>As of now, only shared preferences files. In future we may have others such as sqlite features and it is good to keep things separated.</p><pre>caches/<br>|- sharedpref/shared_preference_helper.dart</pre><p><strong>What inside models?</strong></p><p>All plain data models file will be here. Depending on the number of the model files, if it is more than 10 files, we suggest separating the files by sub folder such as models/auth, models/todo etc. Else, keep it simple with every data model file is within this folder.</p><pre>models/<br>|- user_model.dart<br>|- todo_model.dart</pre><p><strong>What inside services?</strong></p><p>As we have backend firestore and firebase for application data such as user and todo data, we will need a dart classes that represent the CRUD services to handle any communication between the UI code and the backend.</p><pre>services/<br>|- firestore_database.dart<br>|- firestore_service.dart<br>|- firestore_path.dart</pre><p><strong>What inside providers?</strong></p><p>Contains all provider models needed for the app. The idea is like those in models and services in which, different provider class will be created for different key modules.</p><pre>providers/<br>|- auth_provider.dart<br>|- theme_provider.dart</pre><p><strong>What inside UI?</strong></p><p>This directory contains all the UI files for the application. As most of the times, there will be more than 1 files representing a screen, thus is always good to separate it by sub-folder and grouping it based on their key features or modules.</p><pre>ui/<br>|- auth<br>        |- register_screen.dart<br>        |- sign_in_screen.dart<br>|- splash<br>        |- splash_screen.dart<br>|- home<br>        |- home.dart<br>|- todo<br>        |- todos_screen.dart<br>        |- create_edit_todo_screen.dart</pre><p><strong>Use Case: Firestore Service</strong></p><p>Any widgets module can subsribe to updates from Firebase Firestore through streams, as well as write operation such as creation and deletion of data using Future-based APIs.</p><p>For convenient, all Firestore related CRUD services for the demo app is all in 1 place:</p><pre>class FirestoreDatabase { // implementation omitted for brevity<br>  Future&lt;void&gt; setTodo(TodoModel todo); // create / update<br>  Future&lt;void&gt; deleteTodo(TodoModel todo); // delete<br>  Stream&lt;List&lt;TodoModel&gt;&gt; todosStream(); // read<br>  Stream&lt;Job&gt; todoStream({@required String todoId}); // read<br>}</pre><p>With this setup, creating a widget that shows a list of jobs becomes simple:</p><pre>@override<br>Widget build(BuildContext context) {<br>  final database = Provider.of&lt;FirestoreDatabase&gt;(context, listen: false);<br>  return StreamBuilder&lt;List&lt;Job&gt;&gt;(<br>    stream: database.todosStream(),<br>    builder: (context, snapshot) {<br>      // TODO: return widget based on snapshot<br>    },<br>  );<br>}</pre><p>Domain-level model classes are defined, along with fromMap() and toMap() methods for serialization.</p><p><strong>Take note on stream-dependent services</strong></p><p>When using Firestore, is quite common to organise user data inside documents or collections that depend on the unique user uid.</p><p>When reading or writing data, the app need to access to the user uid. This can change at runtime, as user can log out and sign back in with a different account, which eventually a different uid.</p><p>This, the FirestoreDatabase takes the uid as a constructor parameter. So, the moment we have FirebaseUser upon user logged in, we can just pass the uid to the Firestore database when performing CRUD operations.</p><p>To achieve this, FirestoreDatabase will be re-created everytime onAuthStateChanged changed.</p><p>I hope this started kit will helps you as how it helps me to minimize my work in the beginning and I also hope the above explanation can further assist you to understand the design behind it.</p><p>Cheers. :)</p><p><a href="https://www.twitter.com/FlutterComm">JavaScript is not available.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4824cec04e59" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/flutter-provider-architecture-with-firebase-full-guide-by-building-a-working-crud-app-4824cec04e59">Flutter Provider Architecture with Firebase Full Guide — by building a working CRUD app</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Animation — Understanding the core of Staggered and Sequence Animation]]></title>
            <link>https://medium.com/flutter-community/flutter-animation-understanding-the-core-of-staggered-and-sequence-animation-2c80a529d30e?source=rss-38a153c91705------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c80a529d30e</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter-ui]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Ken Lee Chiaw Huat]]></dc:creator>
            <pubDate>Wed, 12 Feb 2020 18:45:02 GMT</pubDate>
            <atom:updated>2020-04-20T02:10:10.501Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Flutter Animation — Understanding the core of Staggered and Sequence Animation</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k_So7w_nX5xTZj7tvhoR6w.png" /></figure><h3><strong>Introduction</strong></h3><p>There are few main areas that I strongly believe as the key elements for any good mobile app design. The first would be the UI design, UX (user experience) and a good animation.</p><p>Since Flutter provides lots of out of the box widget that we can utilize and mix together for a good UI, most if not all, does not come with a good default animation.</p><p>Flutter team are fully aware of it and there has been lots of sharing from the team itself on the animation topic. This include ‘Widget of the Weeks’ series where the team behind Flutter created a very good video tutorial and sharing on the power of animation in Flutter and how to use it.</p><p>In this article, I will share my knowledge and the core basic specifically on staggered and multiple tweens animation. Why? Well most of the time, when we design any mobile app, we will need to implement multiple animation within the same screen and widget.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*jB5HcfkD7B58gw57s2dQ7A.gif" /></figure><h3><strong>Introduction to Flutter Animations</strong></h3><p>Before we move into the details of it, is good to know that in Flutter, there are 2 techniques for animation:</p><ul><li>Implicit Animation</li><li>Explicit Animation</li></ul><h3><strong>Implicit Animations</strong></h3><p>Implicit animation is those widgets that come with pre-defined features/functionalities that are good enough for an animation. They extend ImplicitlyAnimatedWidget class.</p><p>For example, you can’t control the animation when to pause or reverse or doing multiple animation with different widget child groups together.</p><p>Example of implicit type of animation widgets are AnimatedContainer, AnimatedPositioned, AnimatedAlign and AnimatedOpacity.</p><p>So, if you want to have simple animation without the need to pause or reversing the animation, AnimatedFoo got you covered in which Foo is the name of the non-animated version of that widget.</p><p>For the complete list of implicitly animated widgets, go to <a href="https://api.flutter.dev/flutter/widgets/ImplicitlyAnimatedWidget-class.html">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*aBzbZRMb1QTe4k5VHmgn_g.gif" /><figcaption>A simple AnimatedAlign widget</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*8_yKzmKDRP26-dZrMUMSWA.gif" /><figcaption>Another example of implicit animation: AnimatedContainer</figcaption></figure><p>But, to achieve the animation that contains multiple widgets that have different entry point within the same animating duration, the easiest approach is explicit animations.</p><h3><strong>Explicit Animations</strong></h3><p>In explicit animations, as you need to define the AnimationController, Animation and Tween objects, that means you have the full control of when an animation can be start and mixing multiple animation objects into 1 main staggered or sequence animation.</p><ul><li><strong>Animation</strong></li></ul><p>-&gt; It is the core class of Flutter animation and it is an abstract class.</p><p>-&gt; Since it is an abstract class, we can’t instantiate it for animation usage, but we can create one using AnimationController or Tweens.</p><p>-&gt; Example:</p><p>Animation&lt;double&gt; — interpolates values between 2 decimal numbers over a given duration.</p><p>Animation&lt;Color&gt; — interpolates colors between two color values.</p><ul><li><strong>AnimationController</strong></li></ul><p>-&gt; It controls the animation such as total animation duration, starting/stopping/reversing the animation and allowing anyone to know the status of the animation through listener.</p><p>-&gt; It extends the abtract class Animation, which would mean all implemented methods in Animation class will be available in AnimationController.</p><p>-&gt; Code Example:</p><p>-&gt; Controller = AnimatioController(duration: Duration(miliseconds: 2800)).</p><p><strong>Tweens</strong></p><p>-&gt; A tween allowed us to define how to interpolate between two values.</p><p>-&gt; The interpolation is linear and not curve. Linear here means the animation from x to y will remain unchanged. To have a curvy type of animation, use <strong>CurvedAnimation</strong></p><p>-&gt; It is a stateless object that takes only begin and end value.</p><p>Now, with the above understanding, we can move on to the basic structure of staggered animation.</p><p>Let’s assume we want to create a something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*BHSyStFzHdR5kD1l3_rggQ.gif" /></figure><p>From the above picture, you will notice the following:</p><ul><li>The animation started with the avatar picture been loaded from smaller to bigger size and at the same time opacity changed.</li><li>The divider below the avatar have its width size changed.</li><li>The bottom profile section (big blue section) having width enlarged, follow by opacity changed from 0 to 1.</li></ul><p>Basically, there are multiple animation that occur together and some slightly later, in sequence. The complete list of animation in breakdown are as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*gb5lrhZpDkmPcfh7hY2FBA.png" /></figure><p>The key steps to setup the animation in this sequence is:</p><ul><li>Create an AnimationController that manages all of the Animations.</li><li>Create a Tween for each property being animated — Tween for the avatar opacity changes, Tween for avatar sizes changes, Tween for the divider and so on.</li></ul><p>This is the main screen dart file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*rfRdTtCuxDuMKAtEexPZdg.png" /></figure><p><strong>Key info:</strong></p><ul><li>We need to create the AnimationController so that we can specify the total duration of the whole screen, we also need to provide the vsync. Thus, we need to implement SingleTickerProviderStatrMixin. What is vsync? Vsync basically helps in keeping track of the screen, so it won’t simply render the animation when the screen is not being displayed.</li><li>Take note, since we are creating an instance of AnimationController, thus we need to dispose it when the screen is not needed anymore during runtime. Therefore, this main class file is been created as Stateful type of widget.</li><li>As there is a lot of animations occurring, we can create a separate animator class that focus the animation part of the whole screen.</li></ul><p>This is the StaggeredExampleAnimator class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*nVdg6_TCdNWRoNUmQRh4Ew.png" /></figure><p>Here, we have the separated animator class and notice on the constructor in which we have can a reference of the AnimationController from the parent.</p><p>Also, we defined all the Animation objects that has its own animation rules such as opacity changes, size changes and width/height changes.</p><p>For example, the avatarOpacityAnimation is having the following code:</p><p><strong>avatarOpacityAnimation </strong>= Tween(begin: 0.0, end: 1.0).animate(<br> CurvedAnimation(<br> parent: controller,<br> curve: Interval(0.1, 0.4, curve: Curves.<em>ease</em>)))</p><p>This mean, we are creating an animation object that will change its opacity from 0% to 100% and the animation will start at 0.1 seconds until 0.4 seconds. As I mentioned earlier, to have more control such as when the animation can begin and for how long, we must use Interval.</p><ul><li>Tween (begin: 0.0, end: 1.0) — as the opacity min and max range is 0 to 1, thus this are the values.</li></ul><p>This mean, we are creating an animation object that will change its opacity from 0% to 100% and the animation will start at 0.1 seconds until 0.4 seconds. As I mentioned earlier, to have more control such as when the animation can begin and for how long, we must use Interval.</p><ul><li>Tween (begin: 0.0, end: 1.0) — as the opacity min and max range is 0 to 1, thus this are the values.</li><li>Interval (0.1, 0.4, curve: Curves.ease) — this would mean I want the opacity animation to start at the 0.1 interval, and end at 0.4 interval out of the total 1 and using the curve ease. There are others animation curves formula, visit <a href="https://api.flutter.dev/flutter/animation/Curves-class.html">here</a> for the full list.</li><li>Lets take another example, the avatarSizeAnimation code:</li></ul><p><strong>avatarSizeAnimation </strong>= Tween(begin: 10.0, end: 80.0).animate(<br> CurvedAnimation(<br> parent: controller,<br> curve: Interval(0.1, 0.4, curve: Curves.<em>ease</em>)))</p><p>This mean, we are creating an animation object that will change its size from 10 pixels to 80 pixels and the animation will start at 0.1 seconds and end at 0.4 seconds. To control when the animation will start, using the interval will allow us to control the timing.</p><p>In the UI build code, this is how we link the widget to the animation. For example, the avatar widget where we want to control the opacity and the size during load time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*CY9BOrKdi5oZfzaCLtBFig.png" /></figure><p>In the above code snippet, we used the Opacity widget to manage the opacity animation. As because I want to have some border decoration on my avatar picture, we can use the Container widget and mapped the decoration color to the same opacity animation object.</p><p>As for the avatar itself, there is a property called radius that we can used to control the radius size from small to big — and this is done by linking it to the size animation object we created above.</p><p>The result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*QASdCbLV-DbDmlocaNdnvg.gif" /></figure><p>As for the rest of the section such as the divider animation and the bottom square animation is using the same concept that I shared above. As long we understand the purpose of the code for AnimationController, Animation and Tween, we have full control of what we can achieve in explicit animation for Flutter.</p><p>What if you want to have the same widget UI to have more than 2 animation at the same time? A sequence of animation on the same widget? For example, changing position from bottom left, then to top left, then to top right, and then bottom right before ending at bottom left again.</p><p>Introducing multiple tweens.</p><h3><strong>Tween Sequence / Sequence of Tweens</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/1*xJ9aQkrCyqFEv718taWVgw.gif" /></figure><p>If you notice the above, the same widget moved from 1 position to a few more position before it is back again to the main point. Total points 5 points (including the starting point).</p><p>To achieve this, we will need to combine tweens in different intervals of the animation.</p><p>The TweenSequence class was created for this purpose, providing this functionality out of the box.</p><p>The TweenSequence works by providing a set of TweenSequenceItem which consist of a Tween and a weight. The weight will determine how much time each tween will be allowed to run during the duration of the animation.</p><p>The above example can be done by the following code:</p><p>Let’s break down the code.</p><p>The object wandering1CubeAlignmentAnimation is an Animation&lt;Alignment&gt; type of instance class. Why Alignment? Because we want to have the widget position to change and Alignment comes with helpful positioning such as Alignment.bottomLeft.</p><p>The TweenSequenceItem is basically an item which holds a tween and a weight. The weight here is all the same which is 1.0. You can specify the weight to be larger, smaller or same for all. The purpose of weight is basically to control which item (TweenSequenceItem) to have slightly longer playing animation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*iLOVSP2SheV5_oHwp9Bszw.png" /></figure><p>The above code shows how the UI part is been done.</p><p>I hope you gain some useful info and have some fun following the example on staggered animation. With strong foundation, in this case of animation, it is important to understand the core and basic first before designing a real application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*P9YqogmGy4BQ3X0VGhJMRg.gif" /></figure><p>Feel free to leave comments and feedback. The whole source codes are available <a href="https://github.com/KenAragorn/flutter_app_animation">here</a>. Cheers.</p><p><a href="https://www.twitter.com/FlutterComm">JavaScript is not available.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c80a529d30e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/flutter-animation-understanding-the-core-of-staggered-and-sequence-animation-2c80a529d30e">Flutter Animation — Understanding the core of Staggered and Sequence Animation</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Web — Readiness for the world]]></title>
            <link>https://medium.com/@kenaragorn/flutter-web-readiness-for-the-world-65a480d7c660?source=rss-38a153c91705------2</link>
            <guid isPermaLink="false">https://medium.com/p/65a480d7c660</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[flutter-web]]></category>
            <category><![CDATA[responsive-web-design]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Ken Lee Chiaw Huat]]></dc:creator>
            <pubDate>Mon, 20 Jan 2020 18:59:19 GMT</pubDate>
            <atom:updated>2020-01-22T09:58:57.869Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter Web — Important Info and Useful Tips</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fh1EIjm9O442dN9lGUMfQQ.png" /></figure><h3><strong>Introduction</strong></h3><p>Flutter has been pushing hard for making the framework even greater by allowing us to use the same codebase deployed on iOS, Android, macOS, Windows and the Web — all from a single codebase.</p><p>Although as of now, Flutter Web is still in beta mode and we can only try it out if we used master channel, it doesn’t mean that it is not ready to be used, in fact a number of <a href="https://verygood.ventures/flutter-web">companies</a> have created Flutter Web for their product.</p><p>In this article, I will share my thoughts on it, after creating a revamped personal portfolio website of mine using Flutter Web.</p><p>Personally, web is not my strong field vs mobile and desktop development. Web is just, umm, different. However, with Flutter, creating a website is like setting a different build target, in which the same codebase using just Dart to handle the logic, animation and layout in Flutter mobile app development can now be applied towards Flutter web development.</p><p>I used to build Servlet, Angular and React sites as CMS tools for some of my previous mobile apps project. However, given a choice, it will be good if we can use the same programming language used by Flutter which is Dart, or even better if we can use the same codebase. That means, I only focus on one language here, instead of HTML + ES6/7 + CSS combinations such as in React.</p><p>However, as enthusiasm as I want to be, Flutter is not 100% perfectly optimized for all web browsers and most likely it won’t. Still, I think it is good enough for simple website, portfolio and even internal intranet web apps usage.</p><h3><strong>Features that are important but missing from the current Flutter Web</strong></h3><p>To be fair, Flutter for web is still in beta mode. Before stable release, things will most likely change, and Google aims to make it better and more stable. As I mentioned earlier, it doesn’t mean that companies and individuals can’t proceed with building simple website, portfolio site and internal web apps with it. However, at this point of time, the following features are missing and hopefully can be add on in the following releases:</p><ul><li><strong>Support for mouse hover and focus</strong></li></ul><p>There is no mouse hover event handling available and currently we have to override MouseRegion and InkWell widgets, and then lastly, we need to update the index.html to include additional body id. Here is the sample code from my portfolio site.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*u8tzbTYcBPdWWHSdxnAOxA.png" /><figcaption>The index.html. Here I added the body id.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*k5xzCBTQ7BPEOVhBJvZXbA.png" /><figcaption>A separate class, created and it will trigger a cursor with pointer when the method onHover was used.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*s7hYNPLLQAaVmTqOjXCaOA.png" /><figcaption>This is the final widget class that reference to the above and then all our widget UI that need hovering control, we must use this guy.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*YfXEdtKQ0ZEa6SyyFFa3rQ.png" /><figcaption>Just an example of how to use this new InkWellMouseRegion widget.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*D7T3X5Tqdnyg3mvy44m6DQ.gif" /><figcaption>The result from above code</figcaption></figure><ul><li><strong>Support for more plugins such as location and file access</strong></li></ul><p>At the moment, officially, only a few plugins are supported for Flutter Web. Share Preference is 1 of it, and Firebase too. However, there are others useful plugins are not fully ready for the web — yet.</p><ul><li><strong>Browser support</strong></li></ul><p>As of now, Flutter Web supports Chrome and Safari browser, plus several Chromium and Safari based browser. Others not listed here such as Firefox are on the roadmap.</p><ul><li><strong>Text and RichText widget text content are not selectable</strong></li></ul><p>1 of the most common stuff for web user is the ability for them to highlight selected text content and then copy it. However, out of the box, Flutter do not provide such features out of the box.</p><ul><li><strong>Multi-line text editing is not working</strong></li></ul><p>In browser, it is quite common to have multi-line text editing and Flutter Web doesn’t have any answer for this. So, if you’re designing a web system that allow text area, either a change of design such as splitting the text area into a few text widgets or wait for official solution.</p><ul><li><strong>Browser forward button is always disabled</strong></li></ul><p>Although there is solution for handling browser back button, however, there is no solution yet for browser forward button. The forward button is always disabled.</p><h3><strong>Other Useful Tips for the Web</strong></h3><ul><li><strong>Layout builder widget is your best friend</strong></li></ul><p>Layout Builder allows full control on how your site should behave for different width and height. The following code will give the better understanding of the usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*lAzcxf4t11BHBpqTldAo7Q.png" /></figure><p>Although the code can be better, but this give you a better understanding on how we can use Layout Builder widget to build our system. Basically we used this widget to automatically adjust the UI based on the screen width and height. It will only rebuild when the condition is fulfill.</p><p>For example, if the max width detected based on the browser is above 800 pixels, it will rebuild only the _buildScaffoldDesktopArea section and won’t touch the _buildScaffoldMobileArea section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-B4E7cD8070lR2lNzS9Jiw.gif" /></figure><p>With the above sharing, below is the live demo of the portfolio site I created for myself using Flutter Web. Actual link: <a href="https://kenaragorn.github.io/#/">https://kenaragorn.github.io</a>/.</p><h3><strong>Conclusion</strong></h3><p>As I shared in the beginning, Flutter Web is still in beta, and personally I felt for simple site, no issue of using it to create the site. However, if you expect a full fledge web technologies such as React and Angular, it is still very far away. The overall user experience on site developed by Flutter Web is very much mobile app feelings.</p><p>Still, I do hope the above insights and tips will be useful for those keen to explore and try out Flutter Web. Cheers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65a480d7c660" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Push Notification with Firebase Cloud Messaging (FCM) and Routing to Specific Screen]]></title>
            <link>https://medium.com/@kenaragorn/flutter-push-notification-with-firebase-cloud-messaging-fcm-and-routing-to-specific-screen-b065742f2e5e?source=rss-38a153c91705------2</link>
            <guid isPermaLink="false">https://medium.com/p/b065742f2e5e</guid>
            <category><![CDATA[push-notification]]></category>
            <category><![CDATA[firebasecloudmessaging]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[firebase-cloud-functions]]></category>
            <dc:creator><![CDATA[Ken Lee Chiaw Huat]]></dc:creator>
            <pubDate>Mon, 22 Jul 2019 10:21:05 GMT</pubDate>
            <atom:updated>2019-07-22T10:21:05.010Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9CVQBWyf-mD9FUXqY6GVVw.png" /></figure><p>For this topic, I will cover the initial step such as what are the configurations and code that needed to be put in place in your Flutter project as well as steps needed on the Firebase dashboard. Then, we will proceed with the coding part on Flutter focusing on Android platform on how to receive message from FCM. We will then make additional code and changes to test on how we can navigate to different screen on Flutter app based on the content of the message received from the FCM.</p><p>In real world system, most of the time there is a backend system that running to support the front end app. This include pushing specific data that contains info that require the front end system to display in the right section of the app.</p><p>Let’s start by creating a new flutter project.</p><p><strong>Setting up FCM dependency on Flutter project</strong></p><p>In your pubspec.yaml file, you will need to add the firebase_messaging dependency for FCM as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*y_GoXh_LEDSmeu-k1FsVcw.png" /></figure><p>Then, get the package. As I’m using Android Studio, this can be easily done by clicking the pop-out upon adding the above dependency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Z_PmP6_PDJdMRFS8cFPGng.png" /></figure><p>Assuming no error, proceed to the next step.</p><p>Your version of firebase_messaging may be different; you can double check this at firebase_messaging library at pub.dev — Dart packages location.</p><p><strong>Setting up Firebase for Android</strong></p><p>First, assuming we don’t have a Firebase project created, go to <a href="https://console.firebase.google.com/?pli=1">Firebase Console</a>. Create a new project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*DANAx-w-noVhr6BBi65sTg.png" /></figure><p>Enter the name of your project, and follow the screen guide to complete this step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*-FIiJGm690j_NPat745Jiw.png" /></figure><p>You should see a similar screen as below once the project has been successfully created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*_5P3Mjub3dWCFJv10BobEw.png" /></figure><p>Next, we will proceed to the Grow section (left navigation), expand it, look for Cloud Messaging. Click on the Android symbol that appear (refer below — circled in red).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*g4ZtMAetQQ-_8EwlvteB-A.png" /></figure><p>Upon clicking the Android icon, the following screen will appear. You are required to provide the Android package name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*wBOA0bEPbkVBS4GHeCGthw.png" /></figure><p>For the Android package name, you need to go back to your Flutter project, look for AndroidManifest.xml located at your project folder android/app/src/main. Open it, look for package and copy the value into the Firebase Android package name. Once done, click on the Register app button at the bottom of the screen.</p><p>Next, click on the ‘Download config file’ which you need to download the google-services.json and put into your project android/app folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*qkkOALPkPECPEpIbH4ufTA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*5R-4S6cdxszW27bD-gyGcg.png" /></figure><p>Once done, back to the Firebase dashboard, click on Next. You need to follow the additional steps to add Firebase SDK to your project gradle files.</p><p>First is the project level build gradle file located &lt;project&gt;/android/build.gradle where we need to add the google services class path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*SphqULxuVWrIRpd84CvCZQ.png" /></figure><p>This follow by app level build gradle file located at &lt;project&gt;/android/app/build.gradle where we need to apply the plugin for google services we added earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*9QC2vHOrh-CQjRD_WK7naw.png" /></figure><p>Next is to add the following &lt;intent-filter&gt; within activity tag to your &lt;project&gt;/android/app/src/main/AndroidManifest.xml. Add the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*N1RNr9UeqPjqUie9SdzSDw.png" /></figure><p>Sample of updated AndroidManifest.xml file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*VZ41-PwdnYyYIL89DEUJsQ.png" /></figure><p>And that is all needed for the configuration part for both project folder and Firebase side. Next is to the coding part.</p><p>Take note, the above steps are only for Android. Unfortunately, I do have an Apple ID, thus focus area is only for Android.</p><p>Now we are ready for the code part. The end result of the UI will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*Kk4X5duMcS9lvpSjojL1dw.png" /></figure><p>It will contain 2 bottom navigation bar items, in which the 2nd item called Notifications will contain a red color indicator when there is new push message received when the app is in foreground.</p><p>First, we create the main class. In my case, I called it PushMessagingExample class, which is a StatefulWidget type. For convenient, all classes created will be inner class inside the main.dart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*FH3YrDY3YIYu7o7gvjbl2w.png" /></figure><p>When the app is being launch, there is possibility the initial frame to get the token is empty. Hence, I putting a temporary text stored in _homeScreenText that will be used to display at the main screen.</p><p>As we will be having bottom navigation bar, I want to make sure that when there is new message from FCM, it will update the ‘Notifications’ item with a red color indicator. When user click on it, it will reset it back (and the red color indicator is gone). To do that, I will add this integer called _bottomNavBarSelectedIndex that will be used in the later code.</p><p>The boolean _newNotification is needed to display the red indicator on the Notifications icon when there is new FCM when the app is in foreground.</p><p>Last, the most important for this FirebaseMessaging — create an instance of it.</p><p>Next, we will need to override the initState method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Hd6tICuHrNvg8MDa1BFEWg.png" /></figure><p>The first part ‘_firebaseMessaging.configure…’ is needed. Here is where we can provide the code structure when the app received FCM message, how it should handle — when the app is in foreground, <strong>onMessage </strong>will be called. When the app is in background, <strong>onResume </strong>will be called and when the app is not in both foreground or background, <strong>onLaunch </strong>will be called.</p><p>As for iOS, there is additional code we need to put in place. Although I did mention in the beginning of this article, this is more for Android platform, I will just leave the code here — for future reference.</p><p>The getToken() method is optional, however is good to know that there is a method available to get the token — for this example, I will be getting it and display on the man screen.</p><p>The method _navigateToItemDetail as per the name hinted, is to convert the message return from FCM and then route it to the specific detail page on our app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*FrQMvH912HnnxRxoaZAwRg.png" /></figure><p>Now, there is a sub method called _itemForMessage which is specifically handling the conversion of the raw message from FCM to our local dart model/bean.</p><p>Create the inner class MessageBean and another method called _itemForMessage such as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*u1WJF4Q4n2SvbqYdQEUcgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*XJSFy7GlLmu0yUXp76XgPg.png" /></figure><p>Next, we will need to create the detail page that going to display the content of the FCM message. Here, we called it DetailPage and it is also a StatefulWidget class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*tuH1vMftw-GA-aTOOXDxiA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*IB26bSz72hiurLz2QXAC6A.png" /></figure><p>The final piece of the code section is we need to update the build method for the main class PushMessagingExampleState that contains the UI code to display the token, bottom navigation bar and the conditional expression code checking to handle the Notifications icon to show or not an indicator of new message arriving from FCM when the app is still in the foreground.</p><p>As the code is too long, refer to the GitHub link <a href="https://github.com/KenAragorn/flutter_firebase_push_msg/blob/master/lib/main.dart">here</a>.</p><p>Take note, to link the runApp with this class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*TytS1Lyi1LA4ajI9OxLZnQ.png" /></figure><p>Now we are fully ready for testing. Switch to your Firebase dashboard, go to Grow -&gt; Cloud Messaging, click on the ‘Send your first message’ button located at the center top.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*8SkoA2bBZ7E7WNUOTOSfAw.png" /></figure><p>Once clicked, you will reach the ‘Compose notification’ page. Provide some testing notification title and text message that you plan to send out to your Flutter app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*97eW18ZtPUumQ23m2nZTwg.png" /></figure><p>At the ‘Target’ section, under the user segment, select the package of the Flutter project that we just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*OoebNPnUSAEiQNZsyuRPRA.png" /></figure><p>Just click Next once one, however, at the ‘Additional options’ section, you need to provide the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*i2Tz5ZRF0wZ_Ii_UZpN-AQ.png" /></figure><p>Notice the custom data, we added the key-value pair of id, status, status and click_action.</p><p>The first 2 fields namely <strong>id </strong>and <strong>status</strong> is mainly data needed for our testing. As I mentioned earlier, we want to direct user to specific section and post — thus we need some unique identifier such as id and status. You can consider id as the primary key of the message and status is like an indicator to inform the app which section/page this id is for. For this example, the data is for Crime_And_Safety section with id of 2.</p><p><strong>FLUTTER_NOTIFICATION_CLICK</strong> which is something we all have to do. That note, this value must match what you specified in <strong>AndroidManifest </strong>file.</p><p>Save it as draft first. We will move to the Android Studio and run the app first. You can run it in emulator or at the phone, no issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*S10ST6oysSEVDRBD0s3xhg.png" /></figure><p>If there is no error upon running your app, you should be seeing the main screen as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*Kk4X5duMcS9lvpSjojL1dw.png" /></figure><p>We going to test few scenarios. For the first 1, lets test with when the app is running in the foreground. Back to your Firebase console, duplicate the same notification up to 4 as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*_vB92pfYh1zHxCSWExl3CQ.png" /></figure><p>Once done, while the app is still running in the foreground, mouse over to 1 of the draft notification is the list, expand the it and click on Edit notification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*WKILEcUqjhpSiKMX7ivoGA.png" /></figure><p>Once clicked, click on the Review and then follow by Publish. Now, in your app, you will notice the Notifications icon is now change and contains a red indicator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*YZSyDmHqcgq89GAZlo_B5A.png" /></figure><p>So, it works as the code we added earlier is to update the bottom navigation bar item to contains this red stack when there is a new FCM message coming in.</p><p>Click on the icon and it should reset it back to default view. Actual scenario is, when you click on the notification list, it should route you to a different page. But, we will not cover it here.</p><p>Next, click the Home icon on your emulator or your Android phone which will result the app going into background.</p><p>To test the next scenario, we will push another draft notification and we should be receiving it as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*yca0otxhJuc6k7lDx4RrXA.png" /></figure><p>Of course, when you single click on it, it should bring back the app to the foreground. Also, it should route you to the detail page of the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*JiSD07lxf8m1pXpxLC2b9w.png" /></figure><p>Now, if you kill the app and run another push notification, it should work too. The same behavior as above where the app will be launch, and then route to the detail page.</p><p>That is all, for the complete source code, please refer <a href="https://github.com/KenAragorn/flutter_firebase_push_msg">here</a>.</p><p>Thanks and I hope this can be useful for someone out there that want to find a working example of just receiving notification from FCM, but routing to the specific page based on the data receive.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b065742f2e5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Web aka Hummingbird: Step by Step Guide to Install and Setup Hummingbird in Windows 10…]]></title>
            <link>https://medium.com/@kenaragorn/flutter-web-aka-hummingbird-step-by-step-guide-to-install-and-setup-hummingbird-in-windows-10-5bd0d3c09f21?source=rss-38a153c91705------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bd0d3c09f21</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[hummingbird]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-web]]></category>
            <category><![CDATA[android-studio]]></category>
            <dc:creator><![CDATA[Ken Lee Chiaw Huat]]></dc:creator>
            <pubDate>Fri, 21 Jun 2019 13:12:08 GMT</pubDate>
            <atom:updated>2019-06-29T15:25:18.836Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Flutter Web aka Hummingbird: Step by Step Guide to Install and Setup Hummingbird in Windows 10 using Android Studio</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*HgW_03PxLGzpfCJdzsCIAA.png" /></figure><h3><strong>Introduction</strong></h3><p>At the recent Google I/0 2019 conference, Google announced the updated version of Flutter version 1.5 and the biggest announcement to this is the support coming from Flutter itself not just on Android and iOS, but also the web and desktop. That means, Flutter framework is now expanded to building the same system on the same code for multi-platform.</p><p>However, as of now, as this is still technical preview version, there are parts that require us as a developer to make some adjustment on our existing Flutter mobile app project. Also, if you are starting from a new project for Hummingbird, you are required to do a bit of manual work as they still working into making it easier for everyone. Thus, as of now, people that used to Android Studio IDE are require to make some changes with some third party plugin in order to create a new Flutter web project. Hence, this is the details step.</p><h3><strong>Steps by Steps</strong></h3><p><strong>Step 1: Dart SDK</strong></p><p>First, assuming you don’t have anything setup before in your Windows laptop, download the Dart SDK. Take note, is not needed if you just want to use Flutter for mobile development. However, for Flutter Web, you need it. Download and install the Dart SDK <a href="https://dart.dev/get-dart">here.</a> For convenient, just install using the Dart SDK installer for Windows.</p><p><strong>Step 2: Flutter</strong></p><p>Next, install Flutter. I noticed my older Flutter, even after I upgraded, there are some problem. Hence, I decided to start from scratch by renaming my older installed Flutter folder. Go to <a href="https://flutter.dev/docs/get-started/install">here</a> and download the Flutter for Windows. Follow all the instruction specified in the link.</p><p><strong>Step 3: Install Webdev package</strong></p><p>Webdev package is the package required to create a Flutter web project. To do so, run the following command:</p><blockquote>flutter pub global activate webdev</blockquote><p>Assuming there is no error upon running this command, you will notice that there is additional file called webdev.bat inside your flutter\.pub-cache\bin folder.</p><p><strong>Step 4: Update your path</strong></p><p>As part of the Flutter installation in step 2, you are required to update the environment path to include the flutter bin path. However, there are other path needed to be add.</p><blockquote>Dark SDK: &lt;your_installed_Dark_SDK_root_folder&gt;\bin</blockquote><blockquote>Webdev: &lt;your_installed_flutter_root_folder&gt;\.pub-cache\bin</blockquote><p><strong>Step 5: Setting up Android Studio</strong></p><p>As of June 2019, there is no direct plug-in or template to create a web project, instead you have to use third party plugin called Stagehand package that helps you to get your Flutter Web project set up. What is Stagehand? It is basically a Dart project scaffolding generator, just like Yeoman. Below are the steps require to create a Flutter Web project using Stagehand.</p><ul><li>Download, install and setup your Android Studio (if you haven’t)</li><li>To install Stagehand, run the following command:</li></ul><blockquote>Pub global activate stagehand</blockquote><ul><li>Once installed, next we can use it to create a project skeleton into your desired directory. For example, I want all my Flutter Web projects to be located at C:\Flutter Web Projects, in your terminal, CD to that path, then run the following command:</li></ul><blockquote>stagehand flutter-web-test-project</blockquote><p>The above will create a Flutter web project inside this folder. However, I prefer using Flutter Web template ‘Hello World’ provided by Stagehand as it helps to create all the needed files such as main.dart, lib folder and pubspec.yaml.</p><p>So, to create a Flutter web template project, here is the step:</p><p>Assuming you are still inside your Flutter Web Projects main folder, create a directory of your project. For example, let’s call it my-first-flutter-web. In your terminal, CD to the inside of the folder. Run the following command:</p><blockquote>stagehand flutter-web-preview</blockquote><blockquote>Then, follow by running pub get command.</blockquote><p>The above command will create all the needed must have files such as main.dart, pubspec.yaml and index.html into your project automatically.</p><ul><li>Once done, open this project using Android Studio. Inside the Android Studio terminal, run the following command:</li></ul><blockquote>webdev serve</blockquote><p>Open your browser, go to <a href="http://localhost:8080/">http://localhost:8080</a> and you should see Hello World in the center. You should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*39S69_8W1PLY1jfUFngBRA.png" /></figure><p>Tips: To have the famous ‘hot-reload’, replace the above command with the following:</p><blockquote>webdev serve — auto restart</blockquote><p>Please take note, the ‘hot-reload’ is currently for ‘stateless’ support only. What that means is that, application state will be lost on reload. I believe it not a main issue for now, but I hope in near future they can offer ‘stateful’ hot-reload for the Hummingbird.</p><p>Thanks for dropping by, do hope this short article will help some of the Flutter Web learner out there. Cheers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bd0d3c09f21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recommended UI design flow of a mobile app for solo developer]]></title>
            <link>https://medium.com/@kenaragorn/recommended-ui-design-flow-of-a-mobile-app-for-solo-developer-5b8dcefc2b64?source=rss-38a153c91705------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b8dcefc2b64</guid>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[adobe-xd]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Ken Lee Chiaw Huat]]></dc:creator>
            <pubDate>Fri, 07 Jun 2019 07:20:52 GMT</pubDate>
            <atom:updated>2019-06-07T07:22:37.165Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vjLtUqDs6jXUXcntazkDig.jpeg" /></figure><h3><strong>Challenge</strong></h3><p>As part of my journey on building a community mobile app for my town, 1 of the area that matter the most is the user experience and UI. As this a solo person journey of my own, apart from technical involvement such as coding the backend system and server hosting, I needed to build the mobile app UI and the flow.</p><p>I decided to take this as an opportunity to train my visual design skills and learn the design process by creating a mobile app user interface.</p><h3><strong>Design Process</strong></h3><p>After reading and spending enough time on learning from those more experience people in the UI design, I decided to follow most of their design process and add in some of my own.</p><p>My design process that I come up with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*bhoY_895JvtZW22y51sYkA.png" /></figure><p>Take note, this project focuses on UI, not user experience (UX), thus, there is no user research, information mapping, etc. It is based on own self exploration, to at least have a more focus on the UI design process and finding the right design process commonly used out there and try to come out something similar for my own.</p><h3><strong>App Concept</strong></h3><ol><li><strong>Problem definition</strong></li></ol><p>I see there is something missing from the community group for my town area. There are quite number of repeating questions that people is asking within the Facebook Group that created by the town community and generally, most is related to:</p><ul><li>Is there any contact for this or that?</li><li>Any new place for food hunting?</li><li>Any events recently?</li><li>What is the latest good or bad news announcement related to us?</li></ul><p>Although those information is there somewhere within the Facebook group side and some they can easily Google it, however, the real missing part here is that the information is pieces everywhere. Also, some of information is not really confirm or related.</p><p>2. <strong>Value proposition</strong></p><p>This is similar to the elevator sales pitch scenario. For our case here, this is an app that helps the local community to find latest news about the town development and amenities in a single place easily and verified.</p><h3><strong>User Personas</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*HQXV2psRHRUGeqoOUD9HcA.png" /><figcaption>1st group of persona</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*i_TOrNU7aIcf1S_aRYJgEw.png" /><figcaption>2nd group of persona</figcaption></figure><h3><strong>Wireframing</strong></h3><p>After defining and getting the clear understanding of the user goals and their behavior, I listed some of the key features needed of the app. This will be helpful to create a low fidelity of the wireframes.</p><ol><li>Latest events, new openings and happenings such as new dining places, shops, events, etc. (group by category, type, this week, this weekend, next month)</li><li>Search features (keyword)</li><li>Details of the event, places, address and how to go (from current location)</li><li>Allow user to add an event to my reminder list — remind me when the event is about to start a day before</li><li>Allow user to bookmark a place — favorite list for quick access (especially food places)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*PpQU0zgKTVf2Xpj7Wg1aoA.png" /></figure><p>The above is just the sketch of the wireframe done from the paper. Once this low-medium fidelity is ready, I will move on to the next step.</p><h3><strong>Setting Up Mood Board</strong></h3><p>What is mood board? Mood boards are physical or digital compilations of images that are pulled together to convey particular theme, feeling or style. How can it benefit especially in design?</p><p>Mood board are the perfect way to start visualizing and planning a creative project. Instead of staring at a blank page, you can literally start collecting content right where you are.</p><p>Why it is important to have a mood board? Few key benefits:</p><ul><li><strong>To get inspired </strong>-&gt; Mood-boarding is a good way to find ideas and inspiration. Beautiful photos and illustrations helps to find the right feelings and style.</li><li><strong>To find a right color palette</strong> -&gt; Mixing different images in different colors on a board helps us to experiment with color palette even if UI elements are not ready yet.</li><li><strong>To find a style for a design</strong> -&gt; Sometimes clients don’t have any directions or preference of style of the design. Thus, this require designer to help with the client. To see how one or another style works, there is no need to build a detailed prototype for each of them. Create a mood board with different combination of textures, experiment with types of presentation, test fonts and colors. This is proven to be effective, convenient and faster options if to compare with changing prototypes one by one.</li></ul><p>For this, I created 2 mood boards that are quite different feelings and for different groups. One is colorful, fast-paces and exciting; however, the second one is calm, peace, stable and minimal feeling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*LkM19uFH641zxvBTwe6yww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*Qqjwc9oGmBRSdmTTe8EDdg.png" /></figure><p>Based on the mood board options, we then can check with the personas and if can, get real users that fits well with the personas created earlier. Some designers prefer to convey the above mood board to tile style design as it is more breakdown of each version of the mood board into visual design elements such as button styles, color palettes and fonts. This will help to bridges the gap between the mood board and the wireframe.</p><p>For my case, as this is my own internal project and don’t have an actual client for it (yet), the mood board is sufficient for me to proceed with prototyping as I can see clearly the color palette, fonts and style of the visual elements.</p><h3><strong>Prototyping</strong></h3><p>I think the part that are missing is the font style — typography. This can be collected from the mood board activities and then from there, we can apply it to the prototyping section. As I utilizing Adobe XD features to do the grouping of elements for reusable purpose, the same can be apply for the font style.</p><p>So, this is the approach that I find it sufficient and not too much of hassle, but at the same time provide good enough design process for me to proceed. Style will come and goes, hence is good to have a process in place to ensure where there are changes needed, we have a process to support it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b8dcefc2b64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A simple guide to Java Spring Boot RESTful app on the Google Cloud Platform using App Engine…]]></title>
            <link>https://medium.com/@kenaragorn/a-simple-guide-to-java-spring-boot-restful-app-on-the-google-cloud-platform-using-app-engine-59f2ac921f28?source=rss-38a153c91705------2</link>
            <guid isPermaLink="false">https://medium.com/p/59f2ac921f28</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[google-app-engine]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Ken Lee Chiaw Huat]]></dc:creator>
            <pubDate>Fri, 15 Mar 2019 11:09:21 GMT</pubDate>
            <atom:updated>2019-03-15T11:09:21.226Z</atom:updated>
            <content:encoded><![CDATA[<h3>A simple guide to Java Spring Boot RESTful app on the Google Cloud Platform using App Engine Standard + Cloud SQL for MySQL</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*GgHaHMTpJguSHVc7vth6tg.png" /></figure><h3><strong>Background &amp; Introduction</strong></h3><p>As part of my journey to building a good foundation in Google Flutter and creating a useful mobile app utilizing this new framework for the community in my town, I need to have a backend system and a database.</p><p>Instead of wasting time to explore new technologies, I decided to utilize my preliminary Java background knowledge to build a backend system and implement Java Spring Boot to create a core RESTful API for a mobile app. As this is a self-initiative and to keep my cost lowest and thus MySQL is my chosen database for storage.</p><p>Things was fine, in fact within a short period of time, I have created most of the RESTful API. I think it is a good time to migrate it to a proper cloud server and to move forward. The first cloud services that come to my mind is Google Cloud because of the below reasons:</p><p>· Cost wise it is more cheaper</p><p>· They have Google App Engine Standard — a fully managed server-less application platform and free with sufficient quota for my project</p><p>· With 12 months and USD 300 free credit to get started easily — so I can use it for my cloud database (take note, the ‘always-free’ option for storage is only available in US — so for performance reason, I decided to utilize the Asia region with free USD 300 credit). The application that I am building is going to be located in Malaysia. For more info please click <a href="https://cloud.google.com/free/">here.</a></p><h3><strong>Challenges</strong></h3><p>Well, at first, I thought it would not be that too tough since I have get my code ready. All I have to do is to find an official deployment guideline and apply it to my project. If there is any problem, it should be minor issue and I am assuming the documentation is always clear and updated.</p><p>However, to a certain extent it is true until you face with the nightmare of different versions and plugins. After going through a lot of posts and getting a helping hand from the Internet (especially Stack Overflow), I have decided to share it with everyone on the steps that I used.</p><h3><strong>Requirements</strong></h3><p>Before we begin, below are the assumptions on things that you need to have upfront.</p><p>· Java, Spring Boot and Maven installed on your machine</p><p>· A working or sample Java project connecting to local MySQL database</p><p>· A Google Cloud Platform account (GCP) with billing activated (with credit card info)</p><p>· GCloud SDK installed on your local computer with initialization</p><p>· A new or existing Java Spring Boot project</p><h3><strong>Additional Notes</strong></h3><p>As I started building my Java Spring Boot RESTful services from <a href="https://start.spring.io/">https://start.spring.io/</a>, it was a bit late to know that, Google actually has provided plugins to facilitate using GCP services from within Spring. Thus, if you are starting from a new project that want to fully utilize GCP, I strongly suggest you to use the repo from Google’s repo as your new project base (and not from <a href="https://start.spring.io/">https://start.spring.io/</a>). That means creating a needed Spring Controllers that is required on the base of this repo. The link is <a href="https://github.com/spring-cloud/spring-cloud-gcp/tree/master/spring-cloud-gcp-samples">here.</a></p><p>However, if you already have a working Java Spring Boot RESTful project running locally and need to migrate it to the Google App Engine Standard, no worry, this is the main reason why I am writing this article that contains useful information that I have gathered from the internet.</p><h3><strong>Step 1: Download and Setup Cloud SDK</strong></h3><p>Firstly, please install Cloud SDK or download it from this official <a href="https://cloud.google.com/sdk/">link.</a> Once it is installed, open up your Window command prompt to initialize Google Cloud by using the command gcloud init</p><p>What does this command do is it will open up a new browser window and request you to login into your Google Cloud account.</p><p>Next is to create an App Engine within the current Google Cloud project. You can either do it from the Google Cloud Console or from the command prompt by using the command gcloud app create.</p><p>Although we are not required to have an App Engine created now, but our ultimate goal is to deploy everything into Google Cloud, so we can set it up first to ease the process in the future.</p><h3><strong>Step 2: Migrating your local MySQL database to Google Cloud SQL — MySQL</strong></h3><p>Follow these instructions to set up a Google Cloud Project with billing enabled. The link to the instruction are <a href="https://cloud.google.com/sql/docs/mysql/quickstart">here.</a></p><p>This follow by creating a new Google Cloud MySQL instance from the <a href="https://console.cloud.google.com/sql/instances">Google Cloud SQL dashboard</a>. On the same page, click on the ‘Create Instance’ and this will bring you to a sub section that allow you to decide on the database engine type. Select MySQL. Provide require information such as instance ID, root password (if you need it, please remember by writing it somewhere), region and zone. Different region and zone will have different cost.</p><p>For my case, I know the user of the application that I’m building is 99% from Asia specifically Malaysia, so I will choose relevant Asia region. Basically, choosing a zone that is closed to the services, and please take note, you cannot change the region once you have set it. For zone, you can change it anytime.</p><p>Once the database instance is created, click on it. Next we need to create the database and this can be done by clicking ‘Databases’. Once inside, click on the ‘Create database’ button located near the left bottom side of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*sFwYVACnWPjyTK9epSA8PQ.png" /><figcaption>A snapshot from my Google Cloud SQL dashboard — take note on the Create database location</figcaption></figure><p>Follow the guide provided on new database creation. Next step is to export your local MySQL database and then import it to this cloud database. To do that, you can either use the mysqldump command or through MySQL Workbench to export out your local database. For official guide, click on this <a href="https://dev.mysql.com/doc/workbench/en/wb-admin-export-import-management.html">link.</a></p><p>Once you have successfully exported out the SQL file, you need to upload it into Google Cloud Storage — bucket. Only from there, you can import into your created Google Cloud SQL MySQL database.</p><p>For more info on how to create a storage bucket, refer to this official <a href="https://cloud.google.com/storage/docs/creating-buckets">link.</a></p><p>Next, go back to your Google Cloud SQL dashboard, select the database and click on the ‘Import’ link. This will bring you to another page that allow you to import your previously extracted SQL file into the selected database.</p><h3><strong>Step 3: Authorize the database for Google App Engine access</strong></h3><p>Once you have successfully imported all the tables and require data (if any), we need to make sure the selected database allows any of the App Engine in the same project to access the database. This can be easily done by accessing the Google Cloud SQL dashboard, select the database that you just created, look for the keywords ‘App Engine authorization’. Enable it for all apps in this project are all authorized to access the selected database.</p><h3><strong>Step 4: Making your project compatible with Java on Google App Engine Standard</strong></h3><p>Please take note, there are 2 types of Google App Engine — Standard and Flexible. For my case, I need to make sure the costs are the lowest (or free) and able to support Java 8 (since my code is compatible up to Java 8 — for now).</p><p>For more information, please click on the link <a href="https://cloud.google.com/appengine/docs/the-appengine-environments">here.</a></p><p>For the start, to make the project compatible and able to run in Google App Engine Standard environment, make the following changes to <strong><em>application.properties</em></strong> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3I9ziNiAb1kavLKz9Nan5A.png" /><figcaption>Change the top 4 items according to your Google Cloud SQL profiles</figcaption></figure><p>Next, we need to create a new Java class called ServletInitializer and this file must be located the same place as your Spring main application file (the one that contains public static void main).</p><p>For my case, my main application class file is called SetiaAlamCommunityApplication and below is the sample of my <strong><em>ServletInitializer</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*PPUrz5idLlEDyKecXD5guA.png" /><figcaption>Snapshot of my ServletInitializer</figcaption></figure><p>Next, we will need to create a file called <strong><em>appengine-web.xml</em></strong> under the project src/main/webapp/WEB-INF folder. The content is as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*9sUq4Jtu_1nhUZFswKDm9A.png" /><figcaption>Snapshot of my appengine-web.xml</figcaption></figure><p>Once done, create the file called <strong><em>logging.properties</em></strong> under the src/main/resources folder. As for the content, refer below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*6bT4edc4sxjDU8RcN4ZRSg.png" /></figure><p>The reason for to add this file is that, for Spring Boot version &gt;= 1.5.6, you may run into out of memory errors on startup, the work around issue is this.</p><p>Next, we will need to update the <strong><em>pom.xml</em></strong> content according. If you generate a Spring Boot project from <a href="https://start.spring.io/">https://start.spring.io/</a>, make sure you switch to the full version view of the initializer site, and select WAR packaging. This is because, Google App Engine expect your Java application as a packaged WAR file.</p><p>If you have an existing JAR packaging project, you can convert it into a WAR project by modifying the package session (<strong><em>pom.xml</em></strong>):</p><blockquote>&lt;packaging&gt;war&lt;/packaging&gt;</blockquote><p>Also, once the packaging changed to war, it will expect your project to have the ServletInitializer which written above in the project folder.</p><p>Next, Google App Engine Standard deploys the WAR into a Jetty server. Spring Boot’s starter includes Tomcat by default. This will surely introduce conflicts. Hence, we need to exclude Tomcat dependencies:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*eDF2YvUCU0QSpL2KllXVmQ.png" /></figure><p>Then, do not include the Jetty dependencies, however we must include the Servlet API dependency:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*9ejqtN8CnKsHIzlkB1b_Ww.png" /></figure><p>Also, add the Google App Engine Standard plugin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*7FD_lXFhL3p_88Jm8J0wkg.png" /></figure><p>Then, we need to exclude JUL to SLF4J bridge as this is Spring Boot’s default logging bridge which will conflict with Jetty’s logging system. To be able to capture the Spring Boot startup logs, we need to exclude org.slf4j:jul-to-slf4j dependency. The easiest way is to set the dependency scope to provided, so that it won’t be included in the WAR file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*dEA7ao7ERiefD0Ujy62nXQ.png" /></figure><p>Next, since we have database that going to be migrated to Google Cloud SQL using MySQL, we will need to include the dependency of it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*oCKgOmw-dG2u05Ox1dT6NQ.png" /></figure><p>Most of the case, you will be using Hibernate plugin to help with the database query and connection. Thus, we need to include the following Hibernate dependencies:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*mxiIw1mJSoYi6s6EHhrJUw.png" /></figure><p>After that, just need to add this few more dependency and plugin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*xTrzLn7KDAdyxwx7Fe-dBw.png" /></figure><p>Additional plugin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*ht7AJIGxEB39xkVdPGOlYQ.png" /></figure><p>Then, we need to make sure the web.xml is compliance to 3.1 (although they do support version 2.5). Please take note, previously I am stuck when my web.xml is using version 3.0. The worst part is there is no useful error message to inform me that web.xml need to be 3.1 or 2.5. A bug has been reported <a href="https://issuetracker.google.com/issues/127881574">here.</a></p><p>For 3.1, please refer to the following example (take note on the xsd and version):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*McCmdgFWjaiE5sENHoK2vw.png" /></figure><p>After that, if you are using Eclipse, please make sure the project facets (right click on your project, select Properties, look for Project Facets) contains App Engine Java Standard Environment with JRE 8 and the ‘Dynamic Web Module’ is 3.1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*3m9FZxBJxxeY8FYh9giPPw.png" /></figure><p>If you have problem changing the ‘Dynamic Web Module’ version, alternatively you can make the changes directly to the file that represent this facets setting. Locate the file called org.eclipse.wst.common.project.facet.core.xml that are available at &lt;Your-Project-Root&gt;/.settings/.</p><p>Modify the version for jst.web property to 3.1. Again, this is needed because as of now, Google App Engine Standard only support 2.5 and 3.1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*FY2DBHkQoocDRgBrCxQS3Q.png" /></figure><p>Also, make sure you are using Java 8.</p><p>That’s all. To sum it up, you will need the following updated:<br>• pom.xml<br>• web.xml<br>Plus, to have the new files below added to the project directories:<br>• appengine-web.xml<br>• logging.properties<br>• ServletInitializer.java</p><h3><strong>Deploying locally for testing</strong></h3><p>It is important to ensure the setup is working fine and it can run locally without any problem. That mean, the application can connect to Google Cloud SQL MySQL and your RESTful API can be access from yours prefer client such as Postman or browser.</p><p>As I’m using Eclipse with Google Cloud Tools (version 1.8.0) and Spring Tools 3 (aka Spring Tool Suite 3), I will use Eclipse approach on how to deploy locally and test it. If you are interest on using Eclipse to deploy your project into Google Cloud, click on this <a href="https://cloud.google.com/eclipse/docs/">link</a> for the official instruction.</p><p>Once you have fully setup your Eclipse project to be Google App Engine Standard project, you can run it locally by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*2Z1-PeJz65TG5FS2z-b5mg.png" /><figcaption>Right click the project and look for the Run As option</figcaption></figure><p>Alternatively, you can run it without Eclipse by command: mvn appengine:run</p><p>Of course, first you need open up your command prompt, you need to go to the root folder of your project and run the command shared above.</p><p>Upon successfully running it as App Engine (through Eclipse) or by the command shared above, make sure there is no error warning and the Spring boot logo is displayed such as the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*EdDADn00d5hZUCdkzyDUbw.png" /></figure><p>You can then proceed to test your RESTful API. For example, I have the main class as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*SpesIF2j2bTqqXbhVArXGQ.png" /><figcaption>Snapshot of my Main Application class</figcaption></figure><p>And one of my exposed RESTful API is as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*jbXtzirecVzxxqB6f4_X4w.png" /><figcaption>1 of my Rest Controller</figcaption></figure><p>To test it, all I have to do is:</p><p>· Open up browser and visit <a href="http://localhost:8080/test2/happenings">http://localhost:8080/test2/happenings</a> or</p><p>· Use third party tool such as Postman to perform a GET request to the same URL share above</p><p>If everything works well, it should return no error such as file not found (404), and returning expected response back it should base on your RESTful API. For example, my API is always returning JSON data list.</p><h3><strong>Deploying to Google Cloud App Engine Standard</strong></h3><p>Next is to deploy the local app engine compliance project into the Google Cloud environment. Please make sure only when it can run locally without any issue, then only we can start deploying the same application to the Google Cloud App Standard Engine.</p><p>You can use the Eclipse ways by right clicking on the selected project, select ‘Deploy to App Engine Standard…’. Alternatively, you can use the command mvn:appengine:deploy</p><p>If you prefer the command way, make sure you are running it from the root path of the project.</p><p>To test out, visit <a href="https://your-project-id.appspot.com/">https://YOUR-PROJECT-ID.appspot.com</a></p><p>In which the ‘YOUR-PROJECT-ID’ is the Google Cloud Project ID. For example, my project name is called Sample Restful, Google will use this and create the project id such as ‘sample-restful-1531259811321’.</p><p>That is all it takes to build your Java application that utilizing Google Cloud SQL MySQL and deploy it into Google App Engine Standard.</p><p>Enjoy and I hope this sharing will be helpful for you. Cheers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59f2ac921f28" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>