Build Native Mobile Apps with Flutter
Lesson 1-15: Quiz < Code the Unit Converter AppBar and Category Route >
In this exercise, you'll finish the implementation of the CategoryRoute.
Flutter에서 화면을 구현할 때 주로 StatelessWidget 혹은 StatefulWidget을 확장(extend)해서 구현한다. 이때 build() 함수를 여러가지 low-level의 Widget들의 조합으로 정의해야한다.
StatelessWidget: 변경 가능한 상태가 필요하지 않은 위젯
StatefulWidget: 변경 가능한 상태를 가진 위젯
StatelessWidget의 build 함수는 화면이 처음 그려질 때 한번만 불려지며, Widget을 삭제하기 전까지 다시 불려지지 않는다. 별도의 상태를 변경할 수 없는 Widget들을 나타낸다. 즉, 한번 화면에 나타나면 변경될 수 없다.
이러한 StatelessWidget을 구현하기 위해서는 build() 함수를 오버라이드하여 Widget에서 활용할 Low-Level의 Widget들을 반환한다.
👇🏻 example code
class UnitConverterApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Unit Converter',
// TODO: Instead of pointing to exactly 1 Category widget,
// our home should now point to an instance of the CategoryRoute widget.
home: CategoryRoute(),
);
}
}
: controls the size of the shadow below the app bar.
▫️ The value must be non-negative.
▫️ If this property is null, then AppBarTheme.elevation of ThemeData.appBarTheme is used. If that is also null, the default value is 4
: child widget에 Padding을 가지도록 하는 Widget
👇🏻 example code
padding: EdgeInsets.symmetric(horizontal: 8.0),
⬇️ After tap