Flutter 및 Dart 팁 - 검토 주간 #7
13922 단어 codenewbiedartflutterbeginners
지금까지 38개의 Flutter\Dart 팁을 공유했습니다. Flutter & Dart Tips 시리즈의 7번째 포스트에서는 6가지를 더 공유하겠습니다.
1- SafeArea는 시스템 상태 표시줄, 노치, 구멍, 둥근 모서리 등에 의해 차단되지 않도록 충분한 패딩으로 자식을 삽입하는 패딩 위젯입니다.
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
top: true,
bottom: true,
left: true,
right: true,
minimum: EdgeInsets.all(16.0),
maintainBottomViewPadding: true,
child: Text('Check this important text'),
),
);
}
2- MediaQuery를 사용하여 현재 장치 크기, 방향 및 사용자 기본 설정에 대한 정보를 얻습니다.
...
var orientation, size, height, width;
// getting the orientation of the app
orientation = MediaQuery.of(context).orientation;
//size of the widow
size = MediaQuery.of(context).size;
height = size.height;
width = size.width;
...
// checking the orientation
body: orientation == Orientation.portrait
? Container(
color: Colors.green,
height: height / 4,
width: width / 4,
)
: Container(
height: height / 3,
width: width / 3,
color: Colors.yellow,
),
3- 믹스인을 사용하면 하위 클래스를 만들 필요 없이 코드 블록을 연결할 수 있습니다.
...
mixin Fluttering {
void flutter() {
print('fluttering');
}
}
abstract class Bird with Fluttering {
void flap() {
print('flap flap');
}
}
class Hawk extends Bird {
void doHawkThing() {
flap();
flutter();
print('Hawk is Flying');
}
}
main() {
var hawk = new Hawk();
hawk.doHawkThing();
}
4- 함수를 매개변수로 다른 함수에 전달할 수 있습니다.
void main() {
const list = ['London', 'Dublin', 'Belfast'];
list.forEach(
(item) => print('City Of $item'));
}
5- Getter 및 Setter는 개체 속성에 대한 읽기 및 쓰기 액세스를 제공하는 특수 메서드입니다.
class Rectangle {
double left, top, width, height;
Rectangle(this.left, this.top, this.width, this.height);
// Define two calculated properties: right and bottom.
double get right => left + width;
set right(double value) => left = value - width;
double get bottom => top + height;
set bottom(double value) => top = value - height;
}
void main() {
var rect = Rectangle(3, 4, 20, 15);
print(rect.left);
rect.right = 12;
print(rect.left);
}
6- 문자열을 추가하거나 연결하는 네 가지 방법이 있습니다.
void main() {
//1- Using ‘+’ operator.
String str1 = "Dart";
String str2 = "Is";
String str3 = "Fun";
print(str1 + str2 + str3);
//2- String interpolation.
print('$str1 $str2 $str3');
//3- Directly writing string literals.
print('Dart' 'Is' 'Fun');
//4- Strings.join() method.
// Creating List of strings
List<String> str = ["Dart", "Is", "Fun"];
String _thestr = str.join();
print(_thestr);
_thestr = str.join(" ");
print(_thestr);
}
다음주에 보자. 👋🏻
Follow me on for more tips about #coding, #learning, #technology...etc.
Check my Apps on Google Play & Apple Store
표지 이미지NASA on Unsplash
Reference
이 문제에 관하여(Flutter 및 Dart 팁 - 검토 주간 #7), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/offlineprogrammer/flutter-dart-tips-week-in-review-7-5o3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)