Slide 1

Slide 1 text

Introduction to Flutter Slides for an internal talk we had at Codemate Ltd. 14th of September 2017

Slide 2

Slide 2 text

What is Flutter? ● SDK for building cross-platform mobile apps, built by Google ● Targets Android, iOS and Fuchsia ● Consistent UIs across devices and manufacturers ● Superb performance

Slide 3

Slide 3 text

Why Flutter? ● Strongly typed, modern language (Dart with Strong Mode on) ● Same codebase, two platforms: Android & iOS ● AOT compilation -> no Javascript or any other runtime / VM ● No WebViews, no native Views ○ Why? We’ll see. ● Once your UI works, it just works. And keeps working. ○ Manufacturers / OS versions / different devices can’t break it ● Especially Android APIs require a lot of ceremony for simple things ○ Flutter was able to start from scratch and avoid previously made pitfalls

Slide 4

Slide 4 text

Base image from: https://speakerdeck.com/passsy/flutter-60-fps-ui-of-the-future Our cross-platform code Native land ● Also fast performance here, however: ○ Expensive to travel to ● We can’t afford to go here too often, just like we can’t afford beach vacations every week ● Everything in our control ● Things we do here have fantastic performance and are cheap ● We should stay here as much as possible

Slide 5

Slide 5 text

Widgets ● To build UIs, we have Widgets -> the only UI building block in Flutter ● The whole app is a Widget. A screen is a Widget that contains Widgets. Widgets are made by composing basic Widgets into more advanced Widgets. ○ Yo dawg? ● There’s a huge amount of different Widgets ● Can represent a: ○ UI element, such as Text, Button, BottomNavigationBar, TextField, etc. ○ Layout element, such as Padding, Center, Stack, Column, etc. ○ Completely new screen (Activity/ViewController equivalent), for example:

Slide 6

Slide 6 text

Stateless Widgets ● Have no state (duh) ● Immutable -> all instance fields are final ● For displaying something that doesn’t change once it has been initialized

Slide 7

Slide 7 text

Stateful Widgets ● Have a state (duh) ● The state has mutable instance fields that can be read synchronously ● Call setState() method for updating the state ● Framework handles UI Widget updates intelligently and efficiently when necessary ● So basically, really similar to React concepts (count = count + 1;)

Slide 8

Slide 8 text

Widget rendering ● No native Views or WebViews ● Instead, a completely blank Canvas as seen on left ● The Material & Cupertino widgets are made by composing more basic Widgets ● Widgets are made of low-level rendering layer objects ○ In the end, Skia, C++ graphics library, renders them directly to these Canvases ● We have direct access to Canvas ○ pretty much any UI, even a wilder one, is doable

Slide 9

Slide 9 text

What’s the value in custom rendering anyway?

Slide 10

Slide 10 text

An actual ticket from our QA

Slide 11

Slide 11 text

Here’s how it looked like weird black lines Supposed to be white Dropdown items that are supposed to be, you know, visible?

Slide 12

Slide 12 text

Half a day for fixing bugs on two specific devices on one specific OS version.

Slide 13

Slide 13 text

Dependency management ● Ships with Pub, a modern dependency manager for Dart ● Official package repository hosted at pub.dartlang.org ● The whole existing ecosystem of Dart libraries available ○ Excludes lots of web-related libraries ● Also supports packages from Git, if you’re feeling lucky

Slide 14

Slide 14 text

Native Plugins ● Allow access to every native platform API ○ Bluetooth, geolocation, sensors, fingerprint, camera, etc. ● Both official and community-driven plugins available ● Some plugins missing or in early stages ○ There’s a community-driven geolocation plugin with really limited API ○ There’s a community-driven Bluetooth plugin that doesn’t work with iOS just yet ● If a plugin for your use case doesn’t exist, you’ll have to make it yourself ● This is where other frameworks like React Native & Xamarin currently shine and Flutter takes the loss ○ Situation expected to be solved with time

Slide 15

Slide 15 text

Plugin sample: get current battery level iOS code Android code

Slide 16

Slide 16 text

Icons ● Ships with a whole lot of premade, quality vector icons ● Just say “new Icon(Icons.add_call);” ● You can also import your own icons & icon fonts if you want

Slide 17

Slide 17 text

● Column is a vertical stack of children. ○ Opposite of Row, which stacks its children horizontally ● We give padding to the Text widget by wrapping it inside the Padding widget ● Styles come from the app level Theme object, so the whole theme of the app can be easily changed ○ You have the freedom to define your own styles inline too

Slide 18

Slide 18 text

Let’s make some friends

Slide 19

Slide 19 text

friend.dart friend_page.dart

Slide 20

Slide 20 text

Android iOS

Slide 21

Slide 21 text

Performance overlay (GIF taken on slow debug mode) Debug Paint Quickly switch between Android / iOS UI on the same device Debug tools Also debugger, logs and animation debugging.

Slide 22

Slide 22 text

Getting creative https://www.uplabs.com/posts/profile-ui-exploration

Slide 23

Slide 23 text

Navigation

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

= avatarUrl

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

The Hero Widget

Slide 31

Slide 31 text

Demo & source https://github.com/CodemateLtd/FlutterMates

Slide 32

Slide 32 text

Drawbacks ● UI markup & layout system learning curve ○ UI code can look quite ugly ● Not a lot of “hold your hand guides” available ○ Documentation is amazing ● Google’s product loyalty ● Inline maps & video, etc. can’t be done (at least yet) ○ Possible on full screen though ● Hot reload ● AOT compilation & direct canvas rendering for widgets -> amazing performance ● UI will work the same on different devices & manufacturers ○ Native look and feel on Android & iOS ○ Nobody can break our UIs ● You can create as complex and customized UIs as you want However...

Slide 33

Slide 33 text

Thanks! Questions? ● Flutter - A new hope: https://www.youtube.com/watch?v=0ijVuVtu6a4 ● Flutter - 60 FPS UI of the Future: https://speakerdeck.com/albrecht87/flutter-60-fps-ui-of-the-future-droidcon-2017 ● The Official Flutter homepage: https://flutter.io/ Inspiration & references