Flutter

Google UI toolkit for cross-platform apps - single codebase, hot reload, native performance

TL;DR

What: Google’s UI toolkit for building natively compiled applications.

Why: Single codebase for iOS/Android/Web/Desktop, hot reload, beautiful UIs, great performance.

Quick Start

Install: Follow flutter.dev/docs/get-started/install

Verify:

flutter doctor

Create new app:

flutter create my_app
cd my_app
flutter run

Cheatsheet

CommandDescription
flutter create nameCreate new project
flutter runRun on device/emulator
flutter build apkBuild Android APK
flutter build iosBuild iOS app
flutter pub getGet dependencies
flutter pub add pkgAdd package
flutter testRun tests

Gotchas

Basic widget

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('My App')),
        body: const Center(child: Text('Hello, Flutter!')),
      ),
    );
  }
}

Stateful widget

class Counter extends StatefulWidget {
  @override
  _CounterState createState() => _CounterState();
}

class _CounterState extends State<Counter> {
  int _count = 0;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Text('Count: $_count'),
        ElevatedButton(
          onPressed: () => setState(() => _count++),
          child: const Text('Increment'),
        ),
      ],
    );
  }
}

Common widgets

// Layout
Column(children: [...])
Row(children: [...])
Container(padding: ..., child: ...)
ListView.builder(itemBuilder: ...)

// Input
TextField(controller: ..., onChanged: ...)
ElevatedButton(onPressed: ..., child: ...)

// Display
Text('Hello')
Image.network('url')
Icon(Icons.star)
// Push
Navigator.push(context, MaterialPageRoute(builder: (context) => NextPage()));

// Pop
Navigator.pop(context);

// Named routes
Navigator.pushNamed(context, '/details');

Next Steps