learning flutter
Flutter is a multiplatform UI Framework that uses the Dart programming language. Dart includes a Dart VM with just in time (JIT) compilation (for dev hot reloading) and an ahead-of-time (AOT) compiler for producing machine code.
for web Dart can compile to JS and WASM.
The Dart language syntax is very similar to JS/TS
install
follow install guide on oficial site.
run flutter doctor
to verify flutter instalation.
deps:
- I installed flutter with
brew install flutter
- xcode developers tools installed via the macOS app store. and need to run some commands to set up the xcode CLI tools.
- cocoapods is a dep manager for Swift and Objective-C
- android SDK, simplest setup is to just install android studio. had to go to android studio settings and also install Android SDK Command-line Tools.
create project with flutter create myapp
and run with flutter run
flutter hot reload doesn't reset state, hot reset does.
how to run ios or android emulator:
- start iphone emulator:
open -a Simulator
when you have the emulator running flutter start automatically detects it a builds and run the app. - Android:
resources
- https://flutter.dev/learn
- codelabs sample proyects https://docs.flutter.dev/codelabs
- flutter docs https://docs.flutter.dev/
- dart docs https://dart.dev/language
theory
everything is a widget, like react components
widgets by default are stateless
'wiget is an immutable description of a part of a UI'. so flutter is declarative in a sense.
There are layout widgets like Column
and Row
.
entry point of an app is main.dart and the void main() => runApp();
function
widgets must have a build()
method
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context){
return MaterialApp(
title:'myapp',
theme: ThemeData(primarySwatch: Colors.blue)
);
}
}
// `Widget` is the return type of the build fn
state
setState()
triggers a re-rendering of the widget, by running the widget's build method again.
a stateful widget is separated into two classes StatefulWidget
(this is the class that allows the widget to remain immutable) and a accompanying _FooState extends State<Foo>
to initialize data (like making a req to API) in a stateful widget use the void initState()
method. There is also the dispose()
method that runs when the widget is removed from the UI.
there are other state management solutions that don't require you to use stateful widgets at all like 'provider' and 'cubit'
navigation
there is navigator 1.0 and 2.0.
for basic, learn 1.0
pages are in like a stack. navigator push() and navigator pop().