[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intensive if chain refactoring #145194

Merged
Prev Previous commit
Next Next commit
revert mergable_material, update colors
  • Loading branch information
nate-thegrate committed Mar 15, 2024
commit ec60a53bcdb67405a8849b5ecf6d97ef95a8924e
45 changes: 28 additions & 17 deletions packages/flutter/lib/src/material/mergeable_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -508,25 +508,36 @@ class _MergeableMaterialState extends State<MergeableMaterial> with TickerProvid
assert(kMaterialEdges[MaterialType.card]!.topLeft == kMaterialEdges[MaterialType.card]!.bottomLeft);
assert(kMaterialEdges[MaterialType.card]!.topLeft == kMaterialEdges[MaterialType.card]!.bottomRight);
final Radius cardRadius = kMaterialEdges[MaterialType.card]!.topLeft;
Radius animated({required bool isStart}) {
final MergeableMaterialItem? neighbor = index > 0
? _children.elementAtOrNull(isStart ? index - 1 : index + 1)
: null;
if (neighbor is MaterialGap) {
final _AnimationTuple tuple = _animationTuples[neighbor.key]!;
final double t = isStart ? tuple.startAnimation.value : tuple.endAnimation.value;
return Radius.lerp(Radius.zero, cardRadius, t)!;
}
return Radius.zero;
}

final Radius startRadius = start ? cardRadius : animated(isStart: true);
final Radius endRadius = end ? cardRadius : animated(isStart: false);
Radius startRadius = Radius.zero;
Radius endRadius = Radius.zero;

if (index > 0 && _children[index - 1] is MaterialGap) {
startRadius = Radius.lerp(
Radius.zero,
cardRadius,
_animationTuples[_children[index - 1].key]!.startAnimation.value,
)!;
}
if (index < _children.length - 2 && _children[index + 1] is MaterialGap) {
endRadius = Radius.lerp(
Radius.zero,
cardRadius,
_animationTuples[_children[index + 1].key]!.endAnimation.value,
)!;
}

return switch (widget.mainAxis) {
Axis.horizontal => BorderRadius.horizontal(left: startRadius, right: endRadius),
Axis.vertical => BorderRadius.vertical(top: startRadius, bottom: endRadius),
};
if (widget.mainAxis == Axis.vertical) {
return BorderRadius.vertical(
top: start ? cardRadius : startRadius,
bottom: end ? cardRadius : endRadius,
);
} else {
return BorderRadius.horizontal(
left: start ? cardRadius : startRadius,
right: end ? cardRadius : endRadius,
);
}
}

double _getGapSize(int index) {
Expand Down
17 changes: 8 additions & 9 deletions packages/flutter/lib/src/painting/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ Color _colorFromHue(
double secondary,
double match,
) {
final List<double> rgb = switch (hue) {
< 60.0 => <double>[chroma, secondary, 0.0],
< 120.0 => <double>[secondary, chroma, 0.0],
< 180.0 => <double>[0.0, chroma, secondary],
< 240.0 => <double>[0.0, secondary, chroma],
< 300.0 => <double>[secondary, 0.0, chroma],
_ => <double>[chroma, 0.0, secondary],
final (double red, double green, double blue) = switch (hue) {
< 60.0 => (chroma, secondary, 0.0),
< 120.0 => (secondary, chroma, 0.0),
< 180.0 => (0.0, chroma, secondary),
< 240.0 => (0.0, secondary, chroma),
< 300.0 => (secondary, 0.0, chroma),
_ => (chroma, 0.0, secondary),
};
final [int red, int green, int blue] = <int>[for (final double value in rgb) ((value + match) * 0xFF).round()];
return Color.fromRGBO(red, green, blue, alpha);
return Color.fromARGB((alpha * 0xFF).round(), ((red + match) * 0xFF).round(), ((green + match) * 0xFF).round(), ((blue + match) * 0xFF).round());
}

/// A color represented using [alpha], [hue], [saturation], and [value].
Expand Down