flutter_in_action_2nd icon indicating copy to clipboard operation
flutter_in_action_2nd copied to clipboard

4.7.1 Align 偏移公式错误

Open ryosga opened this issue 3 years ago • 1 comments

1. Alignment

  • 原文
    Alignment可以通过其坐标转换公式将其坐标转为子元素的具体偏移坐标: (Alignment.x*childWidth/2+childWidth/2, Alignment.y*childHeight/2+childHeight/2)
  • 改为: (Alignment.x*(parentWidth - childWidth)/2, Alignment.y*(parentHeight - childHeight)/2)

2. FractionalOffset

  • 原文 FractionalOffset的坐标转换公式为: 实际偏移 = (FractionalOffse.x * childWidth, FractionalOffse.y * childHeight)
  • 改为 实际偏移 = (FractionalOffse.x * (parentWidth - childWidth), FractionalOffse.y * (parentHeight - childHeight))

ryosga avatar Mar 04 '22 08:03 ryosga

@ryosga 提出的偏移量计算,应该是子视图的中心点,相对于父视图中心点的偏移量,我写了 demo 验证是对的。 原文的偏移量计算公式来自 Flutter 代码中的注释,这玩意实在理解不了,和代码表现出来的不一样,应该是错的

WonderJeffy avatar Feb 17 '23 07:02 WonderJeffy