앱 state 초기화가 필요한 경우, 변경하는 사항이 build() 메서드 밖에 있는 경우에는 hot restart를 사용하자
코드 수정 내역 반영이 안 되면, hot reload > hot restart > full restart 순으로 해보자
정리
명령어
# flutter run
...
Flutter run key commands.
r Hot reload.
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
* hot reload, hot restart, full restart
hot reload
소스 코드를 실행 중인 dart vm(virtual machine)에 삽입해서 작동
vm이 새 버전의 필드와 함수로 클래스를 업데이트 한 후, 위젯 트리를 자동으로 재빌드
(web은 아직 지원하지 않음)
hot restart
hot reload에 추가로 앱 state가 초기화 됨
full restart
코드 재컴파일 후, 앱을 재시작 함
* hot reload 특수 상황 (동작하지 않거나 오동작하는 경우)
앱이 종료 된 경우
수정한 코드에 컴파일 오류가 발생 한 경우
CupertinoTabView (요놈은 수정 중)
enum을 class로, class를 enum으로 변경 한 경우
font 를 변경 한 경우 (대부분 asset은 지원하나 font는 지원 안 함. hot restart가 필요함)
classControllerextendsGetxController{
var count = 0.obs;
increment() => count++;
}
classHomeextendsStatelessWidget{
@overrideWidget build(context){
// Instantiate your class using Get.put() to make it available for all "child" routes there.final Controller c = Get.put(Controller());
return Scaffold(
// Use Obx(()=> to update Text() whenever count is changed.
appBar: AppBar(title: Obx(() => Text("Clicks: ${c.count}"))),
// Replace the 8 lines Navigator.push by a simple Get.to(). You don't need context
body: Center(child: ElevatedButton(
child: Text("Go to Other"), onPressed: () => Get.to(Other()))),
floatingActionButton:
FloatingActionButton(child: Icon(Icons.add), onPressed: c.increment));
}
}
classOtherextendsStatelessWidget{
// You can ask Get to find a Controller that is being used by another page and redirect you to it.final Controller c = Get.find();
@overrideWidget build(context){
// Access the updated count variablereturn Scaffold(body: Center(child: Text("${c.count}")));
}
}
// 웹 체크 보통 이런식인대import'package:flutter/foundation.dart' show kIsWeb;
if (kIsWeb) {
// running on the web!
} else {
// NOT running on the web! You can check for additional platforms here.
}
// 아래와 같이 제공classGetPlatform{
static bool get isWeb => GeneralPlatform.isWeb;
static bool get isMacOS => GeneralPlatform.isMacOS;
static bool get isWindows => GeneralPlatform.isWindows;
static bool get isLinux => GeneralPlatform.isLinux;
static bool get isAndroid => GeneralPlatform.isAndroid;
static bool get isIOS => GeneralPlatform.isIOS;
static bool get isFuchsia => GeneralPlatform.isFuchsia;
static bool get isMobile => GetPlatform.isIOS || GetPlatform.isAndroid;
static bool get isDesktop =>
GetPlatform.isMacOS || GetPlatform.isWindows || GetPlatform.isLinux;
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "tistory",
"request": "launch",
"type": "dart",
"flutterMode": "debug",
}
]
}
* 추가로 widget이 늘어지니, color bracket 관련 된 거 정도만 설치하면 좋은 듯
1이 install 수도 많고, 2는 베타 버저닝이긴 한대 잘 돌긴 하는 듯 (1, 2 둘 다 archived 됐네)