å®å šã«ç解ããããã«ãæåã«ãªã³ã¯ã«ç€ºãããŠããèšäºãèªãããã¡ã¢ãªå ã§æŽæ°ããããšããå§ãããŸãããã®äžã§ãç§ã¯ãã©ãã¿ãŒããã€ã¹ã®éèŠãªåŽé¢ã®1ã€ã§ããããªãŒã®çžäºäœçšãšãããã®éã®è²¬ä»»ã®åæ£ãåæããŸããããã ããåé¡ã¯æªè§£æ±ºã®ãŸãŸã§ããæåã®éšåã§èª¬æããã¡ã«ããºã å šäœã®æäœã¯ã©ã®ããã«æ§æãããŠããŸããïŒãããããã®èšäºã§ç解ããããšããããšã§ãã
äžè¬èŠå®
Flutterã®æè¡æŠèŠ ãéããšãããããã®ãã€ã³ãã§æ¬¡ã®å³ã衚瀺ãããŸããããã¯ããã¬ãŒã ã¯ãŒã¯ã®äœæè ããã¬ãŒã ã¯ãŒã¯ãåå²ããæ¡ä»¶ã¬ãã«ã瀺ããŠããŸãã
å®éã圌ããããã圌ãèªèº«ãšåŒãã ããã«ãç§ãã¡ã¯ããã±ãŒããèŠãŸãã倧ããå±€ãšå°ããå±€ãåºå¥ã§ããŸãã
ãã¬ãŒã ã¯ãŒã¯ã¬ãã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã®äœææã«äœ¿çšãããã¹ãŠã®ãã®ã§ãããäœæãããšã³ãžã³ã¬ãã«ãšã®å¯Ÿè©±ãå¯èœã«ãããã¹ãŠã®ãŠãŒãã£ãªãã£ã¯ã©ã¹ã§ãããã®ã¬ãã«ã«é¢é£ãããã¹ãŠã¯ããŒãã§æžãããŠããŸãã
ãšã³ãžã³ã¬ãã«-ãã¬ãŒã ã¯ãŒã¯ã¬ãã«ãããäœãã¬ãã«ã§ããã¬ãŒã ã¯ãŒã¯ã¬ãã«ã®åäœãå¯èœã«ããã¯ã©ã¹ãšã©ã€ãã©ãªãå«ãŸããŠããŸããä»®æ³ãã·ã³ããŒããã¹ãã¢ãªã©ãå«ã¿ãŸãã
ãã©ãããã©ãŒã ã¬ãã«-ç¹å®ã®èµ·åãã©ãããã©ãŒã ã«åºæã®ãã©ãããã©ãŒã åºæã®ã¡ã«ããºã ã
ãã¬ãŒã ã¯ãŒã¯ã¬ãã«ã詳ããèŠãŠã¿ãŸãããããã®å³ã§ã¯ãäžäœã¬ãã«ããäžäœã¬ãã«ãžã®ã¬ã€ã€ãŒã®åœ¢åŒã§ç€ºãããŠããŸããäžçªäžã«ã¬ã€ã€ãŒããããŸã財å£ãååã瀺ãããã«ããã®ã¬ã€ã€ãŒã¯ãã¬ãŒã ã¯ãŒã¯ã¬ãã«ã§åºæ¬çãã€åºæ¬çãªãã®ã§ãããã®ã©ã€ãã©ãªãèŠã€ãããããããã®èª¬æã«æžãããŠãããã®ã§ãïŒ
ã³ã¢ãã©ãã¿ãŒãã¬ãŒã ã¯ãŒã¯ããªããã£ãã
ãã®ã©ã€ãã©ãªã§å®çŸ©ãããŠããæ©èœã¯ãFlutterãã¬ãŒã ã¯ãŒã¯ã®ä»ã®ãã¹ãŠã®ã¬ã€ã€ãŒã§äœ¿çšãããæäœã¬ãã«ã®ãŠãŒãã£ãªãã£ã¯ã©ã¹ãšé¢æ°ã§ãã
ãã®ã©ã€ãã©ãªã§å®çŸ©ãããŠããé¢æ°ã¯ãFlutterãã¬ãŒã ã¯ãŒã¯ã®ä»ã®ãã¹ãŠã®ã¬ã€ã€ãŒã§äœ¿çšããããŠãŒãã£ãªãã£ã¯ã©ã¹ãšæäžäœã¬ãã«ã®é¢æ°ã§ãã
ãã®ã©ã€ãã©ãªã«ã¯ããã¹ãŠã®Bindingã®åºæ¬ã¯ã©ã¹ã§ããBindingBaseãå«ãŸããŠããŸãã
ãã€ã³ãã£ã³ã°
ãŸããBindingãšã¯äœããFlutterããããã©ã®ããã«äœ¿çšããããç解ããŸããããååèªäœã¯ããããäœããã®ã€ãªããã§ããããšã瀺ããŠããŸãã Flutterã³ãã³ãã«ãã£ãŠBaseBindingã«æ®ãããããã¥ã¡ã³ãã«ã¯ã次ã®ããšãèšèŒãããŠããŸãã
ã·ã³ã°ã«ãã³ãµãŒãã¹ïŒããã€ã³ãã£ã³ã°ããšãåŒã°ããŸãïŒãæäŸããããã¯ã¹ã€ã³ã®åºæ¬ã¯ã©ã¹ããã®ã¯ã©ã¹ãããã¯ã¹ã€ã³ã®ãonãå¥ã§äœ¿çšããã«ã¯ããã®ã¯ã©ã¹ããç¶æ¿ããŠ[initInstancesïŒïŒ]ãå®è£ ããŸããããã¯ã¹ã€ã³ã¯ãã¢ããªã®åç¶æéäžã«1åã ãæ§ç¯ãããããšãä¿èšŒãããŠããŸãïŒããæ£ç¢ºã«ã¯ããã§ãã¯ã¢ãŒãã§2åæ§ç¯ãããå Žåã«ã¢ãµãŒããããŸãïŒã
ããã¯ãããã¯ã¹ã€ã³ãšããŠæ瀺ãããããŸããŸãªéä¿¡ãµãŒãã¹ã®åºæ¬ã¯ã©ã¹ã§ãããã®ãããªåããã¯ã¹ã€ã³ã¯åæåãããã¢ããªã±ãŒã·ã§ã³ã®åç¶æéäžããã®ã€ã³ã¹ã¿ã³ã¹ã®äžææ§ãä¿èšŒããŸãã
BaseBindingåºæ¬æœè±¡ã¯ã©ã¹ã§ãã次ã«ããã€ã³ãã£ã³ã°ã®å ·äœçãªå®è£ ãèŠãŠã¿ãŸãããããã®äžã§æã ã衚瀺ãããŸãïŒ
ServicesBindingã¯ãã¡ãã»ãŒãžã»ããŒã¿ã»ãã³ãã©ãŒïŒBinaryMessengerïŒã«çŸåšã®ãã©ãããã©ãŒã ããã®ã¡ãã»ãŒãžã転éãã責任ããããŸãã
PaintingBindingã¯ãã¬ã³ããªã³ã°ã©ã€ãã©ãªãšã®éä¿¡ãæ åœããŸãã
RenderBindingã¯ãã¬ã³ããŒããªãŒãšFlutterãšã³ãžã³éã®éä¿¡ãæ åœããŸãã
WidgetBindingã¯ããŠã£ãžã§ããããªãŒãšFlutterãšã³ãžã³éã®éä¿¡ãæ åœããŸãã
SchedulerBinding-次ã®ãããªæ¬¡ã®ã¿ã¹ã¯ã®ã¹ã±ãžã¥ãŒã©ãŒïŒ
- ã·ã¹ãã ãWindow.onBeginFrameã§éå§ããçä¿¡ã³ãŒã«ããã¯ã®åŒã³åºã-ããšãã°ããã£ãã«ãŒãã¢ãã¡ãŒã·ã§ã³ã³ã³ãããŒã©ãŒã®ã€ãã³ãã
- Window.onDrawFrameã·ã¹ãã ãéå§ããç¶ç¶çãªã³ãŒã«ããã¯ã®åŒã³åºããããšãã°ãçä¿¡ã³ãŒã«ããã¯ãå®äºããåŸã«è¡šç€ºã·ã¹ãã ãæŽæ°ããã€ãã³ãã
- é£ç¶ã³ãŒã«ããã¯ã®åŸãWindow.onDrawFrameããæ»ãåã«åŒã³åºããããã¹ããã¬ãŒã ã³ãŒã«ããã¯ã
- ãã¬ãŒã éã§å®è¡ããå¿ èŠãããéã¬ã³ããªã³ã°ã¿ã¹ã¯ã
SemanticsBindingã¯ãã»ãã³ãã£ã¯ã¹ã¬ã€ã€ãŒãšFlutterãšã³ãžã³ã®ãªã³ã¯ãæ åœããŸãã
GestureBindingã¯ããžã§ã¹ãã£ãµãã·ã¹ãã ã®æäœãæ åœããŸãã
ååã瀺ãããã«ããã€ã³ãã£ã³ã°ã¯Flutterãšã³ãžã³ã¬ãã«ãšãã¬ãŒã ã¯ãŒã¯ã¬ãã«èªäœã®éã®éä¿¡ã¬ã€ã€ãŒã§ããããããããç¹å®ã®äœæ¥æ¹åãæ åœããŸãã
WidgetsFlutterBinding
ãã¹ãŠãã©ã®ããã«é£æºããããããããç解ããããã«ãFlutterã¢ããªã±ãŒã·ã§ã³ã®éå§ç¹ã§ããå ŽæïŒrunAppã®åŒã³åºãïŒãèŠãŠã¿ãŸããããåŒã³åºããŠããã¡ãœããã¯binding.dartãã¡ã€ã«ã«ãããããã¯å¶ç¶ã§ã¯ãããŸããããã®èª¬æã«ã¯ãæž¡ãããã¢ããªã±ãŒã·ã§ã³ãŠã£ãžã§ãããå±éããç»é¢ã«æ·»ä»ããããšãèšèŒãããŠããŸãããããäœããããèŠãŠã¿ãŸãããïŒ
void runApp(Widget app) {
WidgetsFlutterBinding.ensureInitialized()
..scheduleAttachRootWidget(app)
..scheduleWarmUpFrame();
}
ããã§ãWidgetsFlutterBindingïŒãŠã£ãžã§ãããã¬ãŒã ã¯ãŒã¯ã«åºã¥ãã¢ããªã±ãŒã·ã§ã³ãã€ã³ãã£ã³ã°ã®å ·äœçãªå®è£ ïŒã«åºäŒããŸãããã®æ žãšãªãã®ã¯ãFlutterãã¬ãŒã ã¯ãŒã¯ãšãšã³ãžã³ãäžç·ã«ä¿æããæ¥çå€ã§ããWidgetsFlutterBindingã¯ãåè¿°ã®ãã€ã³ãã£ã³ã°ã®å€ãã§æ§æãããŠããŸãïŒGestureBindingãServicesBindingãSchedulerBindingãPaintingBindingãSemanticsBindingãRendererBindingãWidgetsBindingããã®ããã«ããŠãã¢ããªã±ãŒã·ã§ã³ãå¿ èŠãªãã¹ãŠã®æ¹åã«ãã©ãã¿ãŒãšã³ãžã³ã§æ¥ç¶ã§ããã¬ã€ã€ãŒãååŸããŸããã
ã¢ããªã±ãŒã·ã§ã³ã®èµ·åã«æ»ããŸããããã§ã¯WidgetsFlutterBindingscheduleAttachRootWidgetãšscheduleWarmUpFrameã¡ãœãããåŒã³åºãããŸãã®ã¯ã圌ãã«äœãèµ·ãããèŠãŠã¿ãŸãããã
ScheduleAttachRootWidget
scheduleAttachRootWidget ã¡ãœããã¯ãattachRootWidgetã®é 延å®è£ ã§ãããã®ã¡ãœããã¯WidgetsBindingã«å±ããŠããŸãããã®èª¬æã¯ãæž¡ããããŠã£ãžã§ãããèŠçŽ ããªãŒã®ã«ãŒãèŠçŽ ã§ããrenderViewElementã«ã¢ã¿ããããããšã瀺ããŠããŸãã
void attachRootWidget(Widget rootWidget) {
_renderViewElement = RenderObjectToWidgetAdapter<RenderBox>(
container: renderView,
debugShortDescription: '[root]',
child: rootWidget,
).attachToRenderTree(buildOwner, renderViewElement);
}
ã³ãŒãããããã®ã¡ãœãããRenderObjectToWidgetAdapterãäœæããããšãããããŸããããã¯ããŠã£ãžã§ããããªãŒã®ã«ãŒããŠã£ãžã§ããã§ãããããªãŒãçžäºã«æ¥ç¶ããããªããžãšããŠäœ¿çšãããŸãããã®å®è£ ãèŠããšãããèªäœã¯RenderObjectãäœæãããã³ã³ãããã£ãŒã«ãããå€ãè¿ããäœææã«RendererBindingããrenderViewãæž¡ããŸãããã®renderViewã¯ãã¬ã³ããŒããªãŒã®ã«ãŒãèŠçŽ ã§ãã
RenderView get renderView => _pipelineOwner.rootNode;
PipelineOwnerã¯ãå®éã«ã¯ã¬ã³ããªã³ã°ããã»ã¹ã管çãããããŒãžã£ãŒã§ããattachRootWidget
ã¡ãœããã«æ»ã..ãattachToRenderTreeã¡ãœããã¯ãäœæãããã¢ããã¿ãŒã§åŒã³åºãããŸãããã®ã¢ããã¿ãŒã䜿çšããŠãèŠçŽ ããªãŒã®ã«ãŒããåããŠäœæããŸããbuildOwnerãattachToRenderTreeã¡ãœããã«æž¡ãããããšã«æ³šæããŠãã ããããã®ã¯ã©ã¹ã¯ããŠã£ãžã§ããã®ç¶æ ãç£èŠããæŽæ°ã®å¿ èŠæ§ãç£èŠãããŠã£ãžã§ããããªãŒã®ç¶æ ã®æŽæ°ã«é¢é£ããä»ã®å€ãã®éèŠãªã¿ã¹ã¯ãå®è¡ãããŠã£ãžã§ããããªãŒãã«ããããŒãžã£ãŒã§ãããããã£ãŠã3ã€ã®ãã©ãã¿ãŒããªãŒãååŸããŸããåããªãŒã¯ããã€ã³ãã£ã³ã°ãä»ããŠä¿åããã³ç®¡çãããŸãã
ScheduleWarmUpFrame
scheduleWarmUpFrame ã¡ãœããã¯SchedulerBindingã«å±ããã·ã¹ãã ä¿¡å·ãVsyncããåŸ ããã«ãã¬ãŒã ãã§ããã ãæ©ãéå§ããããã«ã¹ã±ãžã¥ãŒã«ããããã«äœ¿çšãããŸãããã®æ¹æ³ã¯ã¢ããªã±ãŒã·ã§ã³ã®èµ·åæã«äœ¿çšããããããæåã®ãã¬ãŒã ã¯éåžžã«é«é¡ã«ãªãå¯èœæ§ããããèµ·åã«æéãããããŸãããã®ã¡ãœããã¯ãã¹ã±ãžã¥ãŒã«ããããã¬ãŒã ãå®äºãããŸã§ã€ãã³ãã®ãã£ã¹ãããããããã¯ããŸãã
ã芧ã®ãšãããèµ·åæã«èµ·åãããäž¡æ¹ã®ã¡ã«ããºã ã¯ãããŸããŸãªãã€ã³ãã£ã³ã°ã«é¢é£ããŠçžäºäœçšããŸãããããã®ãã€ã³ãã£ã³ã°ã¯ãå¯æ¥ã«é¢é£ããŠãããã·ã¹ãã ãšã®çžäºäœçšãæäŸããŸãã次ã®å³ã§èŠçŽããŸãããã
çµè«
ãã€ã³ãã£ã³ã°ã¯ãFlutterã¢ããªã±ãŒã·ã§ã³ãç·šæããããã®éèŠãªã¡ã«ããºã ã§ããã¢ããªã±ãŒã·ã§ã³ã®ããŸããŸãªåŽé¢ãçžäºã«æ¥ç¶ãããšã³ãžã³ãšæ¥ç¶ããã®ã¯åœŒã§ãã
圌ã®ããããå«ããŠãä»ã®ãã¹ãŠã®äžè²«ããäœæ¥ãã©ã®ããã«ç·šæããããæ°ã«ããããšãªãããã¬ãŒã ã¯ãŒã¯ã®æäžäœéšåã§ã¢ããªã±ãŒã·ã§ã³ãäœæã§ããŸãããã®èšäºããFlutterããã€ã¹ã®ãã®éšåãç解ããã®ã«åœ¹ç«ã€ããšãé¡ã£ãŠããŸãã
æž èŽããããšãããããŸããïŒ
䜿çšããææïŒ
ãã©ãã¿ãŒ
https://flutter.dev/