Visitar URL original
Remove more instances of deprecated `withOpacity` by AbdeMohlbi · Pull Request #193559 · flutter/flutter · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/painting/gradient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ class LinearGradient extends Gradient {
return LinearGradient(
begin: begin,
end: end,
colors: <Color>[for (final Color color in colors) color.withOpacity(opacity)],
colors: <Color>[for (final Color color in colors) color.withValues(alpha: opacity)],
stops: stops,
tileMode: tileMode,
transform: transform,
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2299,10 +2299,10 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
Widget barrier;
if (barrierColor != null && barrierColor!.alpha != 0 && !offstage) {
// changedInternalState is called if barrierColor or offstage updates
assert(barrierColor != barrierColor!.withOpacity(0.0));
assert(barrierColor != barrierColor!.withValues(alpha: 0.0));
final Animation<Color?> color = animation!.drive(
ColorTween(
begin: barrierColor!.withOpacity(0.0),
begin: barrierColor!.withValues(alpha: 0.0),
end: barrierColor, // changedInternalState is called if barrierColor updates
).chain(
CurveTween(curve: barrierCurve),
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test/painting/box_painter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ void main() {
final BorderSide side3 = side2.copyWith(style: BorderStyle.none);
BorderSide interpolated = BorderSide.lerp(side2, side3, 0.2);
expect(interpolated.style, equals(BorderStyle.solid));
expect(interpolated.color, equals(side2.color.withOpacity(0.8)));
expect(interpolated.color, equals(side2.color.withValues(alpha: 0.8)));

interpolated = BorderSide.lerp(side3, side2, 0.2);
expect(interpolated.style, equals(BorderStyle.solid));
expect(interpolated.color, equals(side2.color.withOpacity(0.2)));
expect(interpolated.color, equals(side2.color.withValues(alpha: 0.2)));
});

test('BorderSide toString test', () {
Expand Down
19 changes: 14 additions & 5 deletions packages/flutter/test/painting/gradient_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,19 @@ void main() {
end: Alignment.topCenter,
colors: <Color>[Color(0xFFFFFFFF), Color(0xAF777777), Color(0x44444444)],
);

final LinearGradient actual = testGradient.withOpacity(0.5);

expect(
actual,
const LinearGradient(
LinearGradient(
begin: Alignment.bottomRight,
end: Alignment.topCenter,
colors: <Color>[Color(0x80FFFFFF), Color(0x80777777), Color(0x80444444)],
colors: <Color>[
const Color(0xFFFFFFFF).withValues(alpha: 0.5),
const Color(0xAF777777).withValues(alpha: 0.5),
const Color(0x44444444).withValues(alpha: 0.5),
],
),
);
});
Expand All @@ -361,11 +366,15 @@ void main() {

expect(
actual,
const LinearGradient(
LinearGradient(
begin: Alignment.bottomRight,
end: Alignment.topCenter,
colors: <Color>[Color(0x80FFFFFF), Color(0x80777777), Color(0x80444444)],
transform: GradientRotation(1),
colors: <Color>[
const Color(0xFFFFFFFF).withValues(alpha: 0.5),
const Color(0xAF777777).withValues(alpha: 0.5),
const Color(0x44444444).withValues(alpha: 0.5),
],
Comment thread
AbdeMohlbi marked this conversation as resolved.
Resolved
transform: const GradientRotation(1),
),
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/test/widgets/routes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ void main() {

Animation<Color?> modalBarrierAnimation;
modalBarrierAnimation = tester.widget<AnimatedModalBarrier>(animatedModalBarrier).color;
expect(modalBarrierAnimation.value, _white.withOpacity(0));
expect(modalBarrierAnimation.value, _white.withValues(alpha: 0.0));

await tester.pump(const Duration(milliseconds: 25));
modalBarrierAnimation = tester.widget<AnimatedModalBarrier>(animatedModalBarrier).color;
Expand Down
Loading