Return to Video

36C3 Wikipaka WG: Flutter - One native code base for every platform

  • 0:00 - 0:19
    music
  • 0:19 - 0:23
    Herald: I would like to welcome our first
    speaker for the day and he's amazing. His
  • 0:23 - 0:28
    talk which he's been working on all night.
    A warm welcome!
  • 0:28 - 0:32
    applause
  • 0:32 - 0:38
    Speaker: Yeah good morning. My name is
    'the one with the braid' and today I will
  • 0:38 - 0:46
    give an introduction into Flutter. What is
    Flutter? Flutter is a software development
  • 0:46 - 0:58
    kit for creating cross-platform
    applications from one single codebase.
  • 0:58 - 1:03
    Here you can see the great logo of
    Flutter. Brief history of Flutter: Flutter
  • 1:03 - 1:13
    was announced by Google in 2015 as a new
    framework for creating Android
  • 1:13 - 1:27
    applications. It was initially launched in
    2018 and since that it has become one of
  • 1:27 - 1:39
    the most popular cross-platform software
    development kits. Getting started with
  • 1:39 - 1:47
    Flutter, well, we will have a look at the
    installation of Flutter, at one of the
  • 1:47 - 1:54
    special features of Flutter called
    widgets. There we'll have a look on two
  • 1:54 - 2:00
    different types of widgets called stateful
    and stateless widgets. And at the end we
  • 2:00 - 2:07
    will have a look at something really
    strange in Flutter: Unlike in actually
  • 2:07 - 2:14
    every other software you use for mobile
    development you write the design in your
  • 2:14 - 2:25
    code but not in any XML files but directly
    into your Flutter code. Installation is
  • 2:25 - 2:34
    quite easy on Linux and Mac OS. You can
    just clone the git repository from Github,
  • 2:34 - 2:41
    update your PATH and enjoy your new
    Flutter installation. On Windows you need
  • 2:41 - 2:49
    to download pre-built binaries as Windows
    is unable to execute shell scripts. That's
  • 2:49 - 2:58
    it about the installation. Now we will go
    a bit deeper into the technology Flutter
  • 2:58 - 3:10
    is using. Flutter is written as an
    extension for the language Dart, that's
  • 3:10 - 3:15
    what you can see over there, it's a
    framework for the language Dart. And you
  • 3:15 - 3:21
    can actually say the language Dart was
    developed for Flutter and Flutter was
  • 3:21 - 3:29
    developed for Dart. Actually no one is
    using Dart without Flutter yet, so it was
  • 3:29 - 3:39
    made just for Flutter. The language Dart
    is written in C++ and C and the so-called
  • 3:39 - 3:47
    Flutter engine is written and C++ and C
    too. Why? It's simply because this allows
  • 3:47 - 3:55
    low-level rendering, that means Flutter
    does not need any libraries of the
  • 3:55 - 4:01
    operating system it's executed on. So if
    you run an Flutter application on Android
  • 4:01 - 4:06
    you won't need any libraries of Android.
    If you run it on iOS you won't need any
  • 4:06 - 4:12
    libraries of iOS and if you run it as a
    webpage you won't need any JavaScript
  • 4:12 - 4:25
    dependencies. What does the engine provide
    us? The engine provides actually the basic
  • 4:25 - 4:34
    rendering of the layout, core functions
    like I/O access, graphic encoding and
  • 4:34 - 4:44
    decoding, animations, accessibility
    options and network of course. It's using
  • 4:44 - 4:55
    the Skia library of Google, it's quite
    well known in Android and even for desktop
  • 4:55 - 5:03
    development. That's what the engine does
    and on top of the engine you will have
  • 5:03 - 5:10
    which is visible, and which is visible is
    called widgets. An application is built
  • 5:10 - 5:20
    out of many widgets. You can just imagine
    widgets like HTML tags, you just put them
  • 5:20 - 5:26
    into each other, they have several childs
    and so on and you get a tree of widgets as
  • 5:26 - 5:36
    you get a DOM tree in JavaScript and HTML.
    That's how you can imagine of. Whoops, I
  • 5:36 - 5:44
    hate these buttons. Let's have a closer
    look at these widgets. As already
  • 5:44 - 5:50
    mentioned at the beginning we have two
    different kinds of widgets. We have these
  • 5:50 - 6:03
    stateless widgets, they provide no
    feedback. For example a simple text or an
  • 6:03 - 6:11
    image or buttons, a ListView, a table,
    they could be displayed as stateless
  • 6:11 - 6:19
    widgets. A stateful widget is able to
    provide feedback means you can tell a
  • 6:19 - 6:27
    stateful widget "if you press this
    button please do this". That's something
  • 6:27 - 6:34
    you only can do with stateful widgets but
    not with a stateless widget. But why do
  • 6:34 - 6:38
    you separate between these stateful and
    stateless widgets? Couldn't you just make
  • 6:38 - 6:48
    one type of widget ? It's due to better
    performance because stateless widget is
  • 6:48 - 6:57
    being rebuilt as soon as its content
    changes. For example we create a text
  • 6:57 - 7:05
    containing the variable "hello_world" with
    the text "Hello world" and now if we
  • 7:05 - 7:13
    change the variable "hello_world" the
    whole widget, this text will be
  • 7:13 - 7:25
    rerendered on the screen. Every stateless
    widget will be just re-redenred without
  • 7:25 - 7:31
    being able to be informed about a change
    of anything. And that's a difference to a
  • 7:31 - 7:39
    stateful widget. A stateful widget is able
    to say "Okay, I now want to change because
  • 7:39 - 7:45
    a timer was running down, because an event
    occurred because of I don't know what".
  • 7:45 - 7:56
    And a stateful widget is not being rebuilt
    by its upper widget, by its super widget
  • 7:56 - 8:05
    and so on. Means a stateful widget will
    not be changed if the state of the upper
  • 8:05 - 8:14
    widget changes. That's the difference
    between this stateful and stateless stuff.
  • 8:14 - 8:23
    I do not want to get deeper into the
    technology. Let's just have a look at some
  • 8:23 - 8:30
    shortened source code. If you write an
    application for example a mobile
  • 8:30 - 8:38
    application in Flutter it will actually be
    just this. Okay you will have to implement
  • 8:38 - 8:46
    this homepage but that's actually all you
    need. You have the main method in which
  • 8:46 - 8:52
    you call runApp() and there you provide an
    application, in this case a Material app.
  • 8:52 - 8:59
    Material means it uses the Material
    design. Material design is a design
  • 8:59 - 9:05
    standard by Google, you know it from
    Android but I could tell Cupertino app as
  • 9:05 - 9:13
    well then it would show an iOS like user
    interface or I could just create my own
  • 9:13 - 9:22
    style if I want but no one would like it.
    And there we provide just the homepage and
  • 9:22 - 9:31
    now we'll have a look at the home page.
    Here you can see a basic class in Dart.
  • 9:31 - 9:38
    Dart is the language for Flutter. You can
    see it is a stateless widget, means if the
  • 9:38 - 9:45
    app opens it will be built, if the app
    closes, it will be moved to trash. If - I
  • 9:45 - 9:51
    don't know what - if the system decides:
    okay better we say if I don't know what,
  • 9:51 - 9:57
    we reduce network traffic, so the
    stateless widget cannot react, it will
  • 9:57 - 10:04
    just get the information from the
    application and the operating system.
  • 10:04 - 10:16
    Yeah. We here... the most important in any
    widget in Flutter is the build method the
  • 10:16 - 10:22
    build-method contains everything which is
    displayed on the screen. In our case we
  • 10:22 - 10:31
    will display a ListTile, means one
    element of an ListView containing some
  • 10:31 - 10:42
    text and a button which will share any
    text if you press it. But that's not the
  • 10:42 - 10:48
    interesting part. Important is this build
    method which tells okay this widget, my
  • 10:48 - 10:59
    widget TestScoreDetail should look like
    this on the screen. Here again, this is
  • 10:59 - 11:05
    everything which is finally displayed on
    the screen, everything which is within
  • 11:05 - 11:15
    this build method. That was a stateless
    widget, a stateful widget is a bit more
  • 11:15 - 11:24
    complicated. You can see over there,
    there's not written just
  • 11:24 - 11:31
    JoinTestScoreTile, but
    JoinTestScoreTileState, means this is the
  • 11:31 - 11:39
    class containing the state and the state
    offers different - you could sort, you
  • 11:39 - 11:48
    could call them stages. First of all, the
    init state, in our case we do not modify
  • 11:48 - 11:52
    anything, it does not need to be
    initialized, that's why we just call the
  • 11:52 - 12:00
    super init state method but what you could
    do an init state for example who would be
  • 12:00 - 12:06
    loading something from network, if my
    widget should display - I don't know -
  • 12:06 - 12:14
    data from Wikidata and you would place the
    code for loading this data in the init
  • 12:14 - 12:25
    state method. This is being executed
    before the widget is built the first time.
  • 12:25 - 12:35
    Here you can see the build-method again
    and here I highlighted why we need a
  • 12:35 - 12:43
    stateful widget in this case. You can see
    here, it's an if-statement, a short and
  • 12:43 - 12:51
    inline if-statement. When you build the
    widget, it checks whether the variable
  • 12:51 - 12:59
    testLoaded is true, testLoaded is
    initially false so the first time the
  • 12:59 - 13:04
    widget will be opened, it will skip down
    there and it will show an progress
  • 13:04 - 13:12
    indicator, means a spinning circle in the
    center. And as soon as this should ever
  • 13:12 - 13:21
    change, it will as soon as this variable
    will get true, it will show this part and
  • 13:21 - 13:32
    that's why we need a stateful widget,
    because the widget has to react on
  • 13:32 - 13:45
    variables within the class. Over there,
    just at the beginning of the
  • 13:45 - 13:52
    implementation of this class, you can see
    some variables initialized at the
  • 13:52 - 13:59
    beginning. These are variables which are
    available within the class. It's just like
  • 13:59 - 14:14
    you can see the use, it's the only use in
    this case over there. And again, as it's a
  • 14:14 - 14:21
    widget, everything which is provided by
    the build, by the whole build method is
  • 14:21 - 14:27
    what the widgets, what the widget looks
    like. So in the first case it will be this
  • 14:27 - 14:38
    and afterwards it will be this. And now one
    more property of a stateful widget: Here
  • 14:38 - 14:48
    we return an expansion tile, you can
    imagine like a part of a list which is
  • 14:48 - 14:53
    expandable with an arrow button and if you
    press it will show some more detailed
  • 14:53 - 15:03
    information and there we set a listener on
    the change of its expansion and as soon as
  • 15:03 - 15:11
    it will be expanded, the first time, we
    will just execute this function loadScore
  • 15:11 - 15:21
    and maybe the loadScore function would be
    the function changing this boolean to true
  • 15:21 - 15:26
    and as soon as it will be changed to true
    we have our widget providing the
  • 15:26 - 15:37
    information within there. That's the main
    difference to a stateful to a stateless
  • 15:37 - 15:48
    widget. Now just a little compared to
    other cross-platform frameworks you maybe
  • 15:48 - 15:56
    know. I will compare it with JavaScript
    frameworks like React and Electron. Okay,
  • 15:56 - 16:03
    if you have a JavaScript mobile
    application, you usually load in webview,
  • 16:03 - 16:10
    consuming about 200 megabytes RAM. This is
    ugly for a mobile device, because no
  • 16:10 - 16:14
    mobile device wants to provide 200
    megabyte RAM for five applications,
  • 16:14 - 16:23
    because not every mobile device has that
    much RAM. That's how JavaScript works
  • 16:23 - 16:29
    because you need a web viewer and webview
    needs all this stuff, webview needs a
  • 16:29 - 16:34
    JavaScript engine, style engine and so on.
    That's different in Flutter, because
  • 16:34 - 16:40
    Flutter code is being compiled to native
    code. Means if I compile this application
  • 16:40 - 16:47
    for Android, the code will be compiled to
    Kotlin code which is then executed. Means
  • 16:47 - 16:57
    no need for JavaScript, no need for virtual
    machines or anything like that. That's
  • 16:57 - 17:04
    why the consumption of memory is much
    lower. The next point is its native look
  • 17:04 - 17:12
    and feel. If you, for example, if you
    write an app in JavaScript you have the
  • 17:12 - 17:17
    problem that its JavaScript and not the
    native design of the platform. If I write
  • 17:17 - 17:25
    an Android app in Flutter, I can just tell
    the app: Ok, you should, you shall now
  • 17:25 - 17:30
    look like an Android app, provide material
    design, provide buttons which look like
  • 17:30 - 17:36
    Android buttons, provide a navigation
    drawer like an Android application and so
  • 17:36 - 17:42
    on. That's actually almost impossible with
    JavaScript but in flutter it's actually
  • 17:42 - 17:50
    the standard. Then this, there I will come
    to one of the problems of Flutter: It's
  • 17:50 - 17:58
    the same layout on all platforms. Means if
    I tell my application: Okay, you shall
  • 17:58 - 18:03
    look like an Android application, it will
    even look like an Android application if I
  • 18:03 - 18:10
    compile it for a Linux desktop or for iOS.
    Means you as developer have to decide
  • 18:10 - 18:16
    which layout will be used and this layout
    will be used or this design will be used
  • 18:16 - 18:25
    on every platform you deploy the app to.
    Of course, you can use some styling stuff
  • 18:25 - 18:33
    within the app to make it more like a
    native designed platform application for
  • 18:33 - 18:39
    your platform and no loss of performance
    is what I just explained at the beginning
  • 18:39 - 18:50
    as native app. I hope I could, I was able
    to introduce some bit of the idea of
  • 18:50 - 18:57
    Flutter, I would just now start like to
    start an Q&A about Flutter, about what it
  • 18:57 - 19:06
    is able, what you can do with Flutter and
    what you cannot do with Flutter. Thank you
  • 19:06 - 19:08
    for your attention.
  • 19:08 - 19:18
    applause
  • 19:18 - 19:25
    I don't know, shall I moderate? I would
    just ... oh, ok well then you can just
  • 19:25 - 19:28
    ask.
    Q: You said that is compiled to native
  • 19:28 - 19:35
    code and then afterwards we need a
    different tool change for each OS.
  • 19:35 - 19:40
    Do we have some experience, what is the
    effort, what do we have to do to, let's say
  • 19:40 - 19:44
    run it in incomprehensible
  • 19:44 - 19:48
    A: Well, you actually, the question was
    whether,
  • 19:48 - 19:54
    what you have to do for running or for
    providing one app at four different
  • 19:54 - 19:58
    platforms. Well, everything you have to do
    is running Flutter build and name of the
  • 19:58 - 20:05
    platform. So if you decide to deploy it to
    iOS, Android, Linux and Mac OS you can
  • 20:05 - 20:15
    just execute "flutter build apk" for
    Android, afterwards "flutter build ios"
  • 20:15 - 20:22
    for iOS, "flutter build linux" for Linux
    and "flutter build macos" for Mac OS. So
  • 20:22 - 20:30
    you actually do not have to go deeper into
    the single platforms. Flutter provides
  • 20:30 - 20:39
    everything you need there. Did I answer
    your question?
  • 20:39 - 20:49
    Q: (incomprehensible)
    A: Yeah, it will install it automatically,
  • 20:49 - 20:54
    if you download it, if you download
    Flutter and you execute it the first time,
  • 20:54 - 21:00
    it will ask you to install this and this
    and this, the Android tool chain, the iOS
  • 21:00 - 21:17
    Xcode tool chain and whatever you need to.
    Q: I have a question. At the main function
  • 21:17 - 21:24
    you just have to define your style and the
    home page right. So what is hindering me
  • 21:24 - 21:29
    to say: Release a version for Android to
    the Android style then just change the
  • 21:29 - 21:33
    style for something that looks more iOS
    and then release a different version for
  • 21:33 - 21:37
    iOS?
    A: Yes, sure you can do it and Flutter
  • 21:37 - 21:47
    even offers a parameter of material app,
    you can provide their theme data class and
  • 21:47 - 21:55
    within this theme data class you could
    tell the application: OK, on iOS I should
  • 21:55 - 21:59
    behave and look like this and on
    Android I should behave and look like
  • 21:59 - 22:04
    this. So even offers native
    functionalities for this.
  • 22:04 - 22:12
    Q: Thank you for this nice talk. Who has
    developed Flutter and how it is protected
  • 22:12 - 22:20
    by being bought by Oracle.
    A: I don't think Oracle will buy Flutter,
  • 22:20 - 22:27
    because it's developed by Google and I'm
    quite sure Google won't sell it. And as
  • 22:27 - 22:34
    its open-source, it will remain open
    source. I'm not sure about license, it was
  • 22:34 - 22:47
    I guess it was Apache or MIT license. So
    it won't become closed-source software
  • 22:47 - 22:52
    tomorrow.
    Q: Hi and thanks again for the talk. What
  • 22:52 - 22:57
    I would actually know, is the performance
    of all native components, I mean like all
  • 22:57 - 23:09
    native code the same on all platforms?
    A: Yes-No because some functions are not
  • 23:09 - 23:15
    available on every platform. For example,
    if I run the application on the web, you
  • 23:15 - 23:21
    won't be able to save local files or open
    local files, because that's not what a
  • 23:21 - 23:28
    website should do or just can do. But
    yeah, on the mobile platforms actually
  • 23:28 - 23:31
    everything is the same, on the desktop
    platforms everything is the same and in
  • 23:31 - 23:38
    the web, it's a bit different.
    Q: Hi thanks for the talk. What about
  • 23:38 - 23:44
    capabilities like Bluetooth Low Energy. Is
    there any restrictions or something like
  • 23:44 - 23:51
    that to get deep into the platform?
    A: Well, Flutter provides access to
  • 23:51 - 23:58
    Bluetooth. The only restrictions you may
    have is from your platform, but even if
  • 23:58 - 24:04
    you want to use a feature which is not
    implemented in Flutter, you can access
  • 24:04 - 24:10
    native code. So from flutter you can just
    call Swift code on iOS and Kotlin code for
  • 24:10 - 24:15
    Android and so on, if anything is not
    implemented in Flutter.
  • 24:15 - 24:21
    Q: Hey I was a little bit late, in the
    talk you maybe already talked about this,
  • 24:21 - 24:26
    but what kind of projects did you make
    with Flutter and did you think that
  • 24:26 - 24:29
    Flutter was a good fit for these projects
    or not?
  • 24:29 - 24:35
    A: Well what I do with flutter is actually
    everything running on mobile devices,
  • 24:35 - 24:42
    because I'm not such a huge fan of the
    native programming languages of iOS and
  • 24:42 - 24:50
    Android. I don't like Java and I don't
    like Swift, that's why I got used to
  • 24:50 - 24:58
    Flutter. And yeah, I think it's actually
    very good for this, because you only write
  • 24:58 - 25:05
    code once and then you can deploy to all
    the mobile platforms. Applications I
  • 25:05 - 25:13
    developed were mostly JugendHackt
    projects, projects of youth hackathons, of
  • 25:13 - 25:22
    the open knowledge foundations.
    Other questions?
  • 25:26 - 25:32
    Q: Hello. All the widgets are emulated and
    not native widgets of the operating
  • 25:32 - 25:42
    system, of iOS or Android?
    A: It's not emulated nor if you use the
  • 25:42 - 25:49
    native design, it's the native design.
    Flutter provides its totally own graphics
  • 25:49 - 25:55
    library, so even if you use Cupertino
    design on iOS, it's not the Cupertino
  • 25:55 - 26:01
    design from iOS but the Cupertino designed
    from Flutter. So independent of the
  • 26:01 - 26:04
    platform, it offers its own graphics
    library.
  • 26:04 - 26:10
    Q: So you lose the integration with
    accessibility features from the operating
  • 26:10 - 26:15
    system?
    A: No that's what I told on this slide:
  • 26:15 - 26:22
    The engine, the low-level engine provides
    a accessibility component, for example,
  • 26:22 - 26:27
    and, yeah, pipes them to the native
    platform.
  • 26:30 - 26:36
    Q: So what's the main advantage compared
    to other frameworks like Qt?
  • 26:36 - 26:43
    A: Better performance, I would just say
    and many more platforms, because most of
  • 26:43 - 26:49
    the frameworks are just - they are usually
    just available for mobile platforms.
  • 26:49 - 26:54
    Electron focus on, for example, for
    desktop platforms and flutter provides
  • 26:54 - 27:00
    them all and just from one single codebase
    and its native code you execute.
  • 27:00 - 27:06
    Q: Have you ever worked with background
    services, native background services on a
  • 27:06 - 27:11
    platform? Like Android service?
    A: Yeah, Flutter provides background
  • 27:11 - 27:18
    services and if you use them, it will just
    subscribe the native background services
  • 27:18 - 27:21
    of the platform you're using.
  • 27:30 - 27:31
    Q: What's the current state of IDE
  • 27:31 - 27:37
    integration because with other frameworks
    I had problems that the IDEs I use are
  • 27:37 - 27:44
    mostly the ones from JetBrains and those
    didn't work with all frameworks I tried.
  • 27:44 - 27:53
    A: Flutter offers official support to
    Android Studio and Visual Studio Code, but
  • 27:53 - 28:01
    for many other IDEs there are third-party
    plug-ins with language support for Dart
  • 28:01 - 28:16
    and Flutter.
    Q: Are there any restrictions on how far
  • 28:16 - 28:27
    you can make your app ready for, for
    example provisioning profiles on iOS to
  • 28:27 - 28:37
    get ready to in the store or is it just
    raw building for that platform and
  • 28:37 - 28:43
    everything else if you want to get it in
    the store or you have to go native?
  • 28:43 - 28:55
    A: No, I never had a problem with that. I
    published three apps for iOS. iOS has most
  • 28:55 - 29:00
    restrictions and I never had any problem,
    because the design of flutter follows all
  • 29:00 - 29:06
    the guidelines and they pay attention on
    following the guidelines of the maintainer
  • 29:06 - 29:10
    of the stores of all the platforms they
    support.
  • 29:14 - 29:22
    Q: The person there asked about IDE. I
    understood IE and that's a good point -
  • 29:22 - 29:30
    web platform: How the Microsoft browsers
    are supported as they are used heavily in
  • 29:30 - 29:35
    big environments.
    A: Sorry what was, what should I say?
  • 29:35 - 29:41
    Q: My question is how Flutter supports the
    Microsoft browsers, even if we don't want
  • 29:41 - 29:47
    use them all but we need do somehow.
    A: According to the README of Flutter Web
  • 29:47 - 29:54
    repository, there's no support for
    browsers by Microsoft and I even tried
  • 29:54 - 30:01
    once, you will see an empty screen in
    Internet Explorer and on Microsoft Edge
  • 30:01 - 30:07
    you will get many crashes. But this will
    change in January as Microsoft will start
  • 30:07 - 30:14
    rolling out the chromium based Microsoft
    edge to all Windows 10 devices and even
  • 30:14 - 30:21
    older Windows devices. So that's
    something, I say I don't care about .
  • 30:21 - 30:24
    Music
  • 30:24 - 30:49
    Subtitles created by c3subtitles.de
    in the year 2021. Join, and help us!
Title:
36C3 Wikipaka WG: Flutter - One native code base for every platform
Description:

more » « less
Video Language:
English
Duration:
31:00

English subtitles

Revisions