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

Jonathan Filbert - A Very Gentle Introduction to Flutter

Jonathan Filbert - A Very Gentle Introduction to Flutter

A deck I used as a material for a Flutter Workshop held by Google Developer Student Clubs @ University of Indonesia.

Jonathan Filbert

September 23, 2021
Tweet

More Decks by Jonathan Filbert

Other Decks in Technology

Transcript

  1. Universitas Indonesia Flutter is Google’s UI toolkit for building beautiful,

    natively compiled applications for mobile, web, and desktop from a single codebase. Flutter.dev What is Flutter?
  2. Universitas Indonesia Google’s new way of developing applications for: Mobile

    Web (Project Hummingbird) Desktop Open Source! What really is Flutter?
  3. Universitas Indonesia Build consistent native mobile apps with a single

    codebase. Hot reload == awesomeness! Easy to learn. Why Flutter?
  4. Universitas Indonesia Before we begin, make sure you have: Development

    Setup Android Studio Flutter SDK Android SDK & Emulator
  5. Universitas Indonesia Start a development emulator Development Setup ~ flutter

    emulators PIXEL_API_V29 ~ flutter emulators --launch PIXEL_API_V29
  6. Universitas Indonesia Open the project in your editor and run.

    Initializing a Flutter Project Android Studio VS Code
  7. Universitas Indonesia Structure of a Flutter app Android & IOS

    Folder Holds a complete app for each respective platform. Use if you want to implement platform specific things. Lib folder Holds your dart code for your Flutter app Pubspec.yml Metadata about your apps (name, verson, etc) and dependencies
  8. Universitas Indonesia In your main.dart import 'package:flutter/material.dart'; void main() {

    runApp( MaterialApp( home: Scaffold( body: Center( child: Text("Hello World"), ), ), ), ); }
  9. Universitas Indonesia Widgets Widgets are a Data Type in Flutter

    that lets you build user interfaces. The central idea is that you build your UI out of widgets. Widgets describe what their view should look like given their current configuration and state. When a widget’s state changes, the widget rebuilds its description, which the framework diffs against the previous description in order to determine the minimal changes needed in the underlying render tree to transition from one state to the next.
  10. Universitas Indonesia Stateless vs Stateful Widgets A widget that is

    a collection of underlying widgets that describe its appearance more specifically. This happens all the way down until the root of all widgets, RenderObject.
  11. Universitas Indonesia Stateless vs Stateful Widgets A widget that has

    a mutable state property. A state property is a mutable variable inside the widget, that when changed, will trigger a widget diffing process in the widget tree. This will result in re-rendering of the changed widget.
  12. Universitas Indonesia Implementing a Stateless Widget . . . void

    main() => runApp(MaterialApp( home: MyApp(), ));
  13. Universitas Indonesia Implementing a Stateless Widget class MyApp extends StatelessWidget

    { const MyApp({Key key}) : super(key: key); @override Widget build(BuildContext context) { return Container( child: Scaffold( appBar: AppBar( title: Text('Startup Name Generator'), ), body: Center( child: Text("Hello World"), ), ), ); } }
  14. Universitas Indonesia Implementing a Stateful Widget void main() => runApp(MaterialApp(

    home: MyApp(), )); class MyApp extends StatefulWidget { MyApp({Key key}) : super(key: key); @override _MyAppState createState() => _MyAppState(); }
  15. Universitas Indonesia Implementing a Stateful Widget class _MyAppState extends State<MyApp>

    { int number = 1; @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Text(number.toString()), ), floatingActionButton: FloatingActionButton( child: Icon(Icons.add), onPressed: () { setState(() { number += 1; }); . . . .
  16. Universitas Indonesia Using the package #pubspec.yml dependencies: flutter: sdk: flutter

    cupertino_icons: ^0.1.2 english_words: ^3.1.0 # add this line . . .
  17. Universitas Indonesia Initializing the Scaffold class MyApp extends StatelessWidget {

    const MyApp({Key key}) : super(key: key); @override Widget build(BuildContext context) { return Container( child: Scaffold( appBar: AppBar( title: Text('Startup Name Generator'), ), body: RandomWord(), . . .
  18. Universitas Indonesia Creating the Random Worlds class RandomWord extends StatefulWidget

    { RandomWord({Key key}) : super(key: key); @override _RandomWordState createState() => _RandomWordState(); }
  19. Universitas Indonesia class _RandomWordState extends State<RandomWord> { String wordpair =

    WordPair.random(maxSyllables: 2).asPascalCase; List<WordPair> _suggestions = <WordPair>[]; . . . Creating the Random Worlds
  20. Universitas Indonesia . . . Widget _buildSuggestion() { return ListView.builder(

    padding: EdgeInsets.all(10.0), itemBuilder: (BuildContext _context, int i) { if (i.isOdd) { return Divider(); } int index = i ~/ 2; if (index >= _suggestions.length) { _suggestions.addAll(generateWordPairs().take(10)); } return _buildRow(_suggestions[index]); . . . Creating the Random Worlds
  21. Universitas Indonesia . . . Widget _buildRow(WordPair wp) { return

    Center( child: ListTile( title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[ Text( wp.asPascalCase, ), Icon( Icons.favorite_border, color: Colors.red, . . . Creating the Random Worlds
  22. Universitas Indonesia . . . @override Widget build(BuildContext context) {

    return _buildSuggestion(); } } . . . Creating the Random Worlds
  23. Universitas Indonesia Interactivity . . . Icon( alreadySaved ? Icons.favorite

    : Icons.favorite_border, color: Colors.red, ), . . .
  24. Universitas Indonesia Interactivity ListTile( . . . onTap: () {

    setState(() { alreadySaved ? _saved.remove(wp) : _saved.add(wp); } ); }, ),