Prevent Switch from looping on and off (#17821)
This commit is contained in:
parent
6c03a3f96b
commit
41fb069cb7
@ -134,13 +134,20 @@ abstract class RenderToggleable extends RenderConstrainedBox {
|
|||||||
_position
|
_position
|
||||||
..curve = Curves.easeIn
|
..curve = Curves.easeIn
|
||||||
..reverseCurve = Curves.easeOut;
|
..reverseCurve = Curves.easeOut;
|
||||||
switch (_positionController.status) {
|
if (tristate) {
|
||||||
case AnimationStatus.forward:
|
switch (_positionController.status) {
|
||||||
case AnimationStatus.completed:
|
case AnimationStatus.forward:
|
||||||
_positionController.reverse();
|
case AnimationStatus.completed:
|
||||||
break;
|
_positionController.reverse();
|
||||||
default:
|
break;
|
||||||
|
default:
|
||||||
|
_positionController.forward();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (value == true)
|
||||||
_positionController.forward();
|
_positionController.forward();
|
||||||
|
else
|
||||||
|
_positionController.reverse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,8 +264,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
|
|||||||
if (isInteractive && !tristate) {
|
if (isInteractive && !tristate) {
|
||||||
if (status == AnimationStatus.completed && _value == false) {
|
if (status == AnimationStatus.completed && _value == false) {
|
||||||
onChanged(true);
|
onChanged(true);
|
||||||
}
|
} else if (status == AnimationStatus.dismissed && _value != false) {
|
||||||
else if (status == AnimationStatus.dismissed && _value != false) {
|
|
||||||
onChanged(false);
|
onChanged(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,4 +187,45 @@ void main() {
|
|||||||
..circle(color: Colors.red[500])
|
..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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user