Scoped Model原理

Scoped Model原理.png
  • DataModel继承自Model,作为AnimatedBuilderanimation
  • ScopedModel是一个Widget,主要是为了将_InheritedModel置入AnimatedBuilder,同时将child传给_InheritedModel
  • child指的是ScopedModelDescendant,实际使用中是子树中包含ScopedModelDescendantWidget
  • 修改DataModel中的数据之后,需要主动调用notifyListeners(),此方法会调用其监听者,这里其实就是AnimatedBuilderbuilder,此过程中新建_InheritedModelScopedModelDescendant作为_InheritedModelchild会触发build函数,在build函数中调用我们传入ScopedModelDescendantbuilder

你可能感兴趣的:(Scoped Model原理)