flutter_parallax icon indicating copy to clipboard operation
flutter_parallax copied to clipboard

Null check operator used on a null value

Open YAPEIZG opened this issue 4 years ago • 2 comments

I am getting this Error:

The following _CastError was thrown during performLayout():
Null check operator used on a null value

The relevant error-causing widget was
Parallax
When the exception was thrown, this was the stack
#0      RenderSliverMultiBoxAdaptor.childMainAxisPosition
#1      RenderSliverHelpers.applyPaintTransformForBoxChild
#2      RenderSliverMultiBoxAdaptor.applyPaintTransform
#3      RenderObject.getTransformTo
#4      RenderBox.localToGlobal
...
The following RenderObject was being processed when the exception was fired: RenderParallaxSingleChildLayoutBox#a29ec NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderParallaxSingleChildLayoutBox#a29ec NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    parentData: <none> (can use size)
    constraints: BoxConstraints(w=428.0, h=130.0)
    size: Size(428.0, 130.0)
    child: RenderSemanticsAnnotations#bb227 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0) (can use size)
        constraints: BoxConstraints(w=428.0, 0.0<=h<=Infinity)
        size: Size(428.0, 149.5)
        child: RenderImage#ae8ff relayoutBoundary=up2 NEEDS-PAINT
            parentData: <none> (can use size)
            constraints: BoxConstraints(w=428.0, 0.0<=h<=Infinity)
            size: Size(428.0, 149.5)
            image: [750×262]
            alignment: center
            invertColors: false
            filterQuality: low

YAPEIZG avatar Jan 28 '21 14:01 YAPEIZG

@letsar @YAPEIZG i think this project is dead the creator is not answering , so the best thing to do is to fork the project and fix the problem b your self :(

elmobark avatar Feb 18 '21 15:02 elmobark

change in file rendering/parallax.dart the method getChildScrollRatio into:

 @override
  double getChildScrollRatio(
      Offset offsetUnit, double childExtent, RenderBox renderBox) {
    final RenderAbstractViewport viewport =
        RenderAbstractViewport.of(renderBox);
    assert(viewport != null);


    assert(renderBox != null);
    final ScrollPosition position = controller.position;
    assert(position != null);
    final bool isHorizontalAxis = (position.axis == Axis.horizontal);


    final Offset localPositionOffset = isHorizontalAxis
        ? new Offset(mainAxisExtent, 0.0)
        : new Offset(0.0, mainAxisExtent);//offsetUnit * mainAxisExtent;

    assert(localPositionOffset != null);
    Offset positionInViewport;
    try{
      positionInViewport = renderBox.localToGlobal(localPositionOffset, ancestor: viewport);
    } catch(e,s){

    }
    if(positionInViewport == null){
      return 0;
    }

    // One dimension should be 0.0, so this should be ok.
    final double distanceFromLeading =
        math.max(positionInViewport.dx, positionInViewport.dy);
    assert(distanceFromLeading != null);
    double scrollRatio = distanceFromLeading /
        (controller.position.viewportDimension + mainAxisExtent);
    return scrollRatio;
  }

This Error appears when the Widget is building and the method trys to access the viewport. This should fix and return 0 while building the widget.

Gastrolize avatar Jul 20 '21 21:07 Gastrolize