'final StackParentData childParentData = child.parentData; Error occuring here'

import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart';

class CustomStack extends Stack { CustomStack({children}) : super(children: children);

@override CustomRenderStack createRenderObject(BuildContext context) { return CustomRenderStack( alignment: alignment, textDirection: textDirection ?? Directionality.of(context), fit: fit, //overflow: overflow, ); } }

class CustomRenderStack extends RenderStack { CustomRenderStack({alignment, textDirection, fit, overflow}) : super( alignment: alignment, textDirection: textDirection, fit: fit, //overflow: overflow );

@override bool hitTestChildren(BoxHitTestResult result, {required Offset position}) { var stackHit = false;

final children = getChildrenAsList();

for (var child in children) {
  final StackParentData childParentData = child.parentData;

  final childHit = result.addWithPaintOffset(
    offset: childParentData.offset,
    position: position,
    hitTest: (BoxHitTestResult result, Offset transformed) {
      assert(transformed == position - childParentData.offset);
      return child.hitTest(result, position: transformed);
    },
  );

  if (childHit) stackHit = true;
}

return stackHit;

} }