- Interactivity:
Flutter has provided state class which helps developer to make the UI interactive. SetState method of stateclass is used to change the UI component at run time depending on the user’s actions.
Setstate method calls the build method, which as a result builds the entire screen to reflect the changes.
-
State Management:
State management tools are provided by flutter which helps to maintain the state of the data throughout the widget trees. Flutter has provided many options like Bloc, Provider etc. I chose Provider as it is popular among the developers and recommended by Flutter itself.
In Android Native the state of the data can be managed using “SavedInstanceState” methods whereas Flutter uses different mechanism.
Understating the State management in flutter was quite hard initially because the app is build using the different widgets and the state management works throughout this widget tree.
-
API Integration and Web calls:
Implementing APIs was the major task in this app as employees can apply the leaves and daily timesheets and can also view the status of the same. To accomplish this, the http package is provided by flutter for implementing web calls. This package provides its own methods for GET and POST API calls which simplifies the implementation.
Flutter has also provided async method to execute asynchronous tasks effectively with minimum code and returns a result as Future class object for further use. The Json response from API calls can be handled easily as it provides methods to encode and decode json response and store it as dart object.
-
Local Data storage:
In every app there are some data values that need to be stored locally so as to use them throughout the lifecycle of the app. Flutter has provided sharedpreferences plugin which is used to store data in key-value pair. Some API response values were stored in SharedPreferences for handling the conditions based on that value. E.g. employee location was stored in shared preference to change the user interface according to the location. Data from API that was not to be change frequently hence was stored in local database using Sqflite package. Both these approaches were quite same that I use in Native Android app and so it was easy to implement.
-
Push Notification:
As app provide interface for both employees and Manger, we wanted to provide push notification feature through which the approval request can be notified to Manager and a response of the request can be notified to employee. We implemented Push notification feature easily with Firebase push notification service. This required some Native configuration to be done at both platforms.
-
Native User Experience:
As Flutter provides 2 different sets of widgets for different Platform it was important to differentiate the code based on which platform it is running on. This was easily detected with built–in methods.
e.g. If the app requires special run time permissions for Android app then the code can be separated by adding if (Platform.Android). This will detect the platform and execute the intended code at run time.
Following Screenshot shows that the widget specific to platform is added at runtime depending on which platform it is running
The Date picker for both platforms are different and separate widgets are provided for it.