• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Codemotion Magazine

Codemotion Magazine

We code the future. Together

  • Discover
    • Live
    • Tech Communities
    • Hackathons
    • Coding Challenges
    • For Kids
  • Watch
    • Talks
    • Playlists
    • Edu Paths
  • Magazine
    • AI/ML
    • Backend
    • Frontend
    • Dev Life
    • DevOps
    • Soft Skills
  • Talent
  • Partners
  • For Companies
Home » Frontend » Mobile Developer » Flutter for Android Developers explained by Faisal Abid
Mobile Developer

Flutter for Android Developers explained by Faisal Abid

At Codemotion Milan 2018, Faisal Abid discussed how Android Developers can benefit from Flutter for cross-platform mobile app development.

Last update January 13, 2020 by Vito Gentile

Flutter is one of the most interesting technologies among the new trends in mobile software development. Thus, it is no surprise that Codemotion Milan 2018 included a talk about Flutter in its agenda. Such talk was delivered by Faisal Abid, Google Developer Expert and CTO at Zoom.ai. Faisal divided his speech into two parts; he started by introducing Flutter, and then discussed how Android developers can benefit from using it.

Introducing Flutter

Flutter is a framework developed by Google, aimed at building native mobile applications for both Android and iOS platforms. Using this technology, developers can easily and quickly build applications that “feel natural”. Many of us have experienced weird behaviours from mobile applications, in terms of animations or features that do not appear consistent with the surrounding mobile OS ecosystem. According to Faisal, Flutter solved this issue by including material design in the Flutter widgets, producing applications with high quality and modern designs.

One of the most common mistakes about Flutter is the belief that it uses HTML5 and WebViews in order to implement both Android and iOS applications, similar to what other cross-platform development frameworks (e.g. PhoneGap) did in the past. Actually, this is not the case. In fact, Flutter allows the developer to create fully native mobile apps, using the Dart programming language.

As mentioned by Faisal, when Google decided to develop Flutter, they had to decide which language to use. Among the many choices available, including Javascript, Python, Scala, and many others, Google opted for Dart. One might consider this choice as driven by ownership (Dart has been developed by Google too). However, the main reason why Google choose Dart is in its learning curve, which resulted in it being the best one among the languages evaluated. Indeed, Dart allows us to develop applications very easily; while it was born as a sort of “evolution of Javascript”, this programming language has mostly simple features, usually included in other programming languages, and thus known by many developers.

By using Dart and Flutter, developers can decide how to deploy their applications; they can opt for Java or Kotlin for Android, or for Swift or Objective-C for iOS. It is worth highlighting that choosing one of these languages does not require any kind of knowledge from the developer’s point of view. Dart remains the only programming language processed by Flutter, while the aforementioned native mobile languages are just useful for understanding what the output will be.

Figure 1. Creation of a new Flutter project with IntelliJ, allowing selection of native languages.

Flutter for Android developers

In the second part of his speech, Faisal described some common patterns that are useful for Android developers who want to move to Flutter. In particular, he identified three interesting patterns: implementing AsyncTasks, managing navigation via Intents and understanding how the Activity’s life cycle is affected by Flutter.

For implementing asynchronous tasks in the background, it is crucial to understand that Flutter has a single-threaded execution model, supporting the so-called Isolates (a way to run Dart code on another thread). Instead of implementing the onPreExecute(), doInBackground() and onPostExecute() methods of the AsyncTask class, Flutter solves the problem by declaring a function as async, and using the await keyword for long run tasks. Dart will “figure out” how to pass this task to a background thread, avoiding freezing the UI.


loadData() async {
    String dataURL = "https://mysite.com/data.json";
    http.Response response = await http.get(dataURL);
    setState(() {
        widgets = json.decode(response.body);
    });
}

In order to navigate among Activities, Android uses Intents. However, there is nothing like Intents in Flutter. Instead, you need to use Navigator and Routes. A Route is an abstraction for a “screen” or “page” of an app (i.e. an Activity on Android); a Navigator is a widget that manages routes. Navigators work like a stack on which you can push() new routes you want to navigate to, and from which you can pop() routes when you want to “go back”. The following snippet shows how to navigate to a route by pushing its name (“\b”) to the Navigator:

Navigator.of(context).pushNamed('/b');

Finally, the third common pattern described by Faisal is about understanding the Activity’s life cycle. In Flutter, all the Activities are widgets. Similar (but not equal) to what happens with Android Activities, you can observe for the following lifecycle events:

  • inactive — The application is in an inactive state and is not receiving user input. This event only works on iOS, as there is no equivalent event to map to on Android
  • paused — The application is not currently visible to the user, not responding to user input, and running in the background. This is equivalent to onPause() in Android
  • resumed — The application is visible and responding to user input. This is equivalent to onPostResume() in Android
  • suspending — The application is suspended momentarily. This is equivalent to onStop() in Android; it is not triggered on iOS as there is no equivalent event to map on iOS

Faisal concluded his talk by mentioning that the official Flutter documentation offers many additional information for Android developers who want to port their applications to Flutter. Moreover, information for other developers (iOS, React native, web devs, Xamarin.Forms) is also available.

facebooktwitterlinkedinreddit
Share on:facebooktwitterlinkedinreddit

Tagged as:Android Codemotion Milan

Machine learning as a service – serving reusable ML models
Previous Post
John Romero: 25 years of DOOM!
Next Post

Related articles

  • Native vs Hybrid: Which Mobile App Platform Should You Choose?
  • Kotlin Users Group – Interview with organiser, Jakub Jablonski
  • Async code on Kotlin: coroutines VS RxJava
  • Become a Mobile Developer and Connect the Virtual and Physical Worlds
  • 5 Mobile App Predictions for 2020
  • Building mobile applications in JavaScript with React Native
  • Kotlin loves React
  • Facebook Hermes becomes open source
  • The state of Developer Ecosystem in 2019: the rise of Kotlin and React
  • XPay Mobile App: integrazione con Google Pay e Apple Pay

Primary Sidebar

Lessons Learned in the Cloud

Dive deep into this whitepaper dedicated to the Cloud and discover more about Kubernetes.

OVH Logo Lessons learned in the cloud

Codemotion Milan 2022

https://youtu.be/ym8iilUy_U0

Latest Articles

Video: How to Use Python for Async Microservices

Microservices

AWS amplify, angular, AWS

Step by Step: Running Angular Applications in AWS

Cloud

django python framework

Top Trending Python Frameworks Today

Languages

serverless cloud

Video: Beyond Serverless Functions

Cloud

Discover More

  • Jamstack: Are Static Sites a New Revolution for the Web?
  • Why Companies Are Implementing the Developer Experience Job Position
  • Video: A JavaScript Developers Guide to WebAssembly (with AssemblyScript)

Footer

  • Magazine
  • Events
  • Community
  • Learning
  • Kids
  • How to use our platform
  • Contact us
  • Write for Us
  • About Codemotion Magazine
  • How to run a meetup
  • Tools for virtual conferences

Follow us

  • Facebook
  • Twitter
  • LinkedIn
  • Instagram
  • YouTube
  • RSS

DOWNLOAD APP

© Copyright Codemotion srl Via Marsala, 29/H, 00185 Roma P.IVA 12392791005 | Privacy policy | Terms and conditions

Follow us

  • Facebook
  • Twitter
  • LinkedIn
  • Instagram
  • RSS

DOWNLOAD APP

CONFERENCE CHECK-IN