示例#1
0
        public override bool debugAssertIsValid(
            bool isAppliedConstraint = false,
            InformationCollector informationCollector = null
            )
        {
            D.assert(() => {
                var verify = new Action <bool, string>((bool check, string message) => {
                    if (check)
                    {
                        return;
                    }

                    var information = new StringBuilder();
                    if (informationCollector != null)
                    {
                        informationCollector(information);
                    }

                    throw new UIWidgetsError(
                        $"{this.GetType()} is not valid: {message}\n{information}The offending constraints were: \n  {this}");
                });

                verify(this.scrollOffset >= 0.0f, "The \"scrollOffset\" is negative.");
                verify(this.crossAxisExtent >= 0.0f, "The \"crossAxisExtent\" is negative.");
                verify(
                    AxisUtils.axisDirectionToAxis(this.axisDirection) !=
                    AxisUtils.axisDirectionToAxis(this.crossAxisDirection),
                    "The \"axisDirection\" and the \"crossAxisDirection\" are along the same axis.");
                verify(this.viewportMainAxisExtent >= 0.0f, "The \"viewportMainAxisExtent\" is negative.");
                verify(this.remainingPaintExtent >= 0.0f, "The \"remainingPaintExtent\" is negative.");
                verify(this.remainingCacheExtent >= 0.0f, "The \"remainingCacheExtent\" is negative.");
                verify(this.cacheOrigin <= 0.0f, "The \"cacheOrigin\" is positive.");
                verify(this.isNormalized, "The constraints are not normalized.");
                return(true);
            });

            return(true);
        }
示例#2
0
 public static Axis?axis(this ScrollMetrics it)
 {
     return(AxisUtils.axisDirectionToAxis(axisDirection: it.axisDirection));
 }
示例#3
0
        public override bool debugAssertIsValid(
            bool isAppliedConstraint = false,
            InformationCollector informationCollector = null
            )
        {
            D.assert(() => {
                bool hasErrors             = false;
                StringBuilder errorMessage = new StringBuilder("\n");
                var verify = new Action <bool, string>((bool check, string message) => {
                    if (check)
                    {
                        return;
                    }
                    hasErrors = true;
                    errorMessage.AppendLine($"  {message}");
                });
                void verifyFloat(float?property, string name, bool mustBePositive = false, bool mustBeNegative = false)
                {
                    verify(property != null, $"The \"{name}\" is null.");
                    if (property.Value.isNaN())
                    {
                        string additional = ".";
                        if (mustBePositive)
                        {
                            additional = ", expected greater than or equal to zero.";
                        }
                        else if (mustBeNegative)
                        {
                            additional = ", expected less than or equal to zero.";
                        }
                        verify(false, $"The \"{name}\" is NaN" + $"{additional}");
                    }
                    else if (mustBePositive)
                    {
                        verify(property >= 0.0f, $"The \"{name}\" is negative.");
                    }
                    else if (mustBeNegative)
                    {
                        verify(property <= 0.0f, $"The \"{name}\" is positive.");
                    }
                }
                verify(axis != null, "The \"axis\" is null.");
                verify(growthDirection != null, "The \"growthDirection\" is null.");
                verifyFloat(scrollOffset, "scrollOffset");
                verifyFloat(overlap, "overlap");
                verifyFloat(crossAxisExtent, "crossAxisExtent");
                verifyFloat(scrollOffset, "scrollOffset", mustBePositive: true);
                verify(crossAxisDirection != null, "The \"crossAxisDirection\" is null.");
                verify(AxisUtils.axisDirectionToAxis(axisDirection) != AxisUtils.axisDirectionToAxis(crossAxisDirection), "The \"axisDirection\" and the \"crossAxisDirection\" are along the same axis.");
                verifyFloat(viewportMainAxisExtent, "viewportMainAxisExtent", mustBePositive: true);
                verifyFloat(remainingPaintExtent, "remainingPaintExtent", mustBePositive: true);
                verifyFloat(remainingCacheExtent, "remainingCacheExtent", mustBePositive: true);
                verifyFloat(cacheOrigin, "cacheOrigin", mustBeNegative: true);
                verifyFloat(precedingScrollExtent, "precedingScrollExtent", mustBePositive: true);
                verify(isNormalized, "The constraints are not normalized."); // should be redundant with earlier checks


                if (hasErrors)
                {
                    List <DiagnosticsNode> diagnosticInfo = new List <DiagnosticsNode>();
                    diagnosticInfo.Add(new ErrorSummary($"{GetType()} is not valid: {errorMessage}"));
                    if (informationCollector != null)
                    {
                        diagnosticInfo.AddRange(informationCollector.Invoke());
                    }
                    diagnosticInfo.Add(new DiagnosticsProperty <SliverConstraints>("The offending constraints were", this, style: DiagnosticsTreeStyle.errorProperty));

                    throw new UIWidgetsError(diagnosticInfo);
                }
                return(true);
            });

            return(true);
        }