Blurstyle for boxshadow v2 (#88697)
This commit is contained in:
@@ -36,11 +36,17 @@ class BoxShadow extends ui.Shadow {
|
||||
Offset offset = Offset.zero,
|
||||
double blurRadius = 0.0,
|
||||
this.spreadRadius = 0.0,
|
||||
this.blurStyle = BlurStyle.normal,
|
||||
}) : super(color: color, offset: offset, blurRadius: blurRadius);
|
||||
|
||||
/// The amount the box should be inflated prior to applying the blur.
|
||||
final double spreadRadius;
|
||||
|
||||
/// The [BlurStyle] to use for this shadow.
|
||||
///
|
||||
/// Defaults to [BlurStyle.normal].
|
||||
final BlurStyle blurStyle;
|
||||
|
||||
/// Create the [Paint] object that corresponds to this shadow description.
|
||||
///
|
||||
/// The [offset] and [spreadRadius] are not represented in the [Paint] object.
|
||||
@@ -51,7 +57,7 @@ class BoxShadow extends ui.Shadow {
|
||||
Paint toPaint() {
|
||||
final Paint result = Paint()
|
||||
..color = color
|
||||
..maskFilter = MaskFilter.blur(BlurStyle.normal, blurSigma);
|
||||
..maskFilter = MaskFilter.blur(blurStyle, blurSigma);
|
||||
assert(() {
|
||||
if (debugDisableShadows)
|
||||
result.maskFilter = null;
|
||||
@@ -68,6 +74,7 @@ class BoxShadow extends ui.Shadow {
|
||||
offset: offset * factor,
|
||||
blurRadius: blurRadius * factor,
|
||||
spreadRadius: spreadRadius * factor,
|
||||
blurStyle: blurStyle,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -91,6 +98,7 @@ class BoxShadow extends ui.Shadow {
|
||||
offset: Offset.lerp(a.offset, b.offset, t)!,
|
||||
blurRadius: ui.lerpDouble(a.blurRadius, b.blurRadius, t)!,
|
||||
spreadRadius: ui.lerpDouble(a.spreadRadius, b.spreadRadius, t)!,
|
||||
blurStyle: a.blurStyle == BlurStyle.normal ? b.blurStyle : a.blurStyle,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -123,12 +131,13 @@ class BoxShadow extends ui.Shadow {
|
||||
&& other.color == color
|
||||
&& other.offset == offset
|
||||
&& other.blurRadius == blurRadius
|
||||
&& other.spreadRadius == spreadRadius;
|
||||
&& other.spreadRadius == spreadRadius
|
||||
&& other.blurStyle == blurStyle;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => hashValues(color, offset, blurRadius, spreadRadius);
|
||||
int get hashCode => hashValues(color, offset, blurRadius, spreadRadius, blurStyle);
|
||||
|
||||
@override
|
||||
String toString() => 'BoxShadow($color, $offset, ${debugFormatDouble(blurRadius)}, ${debugFormatDouble(spreadRadius)})';
|
||||
String toString() => 'BoxShadow($color, $offset, ${debugFormatDouble(blurRadius)}, ${debugFormatDouble(spreadRadius)}), $blurStyle';
|
||||
}
|
||||
|
||||
@@ -2,10 +2,16 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
tearDown(() {
|
||||
debugDisableShadows = true;
|
||||
});
|
||||
|
||||
test('BorderSide control test', () {
|
||||
const BorderSide side1 = BorderSide();
|
||||
final BorderSide side2 = side1.copyWith(
|
||||
@@ -107,7 +113,298 @@ void main() {
|
||||
expect(shadowList, equals(<BoxShadow>[shadow4, shadow1.scale(0.5)]));
|
||||
});
|
||||
|
||||
test('BoxShadow BlurStyle test', () {
|
||||
const BoxShadow shadow1 = BoxShadow(blurRadius: 4.0);
|
||||
const BoxShadow shadow2 = BoxShadow(blurRadius: 4.0, blurStyle: BlurStyle.outer);
|
||||
final BoxShadow shadow3 = BoxShadow.lerp(shadow1, null, 0.25)!;
|
||||
final BoxShadow shadow4 = BoxShadow.lerp(null, shadow1, 0.25)!;
|
||||
final BoxShadow shadow5 = BoxShadow.lerp(shadow1, shadow2, 0.25)!;
|
||||
final BoxShadow shadow6 = BoxShadow.lerp(const BoxShadow(blurStyle: BlurStyle.solid), shadow2, 0.25)!;
|
||||
|
||||
expect(shadow1.blurStyle, equals(BlurStyle.normal));
|
||||
expect(shadow2.blurStyle, equals(BlurStyle.outer));
|
||||
expect(shadow3.blurStyle, equals(BlurStyle.normal));
|
||||
expect(shadow4.blurStyle, equals(BlurStyle.normal));
|
||||
expect(shadow5.blurStyle, equals(BlurStyle.outer));
|
||||
expect(shadow6.blurStyle, equals(BlurStyle.solid));
|
||||
|
||||
List<BoxShadow> shadowList = BoxShadow.lerpList(<BoxShadow>[shadow2, shadow1], <BoxShadow>[shadow3], 0.5)!;
|
||||
expect(shadowList[0].blurStyle, equals(BlurStyle.outer));
|
||||
expect(shadowList[1].blurStyle, equals(BlurStyle.normal));
|
||||
|
||||
shadowList = BoxShadow.lerpList(<BoxShadow>[shadow6], <BoxShadow>[shadow3, shadow1], 0.5)!;
|
||||
expect(shadowList[0].blurStyle, equals(BlurStyle.solid));
|
||||
expect(shadowList[1].blurStyle, equals(BlurStyle.normal));
|
||||
|
||||
shadowList = BoxShadow.lerpList(<BoxShadow>[shadow3], <BoxShadow>[shadow6, shadow1], 0.5)!;
|
||||
expect(shadowList[0].blurStyle, equals(BlurStyle.solid));
|
||||
expect(shadowList[1].blurStyle, equals(BlurStyle.normal));
|
||||
|
||||
shadowList = BoxShadow.lerpList(<BoxShadow>[shadow3], <BoxShadow>[shadow2, shadow1], 0.5)!;
|
||||
expect(shadowList[0].blurStyle, equals(BlurStyle.outer));
|
||||
expect(shadowList[1].blurStyle, equals(BlurStyle.normal));
|
||||
});
|
||||
|
||||
test('BoxShadow toString test', () {
|
||||
expect(const BoxShadow(blurRadius: 4.0).toString(), equals('BoxShadow(Color(0xff000000), Offset(0.0, 0.0), 4.0, 0.0)'));
|
||||
expect(const BoxShadow(blurRadius: 4.0).toString(), equals('BoxShadow(Color(0xff000000), Offset(0.0, 0.0), 4.0, 0.0), BlurStyle.normal'));
|
||||
expect(const BoxShadow(blurRadius: 4.0, blurStyle: BlurStyle.solid).toString(), equals('BoxShadow(Color(0xff000000), Offset(0.0, 0.0), 4.0, 0.0), BlurStyle.solid'));
|
||||
});
|
||||
|
||||
testWidgets('BoxShadow BoxStyle.solid', (WidgetTester tester) async {
|
||||
final Key key = UniqueKey();
|
||||
debugDisableShadows = false;
|
||||
await tester.pumpWidget(
|
||||
Center(
|
||||
child: RepaintBoundary(
|
||||
key: key,
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: Center(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
boxShadow: <BoxShadow>[BoxShadow(blurRadius: 3.0, blurStyle: BlurStyle.solid)],
|
||||
),
|
||||
width: 10,
|
||||
height: 10,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
find.byKey(key),
|
||||
matchesGoldenFile('boxShadow.boxStyle.solid.0.0.png'),
|
||||
);
|
||||
debugDisableShadows = true;
|
||||
});
|
||||
|
||||
testWidgets('BoxShadow BoxStyle.outer', (WidgetTester tester) async {
|
||||
final Key key = UniqueKey();
|
||||
debugDisableShadows = false;
|
||||
await tester.pumpWidget(
|
||||
Center(
|
||||
child: RepaintBoundary(
|
||||
key: key,
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: Center(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
boxShadow: <BoxShadow>[BoxShadow(blurRadius: 8.0, blurStyle: BlurStyle.outer)],
|
||||
),
|
||||
width: 20,
|
||||
height: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
find.byKey(key),
|
||||
matchesGoldenFile('boxShadow.boxStyle.outer.0.0.png'),
|
||||
);
|
||||
debugDisableShadows = true;
|
||||
});
|
||||
|
||||
testWidgets('BoxShadow BoxStyle.inner', (WidgetTester tester) async {
|
||||
final Key key = UniqueKey();
|
||||
debugDisableShadows = false;
|
||||
await tester.pumpWidget(
|
||||
Center(
|
||||
child: RepaintBoundary(
|
||||
key: key,
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: Center(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
boxShadow: <BoxShadow>[BoxShadow(blurRadius: 4.0, blurStyle: BlurStyle.inner)],
|
||||
),
|
||||
width: 20,
|
||||
height: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
find.byKey(key),
|
||||
matchesGoldenFile('boxShadow.boxStyle.inner.0.0.png'),
|
||||
);
|
||||
debugDisableShadows = true;
|
||||
});
|
||||
|
||||
testWidgets('BoxShadow BoxStyle.normal', (WidgetTester tester) async {
|
||||
final Key key = UniqueKey();
|
||||
debugDisableShadows = false;
|
||||
await tester.pumpWidget(
|
||||
Center(
|
||||
child: RepaintBoundary(
|
||||
key: key,
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: Center(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
boxShadow: <BoxShadow>[BoxShadow(blurRadius: 4.0, blurStyle: BlurStyle.normal)],
|
||||
),
|
||||
width: 20,
|
||||
height: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
find.byKey(key),
|
||||
matchesGoldenFile('boxShadow.boxStyle.normal.0.0.png'),
|
||||
);
|
||||
debugDisableShadows = true;
|
||||
});
|
||||
|
||||
testWidgets('BoxShadow BoxStyle.normal.wide_radius', (WidgetTester tester) async {
|
||||
final Key key = UniqueKey();
|
||||
debugDisableShadows = false;
|
||||
await tester.pumpWidget(
|
||||
Center(
|
||||
child: RepaintBoundary(
|
||||
key: key,
|
||||
child: Container(
|
||||
color: Colors.amber,
|
||||
width: 128,
|
||||
height: 128,
|
||||
child: Center(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black,
|
||||
boxShadow: <BoxShadow>[BoxShadow(blurRadius: 16.0, offset: Offset(4, 4), blurStyle: BlurStyle.normal, color: Colors.green, spreadRadius: 2)],
|
||||
),
|
||||
width: 64,
|
||||
height: 64,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
find.byKey(key),
|
||||
matchesGoldenFile('boxShadow.boxStyle.normal.wide_radius.0.0.png'),
|
||||
);
|
||||
debugDisableShadows = true;
|
||||
});
|
||||
|
||||
testWidgets('BoxShadow BoxStyle.outer.wide_radius', (WidgetTester tester) async {
|
||||
final Key key = UniqueKey();
|
||||
debugDisableShadows = false;
|
||||
await tester.pumpWidget(
|
||||
Center(
|
||||
child: RepaintBoundary(
|
||||
key: key,
|
||||
child: Container(
|
||||
color: Colors.amber,
|
||||
width: 128,
|
||||
height: 128,
|
||||
child: Center(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black,
|
||||
boxShadow: <BoxShadow>[BoxShadow(blurRadius: 16.0, offset: Offset(4, 4), blurStyle: BlurStyle.outer, color: Colors.red, spreadRadius: 2)],
|
||||
),
|
||||
width: 64,
|
||||
height: 64,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await expectLater(
|
||||
find.byKey(key),
|
||||
matchesGoldenFile('boxShadow.boxStyle.outer.wide_radius.0.0.png'),
|
||||
);
|
||||
debugDisableShadows = true;
|
||||
});
|
||||
|
||||
testWidgets('BoxShadow BoxStyle.solid.wide_radius', (WidgetTester tester) async {
|
||||
final Key key = UniqueKey();
|
||||
debugDisableShadows = false;
|
||||
await tester.pumpWidget(
|
||||
Center(
|
||||
child: RepaintBoundary(
|
||||
key: key,
|
||||
child: Container(
|
||||
color: Colors.grey,
|
||||
width: 128,
|
||||
height: 128,
|
||||
child: Center(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black,
|
||||
boxShadow: <BoxShadow>[BoxShadow(blurRadius: 16.0, offset: Offset(4, 4), blurStyle: BlurStyle.solid, color: Colors.purple, spreadRadius: 2)],
|
||||
),
|
||||
width: 64,
|
||||
height: 64,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await expectLater(
|
||||
find.byKey(key),
|
||||
matchesGoldenFile('boxShadow.boxStyle.solid.wide_radius.0.0.png'),
|
||||
);
|
||||
debugDisableShadows = true;
|
||||
});
|
||||
|
||||
testWidgets('BoxShadow BoxStyle.inner.wide_radius', (WidgetTester tester) async {
|
||||
final Key key = UniqueKey();
|
||||
debugDisableShadows = false;
|
||||
await tester.pumpWidget(
|
||||
Center(
|
||||
child: RepaintBoundary(
|
||||
key: key,
|
||||
child: Container(
|
||||
color: Colors.green,
|
||||
width: 128,
|
||||
height: 128,
|
||||
child: Center(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black,
|
||||
boxShadow: <BoxShadow>[BoxShadow(blurRadius: 16.0, offset: Offset(4, 4), blurStyle: BlurStyle.inner, color: Colors.amber, spreadRadius: 2)],
|
||||
),
|
||||
width: 64,
|
||||
height: 64,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await expectLater(
|
||||
find.byKey(key),
|
||||
matchesGoldenFile('boxShadow.boxStyle.inner.wide_radius.0.0.png'),
|
||||
);
|
||||
debugDisableShadows = true;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user