Unverified Commit 41fb069c authored by Hans Muller's avatar Hans Muller Committed by GitHub

Prevent Switch from looping on and off (#17821)

parent 6c03a3f9
......@@ -134,13 +134,20 @@ abstract class RenderToggleable extends RenderConstrainedBox {
_position
..curve = Curves.easeIn
..reverseCurve = Curves.easeOut;
switch (_positionController.status) {
case AnimationStatus.forward:
case AnimationStatus.completed:
_positionController.reverse();
break;
default:
if (tristate) {
switch (_positionController.status) {
case AnimationStatus.forward:
case AnimationStatus.completed:
_positionController.reverse();
break;
default:
_positionController.forward();
}
} else {
if (value == true)
_positionController.forward();
else
_positionController.reverse();
}
}
......@@ -257,8 +264,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
if (isInteractive && !tristate) {
if (status == AnimationStatus.completed && _value == false) {
onChanged(true);
}
else if (status == AnimationStatus.dismissed && _value != false) {
} else if (status == AnimationStatus.dismissed && _value != false) {
onChanged(false);
}
}
......
......@@ -187,4 +187,45 @@ void main() {
..circle(color: Colors.red[500])
);
});
testWidgets('Drag ends after animation completes', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/17773
bool value = false;
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return new Material(
child: new Center(
child: new Switch(
value: value,
onChanged: (bool newValue) {
setState(() {
value = newValue;
});
},
),
),
);
},
),
),
);
expect(value, isFalse);
final Rect switchRect = tester.getRect(find.byType(Switch));
final TestGesture gesture = await tester.startGesture(switchRect.centerLeft);
await tester.pump();
await gesture.moveBy(new Offset(switchRect.width, 0.0));
await tester.pump();
await gesture.up();
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
expect(value, isTrue);
expect(tester.hasRunningAnimations, false);
});
}
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