Skip to content

Instantly share code, notes, and snippets.

@buonzz
Last active June 18, 2024 10:52
Show Gist options
  • Save buonzz/c36cbef6d6b6147f9a4c4afb5b03a1c1 to your computer and use it in GitHub Desktop.
Save buonzz/c36cbef6d6b6147f9a4c4afb5b03a1c1 to your computer and use it in GitHub Desktop.
flutter cheatsheet

Installation

clone

git clone https://github.com/flutter/flutter.git -b stable

add the flutter/bin to your PATH variable

run flutter doctor

flutter doctor

install android studio from https://developer.android.com/studio make sure ANDROID_SDK_ROOT is set to the path of your SDK

setup android studio emulator to have at least one device to test with

see more at https://flutter.dev/docs/get-started/install/windows

commands

install package

flutter pub add <package-name>

clean

flutter clean

get dependencies

flutter pub get

Concepts

  • Similar to ReactJS
  • Widget = Component
  • Uses Dart programming language (similar to ES6)
  • Sample project https://github.com/buonzz/startup_namer
  • pubspec.yaml is like packages.json
  • https://pub.dev/ is like npmjs.com
  • BLoC - Business Logic Component, predictable state management library for Dart

Dart Basics

each app has main function

void main() {
  print('Hello, World!');
}

importing

// Importing core libraries
import 'dart:math';
// Importing libraries from external packages
import 'package:test/test.dart';
// Importing files
import 'path/to/my_other_file.dart';

StatelessWidget - dont have properties that change over time StatefulWidget - changes based on user interaction and other factors, store mutable state in a seperate class called State StatefulWidgets don’t have a build method; instead, their user interface is built through their State object

get a state class from any parent

StudentState extends InheritedWidget

final studentState = StudentState.of(context);

UI

  • SafeArea - widget that avoids operating system interfaces

Basic Layout with navigation menu on top

main > runApp > MaterialApp.home > SafeArea.child > StatelessWidget.build > Material.child > Column.children > MyAppBar and Expanded

State Management

Riverpod - state management for flutter.

  • Provider - simple immutable objects
  • StateProvider - simple mutable objects
  • FutureProvider - values that are resolved asynchronously
  • StreamProvider - values that come from a continuous stream

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment