asyncPrepare method

void asyncPrepare(
  1. BuildContext context,
  2. bool isOnce,
  3. ValueChanged<Rect>? onCallBack
)

Widget rendering listener. Widget渲染监听. context: Widget context. isOnce: true,Continuous monitoring false,Listen only once. onCallBack: Widget Rect CallBack.

Implementation

void asyncPrepare(BuildContext context, bool isOnce,
    ValueChanged<Rect>? onCallBack) {
  if (_hasMeasured) return;
  WidgetsBinding.instance?.addPostFrameCallback((Duration timeStamp) {
    RenderBox? box = getRenderBox(context);
    if (box != null) {
      if (isOnce) _hasMeasured = true;
      double width = box.semanticBounds.width;
      double height = box.semanticBounds.height;
      if (_width != width || _height != height) {
        _width = width;
        _height = height;
        if (onCallBack != null) onCallBack(box.semanticBounds);
      }
    }
  });
}