7. Widgets
• != Activity
• != Fragment
• Like View…
• …but unlike View
7https://flutter.io/widgets/
8. Widgets
8
main() {
runApp(
new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.green,
),
home: new Scaffold(
appBar: new AppBar(
title: new Text("Flutter Demo"),
),
body: new Text("Hello World!"),
),
),
);
https://flutter.io/widgets/
9. Stateless Widget
• Immutable views (widgets)
• Only one time is built
• Examples: Text, Icon, IconButton, etc.
9https://flutter.io/widgets/
10. Stateless Widget
10
new Text(
'Hello! How are you?',
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: new TextStyle(fontWeight: FontWeight.bold),
)
https://flutter.io/widgets/
11. Stateful Widget
• Still immutable, but…
• Contains State<W>
• Redraw after setState(() -> {}) call
• Examples: AppBar, Scaffold, TextField, etc.
11https://flutter.io/widgets/
17. What does it mean for Android developers?
17
Android SDK Flutter
View / XML Widget
Activity / Fragment ~ State
Intent / FragmentManager (navigation) Navigator
Async UI async / await like JS or Kotlin coroutines
-dpi 1.0x, 2.0x, 3.0x
build.gradle pubspec.yaml
strings.xml static class Strings (till)
18. String resources
18
class Strings {
static String appName = "Flutter Demo";
static String hotels = "Hotels";
}
new MaterialApp(
title: Strings.appName,
theme: new ThemeData(
primaryColor: Colors.white,
),
home: new HotelsPage(),
),