Skip to content

Instantly share code, notes, and snippets.

@buonzz
Last active October 26, 2024 14:37
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

create new project

flutter create . --org com.bilersolutions.<yourproject>

rename

rename setAppName --targets ios,android --value "YourAppName"

commands

install package

flutter pub add <package-name>

clean

flutter clean

get dependencies

flutter pub get

Concepts

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

Display on-screen keyboard in iOS simulator

⇧ + ⌘ + K

Open DevTools in browser for vscode

Ctrl + Alt + d

click "Open Devtools in Web Browser"

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

Boilerplate

Resources

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