Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting Started With Flutter

Getting Started With Flutter

This presentation is an introduction to Flutter. There's a technical and a non-technical part, which talks about the characteristics of Flutter, and what can be useful to know before starting to use it.

Yannick VG

March 19, 2019
Tweet

Other Decks in Programming

Transcript

  1. Who am I? Yannick Van Godtsenhoven Android Team Lead /

    Developer @ PlayPass We provide solutions for events and venues all around the world ◦ Cashless Payments ◦ Access Control ◦ Accreditation Management ◦ Brand Activation Rock Werchter, Graspop, Dour, Lollapalooza, Standon Calling, RSCA, 40-45 Musical ...
  2. What is Flutter? “Mobile app SDK for crafting high-quality native

    experiences on iOS and Android” “A powerful general purpose open UI toolkit for building stunning experiences on any device: embedded, mobile, desktop and beyond” Completely open source by Google 2015 2019 2017 2018 “Sky” Beta Alpha 1.0 1.2
  3. Productive Stateful hot reload Multiple IDE Develop on one OS,

    just test on the other * Dart DevTools * most of the time
  4. Open Completely open source Free Community Very nice documentation Lots

    of plugins https://github.com/flutter/flutter https://flutter.dev https://pub.dartlang.org Gitter, Slack, Medium, ...
  5. Cross Platform Write once, run everywhere ( ) Doesn’t use

    native components, has its own components that look native Talks to the system for things like storage, permissions, location, ... Embed native views in Flutter Embed Flutter in native views
  6. Technically Written in Dart Full screen app AOT compilation Skia

    Engine compiled into the app Platform Channels JIT compilation
  7. VS Xamarin React Native Flutter Performance Productivity Price expensive free

    free Custom UI Native Understanding needed needed not needed Platform Updates needed but fast needed not needed Min Android ? 4.1 (16) 4.1 (16) Min iOS ? 9 8 Maturity Stable Widely Used Young
  8. How

  9. Setup Download SDK from flutter.dev and add the `flutter` tool

    to your path Run `flutter doctor` to see what’s missing
  10. IDE Flutter plugins available for both AS plugin has more

    functionality (Outline View, Inspector, …) Android Studio Visual Studio Code
  11. Widgets, widgets, widgets THE main building block for Flutter applications

    Every widget has a specific purpose An application is a composition of widgets
  12. Style Input Material Cupertino ... Async Layout Material Scaffold AppBar

    BottomNavigationBar Drawer FloatingActionButton SimpleDialog SnackBar Card
  13. What are widgets really? They are configuration for Elements, pieces

    of an app’s UI Element = instantiated Widget that is displayed on screen Everything on screen is in a tree of Elements Widget Tree Element Tree RootWidget RootElement ChildWidget ChildElement ChildWidget ChildElement
  14. Stateless Widget Doesn’t have any property that has a value

    that changes over time class StatelessWidgetExample extends StatelessWidget { final String value; const StatelessWidgetExample({Key key, this.value}) : super(key: key); @override Widget build(BuildContext context) { return Text(value); } }
  15. Stateful Widget When you want your widget to change when

    some data changes over time class StatefulWidgetExample extends StatefulWidget { final String immutableValue; StatefulWidgetExample({this.immutableValue}); @override _StatefulWidgetExampleState createState() => _StatefulWidgetExampleState(); } class _StatefulWidgetExampleState extends State<StatefulWidgetExample> { int mutableValue; @override Widget build(BuildContext context) { return Text('${widget.immutableValue}: $mutableValue'); } } return GestureDetector( onTap: () { setState(() { mutableValue++; }); }, child: Text('${widget.immutableValue}: $mutableValue'));
  16. State (0) State (1) Text (0) Text (1) Stateful Widget

    Widget Tree Element Tree Stateful Widget Stateful Element Stateless Element
  17. Build efficient UIs Use stateless widgets as much as possible

    Dont pass values around in the widget hierarchy InheritedWidget Inherited Widget Child Widget Child Widget Chil d Widget Child Widget MyInteritedWidget.of(context).whateverValue
  18. Bloc Pattern Architectural Pattern pushed by Google… for now Business

    Logic Component Very much like MVVM Bloc = ViewModel Reactive
  19. class IncrementBloc implements BlocBase { int _counter; StreamController<int> _counterController =

    StreamController<int>(); StreamSink<int> get _inAdd => _counterController.sink; Stream<int> get outCounter => _counterController.stream; IncrementBloc(){ _counter = 0; } void increaseCount(){ _counter = _counter + 1; _inAdd.add(_counter); } void dispose(){ _actionController.close(); _counterController.close(); } }
  20. @override Widget build(BuildContext context) { final IncrementBloc bloc = BlocProvider.of<IncrementBloc>(context);

    ... StreamBuilder<int>( stream: bloc.outCounter, initialData: 0, builder: (BuildContext context, AsyncSnapshot<int> snapshot){ return Text('We counted ${snapshot.data} times'); } ), ... FloatingActionButton( child: const Icon(Icons.add), onPressed: (){ bloc.increaseCount(); }, ), ... }
  21. Bloc Pattern Advantages Separation of concerns Testability Less Stateful widgets,

    rebuild on changes Multiple Blocs for even more separation
  22. Why

  23. Stateless Tile Widget Stateless Tile Widget Stateless Tile Widget Stateless

    Tile Widget Swap Row Widget Row Element Stateless Tile Element Stateless Tile Element Stateless
  24. Stateful Tile Widget Stateful Tile Widget Stateful Tile Widget Stateful

    Tile Widget Swap Row Widget Row Element Stateful Tile Element Stateful Tile Element State red State green Stateful
  25. Stateful Tile Widget Key 2 Stateful Tile Widget Key 1

    Stateful Tile Widget Key 1 Stateful Tile Widget Key 2 Swap Row Widget Row Element Stateful Tile Element Key 2 Stateful Tile Element Key 1 State red State green Stateful with keys
  26. Stateful Tile Widget Key 1 Stateful Tile Widget Key 2

    Stateful Tile Widget Key 2 Stateful Tile Widget Key 1 Swap Row Widget Row Element Stateful Tile Element Key 1 State red Stateful Tile Element Key 2 State green Stateful with keys
  27. Stateful Tile Widget Key 1 Stateful Tile Widget Key 2

    Stateful Tile Widget Key 2 Stateful Tile Widget Key 1 Swap Row Widget Row Element Stateful Tile Element Key 1 State red§ Stateful Tile Element Key 2 State green Stateful with keys