Unverified Commit 96a63cfe authored by nt4f04uNd's avatar nt4f04uNd Committed by GitHub

use FadeTransition instead of Opacity where applicable (#75110)

parent bac1af32
...@@ -758,8 +758,8 @@ class _ContextMenuRoute<T> extends PopupRoute<T> { ...@@ -758,8 +758,8 @@ class _ContextMenuRoute<T> extends PopupRoute<T> {
children: <Widget>[ children: <Widget>[
Positioned.fromRect( Positioned.fromRect(
rect: sheetRect, rect: sheetRect,
child: Opacity( child: FadeTransition(
opacity: _sheetOpacity.value, opacity: _sheetOpacity,
child: Transform.scale( child: Transform.scale(
alignment: getSheetAlignment(_contextMenuLocation), alignment: getSheetAlignment(_contextMenuLocation),
scale: sheetScale, scale: sheetScale,
...@@ -1028,8 +1028,8 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T ...@@ -1028,8 +1028,8 @@ class _ContextMenuRouteStaticState extends State<_ContextMenuRouteStatic> with T
return Transform.scale( return Transform.scale(
alignment: _ContextMenuRoute.getSheetAlignment(widget.contextMenuLocation), alignment: _ContextMenuRoute.getSheetAlignment(widget.contextMenuLocation),
scale: _sheetScaleAnimation.value, scale: _sheetScaleAnimation.value,
child: Opacity( child: FadeTransition(
opacity: _sheetOpacityAnimation.value, opacity: _sheetOpacityAnimation,
child: child, child: child,
), ),
); );
......
...@@ -1211,8 +1211,8 @@ class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin { ...@@ -1211,8 +1211,8 @@ class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Opacity( return FadeTransition(
opacity: _opacityAnimation.value, opacity: _opacityAnimation,
child: Transform( child: Transform(
transform: Matrix4.rotationZ(_orientationOffset + _orientationAnimation.value) transform: Matrix4.rotationZ(_orientationOffset + _orientationAnimation.value)
..setTranslationRaw(0.0, _arrowIconBaselineOffset, 0.0), ..setTranslationRaw(0.0, _arrowIconBaselineOffset, 0.0),
......
...@@ -373,8 +373,8 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta ...@@ -373,8 +373,8 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta
assert(widget.helperText != null); assert(widget.helperText != null);
return Semantics( return Semantics(
container: true, container: true,
child: Opacity( child: FadeTransition(
opacity: 1.0 - _controller.value, opacity: Tween<double>(begin: 1.0, end: 0.0).animate(_controller),
child: Text( child: Text(
widget.helperText!, widget.helperText!,
style: widget.helperStyle, style: widget.helperStyle,
...@@ -391,8 +391,8 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta ...@@ -391,8 +391,8 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta
return Semantics( return Semantics(
container: true, container: true,
liveRegion: true, liveRegion: true,
child: Opacity( child: FadeTransition(
opacity: _controller.value, opacity: _controller,
child: FractionalTranslation( child: FractionalTranslation(
translation: Tween<Offset>( translation: Tween<Offset>(
begin: const Offset(0.0, -0.25), begin: const Offset(0.0, -0.25),
...@@ -441,8 +441,8 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta ...@@ -441,8 +441,8 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta
if (widget.errorText != null) { if (widget.errorText != null) {
return Stack( return Stack(
children: <Widget>[ children: <Widget>[
Opacity( FadeTransition(
opacity: 1.0 - _controller.value, opacity: Tween<double>(begin: 1.0, end: 0.0).animate(_controller),
child: _helper, child: _helper,
), ),
_buildError(), _buildError(),
...@@ -454,8 +454,8 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta ...@@ -454,8 +454,8 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta
return Stack( return Stack(
children: <Widget>[ children: <Widget>[
_buildHelper(), _buildHelper(),
Opacity( FadeTransition(
opacity: _controller.value, opacity: _controller,
child: _error, child: _error,
), ),
], ],
......
...@@ -573,6 +573,7 @@ class _RailDestination extends StatelessWidget { ...@@ -573,6 +573,7 @@ class _RailDestination extends StatelessWidget {
), ),
); );
} else { } else {
final Animation<double> labelFadeAnimation = extendedTransitionAnimation.drive(CurveTween(curve: const Interval(0.0, 0.25)));
content = Padding( content = Padding(
padding: padding ?? EdgeInsets.zero, padding: padding ?? EdgeInsets.zero,
child: ConstrainedBox( child: ConstrainedBox(
...@@ -587,9 +588,9 @@ class _RailDestination extends StatelessWidget { ...@@ -587,9 +588,9 @@ class _RailDestination extends StatelessWidget {
heightFactor: 1.0, heightFactor: 1.0,
widthFactor: extendedTransitionAnimation.value, widthFactor: extendedTransitionAnimation.value,
alignment: AlignmentDirectional.centerStart, alignment: AlignmentDirectional.centerStart,
child: Opacity( child: FadeTransition(
alwaysIncludeSemantics: true, alwaysIncludeSemantics: true,
opacity: _extendedLabelFadeValue(), opacity: labelFadeAnimation,
child: styledLabel, child: styledLabel,
), ),
), ),
...@@ -604,6 +605,8 @@ class _RailDestination extends StatelessWidget { ...@@ -604,6 +605,8 @@ class _RailDestination extends StatelessWidget {
case NavigationRailLabelType.selected: case NavigationRailLabelType.selected:
final double appearingAnimationValue = 1 - _positionAnimation.value; final double appearingAnimationValue = 1 - _positionAnimation.value;
final double verticalPadding = lerpDouble(_verticalDestinationPaddingNoLabel, _verticalDestinationPaddingWithLabel, appearingAnimationValue)!; final double verticalPadding = lerpDouble(_verticalDestinationPaddingNoLabel, _verticalDestinationPaddingWithLabel, appearingAnimationValue)!;
final Interval interval = selected ? const Interval(0.25, 0.75) : const Interval(0.75, 1.0);
final Animation<double> labelFadeAnimation = destinationAnimation.drive(CurveTween(curve: interval));
content = Container( content = Container(
constraints: BoxConstraints( constraints: BoxConstraints(
minWidth: minWidth, minWidth: minWidth,
...@@ -621,9 +624,9 @@ class _RailDestination extends StatelessWidget { ...@@ -621,9 +624,9 @@ class _RailDestination extends StatelessWidget {
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
heightFactor: appearingAnimationValue, heightFactor: appearingAnimationValue,
widthFactor: 1.0, widthFactor: 1.0,
child: Opacity( child: FadeTransition(
alwaysIncludeSemantics: true, alwaysIncludeSemantics: true,
opacity: selected ? _normalLabelFadeInValue() : _normalLabelFadeOutValue(), opacity: labelFadeAnimation,
child: styledLabel, child: styledLabel,
), ),
), ),
...@@ -679,28 +682,6 @@ class _RailDestination extends StatelessWidget { ...@@ -679,28 +682,6 @@ class _RailDestination extends StatelessWidget {
), ),
); );
} }
double _normalLabelFadeInValue() {
if (destinationAnimation.value < 0.25) {
return 0;
} else if (destinationAnimation.value < 0.75) {
return (destinationAnimation.value - 0.25) * 2;
} else {
return 1;
}
}
double _normalLabelFadeOutValue() {
if (destinationAnimation.value > 0.75) {
return (destinationAnimation.value - 0.75) * 4.0;
} else {
return 0;
}
}
double _extendedLabelFadeValue() {
return extendedTransitionAnimation.value < 0.25 ? extendedTransitionAnimation.value * 4.0 : 1.0;
}
} }
/// Defines the behavior of the labels of a [NavigationRail]. /// Defines the behavior of the labels of a [NavigationRail].
......
...@@ -596,8 +596,8 @@ class _PopupMenu<T> extends StatelessWidget { ...@@ -596,8 +596,8 @@ class _PopupMenu<T> extends StatelessWidget {
return AnimatedBuilder( return AnimatedBuilder(
animation: route.animation!, animation: route.animation!,
builder: (BuildContext context, Widget? child) { builder: (BuildContext context, Widget? child) {
return Opacity( return FadeTransition(
opacity: opacity.evaluate(route.animation!), opacity: opacity.animate(route.animation!),
child: Material( child: Material(
shape: route.shape ?? popupMenuTheme.shape, shape: route.shape ?? popupMenuTheme.shape,
color: route.color ?? popupMenuTheme.color, color: route.color ?? popupMenuTheme.color,
......
...@@ -547,8 +547,8 @@ class _HeroFlight { ...@@ -547,8 +547,8 @@ class _HeroFlight {
left: offsets.left, left: offsets.left,
child: IgnorePointer( child: IgnorePointer(
child: RepaintBoundary( child: RepaintBoundary(
child: Opacity( child: FadeTransition(
opacity: _heroOpacity.value, opacity: _heroOpacity,
child: child, child: child,
), ),
), ),
......
...@@ -117,7 +117,7 @@ void checkBackgroundBoxHeight(WidgetTester tester, double height) { ...@@ -117,7 +117,7 @@ void checkBackgroundBoxHeight(WidgetTester tester, double height) {
void checkOpacity(WidgetTester tester, Finder finder, double opacity) { void checkOpacity(WidgetTester tester, Finder finder, double opacity) {
expect( expect(
tester.renderObject<RenderAnimatedOpacity>( tester.firstRenderObject<RenderAnimatedOpacity>(
find.ancestor( find.ancestor(
of: finder, of: finder,
matching: find.byType(FadeTransition), matching: find.byType(FadeTransition),
......
...@@ -2331,14 +2331,23 @@ Finder _opacityAboveLabel(String text) { ...@@ -2331,14 +2331,23 @@ Finder _opacityAboveLabel(String text) {
} }
// Only valid when labelType != all. // Only valid when labelType != all.
double _labelOpacity(WidgetTester tester, String text) { double? _labelOpacity(WidgetTester tester, String text) {
final Opacity opacityWidget = tester.widget<Opacity>( // We search for both Opacity and FadeTransition since in some
find.ancestor( // cases opacity is animated, in other it's not.
final Iterable<Opacity> opacityWidgets = tester.widgetList<Opacity>(find.ancestor(
of: find.text(text), of: find.text(text),
matching: find.byType(Opacity), matching: find.byType(Opacity),
), ));
if (opacityWidgets.isNotEmpty)
return opacityWidgets.single.opacity;
final FadeTransition fadeTransitionWidget = tester.widget<FadeTransition>(
find.ancestor(
of: find.text(text),
matching: find.byType(FadeTransition),
).first, // first because there's also a FadeTransition from the MaterialPageRoute, which is up the tree
); );
return opacityWidget.opacity; return fadeTransitionWidget.opacity.value;
} }
Material _railMaterial(WidgetTester tester) { Material _railMaterial(WidgetTester tester) {
......
...@@ -1182,7 +1182,7 @@ Future<void> main() async { ...@@ -1182,7 +1182,7 @@ Future<void> main() async {
bool isVisible = true; bool isVisible = true;
node.visitAncestorElements((Element ancestor) { node.visitAncestorElements((Element ancestor) {
final RenderObject r = ancestor.renderObject!; final RenderObject r = ancestor.renderObject!;
if (r is RenderOpacity && r.opacity == 0) { if (r is RenderAnimatedOpacity && r.opacity.value == 0) {
isVisible = false; isVisible = false;
return false; return false;
} }
...@@ -2920,12 +2920,12 @@ Future<void> main() async { ...@@ -2920,12 +2920,12 @@ Future<void> main() async {
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>(); final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
final ScrollController controller = ScrollController(); final ScrollController controller = ScrollController();
RenderOpacity? findRenderOpacity() { RenderAnimatedOpacity? findRenderAnimatedOpacity() {
AbstractNode? parent = tester.renderObject(find.byType(Placeholder)); AbstractNode? parent = tester.renderObject(find.byType(Placeholder));
while (parent is RenderObject && parent is! RenderOpacity) { while (parent is RenderObject && parent is! RenderAnimatedOpacity) {
parent = parent.parent; parent = parent.parent;
} }
return parent is RenderOpacity ? parent : null; return parent is RenderAnimatedOpacity ? parent : null;
} }
await tester.pumpWidget( await tester.pumpWidget(
...@@ -2977,14 +2977,14 @@ Future<void> main() async { ...@@ -2977,14 +2977,14 @@ Future<void> main() async {
// Starts Hero animation and scroll animation almost simultaneously. // Starts Hero animation and scroll animation almost simultaneously.
// Scroll to make the Hero invisible. // Scroll to make the Hero invisible.
await tester.pump(); await tester.pump();
expect(findRenderOpacity()?.opacity, anyOf(isNull, 1.0)); expect(findRenderAnimatedOpacity()?.opacity.value, anyOf(isNull, 1.0));
// In this frame the Hero animation finds out the toHero is not paintable, // In this frame the Hero animation finds out the toHero is not paintable,
// and starts fading. // and starts fading.
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 100)); await tester.pump(const Duration(milliseconds: 100));
expect(findRenderOpacity()?.opacity, lessThan(1.0)); expect(findRenderAnimatedOpacity()?.opacity.value, lessThan(1.0));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// The Hero on the new route should be invisible. // The Hero on the new route should be invisible.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment