An Intro To Flutter

Share if the site was helpful

An Intro To Flutter

When Google I/O came and went in May one of the topics that captured a lot of interest was Flutter. Offering a whole new option for cross platform code, Flutter has been gaining traction over the past few years. I talked about it briefly a few weeks ago, but let’s dive more into the details of why it may be worth learning.

What is Flutter?

First, let’s get a quick primer of what Flutter actually is.  It’s a toolkit developed in 2017 by Google that allows you to write code for both Android and iOS devices.  You can write code once, and then implement it anywhere.  And by anywhere, I mean Android, iOS, web, and desktop.  Already if you’re a freelancer I’m sure you see some appeal here!

It’s written in Dart which hasn’t been too popular of a language in the past, but Flutter is breaking that trend.  It’s been featured at I/O for a few years straight now, and Google uses it for internal apps, so it’s not going away any time soon.  The framework revolves around widgets.  Everything in a Flutter app is a widget.  Widgets describe what a view should look like given its current state, and when that state changes a widget rebuilds its description.  It sounds kind of foreign until you dive in.

Let’s see some code!

I won’t waste time going through how to set up Flutter on your computer.  Here’s a good link to walk you through that (don’t worry it’s super simple).  For my personal use I’ve been using Flutter in Visual Studio Code, but you can also develop in other IDE’s such as Android Studio if you’re more comfortable with those. To get started run the command flutter create hello_world.  This will take care of everything for you creating a new application named hello_world.  To run it, type cd hello_worldto enter that directory, and then type flutter runto kick things off.

Congratulations!  You’re officially looking at your first flutter app. Whether you ran it on an iPhone or an Android device (or somewhere else) you should see an app that looks like this:

So what made this app? Well, this is from the default code that Flutter made for us.  In your navigation sidebar you should see folders for things such as android, ios, and lib.  There are some others as well, but I point these out because at its core you’ll work in the lib folder.  And the others will allow you to transport that code into iOS and Android phones. That’s REALLY oversimplifying it, but it’s not wrong!

main.dart:

Let’s open the lib folder, and inside we’ll see one file named main.dart.  This is the core of your app right now.  If you open up main.dart you’ll see what is creating the widgets currently showing on your phone.  For anyone just reading and not following along, here’s what it looks like:

In here we can see pretty hefty comments explaining everything.  The app starts by calling the method runApp() and passing in an instance of our class MyApp.  And as we can see right below that, MyApp is a StatelessWidget.  There are stateful and stateless widgets in Flutter, and we’ll go into them down the road, but for now just know what a widget is.

One really cool thing about Flutter is hot reloading.  When you want to rerun an app and see any changes you’ve made, you only have to recompile widgets that have changed their state.  The end result of this is incredibly fast reload speeds (milliseconds). Go ahead and try this out.  Under theprimarySwatchattribute change it from Colors.blue to Colors.red. Once you’ve done that save the project and in the terminal press “r”. Instantly you’ll see the theme of your app change from blue to red.  It’s really that simple to reload!

I’ve loved my experience thus far with Flutter because of the way it is structured and hot-reloading. There’s a whole world of development to explore, but if you get started and want to let us know what you like/dislike about it let us know in the comments below!

 

 

Google I/O, Until Next Year

Share if the site was helpful

Google I/O, Until Next Year

Well Google I/O is a wrap everyone, and if you tuned in then hopefully you left with some cool takeaways.  If not then don’t worry, that’s what we’re here for.  When the conference first kicked off we wrote about day 1 and its highlights, but obviously the fun didn’t stop there.  The following is a crash course selection of (in my opinion) the most important and amazing takeaways for and android junky.

Flutter:

If you’re an android developer, then your undoubtedly familiar with Java and segueing in to Kotlin.  You might not have heard about Flutter before though.  It’s Google’s mobile app SDK for easily creating high quality apps on both Android and iOS devices.  Written in Dart (a language developed by Google as well), Flutter works with existing code and is used to develop at ridiculously high speeds.  Here’s a great video from Google I/O that goes more in depth on how to use Flutter to enhance your material design.

Duplex:

Now this one blows my mind, and I know I’m not alone here.  When you think of a sci-fi future it’s reasonable if computers playing our personal secretaries pops into your mind.  This seems to be the present now. 

I’m very interested to see how Duplex functions successfully in real world applications, but the Google 2018 keynote showed a quick performance of the Google Assistant booking a haircut appointment for Google’s CEO, Sundar Pichai.  From an outsider’s view the conversation was impossible to distinguish from an everyday conversation between two people, and when it was done the Google Assistant confirmed to Sundar that the appointment had been booked and added to his calendar.  It’s only a matter of time before this is both client and server side so that duplex will be having conversations with itself to schedule our days, and that’s pretty wild.

Android P Beta:

Yes, I know we discussed android P in the last blog on Google I/O.  But you’ll have to bear with me because it’s happening again! As of this week the Android P beta is available on Pixel devices as well as 7 other flagship devices.  Android P brings all kinds of cool new features to the table.  A lot of these revolve around predicting what you the user are about to do.  There’s an adaptive battery that adjusts your screen’s brightness and what apps are running in an effort to both improve your experience and conserve precious battery power.

My personal favorite feature of P is Wi-Fi RTT.  Round Trip Time takes our current location services capabilities and amplifies them.  Essentially by triangulating between multiple Wi-fi access points nearby, a user’s position can be calculated within about a meter.  Just use your imagination for what applications this could come in handy for!  For more on Android P you can read our past posts or watch some Google I/O talks.

There’s lots more to take away from Google I/O, and honestly I’m cutting myself off here because otherwise I’d end up writing a paragraph or two about every session that I watched from the entire conference.  It’s a great year to be an android developer or even just own an android device.

What interested you the most from the conference?  Let us know in the comments below!

 

en English
X