-
Flutter_20230413_00. Flutter 입문> Frontend/Flutter 2023. 4. 13. 19:26
1. What is Class ? (Lec 35)
- Dart is an object-oriented language.
- Object is created by calling the constructor of a class
- This simply means that Class is a blueprint of making/customizing Object.
2. Building widgets + Restructuring (Lec 36~37)
class GradientContainer extends StatelessWidget { // GradientContainer({key}): super({key: key}); const GradientContainer({super.key}); // constructor: initialize // key will recieved and forward it to superClass // const is this is ta class that can be optimized that can be //[reused] !! @override Widget build(BuildContext context) { return Container( decoration: const BoxDecoration( gradient: LinearGradient( colors: [Color.fromARGB(255, 4, 2, 80), Color.fromARGB(255, 45, 7, 98)], begin: Alignment.topLeft, end: Alignment.bottomRight, )), child: const Center( child: Text( 'Hello World!', style: TextStyle(color: Colors.white, fontSize: 28), ), ), ); } }
3. Variables (Lec 38~ 42)
- final vs const
: final and const should not be changed.
: final은 실행시, const는 빌드시 값을 가지고 있어야함.
double? number = 1; // type ? will allow to keep null double number = null; // Error
dynamic message = 'Hello, World'; //able to change type message = 8;
- reformat
import 'package:flutter/material.dart'; class GradientContainer extends StatelessWidget { // GradientContainer({key}): super({key: key}); // constructor: initialize // key will recieved and forward it to superClass // const is this is ta class that can be optimized that can be [reused] !! const GradientContainer(this.text, {super.key}); // => same as below two lines // const GradientContainer(String text1, {super.key}): text1 = text2; // final String text2; // this.text means when it build, dart look for the class variable with that name, and mapped if there is a same name. // when this.text is added, const should not be front because , the text might be changed. // -> however if final is added, add const because it will always be the same object. final String text; // this is used to call from inside => only be set once and static cannbe set to final. @override Widget build(BuildContext context) { return Container( decoration: const BoxDecoration( gradient: LinearGradient( colors: [Color.fromARGB(255, 4, 2, 80), Color.fromARGB(255, 45, 7, 98)], begin: Alignment.topLeft, end: Alignment.bottomRight, )), child: Center( child: Text( text, style: const TextStyle(color: Colors.white, fontSize: 28), ), ), ); } }
'> Frontend > Flutter' 카테고리의 다른 글
Flutter_05. If-Statement & 퀴즈 데이터 (0) 2023.04.22 Flutter_04. Rendering Contents conditionally (0) 2023.04.19 Flutter_03. Excercise (0) 2023.04.18 Flutter_20230414_02. StatefulWidget (0) 2023.04.17 Flutter_20230414_01. Flutter (0) 2023.04.14