Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Few days ago, Google has announced the beta release of Flutter at Mobile World Congress 2018. A mobile UI framework to build native apps for both iOS and Android. It uses Dart to write application. The code is compiled using the standard Android and iOS toolchains for the specifc mobile platform, hence, better performance and startupĀ times.
Flutter has a lot of benefits suchĀ as:
- Open Source.
- Hot reload for quicker development cycle.
- Native ARM codeĀ runtime.
- Rich widget set & growing community of plugins backed byĀ Google.
- Excellent editor integretation: Android Studio & Visual StudioĀ Code.
- Single codebase for iOS and Android, full native performance (does not use JavaScript as a bridge or WebViews)Ā .
- React Native competitor.
- Dart feels more Java, easy for Java developers to jump onĀ it.
- It use Widgets, so for people coming from web developement background everything should seem very familiar.
- It might end the Google vs Oracle JavaĀ wars.
So it was a great opportunity to get my hands dirty and create a Flutter application based on Serverless Golang API I built in my previous post āServerless Golang API with AWSĀ Lambdaā
The Flutter application will call API Gateway which will invoke a Lambda Function that will use TMDB API to get a list of movies airing this week in theatres in real-time. The application will consume the JSON response and display results in a ListView.
Note: All code can be found on myĀ GitHub.
To get started, follow my previous tutorial on how to create a Serverless API, once deployed, copy to clipboard the API Gateway InvokeĀ URL.
Next, get the Flutter SDK by cloning the following GitHub repository:
git clone -b beta https://github.com/flutter/flutter.git
Note: Make sure to add flutter/bin folder to your PATH environment variable.
Next, install the missing dependencies and SDKĀ files:
Start Android Studio, and install Flutter plugin from File>Settings>PluginsĀ :
Create a new FlutterĀ project:
Note: Flutter comes with a CLI that you can use to create a new project āflutter create PROJECT_NAMEā
Android Studio will generate the files for a basic Flutter sample app, we will work in lib/main.dart file:
Run the app. You should see the following screen:
Create a simple POJO class Movie with a set of attributes andĀ getters:
Create a widget, TopMovies, which creates itās State, TopMoviesState. The state class will maintain a list ofĀ movies.
Add the stateful TopMovies widget to main.dart:
Add the TopMoviesState class. Most of the appās logic will resides in thisĀ class.
Letās initialize our _movies variable with a list of movies by invoking API Gateway, we will iterate through the JSON response, and add the movies using the _addMovie function:
The _addMovie() function will simply add the movie passed as an argument to list ofĀ _movies:
Now we just need to display movies in a scrolling ListView. Flutter comes with a suit of powerful basic widgets. In the code below I used the Text, Row, Image widgets. In addition to Padding & Align components to display properly a MovieĀ item:
Finally, update the build method for MyApp to call the TopMovies widgetĀ instead:
Restart the app. You should see a list of movies airing today in cinemaĀ !
Thatās itĀ ! we have successfully created a Serverless application in just 143 lines of code and it works like a charm on both Android andĀ iOS.
Flutter is still in womb so of course it has someĀ cons:
- Steep learning curve compared to React Native which uses JavaScript.
- Unpopular comparing to Kotlin orĀ Java.
- Does not support 32-bit iOSĀ devices.
- Due to autogenerated code, the build artifact is huge (APK for Android is almost 25 Mb, While I built the same app in Java for 3Ā Mb).
But for a beta release it look very stable and well designed. I canāt wait to see what you can build with itĀ !
Serverless Application with Flutter & Lambda was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.