Flutterã§ã®éçºãã¹ã ã¼ãºã«è¡ãããã®Tipsé
以ä¸ã®ããã¥ã¡ã³ãã«ãã¶ãå 容ãå«ã¾ãã¦ãã¾ãããåãè¯ããªã¨æã£ã¦ããããæ¹ãå ±æãã¾ãã
æ¬è¨äºã®å 容ã¯ãããç¨åº¦æ¸ãã¦ãããè²ã è¨äºãèªãã§ããã¨èªç¶ã¨èº«ã«ã¤ãã¦ããé¡ã®ãã®ã§ãããåãããè²ã ç¥ã£ã¦ããã¨æãã®ã¨ããã§ã«æ £ãã¦ããå ´åã§ãå°ãã¯æ°ããçºè¦ãããããããã¾ããã
ã¾ããFlutterã®å¹çè¯ãå¦ã³æ¹ ã«ãæ¸ããéããèªåã§Flutterã³ã¼ããæ¸ãåã«ã¯Android Studioã®æ¹ãæãã¨æãã¦ããããããã«æ²¿ã£ã説æã«ãªã£ã¦ãã¾ãããVS Codeã§ã大ä½éããå 容ã§ããã¾ãããã¼ãã¼ãã·ã§ã¼ãã«ããã¯macOSã§ã®ããã©ã«ãã¨ãªã£ã¦ããã®ã§ãç°å¢ãéãå ´åã¯éæèªã¿æ¿ãã¦ãã ããã
[è¿½è¨ 2019/03/03] æè¿ã¯VS Codeã«çµãã®ãè¯ãããªã¨æã£ã¦ãã¦ãã¾ã(â 2022å¹´2æããVS Codeã«ä¹ãæãã¾ãã)
æ°è¦ã¢ããªä½æ
æ®éã«Flutterã¢ããªãä½æããæé ã¯å ¬å¼ããã¥ã¡ã³ãã«åãããããè¨è¼ããã¦ãã¾ãã
åºæ¬ã¯ãã®éãã§è¯ãã§ãããã¿ã¼ããã«çµç±ã®å ´åã flutter create app_name
ã ãã ã¨ä»¥ä¸ã®ãããªããã©ã«ãå¤ãè¨å®ããã¦ãã¾ãããã¨ãã好ã¿ã®ãã®ã«å¤ããã®ããã£ãããªæéã§ãã
- æå±(ã¢ããªIDã®ååé¨åã«å©ç¨ããã): com.example
- flutter_driver (UIãã¹ã): ç¡ã
ãã®ããã次ã®ããã«èªåã®å¥½ã¿ã®ãã®ãã¡ã¢ãããã³ãã³ããã¹ããªã¼ããå¼ã³åºããããã«ãã¦ããã¨ä¾¿å©ã§ãã
flutter create \
--org com.mono0926 \
--with-driver-test \
app_name
ã¡ãªã¿ã«ããã®è¨å®ã¯ä»¥ä¸ã®ã»ãã·ã§ã³åç»ã§ãªã¹ã¹ã¡ããã¦ãããã®ã§ãã
ãã ãå人çã«ã¯Android Studioã®âNew Flutter Projectâã§ããããé¸æãã¦ããã®ã好ã¿ã§ã(ããããã®å ´åflutter_driveræå®ã¯ã§ããªãããð¤)ã
VS Codeã®å ´åã¯ã次ã®ããã«Dartã®æ¡å¼µã®è¨å®ã§æå®ã§ãã¾ãã
ãã¤ãã£ãã¢ããªå´ã®è¨èªè¨å®ã¯ãç¾å¨ã§ã¯ä»¥ä¸ãããã©ã«ãã§ã(以åã¯éã§ãããå¤ããã¾ãã)ã
- iOS: Swift (not Objective-C)
- Android: Kotlin(not Java)
大æµã®å ´åãã®é¸æã®ã¾ã¾ã®æ¹ãè¯ãã§ãããã©ããã¦ãå¤ãããæãããã°ããã¸ã§ã¯ãä½ææã«æ³¨æãã¦é¸æãã¾ãããã
ç¹ã«ããã¤ãã£ãè¨èªã®ç¨®é¡ã¯ãå¾ããå¤ãããå ´åãä½ãç´ããããã«æºããä½æ¥(è¨å®ã«å¿ãã¦çããå·®åãæåã§é©ç¨ãªã©)ãå¿ è¦ã«ãªãã®ã§ãå°ãé¢åãªãã¨ã«ãªãã¾ãã
ã¾ããå人çã«ã¯æè¿ã¯ããã«å·¥å¤«ãã¦ããã¸ã§ã¯ãçæå¾ã«ãã¤ãè¡ã調æ´ãã¹ã¯ãªããã§é©ç¨ããä»çµã¿ãæ´ãããã¨ããã¦ãã¦ãã¡ãã£ã¨ããããã¸ã§ã¯ããä½ãæ©ä¼ãå¤ãå ´åã¯æãããã«ãªãã¾ãã
ããã¸ã§ã¯ãã®ã«ã¼ãã« analysis_options.yaml ã追å
ã¢ããªãä½ã£ãããã¾ãåãã« analysis_options.yaml ãç½®ãã¦éç解æãå³ããããã®ãè¯ãã¨æã£ã¦ãã¾ãã詳ããã¯ä»¥ä¸ã®è¨äºã«æ¸ãã¾ããã
dartfmt ãæ´»ç¨
Dartã³ã¼ããæ¸ãã«ããã£ã¦ãéä¸dart formatã使ã£ã¦æ´å½¢ãã¦ããã®ã¯å®è³ªå¿
é ã§ã以ä¸ã§ãå§ãããã¦ãã¾ããã©ããªã«éã«æ¸ããã¨ãã dart format
ä¸çºã§ä¸æã®ããããªãã©ã¼ãããã«æ´å½¢ãã¦ããã¾ãã
To automatically format the code in the current source code window, right-click in the code window and select Reformat Code with dartfmt. You can add a keyboard shortcut to this in Keymap section of IntelliJ Preferences.
ãã Android Studioã§dartfmtããããæ¹æ³ã¨ãã¦ãå³ã¯ãªãã¯ãã¦âReformat Code with dartfmtâãé¸ã¶ãoption + command + Lã®ã·ã§ã¼ãã«ããã§å®è¡ããããæ¹ãç´¹ä»ããã¦ãã¦ããã¾ãã¡ã«æãã¾ãã
ä¸ã ãã®æä½ãããã®ã§ã¯ãªããã»ã¼ãããã¨èªåçã«dart formatãããã¦ããã以ä¸ã®è¨å®ãããæ¹ãé¥ãã«å¿«é©ã§ãããµãã¡ãã¥ã¼ã®âOrganize imports on saveâã¯ãã»ã¼ãæã«importã®ä¸¦ã³é æ´çããã³ä¸ä½¿ç¨ãªãã®ã®åé¤ããã¦ããã¦ããã¡ãã¯ãªã³ã«ããã好ã¿ã«ä¾ãã¨æãã¾ã(åºæ¬çã«ã¯ä¾¿å©ãªãã®ã®ãä¸æçã«ã³ã¡ã³ãã¢ã¦ããããã®ã«å¯¾å¿ããimportåãã«ããããã¦é¢åãªãã¨ããã¾ã«ããã®ã§)ã
ã¾ãããã©ã¼ãããã®ããã£ã¦ããªãæ¢åããã¸ã§ã¯ãã«å¯¾ãã¦ãä¸æã«å®è¡ãããå ´åã¯ä»¥ä¸ã®ã³ãã³ãã§ã§ãã¾ãã
( -w
ç¡ãã§dryrunã«ãªãã¾ããgit管çãªã©ãã¦ããã°ç¹ã«æãããã« -w
ä»ãã§å®è¡ãã¦ãã¾ã£ãåé¡ãªãã§ã)
dart format --fix lib
(ã¡ãªã¿ã«ãdart format
ã¯ä»¥å㯠dartfmt
ã¨å¼ã°ãã¦ãã¾ããããdartã®ãµãã³ãã³ãã«æ´çããã¾ããã)
Dartã®æ«å°¾ã³ã³ãã¯å¤§äº
Dartã®æ«å°¾ã³ã³ãã¯ãã®æç¡ã«ãã£ã¦dartfmtçµæãå¤ãã£ãããã¾ããUsing trailing commasã«ä»¥ä¸ã®å³ã¨ã¨ãã«èª¬æããã¦ããããã«ãåºæ¬çã«ã¯æ«å°¾ã« â,â ãå ¥ããæ¹ãããããã¤æ¨ªå¹ ãã³ã³ãã¯ãã«æ´å½¢ããã¾ãã
ã³ã³ãã®å ¥ãå ·åã«ã¤ãã¦ã¯ãFlutter/Dart ã³ã¼ãã£ã³ã° ã¹ã¿ã¤ã« ã®å 容ãããããã©ã³ã¹è¯ãæ°ããã¦ãã¾ãã
Alt + Enterã«ããAssistã»Quick Fixæ´»ç¨
JetBrains製IDEã§ããªãã¿ã®æ©è½ã§ãããIDEãã次ã®ããã«ä½ãææ¡ãããã¨è¡ã«ãã¼ã¯ãã¤ãã¦Alt + Enterã§ãã®åè£ããé¸æããã¨ã³ã¼ããä¿®æ£ãã¦ããã¾ã(ãã¼ã¯ãã¯ãªãã¯ã§ãã§ãã¾ãããã¼ãã¼ãã·ã§ã¼ãã«ããã®æ¹ãæãã¾ã)ã
Flutterã³ã¼ããæ¸ãã«ããã£ã¦å¤ç¨ããã®ããWidgetã§ã©ããããã³éã«Widgetãåé¤ããæ©è½ã§ãããããç¥ããªãã¨ç¹ã«ãã¹ãã®æ·±ãWidgetã®ç·¨éã®éã«ç¡é§ãªè¦å´ãå¼·ãããã¾ãã
åæ§ã®ãã¨ã¯å³ã«ããFlutter Outlineããã®å³ã¯ãªãã¯ã§ãå¯è½ã§ãã
Flutter Performance ã¿ãã®æ´»ç¨
Flutterã®Widgetã®æ±ããé©åã§ãªãã¨ãbuildã¡ã½ãããæå³ãã¬é«ãé »åº¦ã§å¼ã°ãã¦ãã¾ããã¨ãããã¾ããbuildã¡ã½ããããã®ä»ã©ã¤ããµã¤ã¯ã«ã®é¢ä¿ããã¨ããã«ãã°ãä»è¾¼ãã®ãè¯ãã§ãããã¨ããããããããã®Widgetã®ãªãã«ãåæ°è¦ãã ãã§å¤§ä½åããæ´ãããããã®ã§ãã¡ããã¡ãã観å¯ãã¦ãã¾ãã
以ä¸ã®è¨äºãæ¸ãéã«ãå¤ç¨ãã¾ããã
ãããããã¾ã«è¡¨ç¤ºããããããã¨ãããã®ã§ããã«ãªãã¼ãããããããã§ãç´ããªãæã¯IDEãåèµ·åããããã¦ãã¾ãð¤
UIã®ãã¬ãã¥ã¼æ©è½ã¯ç¡ãã®ï¼
ä¸å¿ããã¾ãããã¾ã å®é¨çãªæ©è½ã§ä¸å®å®ãªã®ã§åã¯åã£ã¦ãã¾ãã¾ããã
ãã¡ãã¨åãããã«ãªãã¨ä¾¿å©ãªã®ã§æå¾ ãã¦ãã¾ãã次ã®Issueãè³¼èªãã¦ããã¨ãåããããã¨åããã¾ãã
2019å¹´9æã«ãFlutteréçºãã¼ã å é¨ã§ãããã¿ã¤ãã¨ãã¦éçºä¸ã®HotUIã¨ããæ©è½ã«ã¤ãã¦ã®ææ¸ãå ¬éãããå°æ¥ããã«è¿ãå½¢ã®ãã®ãIDEã«çµ±åãããã¨äºæ³ãããã®ã§ããããã¨ã¦ã楽ãã¿ã§ãã
以ä¸ã®æ©è½ãªã©ãæ¤è¨ããã¦ããããã§ãããã«é¢ãã¦ã¯ SwiftUI ã«å¯¾ãã¦æ確ã«å£ã£ã¦ããé¨åã§ä¸æºã ã£ãã®ã§ã対å¿ãããã¨å¬ããã§ãã
- Widgetå ¨ä½ããã³ãã®ä¸ã®ä¸é¨åã®ãã¬ãã¥ã¼è¡¨ç¤º
- ãã¬ãã¥ã¼UIããã®ã³ã¼ãå¤æ´æä½
ååå®è£ æã¯ãã·ãã¥ã¬ã¼ã¿ã¼ã§ã®ã¬ã¤ã¢ã¦ãçµæãHot Reloadã§ç¢ºèªããªããå®è£ ããã°è¯ãã ããªã®ã§ãã¬ãã¥ã¼ã欲ããã¨æããã¨ã¯ãã¾ããªãã§ãããå¾ããå種ã½ã¼ã¹ã³ã¼ããã©ãããUIãæ§ç¯ãã¦ããã®ã確èªãããã¨ããªã©ã«ãã¬ãã¥ã¼ãããã¨ã¨ã¦ãæãã¯ãã§ãã
常ç¨ãããããã±ã¼ã¸
å©ç¨ããããã±ã¼ã¸ã¯ã¢ããªã«ãã£ã¦ç°ãªãã¾ããããã®ä¸ã§ãå人çã«ããã¯å¸¸ã«å ¥ãã¦ããã¨æãã¨æããã®ãåæãã¾ãã
quiver
Dartã¯ã¾ãã¾ãæ°ã«å ¥ã£ã¦ãããã®ã®ãããããç°¡åã«æ¸ããªãã®ããã¨é©ããã¨ãã¡ããã¡ããããã¾ãã
ä¾ãã°ã0ããé ã«10åã®è¦ç´ ã欲ããæ(ããããrangeé¢æ°)ã«ã次ã®ãããªã³ã¼ããæ¸ãå¿ è¦ãããã¾ãã
List<int>.generate(10, (i) => i)
quiverãã¤ã³ã¹ãã¼ã«ãã¦ããã°ã次ã®ããã«ã·ã³ãã«ã«æ¸ãã¦è¯ãã§ãã
import 'package:quiver/iterables.dart';
range(0, 10)
Flutterãã¬ã¼ã ã¯ã¼ã¯ã§ã¯ãã¹ãã§ä½¿ããã¦ãããã dev_dependencies
ã«æå®ããã¦ãã¦ãã®ã¾ã¾åç
§ã§ãã¾ããããã¢ããªã³ã¼ãã¨ãã¦ä½¿ãããå ´åã¯å¥éã¢ããªã® pubspec.yaml
ã® dependencies
ã«æå®ãå¿
è¦ã§ãã
JavaScriptã«ãããLodash ã®ãããªãã®ã§ãããDartæ¬ä½ã«ã¯æè¿ã®JavaScriptããã便å©ãªã¡ã½ããã®ä¸è¶³ãæããã®ã§ããå¿ è¦åº¦ãé«ãæ°ããã¦ãã¾ãã
ã¨ããããã§ãDartã³ã¼ãæ¸ãã¦ã¦ã¡ãã£ã¨ä¸ä¾¿ã ã¨æã£ããquiverã§ç°¡åã«æ¸ããªããçãã¨è¯ãã¨æãã¾ãã主è¦ãªæ©è½ã¯ README ã«åæããã¦ãã¾ãã
åæ§ã«ãDartæ¬ä½ã«ã¯å ¥ã£ã¦ãªããããã±ã¼ã¸ã§è£å¡«ã§ãããã®ã¨ãã¦ã tuple ãªã©ãããã¾ãã
ã¡ãªã¿ã«ãDartæ¬ä½æ¹åã«ã¤ãã¦ä»å¾æå¾ ã§ããããªãã®ã¯ä»¥ä¸ã§ããã¾ã¨ãããã¦ãã¾ãã
rxdart
åãã¯ãDartã«ã¯æ¨æºã§Streams API ãããã®ã§ãrxdartã¯ããã§è¶³ããªãæã«éå®çã«å°å ¥ããã°è¯ãããªã¨æã£ããã®ã®ã大æµè¶³ããªããªãã®ã§æè¿ã¯ããã¸ã§ã¯ããä½ã£ããããå ¥ãã¦ãã¾ãã
ã¡ãã£ã¨ããStreamã®å¦çãªãRxDartç¡ãã¨ãæ¸ã¿ã¾ãããBLoCãã¿ã¼ã³ã使ãå ´åã¯å¿ é ã ã¨æã£ã¦ãã¾ãã
DartPad ã§ã¯RxDartã使ããªãã®ã§ãããã§Streamæ±ãããæã¯æ¨æºã®Streams APIã§ææ ¢ãã¦ãã¾ã( ´・â¿ï½¥ï½)
intl
å¤è¨èªå¯¾å¿ã®ããã®ããã±ã¼ã¸ã§ãããå¤è¨èªå¯¾å¿ããã¨ãä¾ãã°DateTimeãISO8601以å¤ã®æååã¨ãã¦è¡¨ç¤ºãããå ´åãªã©ã«ãå¿
è¦ãªã®ã§åãããå
¥ãã¦ãããæ¹ãè¯ãããªã¨æã£ã¦ãã¾ãã
(大æµã®ã¢ããªã¯ã¾ã1è¨èªã®ã¿ã®å¯¾å¿ã§ãæè¨ã¯åãããå¤è¨èªå¯¾å¿å¯è½ãªããã«ãã¦ããã®ãè¯ãã¨æã£ã¦ãã¾ãã)
å¼ããã±ã¼ã¸
å人çã«ä½ãå¿ è¦æ§ã«è¿«ããã¦ä½ã£ãã®ã§ã以ä¸ã大æµä½¿ã£ã¦ãã¾ããããã£ããã©ããã§ãã
- bloc_provider: BLoCãæ±ãããããããã
- simple_logger: ã·ã³ãã«ã»ä¾¿å©ãªãã¬ã¼
ãããããè¨äºãæ¸ãã¾ããã
ããã¥ã¡ã³ãä¸è¶³ãªãã®ãå¤ãã§ãããä»ã«ãè²ã å ¬éãã¦ãã¾ãã
ä»ã«ã常ç¨ããã¬ãã«ã®ä¾¿å©ãªããã±ã¼ã¸ãå¤ãã§ãããå ¬å¼ããã¥ã¡ã³ãã® Commonly Used Dart Libraries ãªã©è¦ãã®ãããããã§ãã
ã¢ããã¼ã·ã§ã³æ´»ç¨
Dartã¯Javaãªã©ã§ããªãã¿ã®ã¢ããã¼ã·ã§ã³ãããã¾ãã以ä¸ãªã©ã代表ä¾ã§ãã
ï¼ override
ãããä»ãã¦ããã¨ãOverrideããã¤ãããã¿ã¤ããªã©ã§å¥ã¡ã½ããæ±ãã«ãªã£ã¦ãã¾ã£ãã¨ãããã¹ãããå ´åãè¦åãåºãã¦ããã¾ããIDE使ã£ã¦ãè¡åè¯ãæ¸ãã¦ããã¨èªç¶ã«ä»ä¸ããã¾ãããä»ãå¿ããå ´åãææããã¾ãã
ï¼ required
å¿ é ãªãã©ã¡ã¼ã¿ã¼ã«ï¼ requiredãä»ãã¦ããã¨ãä¸æå®ã®æã«è¦åãåºãã¦ããã¾ããassertã§æ¾ãã®ãããã§ããããããã«ãããã¡ããæå®ãã¦ããã¨æå³ããªãå¼æ°æ¸¡ãå¿ããå®è¡åã«æ°ä»ãã¾ãã
ï¼ immutable
ãããä»ãã¦ããã¨ããã®ã¯ã©ã¹ã®ãã£ã¼ã«ãã¯ä¸å¤(åä»£å ¥ä¸å¯)ã§ãããã¨ã示ãã¾ãã
ã¾ããWidgetåºåºã¯ã©ã¹ã«ã¤ãã¦ããããã
final
ã§ã¯ãªããã£ã¼ã«ãã宣è¨ããã¦ããã¨è¦åãåºã¾ãã
ãã¡ãããèªä½ã¯ã©ã¹ã«ä»ä¸ãã¦åããä¸å¤ã§ãããã¨ã示ãã¾ãã
ãã ã final
ã¯å代å
¥ä¸å¯ã§ãã£ã¦ãä¾ãã°Listã®ä¸èº«ãä¸å¤ã§ãããã¨ãªã©ã¯ä¿è¨¼ã§ããããã®å ´å㯠UnmodifiableListView ãªã©ã使ãã¾ãã
ããããããã¯å¤æ´æä½ãã³ã³ãã¤ã«æã«é²ããã®ã§ã¯ãªããä¾ãã°æ¬¡ã®ãããªæä½ãããã¨ã
final x = UnmodifiableListView([1]);
x.add(2);
次ã®ãããªå®è¡æã¨ã©ã¼ã¨ãªãã¾ããããå°ã確å®ã«é²ããããã®ã§ããð¤
ãã®ä»ã以ä¸ãªã©ãæ´»ç¨ããã¨ãã¹é²æ¢ã«å½¹ç«ã¡ã¾ãã
- ï¼ mustCallSuper: ç¶æ¿å
ã§
super.xxx
ã®ããã«override
ããã¡ã½ãããå¼ã³å¿ããã¨è¦å表示 - ï¼ protected: ã¡ã½ããããç¶æ¿å ã§ã®å©ç¨ã®ã¿è¨±å¯ãã¦ãå¤ããå¼ã¶ã¨è¦å表示
- ï¼ visibleForTesting: ãã®ããã±ã¼ã¸ã®
lib
ãã©ã«ããããã¯ãã¹ãç¨ã®test
ãã©ã«ã以å¤ããå¼ã¶ã¨è¦å表示
Builder Widgetã§å ¥ãåã®BuildContextãæä¾
ä¾ãã°ã次ã®ããã« SnackBar ã表示ãããã¨ãã¾ãã
次ã®ããã«æ¸ãã¨æ®éã«åãã¨æãããããã
次ã®ãããªã¨ã©ã¼ãåºã¦ãã¾ãã¾ãð¤¯
ã¨ã©ã¼ã«èããã«ããèªãã§ã¿ãã¨ã次ã®ããã«æ¸ããã¦ãã¾ãã
- Scaffold.of()ãScaffoldãå«ã¾ãªãcontextã§å¼ã°ãã¦ãã
- Builderã使ãã®ãæãã·ã³ãã«ãªåé¿ç
- Widgetåå²ããã®ã(ããã©ã¼ãã³ã¹è¦³ç¹ã§)å¹çç
- GlobalKeyãScaffoldã«å ¥ãã¦ãcurrentStateããããã£ã§ScaffoldStateãåå¾ãã
ãã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ã®è¨ãéãã確ãã«contextã¯Homeã«æ¸¡ã£ã¦ãã¦ãããã®ã§ãããScaffoldé ä¸ã®ãã®ã§ã¯ããã¾ããã
(ãã®ããã«Flutterã§ã¯å®è¡æã¨ã©ã¼ãåºãæã«åå ã¨è§£æ±ºçãªã©å«ããä¸å¯§ãªã¨ã©ã¼ãåãããã®ã§ãé©å½ã«ã°ã°ã£ã¦å ´å½ããçãªå¯¾å¦ãããåã«ã¾ãã¯ããèªãã§èãã¾ãããã)
Widgetåå²
ã¾ããæãæ¨å¥¨ã£ã½ãWidgetåå²ãããã¿ã¼ã³ã試ãã¦ã¿ã¾ããWidgetåå²ã¯é¢åã«æããããããã¾ãããããããIDEã®æ©è½ã§ã§ãã¾ãã
次ã®ããã«å³ã¯ãªãã¯ã®Refactorããé¸ãã§ãè¯ãã§ããã
command + shift + Aã®ã¯ã¤ãã¯ã¢ã¯ã·ã§ã³ããé¸ã¶æ¹ãå¹ççã§ãã
åå²ããã¨æ¬¡ã®ããã«ãªã£ã¦ãSnackBarãç¡äºã«è¡¨ç¤ºã§ãã¾ããã¤ãã§ã«Scaffoldé ä¸ãconstã«ã§ãã¦ãããã©ã¼ãã³ã¹çã«ããã¿ã¼ã«ãªãã¾ããã
Builder Widget
ã¨ã¯ãããåããã¨ãã¯ãã³ã¼ãéãå°ãè¨ããã®ã§ãåãbuildã¡ã½ããå ã§å®çµãããæãããå¾ã¾ããããã§Builder Widgetã®åºçªã§ããããã使ãã¨æ¬¡ã®ããã«ãã£ããã¨åä½ããã³ã¼ããæ¸ãã¾ãã
å種Widgetã§ãchildã§ã¯ãªãbuilderå¼æ°ãæä¾ããã¦ãããã®ãããã¾ããããããã¯å©ç¨è ãBuilderãå¥é使ããã«æ¸ããããªé æ ®ã¨è¨ãã¾ãã
ããããBuildContextã¨ã¯ï¼
ã¡ãªã¿ã«ãBuildContextã¨ã¯ãªããªã®ãã¨ããã¨ãå®ä½ã¯Elementã§ããWidget(ãStatefulWidgetã®State)ã®buildã¡ã½ããã«æ¸¡ãéã«Elementãã®ãã®ãé²åããã«BuildContextæ½è±¡ã¯ã©ã¹ã¨ãããã¨ã§è¦ããããªããã®ãé è½ãã¦ãã¾ãã
ã¤ã¾ãBuildContextãããã®ä¸ä½ã®Elementããªã¼æ§é ã辿ãã¾ããå ã ã®ã¨ã©ã¼ã¯ãããããå¿ è¦ãªWidget(ãã®ä¾ã®å ´åScaffold)ã辿ããªããæ ã«çºçãã¦ããããã®Widgeté ä¸ã®BuildContext(Element)ã«ã¢ã¯ã»ã¹ããæ段ã¨ãã¦ä»¥ä¸ã®ãããããè¡ãªã£ããã¨èããã¨åãããããã§ãã
- å¥Widgetã«åãåºã
- Builder Widgetãçµç±ãã
ãã詳ããã¯ãFlutter ã® Widget ããªã¼ã®è£å´ã§èµ·ãã£ã¦ããã㨠ãåç §ãã¦ãã ããã
Placeholderã§UIã®TODOçãªé¨åã示ã
UIãçµãã§ãã¦ã諸äºæ ã§è¡¨ç¤ºãããã®ãä¸ç¢ºå®ã ã£ãããä»ã®å®è£ ã«éä¸ãããã®ã§å¾åãã«ãããã¨ãããã¾ãããã¾ãããããæã«ä½¿ãããã®ã¨ãã¦Placeholderãããã¾ãã
ã³ã¼ã:
Containerãªã©ã§æ¸ã¾ãã¦ãã¾ããã¨ãã§ãã¾ãããæå³çã«ãè¦ãç®çã«ãä½æ¥éä¸ã§ãããã¨ãæ確ã«ãªãã®ã§ãPlaceholderãæ´»ç¨ããæ¹ãè¯ãã§ãã
Flutterã®Widgetã¯ãä»ã«ããããªã®ã¾ã§ç¨æããã¦ããã®ãã¨é©ããã¨ãã¡ããã¡ããããã¾ãããFlutter Widget of the Weekã®ãã¬ã¤ãªã¹ã ãªã©ãã£ããç®ãéãããããã¨è¿½ããããã§ãã
ãã¼ãã¼ãã·ã§ã¼ãã«ããã®è¦ãæ¹
ãããã¼ãã¼ãã·ã§ã¼ãã«ããã®ãã¼ãã·ã¼ããªã©ãããã¾ãããåã¯ãããããã®ã«ã¯å
¨ãé ¼ã£ã¦ãã¾ããããªããªãè¦ãªãã¨ãIDEä¸ã®æä½ã§åããããã§ãã
(ãã¼ãã·ã¼ããæ©è½ä¸è¦§ã®ä¿¯ç°ã®ããã«ä½¿ããªãããã ã¨æãã¾ããã)
ã¾ããIDEã®Helpã¡ãã¥ã¼ãè¦ã(command + shift + / ã§ã表示å¯è½)ã¨ã次ã®ããã«ããã¹ãå
¥åæ¬ãããããã«ããã¹ããå
¥åããã¨ããããæä½ãæ¤ç´¢ã§ãã¾ãã
(ä¸è¿°ã®command + shift + Aã®ã¯ã¤ãã¯ã¢ã¯ã·ã§ã³ã®ã·ã§ã¼ãã«ãããããã«è¨è¼ããã¦ãã¾ããã)
ãã®ããã«ããããã³ãã³ããé¸ã³ã¤ã¤é »åº¦ã®é«ããã®ã¯ãã¼ãã¼ãã·ã§ã¼ãã«ãããè¦ãã¦ããå®è¡ã§ããããã«ãã¦ãã¾ãã
ãªã®ã§ãã¾ãã¯ä»¥ä¸ç¨åº¦ã®æå°éã®ãã®ã ãè¦ãã¦ã触ããªããå¿ è¦ã«å¿ãã¦é 次è¦ãã¦ããã°è¯ãã¨æãã¾ãããé »åº¦ã®ä½ããã®ã¯Quick Actionçµç±ãªã©ã§æ¸ã¾ãã¦ãã¾ã£ã¦ååã ã¨æã£ã¦ãã¾ãã
command + shift + O: ãã¡ã¤ã«æ¤ç´¢
shift2é£æ: å ¨æ¤ç´¢
command + N: ã²ãªå½¢çæ
ãã¼ãã·ã¼ã
å ¬å¼ãã¼ãã·ã¼ããããã¾ãããã¼ãã¼ãã·ã§ã¼ãã«ããã«ã¤ãã¦ã¯ä¸è¿°ã®éããã¾ãé ¼ããIDE触ããªããè¦ããã°è¯ãã¨æãã¾ããããã®ä»Tipsãçãè¾¼ã¾ãã¦ããã®ã§ãä¸èªãã¦ããã¨è¯ãã§ãã
åºæ¬çã«Debugå®è¡ã§è¯ãæ°ããã
æ®éã«Runã§å®è¡ããã¨ãã¬ã¼ã¯ãã¤ã³ããæ¢ãããã¾ããã
ãã®ãããRunã§å®è¡ä¸ã«ãã¬ã¼ã¯ãã¤ã³ããæ¢ããããªã£ãããDebugã§åèµ·åãããã¡ã«ãªãã¾ãã
次ã®ããã«ãããã¦Debugã§ã¯ãªãRunã«ããçç±ãç¡ãããã«æãã®ã§ã常æDebugã§è¯ãæ°ããã¦ãã¾ãð¤
Xcodeãªã©ã§ã¯ãããåºå¥ããã¦ããããRunã§ãã¬ã¼ã¯ãã¤ã³ããæ¢ã¾ã£ã¦ãFlutterãåããã§è¯ãæ°ããã¦ãã¾ããããªãåãã¦ããã®ã§ãããð¤
(ãããã©ã«ããããã°å®è¡ã§ããªãã·ã§ã³ã¨ãã¦ãããã¬ã¼ãã¢ã¿ããããªãã¢ã¼ããããããããã使ããããæ°ããã¾ãã)
ç´ããããã§ãããä¸è¿°ã®âRunâã»âDebugâã¯ã¢ã¼ãã¨ãã¦ã¯ã¨ãã«âDebug Modeâã§ãããã¢ã¼ãã¯ä»ã«ä»¥ä¸ããã£ã¦ããããã¯ããããé©ããå ´é¢ã§ä½¿ãå¿ è¦ãããã¾ãã
- Profile Mode: ããã©ã¼ãã³ã¹ãã¥ã¼ãã³ã°ã®éãªã©ã«ãããã¡ã¤ãªã³ã°ããæç¨
- Release Mode: ãªãªã¼ã¹ãã«ãç¨(JITã§ã¯ãªãAOTã«ãªã£ã¦Hot Reloadãå¹ããªããªã代ããã«éããªã)
ããã©ã¼ãã³ã¹ãè½ã¡ããªã©å®éã«ãªãªã¼ã¹ããç¶æ ã¨ã¯ç°ãªããããé常éçºããéã®âDebug Modeâæã¯æ¬¡ã®ããã«å³ä¸ã«DEBUGããã¼ã表示ããã¾ãã
MaterialApp Widgetã®debugShowCheckedModeBannerã false
ã«ãããã¨ã§ãDebug Modeã§ãé表示ã«ãããã¨ãã§ãã¾ãããåºå¥ãä»ããªããªã£ã¦ãã¹ã®åå ã«ãªããããªãã®ã§ãé常ããã©ã«ãã® true
ã¨ããæ¹ãè¯ãã¨æãã¾ã(ã¹ã¯ã·ã§ã®è¦æ ããè¯ããããæãªã©ä¸æçã«falseã«ããç¨åº¦ã«ã¨ã©ããã®ãè¯ãã¨æãã¾ã)ã
ãã«ãã®ã¢ã¼ãã«ã¤ãã¦ã詳ããã¯ä»¥ä¸ã«è¼ã£ã¦ãã¾ã:
Live Templatesæ´»ç¨
Live Templatesã¨ãã£ã¦ããã¬ã¼ã¹ãã«ãã¼ä»ãã®ã¹ãããããç°¡åã«å¼ã³åºãæ©è½ãããã¾ãã
ä¾ãã°ãStatefulWidgetã®ã²ãªå½¢ãæ¸ãããå ´åã stful
ã¨å
¥å(éä¸ã¾ã§æã£ã¦åè£ããé¸æã§ãOK)ãã¦ã¿ããã¨ã³ã¿ã¼ãæ¼ãã¨æ¬¡ã®ããã«ä¸ç¬ã§StatefulWidgetã®ã³ã¼ããåºåããã¦ããã®ã¾ã¾æä½éå¿
è¦ãªã¨ããã®ã¿è¿½å ã§å
¥åãã¾ãã
èªä½ãããã¨ãã§ããã®ã§ããã¤ã©ã¼ãã¬ã¼ãçãªã³ã¼ããæ¸ããã¨ãä½åããã£ããæ¢åã®ãã³ãã¬ã¼ããåèã«ããªãããã®é½åº¦ç»é²ããã¨è¯ãã§ãã
èªä½ãããã³ãã¬ã¼ãã¯ä»¥ä¸ã«ä¿åãããã®ã§ããã¼ã ã¡ã³ãã¼éãèªåãã·ã³éãªã©ã§å ±æããã¨ä¾¿å©ã§ãã
~/Library/Preferences/AndroidStudio3.5/templates
source_genã»build_runner ã«ããã³ã¼ãçæããã
ãã¤ã©ã¼ãã¬ã¼ãçãªã³ã¼ãè¨è¿°ã®çååã®æ段ã¨ãã¦ãç¨éã«ãã£ã¦ã¯Live Templatesãããsource_genã»build_runner ã«ããã³ã¼ãçæãé©ãã¦ãããã¨ãããã¾ãã代表çãªä¾ã¨ãã¦JSONã®ã¢ãã«å¤æã³ã¼ããããããã㯠json_serializable ã¨ããããã±ã¼ã¸ãæä¾ããã¦ãã¾ãã
詳ããã¯æ¬¡ã®è¨äºãè¦ã¦ãã ããã
ã¡ãã£ã¨éå¤ãªæãã«ãªãã¾ãããããã£ã¨Tipsãã¾ã¨ãã¦ã¿ã¾ãããã¾ã æ¸ãå¿ãã¦ãããã¨ãããããã§ãæ°ä»ã次第追è¨ãã¦ããã¾ãð¶
æ¬è¨äºã¯å ·ä½çãªTipséã§ããããFlutterãä½ç³»çã«å¦ã¶ããããã®æµãã¯ä»¥ä¸ã覧ãã ããã