From 27ac523ea079a42a14a8a3f88a6a0d8ace3dce45 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 19 Mar 2018 17:27:34 -0700 Subject: [PATCH] Provide an initial rotation of the ExpansionIcon if isExpanded = true on initState (#15657) * rotate expansion icon fully if initial state expanded = true * add test case for initially expanded * remove unused import * Update expand_icon_test.dart add linebreak * import dart:math as math --- .../flutter/lib/src/material/expand_icon.dart | 5 +++++ .../flutter/test/material/expand_icon_test.dart | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/flutter/lib/src/material/expand_icon.dart b/packages/flutter/lib/src/material/expand_icon.dart index 3a1b775d44..369636d358 100644 --- a/packages/flutter/lib/src/material/expand_icon.dart +++ b/packages/flutter/lib/src/material/expand_icon.dart @@ -1,6 +1,7 @@ // Copyright 2015 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:math' as math; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; @@ -72,6 +73,10 @@ class _ExpandIconState extends State with SingleTickerProviderStateM curve: Curves.fastOutSlowIn ) ); + // If the widget is initially expanded, rotate the icon without animating it. + if (widget.isExpanded) { + _controller.value = math.pi; + } } @override diff --git a/packages/flutter/test/material/expand_icon_test.dart b/packages/flutter/test/material/expand_icon_test.dart index 94fd279161..5cd3f511af 100644 --- a/packages/flutter/test/material/expand_icon_test.dart +++ b/packages/flutter/test/material/expand_icon_test.dart @@ -67,6 +67,23 @@ void main() { expect(expanded, isFalse); }); + + testWidgets('ExpandIcon is rotated initially if isExpanded is true on first build', (WidgetTester tester) async { + bool expanded = true; + + await tester.pumpWidget( + wrap( + child: new ExpandIcon( + isExpanded: expanded, + onPressed: (bool isExpanded) { + expanded = !isExpanded; + }, + ) + ) + ); + final RotationTransition rotation = tester.firstWidget(find.byType(RotationTransition)); + expect(rotation.turns.value, 0.5); + }); } Widget wrap({ Widget child }) {