Trick To Improve Flutter Code

Using Keys

Every widget in FLutter can have a key. Most of your widgets don’t need a key, especially stateless widgets, so you don’t have to accept Key.

The Key usually used to determine each item in the ListView.

Why each item in the ListView need a key?


Widget Lifecycle and Context

Widget Lifecycle

Widget Lifecycle

You can read this link to get more information about the widget lifecycle. Many blogs wrote about it. So now, I just want to mention some major information.

Stateless Widgets

  • Stateless Widget only runs the constructor function and build() method.

Stateful Widgets

The constructor function is not a part of the life cycle. But it calls first.

createState()

  • A BuildContext is assigned to the state. (The detail about Context below)
  • Used to initialize data that relies on a specific…


How build & paint on screen?

To answer this question, we have to know about widget trees, element trees, and render trees inside Flutter.

Widget Tree, Element Tree, Render Tree.

What you work with is a widget tree. But actually, when you run an app, Flutter will create a widget tree, element tree, and render tree.

Widget Tree — Element Tree — Render Tree

Widget Tree

  • Widget tree is constantly changing basically whenever you call setState.
  • Whenever the build methods get executed, Flutter rebuilds that widget tree, whilst that happens relatively often.
  • It links widgets with rendered…


This topic I only want to focus on the importance configuration. You can read more at https://kafka.apache.org/documentation/#producerconfigs to get more information.

ACK

ACK = 0

  • You won’t know the broker down, so the data will be lost.
  • This configuration only for the data which still be okay when It lose the messages. Ex: log, metrics, GPS tracking.
  • If an ACK is not received, the producer may retry.
  • If the leader partition down…

Apache Kafka is an open-source stream-processing software platform developed by LinkedIn and donated to the Apache Software Foundation, written in Scala and Java. The project aims to provide a unified, high-throughput, low-latency platform for handling real-time data feeds. (Wikipedia).

Brokers: is a Kafka Server. A Kafka cluster is composed of multiple brokers.

  • Connected to any broker, you will be connected to the entire cluster.
  • Each broker has some kind of data, not all data.
  • Each broker contains certain topic partitions.
  • A good number of the broker is 3 for a cluster.


At this part, I will describe how android work with your activity to draw on the screen.

If you create too many things to do for render, the system will be drop frames and screen will be laggy or janky. It happens regularly when a user dragging a list view or trying to type in some data.

This is what the user easy to see and complain about.

2. Rendering pipeline.

Rendering pipeline is broken up into two key…


Nowadays, we can create an Android app so easy. But, not too much developer think about performance or performance is the last thing on their minds.

  • Each user likes or don’t like some feature but all of them like a good performance.
  • Users notice bad performance before any other features in your app.
  • Bad performance always is the most reason for bad reviews on Play Store.


Gradle is an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven for declaring the project configuration. (Wikipedia)

Gradle Build Scripts

Sample of Gradle task

After look this example. Is this a JSON format or Python code? The answer is that Gradle scripts are written in a special purpose build language provided by Gradle. It sits on top of a generic scripting language called Groovy.


App Manifest

The web app manifest is a simple JSON file that gives you the developer the ability to control how your appears to users in areas where they would normally see apps and more importantly how it behaves when it’s launced from the home screen. This is an example from Google:

HTTPS

HTTPS helps prevent intruders from tampering with the communication between your pwa and your user’s browser. GitHub page and Firebase both support static hosting over HTTPS and the Google Cloud platform offers app engine. Which can support HTTPS and is useful if you need any back end logic. Firsbase’s hosting…


Service Worker

What is Service Worker?

Service Workers is a JavaScript file that is run by your browser in the background separate from your webpage and handles events fired either by the browser or your webpage. Since it’s run in the background it doesn’t need the webpage to be open and doesn’t show any markup.

How does a Service Worker work?

Kim Quy

Travis

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store