⌨️ 목적
플러터의 효율적인 개발을 위한 기초적인 가이드라인을 제공합니다.
⌨️ 주요 패키지
- 네비게이터: auto_route
- 상태관리: Provider
- 다이내믹링크: firebase_dynamic_links
- 인증: firebase_auth
- 로컬스토리지: flutter_secure_storage
- 네트워킹
- https: dio
- socket: web_socket_channel
- 국제화: easy_localization
- 애니메이션: lottie
- Push messages: firebase_messaging
- 에러 보고: firebase_crashlytics
⌨️ 개발 & 운영환경 분리
Flavors in Flutter
In this blog, we will be looking at how to implement Flavors in Flutter and configure Flavors in Android and iOS :). So let’s get started…
towardsdev.com
⌨️ 성능 측정
Performance in Flutter: What is it? How is it measured? How is it interpreted? How is it improved?
Once I was watching Star Wars, and Yoda said, “If you want to control your performance in Flutter, measure it, you must.”
medium.com
⌨️ Best Practice
(1)
Refactor code into widgets rather than methods
Don't
Text buildHello() => Text('Hello');
Do
So this prevents unnecessary rebuilds
class HelloWidget extends StatelessWidget {
const HelloWidget({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Text('Hello');
}
}
(2)
Use const constructor
Don't
Container(
width: 100,
child: const Text('Hello World')
);
Do
const Container(
width: 100,
child: const Text('Hello World')
);
(3)
Use SizedBox instead of Container as Placeholder widgets.
Don't
return _loaded ? SizedBox() : YourWidget();
Do
return _loaded ? SizedBox.shrink() : YourWidget();
(4)
Avoid print() calls
Don't
print('')
Do
debugPrint('')
(5)
Use private variable/method whenever possible
Don't
class Student {
String name;
String rollNo;
Student({
required this.name,
required this.rollNo,
});
}
Do
class Student{
String _name;
String _roolNo;
Student({
required String name,
required String roolNo,
}) : _name = name,
_roolNo = roolNo;
}
(6)
Don’t use ‘+’ for concatenating strings, use string interpolation
Don't
final String firstName = "John";
final String text = firstName + " Doe"
Do
final String firstName = "John";
final String text = "$firstName Doe"
(7)
Using async/await more readable way
Don't
Future<int> getUsersCount() {
return getUsers().then((users) {
return users?.length ?? 0;
}).catchError((e) {
log.error(e);
return 0;
});
}
Do
Future<int> getUsersCount() async {
try {
var users = await getActiveUser();
return users?.length ?? 0;
} catch (e) {
log.error(e);
return 0;
}
}
(8)
Use spread collections
Don't
var y = [4,5,6];
var x = [1,2];
x.addAll(y);
Do
var y = [4,5,6];
var x = [1,2,...y]; // 1,2,4,5,6
(9)
Use Literal to initialize growable collections.
Don't
var points = List();
var addresses = Map();
var points = List<Point>();
var addresses = Map<String, Address>();
Do
var points = [];
var addresses = {};
var points = <Point>[];
var addresses = <String, Address>{};
(10)
Use WidgetsBinding.instance.addPostFrameCallback
목적
- In some cases, we need to perform some action after the frame is rendered.
- Neither do not try to use any delay function, nor create custom callbacks!
- This will improve the performance by avoiding unnecessary rebuilds.
Do
WidgetsBinding.instance.addPostFrameCallback((_) {
//Perform the action here
});
'flutter' 카테고리의 다른 글
Scroll to Section (0) | 2024.02.03 |
---|---|
protobuf3 install (1) | 2024.01.29 |
🍃 flutter_ScrollPhysics (0) | 2022.11.16 |
Stateful to Provider (0) | 2022.11.14 |
flutter efficient (0) | 2022.07.18 |