Flutter (Software)

Open-Source UI-Software-Entwicklungskit für plattformübergreifende Anwendungen

Flutter ist ein quelloffenes Benutzerschnittstellen-Entwicklungs-Kit von Google. Mit Flutter können Cross-Platform Apps in der Programmiersprache Dart entwickelt werden. Ein Flutter-Programm soll ohne größere Anpassungen auf folgenden Zielplattformen lauffähig sein: Webanwendung, Android, iOS, Windows, Linux, macOS und Google Fuchsia.[7][4][5] Laut Hersteller liegt der Fokus von Flutter auf kurzen Entwicklungszeiten, schneller Ausführungsgeschwindigkeit und „nativer User Experience“.[8]

Flutter

Basisdaten

Entwickler Google, Jonah Williams[1], Adam Barth, Greg Spencer, Ian Hickson
Erscheinungsjahr 2017[2]
Aktuelle Version 3.19.0[3]
(15. Februar 2024)
Betriebssystem Android, iOS, Windows, Linux, macOS, Google Fuchsia[4][5]
Programmiersprache C++, Dart[6], Skia
Kategorie Framework
Lizenz 3-Klausel-BSD
flutter.dev

Aufbau Bearbeiten

Flutter selbst ist in C++ geschrieben und verwendet die Dart Virtual Machine (Dart-VM), sowie die Grafikbibliothek Skia.[9] Bei der Ausführung von Programmen versucht Flutter zumindest eine Bildrate von 60 fps zu erreichen, bzw. 120 fps, wenn die Hardware dies zulässt.[10]

Flutter-Programme für Android, iOS, Windows, Linux und macOS werden entweder per JIT-Compiler auf einer Dart VM oder mittels AOT-Compiler direkt für die Zielplattform kompiliert.[11] Flutter-Webanwendungen werden nach JavaScript übersetzt und sind so direkt in modernen Webbrowsern lauffähig.[12]

Widget Bearbeiten

Die grundlegende Komponente in einem Flutter-Programm ist ein Widget, das wiederum selbst aus Widgets bestehen kann. Ein Widget bündelt die Logik, Interaktion und Darstellung innerhalb eines Objekts und erinnert im Aufbau an die JavaScript-Softwarebibliothek React.[13] Es gibt eine Reihe vorgefertigter Widgets, die bekannte und oft benötigte Interaktionen abbilden, wie zum Beispiel Buttons, Listen, Checkboxes, Tabs etc. Flutter verwendet nicht die Widgets der jeweiligen Plattform, sondern implementiert diese selbst.[14][15] Widgets für Android folgen den Material-Design-Richtlinien[16] während Widgets für andere Betriebssystem wie iOS, Windows, Linux oder macOS den jeweiligen Richtlinien folgen. Obwohl Widgets eine wesentliche Rolle bei Flutter einnehmen, können Programme auch (fast) ohne Widgets programmiert werden, indem man direkt auf einen Canvas zeichnet.[17][18][19]

Codebeispiele Bearbeiten

Die automatisch generierte main.dart Klasse, nachdem ein neues Projekt erstellt wurde, sieht folgendermaßen aus.

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Ein Hallo-Welt-Programm in Flutter könnte folgendermaßen aussehen. In diesem Fall werden die Material-Widgets verwendet.

import 'package:flutter/material.dart';

void main() => runApp(HelloWorldApp());

class HelloWorldApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Hello World App',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Hello World App'),
        ),
        body: Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }
}

Kompatibilität mit anderen Technologien Bearbeiten

Flutter kann mit anderen Technologien zusammenarbeiten.

Ein Beispiel für eine solche Software ist die Unity-Engine. Es ist möglich, den Code so zu verwalten, dass die Effizienz erhalten bleibt.[20]

Einzelnachweise Bearbeiten

  1. github.com.
  2. Chris Bracken: v0.0.6: Rev alpha branch. In: github.com. 12. Mai 2017, abgerufen am 14. November 2020 (englisch).
  3. github.com.
  4. a b Tim Sneath: Flutter and Desktop Apps. In: medium.com. 17. Juni 2020, abgerufen am 29. August 2020 (englisch).
  5. a b Chris Sells: Canonical enables Linux desktop app support with Flutter. In: medium.com. 9. Juli 2020, abgerufen am 26. August 2020 (englisch).
  6. medium.freecodecamp.org.
  7. Open-Source Clues to Google's Mysterious Fuchsia OS. Abgerufen am 30. Januar 2020 (englisch).
  8. Flutter - Beautiful native apps in record time. Abgerufen am 30. Januar 2020 (englisch).
  9. Skia | Documentation. Abgerufen am 6. März 2023 (englisch).
  10. Flutter performance profiling. Abgerufen am 1. März 2020 (englisch).
  11. Dart.dev Platforms. Abgerufen am 4. Februar 2021 (englisch).
  12. Web support for Flutter. Abgerufen am 30. Januar 2020 (englisch).
  13. Flutter - 60 FPS UI of the Future - Everything is a widget. Abgerufen am 1. März 2020 (englisch).
  14. Introduction to widgets. Abgerufen am 30. Januar 2020 (englisch).
  15. StatefulWidget class - widgets library - Dart API. Abgerufen am 30. Januar 2020.
  16. Material Components widgets. Abgerufen am 30. Januar 2020 (englisch).
  17. Canvas class. Abgerufen am 1. März 2020 (englisch).
  18. Zerker - a lightweight and powerful flutter graphic animation library. Abgerufen am 1. März 2020 (englisch).
  19. 2D game engine made on top of Flutter. Abgerufen am 1. März 2020 (englisch).
  20. Flutter with Unity – can it work? Our experience using these two tools to create quality applications. - Blog - Codigee. Abgerufen am 14. März 2023 (englisch).