Use dart analyze package for num.clamp (#139867)
Extacted from #130101, dropped the `@_debugAssert` stuff from that PR so it's easier to review.
This commit is contained in:
@@ -489,7 +489,7 @@ class _SegmentedControlState<T> extends State<CupertinoSlidingSegmentedControl<T
|
||||
final int numOfChildren = widget.children.length;
|
||||
assert(renderBox.hasSize);
|
||||
assert(numOfChildren >= 2);
|
||||
int index = (dx ~/ (renderBox.size.width / numOfChildren)).clamp(0, numOfChildren - 1); // ignore_clamp_double_lint
|
||||
int index = (dx ~/ (renderBox.size.width / numOfChildren)).clamp(0, numOfChildren - 1);
|
||||
|
||||
switch (Directionality.of(context)) {
|
||||
case TextDirection.ltr:
|
||||
|
||||
@@ -358,7 +358,7 @@ class _RawMaterialButtonState extends State<RawMaterialButton> with MaterialStat
|
||||
right: densityAdjustment.dx,
|
||||
bottom: densityAdjustment.dy,
|
||||
),
|
||||
).clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity); // ignore_clamp_double_lint
|
||||
).clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity);
|
||||
|
||||
|
||||
final Widget result = ConstrainedBox(
|
||||
|
||||
@@ -351,7 +351,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
|
||||
final double dx = math.max(0, densityAdjustment.dx);
|
||||
final EdgeInsetsGeometry padding = resolvedPadding!
|
||||
.add(EdgeInsets.fromLTRB(dx, dy, dx, dy))
|
||||
.clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity); // ignore_clamp_double_lint
|
||||
.clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity);
|
||||
|
||||
// If an opaque button's background is becoming translucent while its
|
||||
// elevation is changing, change the elevation first. Material implicitly
|
||||
|
||||
@@ -3417,7 +3417,7 @@ class _MenuPanelState extends State<_MenuPanel> {
|
||||
final double dx = math.max(0, densityAdjustment.dx);
|
||||
final EdgeInsetsGeometry resolvedPadding = padding
|
||||
.add(EdgeInsets.symmetric(horizontal: dx, vertical: dy))
|
||||
.clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity); // ignore_clamp_double_lint
|
||||
.clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity);
|
||||
|
||||
BoxConstraints effectiveConstraints = visualDensity.effectiveConstraints(
|
||||
BoxConstraints(
|
||||
@@ -3562,7 +3562,7 @@ class _Submenu extends StatelessWidget {
|
||||
final double dx = math.max(0, densityAdjustment.dx);
|
||||
final EdgeInsetsGeometry resolvedPadding = padding
|
||||
.add(EdgeInsets.fromLTRB(dx, dy, dx, dy))
|
||||
.clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity); // ignore_clamp_double_lint
|
||||
.clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity);
|
||||
|
||||
return Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
|
||||
@@ -617,7 +617,7 @@ class PaginatedDataTableState extends State<PaginatedDataTable> {
|
||||
),
|
||||
if (!widget.showEmptyRows)
|
||||
SizedBox(
|
||||
height: (widget.dataRowMaxHeight ?? kMinInteractiveDimension) * (widget.rowsPerPage - _rowCount + _firstRowIndex).clamp(0, widget.rowsPerPage)), // ignore_clamp_double_lint
|
||||
height: (widget.dataRowMaxHeight ?? kMinInteractiveDimension) * (widget.rowsPerPage - _rowCount + _firstRowIndex).clamp(0, widget.rowsPerPage)),
|
||||
DefaultTextStyle(
|
||||
style: footerTextStyle!,
|
||||
child: IconTheme.merge(
|
||||
|
||||
@@ -531,8 +531,8 @@ class _IndicatorPainter extends CustomPainter {
|
||||
final double index = controller.index.toDouble();
|
||||
final double value = controller.animation!.value;
|
||||
final bool ltr = index > value;
|
||||
final int from = (ltr ? value.floor() : value.ceil()).clamp(0, maxTabIndex); // ignore_clamp_double_lint
|
||||
final int to = (ltr ? from + 1 : from - 1).clamp(0, maxTabIndex); // ignore_clamp_double_lint
|
||||
final int from = (ltr ? value.floor() : value.ceil()).clamp(0, maxTabIndex);
|
||||
final int to = (ltr ? from + 1 : from - 1).clamp(0, maxTabIndex);
|
||||
final Rect fromRect = indicatorRect(size, from);
|
||||
final Rect toRect = indicatorRect(size, to);
|
||||
_currentRect = Rect.lerp(fromRect, toRect, (value - from).abs());
|
||||
|
||||
@@ -1052,7 +1052,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
||||
if (widget.maxLength! > 0) {
|
||||
// Show the maxLength in the counter
|
||||
counterText += '/${widget.maxLength}';
|
||||
final int remaining = (widget.maxLength! - currentLength).clamp(0, widget.maxLength!); // ignore_clamp_double_lint
|
||||
final int remaining = (widget.maxLength! - currentLength).clamp(0, widget.maxLength!);
|
||||
semanticCounterText = localizations.remainingTextFieldCharacterCount(remaining);
|
||||
}
|
||||
|
||||
|
||||
@@ -400,10 +400,10 @@ class BorderRadius extends BorderRadiusGeometry {
|
||||
// RRects don't make sense.
|
||||
return RRect.fromRectAndCorners(
|
||||
rect,
|
||||
topLeft: topLeft.clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
topRight: topRight.clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
bottomLeft: bottomLeft.clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
bottomRight: bottomRight.clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
topLeft: topLeft.clamp(minimum: Radius.zero),
|
||||
topRight: topRight.clamp(minimum: Radius.zero),
|
||||
bottomLeft: bottomLeft.clamp(minimum: Radius.zero),
|
||||
bottomRight: bottomRight.clamp(minimum: Radius.zero),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -286,10 +286,10 @@ abstract class BoxBorder extends ShapeBorder {
|
||||
rect.top - insets.top,
|
||||
rect.right + insets.right,
|
||||
rect.bottom + insets.bottom,
|
||||
topLeft: (rect.tlRadius + Radius.elliptical(insets.left, insets.top)).clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
topRight: (rect.trRadius + Radius.elliptical(insets.right, insets.top)).clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
bottomRight: (rect.brRadius + Radius.elliptical(insets.right, insets.bottom)).clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
bottomLeft: (rect.blRadius + Radius.elliptical(insets.left, insets.bottom)).clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
topLeft: (rect.tlRadius + Radius.elliptical(insets.left, insets.top)).clamp(minimum: Radius.zero),
|
||||
topRight: (rect.trRadius + Radius.elliptical(insets.right, insets.top)).clamp(minimum: Radius.zero),
|
||||
bottomRight: (rect.brRadius + Radius.elliptical(insets.right, insets.bottom)).clamp(minimum: Radius.zero),
|
||||
bottomLeft: (rect.blRadius + Radius.elliptical(insets.left, insets.bottom)).clamp(minimum: Radius.zero),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -299,10 +299,10 @@ abstract class BoxBorder extends ShapeBorder {
|
||||
rect.top + insets.top,
|
||||
rect.right - insets.right,
|
||||
rect.bottom - insets.bottom,
|
||||
topLeft: (rect.tlRadius - Radius.elliptical(insets.left, insets.top)).clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
topRight: (rect.trRadius - Radius.elliptical(insets.right, insets.top)).clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
bottomRight: (rect.brRadius - Radius.elliptical(insets.right, insets.bottom)).clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
bottomLeft:(rect.blRadius - Radius.elliptical(insets.left, insets.bottom)).clamp(minimum: Radius.zero), // ignore_clamp_double_lint
|
||||
topLeft: (rect.tlRadius - Radius.elliptical(insets.left, insets.top)).clamp(minimum: Radius.zero),
|
||||
topRight: (rect.trRadius - Radius.elliptical(insets.right, insets.top)).clamp(minimum: Radius.zero),
|
||||
bottomRight: (rect.brRadius - Radius.elliptical(insets.right, insets.bottom)).clamp(minimum: Radius.zero),
|
||||
bottomLeft:(rect.blRadius - Radius.elliptical(insets.left, insets.bottom)).clamp(minimum: Radius.zero),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1006,7 +1006,7 @@ class TextStyle with Diagnosticable {
|
||||
fontFamily: fontFamily ?? _fontFamily,
|
||||
fontFamilyFallback: fontFamilyFallback ?? _fontFamilyFallback,
|
||||
fontSize: fontSize == null ? null : fontSize! * fontSizeFactor + fontSizeDelta,
|
||||
fontWeight: fontWeight == null ? null : FontWeight.values[(fontWeight!.index + fontWeightDelta).clamp(0, FontWeight.values.length - 1)], // ignore_clamp_double_lint
|
||||
fontWeight: fontWeight == null ? null : FontWeight.values[(fontWeight!.index + fontWeightDelta).clamp(0, FontWeight.values.length - 1)],
|
||||
fontStyle: fontStyle ?? this.fontStyle,
|
||||
letterSpacing: letterSpacing == null ? null : letterSpacing! * letterSpacingFactor + letterSpacingDelta,
|
||||
wordSpacing: wordSpacing == null ? null : wordSpacing! * wordSpacingFactor + wordSpacingDelta,
|
||||
|
||||
@@ -2054,8 +2054,8 @@ class _SelectableFragment with Selectable, ChangeNotifier implements TextLayoutM
|
||||
@override
|
||||
TextSelection getLineAtOffset(TextPosition position) {
|
||||
final TextRange line = paragraph._getLineAtOffset(position);
|
||||
final int start = line.start.clamp(range.start, range.end); // ignore_clamp_double_lint
|
||||
final int end = line.end.clamp(range.start, range.end); // ignore_clamp_double_lint
|
||||
final int start = line.start.clamp(range.start, range.end);
|
||||
final int end = line.end.clamp(range.start, range.end);
|
||||
return TextSelection(baseOffset: start, extentOffset: end);
|
||||
}
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ class FilteringTextInputFormatter extends TextInputFormatter {
|
||||
// The length added by adding the replacementString.
|
||||
final int replacedLength = originalIndex <= regionStart && originalIndex < regionEnd ? 0 : replacementString.length;
|
||||
// The length removed by removing the replacementRange.
|
||||
final int removedLength = originalIndex.clamp(regionStart, regionEnd) - regionStart; // ignore_clamp_double_lint
|
||||
final int removedLength = originalIndex.clamp(regionStart, regionEnd) - regionStart;
|
||||
return replacedLength - removedLength;
|
||||
}
|
||||
|
||||
|
||||
@@ -889,7 +889,7 @@ class TextEditingValue {
|
||||
// The length added by adding the replacementString.
|
||||
final int replacedLength = originalIndex <= replacementRange.start && originalIndex < replacementRange.end ? 0 : replacementString.length;
|
||||
// The length removed by removing the replacementRange.
|
||||
final int removedLength = originalIndex.clamp(replacementRange.start, replacementRange.end) - replacementRange.start; // ignore_clamp_double_lint
|
||||
final int removedLength = originalIndex.clamp(replacementRange.start, replacementRange.end) - replacementRange.start;
|
||||
return originalIndex + replacedLength - removedLength;
|
||||
}
|
||||
|
||||
|
||||
@@ -841,7 +841,7 @@ class _AnimatedPaddingState extends AnimatedWidgetBaseState<AnimatedPadding> {
|
||||
return Padding(
|
||||
padding: _padding!
|
||||
.evaluate(animation)
|
||||
.clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity), // ignore_clamp_double_lint
|
||||
.clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity),
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user